/* * parser.mly * Parser for lambda * There should be 8 shift-reduce errors. */ %{ (* This is where ocaml declarations go *) open Node %} /* %token INT */ %token IDENT %token LET EQUAL LAMBDA LPAREN RPAREN DOT EOF SEMI %start program /* the entry point */ %type program %% program: declaration SEMI program { $3 } | expression SEMI program { $1::$3 } | SEMI program { $2 } | EOF { [] }; declaration: LET IDENT EQUAL expression { print_string "Parsed: "; print_exp $4; print_newline(); global_env := ($2,bruijnize $4)::!global_env }; expression: simpexp { $1 } | application { $1 }; simpexp: IDENT { StrVar($1) } /* | INT { Num($1) } */ | LPAREN expression RPAREN { $2 } | abstraction { $1 } abstraction: LAMBDA IDENT DOT expression { Lambda($2,$4) }; application: application simpexp { Apply($1,$2) } | simpexp simpexp { Apply($1,$2) }; %% (* End of parser.mly *)