Module Ast (.ml)


module Ast: sig .. end
Bombs-Must-Detonate: AST Definition & Print function

Bombs-Must-Detonate : AST Types
Author(s): Brian Go, Brian Go



SYNTAX TREE

type field_info =
| VIdUnspecified (*Not yet set by type checkerNot yet set by type checker*)
| VIdStructField of int (*The field is the (int)th field of the structThe field is the (int)th field of the struct*)
| VIdEnumValue of int (*The field is the (int)th value of an enumThe field is the (int)th value of an enum*)
Field info is annotated by the type checker for use in the IR compiler

Field info is annotated by the type checker for use in the IR compiler


type global_expression =
| SynFunctionDeclare of function_declare
| SynRemotableFunctionDeclare of function_declare
| SynTemplatedDeclare of string list * global_expression
| SynFunctionDefine of function_define
| SynTemplatedDefine of string list * global_expression
| SynStructDeclare of struct_declare
| SynGlobalEnumDeclare of enum_declare
| SynGlobalVarDeclare of var_declare
| SynInclude of include_data Pervasives.ref
| SynStateMachine of fsm_state_machine
Top-level expressions

Top-level expressions


type include_data =
| IncludeFileName of string
| IncludeAst of global_expression list
The include string is replaced by an AST so as to only parse it once

The include string is replaced by an AST so as to only parse it once


type expression =
| SynVarDeclare of var_declare
| SynEnumDeclare of enum_declare
| SynVarAssign of var_assign
| SynCond of conditional
| SynLoop of loop
| SynFunctionCall of function_call
| SynReturnStatement of return_statement
| SynBreak (*Produces a type error if not in a loopProduces a type error if not in a loop*)
| SynContinue (*Produces a type error if not in a loopProduces a type error if not in a loop*)
Expressions

Expressions

type function_declare = data_type * string * (data_type * string) list 
Functions

return type, name, arg list

Functions

return type, name, arg list

type function_define = function_declare * expression list 
declaration, body

declaration, body


type function_call =
| SynLocalCall of string * value_producer list * bool Pervasives.ref (*name, args, true if it is a variable-functionname, args, true if it is a variable-function*)
| SynRemoteCall of string * value_producer list * var_ident (*name, args, return value target variablename, args, return value target variable*)
| SynRemoteCallNoResult of string * value_producer list (*name, argsname, args*)

type return_statement =
| SynVoidReturn
| SynValueReturn of value_producer
type struct_declare = string * var_declare list 
Data Structures

name, fields

Data Structures

name, fields

type enum_declare = string * string list 
name, values

name, values


type var_declare =
| SynVarDeclareNoInit of data_type * string (*type, nametype, name*)
| SynVarDeclareWithInit of data_type * string * value_producer (*type, name, initial valuetype, name, initial value*)
Variables

Variables


type var_assign =
| SynVarAssignment of var_ident * value_producer (*var_ident = value_producervar_ident = value_producer*)
| SynVarModify of var_ident * binop * value_producer (*e.g. +=,*=. for cons (::=), the list is on the LHSe.g. +=,*=. for cons (::=), the list is on the LHS*)

type conditional =
| SynIf of value_producer * expression list
| SynIfCase of value_producer * expression list * continued_conditional
Conditionals

Conditionals


type continued_conditional =
| SynFinalElse of expression list
| SynElse of conditional

type loop =
| SynWhile of value_producer * expression list
| SynFor of expression * value_producer * expression * expression list (*init, test, step, body. Note: step expression must end in a semicoloninit, test, step, body. Note: step expression must end in a semicolon*)
| SynDoWhile of expression list * value_producer
Loops

Loops


type value_producer =
| SynValue of value
| SynFunctionCallValue of function_call
| SynVarIdentifier of var_ident
| SynBinop of value_producer * binop * value_producer
| SynPrefixUnop of pre_unop * value_producer
| SynParenthesized of value_producer
| SynArrayValueProducer of value_producer list
| SynListValueProducer of list_value_producer
Value Producers

Value Producers


type value =
| SynIntValue of int
| SynFloatValue of float
| SynStringValue of string
| SynBoolValue of bool

type list_value_producer =
| SynListNil of data_type
| SynListList of value_producer list
| SynListCons of value_producer * value_producer (*car, cdrcar, cdr*)

type var_ident =
| SynVarName of string
| SynStructOrEnumValue of var_ident * string * field_info Pervasives.ref (*field info set by type checker for use by IR compilerfield info set by type checker for use by IR compiler*)
| SynArrayCell of var_ident * value_producer

type data_type =
| SynIntType
| SynFloatType
| SynStringType
| SynBoolType
| SynVoidType
| SynEnumOrStructType of string * data_type list Pervasives.ref (*field types set by type checker for use by IR compilerfield types set by type checker for use by IR compiler*)
| SynArrayType of data_type * value_producer
| SynListType of data_type
| SynRefType of data_type
| SynArrowType of data_type list * data_type (*arg types, return typearg types, return type*)
Data Types

Data Types


type binop =
| SynBinopAnd
| SynBinopOr
| SynBinopAdd
| SynBinopSub
| SynBinopMul
| SynBinopDiv
| SynBinopIDiv
| SynBinopMod
| SynBinopConcat
| SynBinopCons
| SynCompLt
| SynCompGt
| SynCompLte
| SynCompGte
| SynCompEq
| SynCompNeq
Operators

Operators


type pre_unop =
| SynUnopNot
| SynUnopCar
| SynUnopCdr
| SynUnopTrunc
| SynUnopDeref
| SynUnopNeg
| SynUnopNull
type fsm_state_machine = string * string * fsm_state list 
State Machine Syntax

name, onInit handler, state list

State Machine Syntax

name, onInit handler, state list

type fsm_state = string * fsm_callback list * fsm_transition list 
name, callbacks, transitions

name, callbacks, transitions


type fsm_callback =
| SynFsmOnInit of string (*This is not actually a callback but is executed every time the state is visitedThis is not actually a callback but is executed every time the state is visited*)
| SynFsmOnMoveRequest of string
| SynFsmOnTeammateDeath of string
| SynFsmOnBombDetonate of string
| SynFsmOnDeath of string
type fsm_transition = string list * (string * float) list 
type src_program = global_expression list 
val concat : string list -> string
val string_of_global_expression : global_expression -> string
val string_of_arglist : (data_type * string) list -> string
val string_of_datatype : data_type -> string
val string_of_string_list : string list -> string
val string_of_expr_list : expression list -> string
val string_of_var_declare_list : var_declare list -> string
val string_of_var_declare : var_declare -> string
val string_of_include : include_data -> string
val string_of_value_producer : value_producer -> string
val string_of_datatype_list : data_type list -> string
val string_of_expr : expression -> string
val string_of_value : value -> string
val string_of_function_call : function_call -> string
val string_of_variable_identifier : var_ident -> string
val string_of_unop : pre_unop -> string
val string_of_value_producer_list : value_producer list -> string -> string
val string_of_list_value_producer : list_value_producer -> string
val string_of_var_assign : var_assign -> string
val string_of_conditional : conditional -> string
val string_of_continued_conditional : continued_conditional -> string
val string_of_loop : loop -> string
val string_of_return_statement : return_statement -> string
val string_of_binop : binop -> string
Pretty-printable string of a binary operator
val string_of_ast : global_expression list -> string
Pretty-printable string of the AST
val print_ast : global_expression list -> unit
Pretty print the AST