module Pascal_ast: sig end
Abstract syntax tree with a Pascal looking-like structure.
Author(s): Samuel Mimram, Julien Cristau
exception Parse_error of (string * (int * int))
A parsing error occured. The arguments are the column and line numbers.
type
pascal_type =
Types of values.
type
nature =
| |
Varb |
| |
Cst |
| |
Fun |
| |
Unknown_nature |
type
variable = {
|
var_name : string ; |
|
mutable var_type : pascal_type ; |
|
mutable var_def : definition option ; |
|
mutable var_nature : nature ; |
|
var_pos : int * int ; |
}
A reference to an identifier. var_by_name
is only meaningful for procedures' and functions' arguments (yet) and should be set to false
else.
type
expression = {
}
A typed expression.
type
expr =
An expression.
type
stt =
A statement.
type
statement = {
}
type
environment = (string * definition) list
type
block = {
}
A block (i.e. a list of statements in an environment).
type
procedure = definition list * block
A procedure (arguments, code).
type
value =
What an identifier can be.
type
asm_value =
Definition in the assembly side.
type
definition = {
|
def_name : string ; |
|
mutable def_type : pascal_type ; |
|
def_nature : nature ; |
|
mutable def_value : value ; |
|
def_pos : int * int ; |
|
mutable def_coord : int list ; |
|
mutable def_used : bool ; |
|
mutable def_asm : asm_value ; |
}
An identifier definition.
exception Already_defined
A variable is being redefined.
val create_environment : unit -> environment
Create a new empty environment.
val fold_env : (string -> definition -> 'a -> 'a) ->
'a -> environment -> 'a
Fold a function throughout an environment.
val iter_env : (string -> definition -> unit) -> environment -> unit
Iter a function on all elements of an environment.
val env_of_def_list : definition list -> (string * definition) list
val add_def : environment ->
string -> definition -> (string * definition) list
Add a definition to an environment.
Raises Already_defined
if a previous definition was already made with the same name.
val get_def : environment -> string -> definition
Get a the value associated to a name in an environment. Remark: don't forget that procedures and functions are binders and should therefore be added to the current environment.
Raises Not_found
if no definition was made for that name.
val concat_env : bool ->
(string * definition) list ->
environment -> environment
Concatenate two environments. The first argument determines whereas the function should check for duplicate definitions or not.
val string_of_type : pascal_type -> string
type
program = string * block
A program.
val check_block : block -> environment list -> unit
Do several checks on a block:
- check that called variables
- check data types
Raises Parse_error
if an error was detected.
val check : 'a * block -> unit
Check that the program is syntaxically and lexically correct.
val pretty_print : string * block -> string
Get a nice human-readable representation of the AST.
exception Asm_error of string
An error occured during the pascal-to-asm conversion.
val eval_expr_int : expression -> int
Compute the value of a constant integer expression.
val eval_expr_bool : expression -> bool
val eval_expr : expression -> Asm_ast.value
val sizeof : pascal_type -> int
Get the size needed by a type (in bytes).
val regc : int Pervasives.ref
val fresh_reg : unit -> int
val asm_of_proc : string ->
procedure ->
int list -> Asm_ast.procedure list * Asm_ast.procedure
Get an asm-like AST corresponding to a pascal-like AST.
Returns a list of procedures incidently defined and the Asm_ast.procedure
corresponding to the procedure.
val asm_of_prog : 'a * block -> Asm_ast.procedure list * Asm_ast.procedure