Download Home Construction Modeling Language (HCML) Final Project Report
Transcript
%token <string> IDENT
%token EOF
%nonassoc NOELSE
%nonassoc ELSE
%right ASSIGN
%left EQ NEQ
%left LT GT LEQ GEQ OR AND
%left IPLUS IMINUS FPLUS FMINUS
%left ITIMES IDIVIDE FTIMES FDIVIDE
%nonassoc UMINUS
%start program
%type <Ast.program> program
%%
/* rules */
program:
/* nothing */
{ [], [] }
| program vdecl
{ ($2 :: fst $1), snd $1 }
| program fdecl
{ fst $1, ($2 :: snd $1) }
fdecl:
vtype_list IDENT LEFTPR formals_opt RGHTPR LEFTBR vdecl_list stmt_list RGHTBR
{ { ftype = $1;
fname = $2;
formals = $4;
locals = List.rev $7;
body = List.rev $8 } }
vtype_list:
/* nothing */
| vtype_list fdecl
formals_opt:
{ [] }
{ $2 :: $1 }