snoeathurc.h
This commit is contained in:
@ -46,9 +46,19 @@ let parse_error_rich =
|
||||
%token <Position> FUN FN COMMA SEMICOLON READ WRITE
|
||||
%token <Position> LPAR RPAR LBRACKET RBRACKET LCURLY RCURLY
|
||||
|
||||
%token <Position> TIMES DIVIDE NUMNEG
|
||||
%token <Position> NOT AND OR
|
||||
%token <bool * Position> BOOLVAL
|
||||
|
||||
%token <Position> FILTER SCAN REPLICATE
|
||||
|
||||
%nonassoc ifprec letprec
|
||||
%left AND OR
|
||||
%nonassoc NOT
|
||||
%left DEQ LTH
|
||||
%left PLUS MINUS
|
||||
%left TIMES DIVIDE
|
||||
%nonassoc NUMNEG
|
||||
|
||||
%start Prog
|
||||
%type <AbSyn.UntypedProg> Prog
|
||||
@ -59,6 +69,7 @@ let parse_error_rich =
|
||||
%type <AbSyn.UntypedExp list> Exps
|
||||
%type <AbSyn.UntypedFunArg> FunArg
|
||||
// TODO: Task 1(b): add any new nonterminals here
|
||||
%type <AbSyn.UntypedExp> MultiLet
|
||||
|
||||
%%
|
||||
|
||||
@ -127,12 +138,31 @@ Exp : NUM { Constant (IntVal (fst $1), snd $1) }
|
||||
{ Reduce ($3, $5, $7, (), $1) }
|
||||
| REDUCE LPAR OP BinOp COMMA Exp COMMA Exp RPAR
|
||||
{ Reduce ($4, $6, $8, (), $1) }
|
||||
| REPLICATE LPAR Exp COMMA Exp RPAR
|
||||
{ Replicate ($3, $5, (), $1) }
|
||||
| FILTER LPAR FunArg COMMA Exp RPAR
|
||||
{ Filter ($3, $5, (), $1) }
|
||||
| SCAN LPAR FunArg COMMA Exp COMMA Exp RPAR
|
||||
{ Scan ($3, $5, $7, (), $1) }
|
||||
| LPAR Exp RPAR { $2 }
|
||||
// TODO: task 1(b): replace this with a more general production
|
||||
| LET ID EQ Exp IN Exp %prec letprec
|
||||
{ Let (Dec (fst $2, $4, $3), $6, $1) }
|
||||
| LET ID EQ Exp MultiLet %prec letprec
|
||||
{ Let (Dec (fst $2, $4, $3), $5, $1) }
|
||||
| ID LBRACKET Exp RBRACKET
|
||||
{ Index (fst $1, $3, (), $2) }
|
||||
|
||||
| Exp TIMES Exp { Times ($1, $3, $2) }
|
||||
| Exp DIVIDE Exp { Divide ($1, $3, $2) }
|
||||
| NUMNEG Exp { Negate ($2, $1) }
|
||||
|
||||
| Exp AND Exp { And ($1, $3, $2) }
|
||||
| Exp OR Exp { Or ($1, $3, $2) }
|
||||
| NOT Exp { Not ($2, $1) }
|
||||
| BOOLVAL { Constant (BoolVal (fst $1), snd $1) }
|
||||
;
|
||||
|
||||
MultiLet : IN Exp { $2 }
|
||||
| SEMICOLON ID EQ Exp MultiLet
|
||||
{ Let (Dec (fst $2, $4, $3), $5, $1) }
|
||||
;
|
||||
|
||||
Exps : Exp COMMA Exps { $1 :: $3 }
|
||||
|
Reference in New Issue
Block a user