Module Prom


module Prom: sig .. end
Interpreter of "prom".

This source is released to the public domain since 2002. No warranty. Citation of the project Structio and the following URL is appreciated. http://structio.sourceforge.net/repasa


val show_warning : bool Pervasives.ref
Indicates if warnings should be shown
val numlines : int Pervasives.ref
Number of line in parsing
val filename : string Pervasives.ref
Name of file that is being parsed

type texpr =
| Tfloat
| Tint
| Tstring
| Tarr_int
| Tarr_float
| Tarr_string
| Tunknown
Type of an expression. The types are a not linear order.
val string_of_texpr : texpr -> string
string_of_texpr t Returns a string with the type of t
val parse_texpr : string -> texpr
parse_texpr s Parses the string s with a simple type
val type_leq : texpr -> texpr -> bool
type_leq t1 t2 decides if t1 is less or equal to t2
val comp_types : texpr -> texpr -> bool
comp_types t1 t2 Decides if the types t1 and t2 are comparable
val max_type : texpr -> texpr -> texpr
max_type t1 t2 Returns the greather of two compatible types
val array_of : texpr -> texpr
array_of s Receives a simple type s and returns the type for arrays of that type
val of_array : texpr -> texpr
array_of a Receives an array type a and returns the type of the elements
val string_of_typval : Decpred1.typval -> string
string_of_typval v pretty prints value v
val typeof_typval : string -> texpr -> Decpred1.typval -> texpr
typeof_typval pos texp v checks type of value v, confirms its compatibility with texp and returns it. In case of error fails and the output message refers to position pos.

type binaryop =
| Add
| Subs
| Mult
| Div
| Mod
Operators, memory representation and expressions

type unaryop =
| Minus (*Memory access*)

type mem =
| Var of string
| Array of string * expr

type expr =
| Mem of mem
| Val of Decpred1.typval
| Size of string
| UnaryOp of unaryop * expr
| BinaryOp of binaryop * expr * expr
val string_of_mem : mem -> string
string_of_mem m pretty prints variable or array m
val typeof_mem : bool ->
string ->
(string, texpr) Hashtbl.t -> texpr -> mem -> texpr
warn indicates if warnings should be printed for variables withouth type
val string_of_unaryop : unaryop -> string
string_of_unaryop u pretty prints unary operator u
val typeof_unaryop : string ->
(string, texpr) Hashtbl.t ->
texpr -> unaryop * expr -> texpr
val string_of_binaryop : binaryop -> string
string_of_binaryop b pretty prints binary operator b
val typeof_binaryop : string ->
(string, texpr) Hashtbl.t ->
texpr -> binaryop * expr * expr -> texpr
val string_of_expr : expr -> string
string_of_expr e Pretty prints expression e
val typeof_expr : string ->
(string, texpr) Hashtbl.t -> texpr -> expr -> texpr
val string_of_bool : bool -> string
val test_typeof_expr : unit -> unit

type binrel =
| Ceq
| Clt
| Ceqlt
| Cgt
| Ceqgt
| Cneq
Condition

type bincond =
| Cand
| Cor

type unarycond =
| Cnot

type cond =
| CondTrue
| CondFalse
| BinaryRel of binrel * expr * expr
| UnaryCond of unarycond * cond
| BinaryCond of bincond * cond * cond
val string_of_binrel : binrel -> string
string_of_binrel b pretty prints binary relation b
val check_type_binrel : string ->
(string, texpr) Hashtbl.t -> binrel * expr * expr -> unit
val string_of_unarycond : unarycond -> string
string_of_unarycond b pretty prints unary boolean operator b
val string_of_bincond : bincond -> string
string_of_unarycond u pretty prints unary boolean operator b
val string_of_cond : cond -> string
string_of_cond c pretty prints condition c
val check_type_cond : string -> (string, texpr) Hashtbl.t -> cond -> unit
val test_check_type_cond : unit -> unit
type position = string 

type stmt =
| Assert of position * cond
| Assign of position * mem * expr
| If of position * cond * stmt list * stmt list
| Message of position * expr list
| Nop
| Return of position * expr
| While of position * cond * stmt list
Statement
val string_of_stmts : int -> int -> stmt list -> string
string_of_stmts ind deltaind s Pretty prints list of statement s, beginning indentation in column ind (normally pass 0), and incrementing it by deltaind in each inner block
val check_type_stmts : texpr -> (string, texpr) Hashtbl.t -> stmt list -> unit
val test_check_type_stmts : unit -> unit

type state_prog = {
   v : (string, Decpred1.typval) Hashtbl.t; (*Variables*)
   a : (string, (int, Decpred1.typval) Hashtbl.t) Hashtbl.t; (*Arrays*)
}
State of a program
val binaryopfloat : string -> binaryop -> float -> float -> float
binaryopfloat binaryop f1 f2 Performs the binary operation binaryop between the flotants f1 and f2
val valexpr : string -> state_prog -> expr -> Decpred1.typval
valexpr pos state e evaluates the expression e thata appears in position pos in the state state
val test_valexpr : unit -> unit
val valcond : string -> state_prog -> cond -> bool
valcond pos state c returns the boolean value of the condition e that appears in position pos, when it is evaluated in state state
val test_valcond : unit -> unit
val cast_val : string -> Decpred1.typval -> Decpred1.typval -> Decpred1.typval
cast_val pos oldval newval Returns the value newval with the type of oldval.
val int_stmts : state_prog -> stmt list -> Decpred1.typval
int_stmts state stmts executes the statements stmts beginning in the given state, modifies the state according to the instructions. It ends normally with Return, returning the value computed.
val test_int_stmts : unit -> unit