Add parsing of let/in.
This commit is contained in:
parent
c84ff11d0d
commit
a97b50f497
|
@ -125,8 +125,8 @@ struct ast_let : public ast {
|
|||
definition_group definitions;
|
||||
ast_ptr in;
|
||||
|
||||
ast_let(ast_ptr i, definition_group g)
|
||||
: in(std::move(i)), definitions(std::move(g)) {}
|
||||
ast_let(definition_group g, ast_ptr i)
|
||||
: definitions(std::move(g)), in(std::move(i)) {}
|
||||
|
||||
void print(int indent, std::ostream& to) const;
|
||||
void find_free(type_mgr& mgr, type_env_ptr& env, std::set<std::string>& into);
|
||||
|
|
|
@ -22,6 +22,8 @@ extern yy::parser::symbol_type yylex();
|
|||
%token DATA
|
||||
%token CASE
|
||||
%token OF
|
||||
%token LET
|
||||
%token IN
|
||||
%token OCURLY
|
||||
%token CCURLY
|
||||
%token OPAREN
|
||||
|
@ -40,8 +42,9 @@ extern yy::parser::symbol_type yylex();
|
|||
%type <std::vector<branch_ptr>> branches
|
||||
%type <std::vector<constructor_ptr>> constructors
|
||||
%type <std::vector<parsed_type_ptr>> typeList
|
||||
%type <definition_group> definitions
|
||||
%type <parsed_type_ptr> type nonArrowType typeListElement
|
||||
%type <ast_ptr> aAdd aMul case app appBase
|
||||
%type <ast_ptr> aAdd aMul case let app appBase
|
||||
%type <definition_data_ptr> data
|
||||
%type <definition_defn_ptr> defn
|
||||
%type <branch_ptr> branch
|
||||
|
@ -53,17 +56,13 @@ extern yy::parser::symbol_type yylex();
|
|||
%%
|
||||
|
||||
program
|
||||
: definitions { }
|
||||
: definitions { global_defs = std::move($1); }
|
||||
;
|
||||
|
||||
definitions
|
||||
: definitions definition { }
|
||||
| definition { }
|
||||
;
|
||||
|
||||
definition
|
||||
: defn { auto name = $1->name; global_defs.defs_defn[name] = std::move($1); }
|
||||
| data { auto name = $1->name; global_defs.defs_data[name] = std::move($1); }
|
||||
: definitions defn { $$ = std::move($1); auto name = $2->name; $$.defs_defn[name] = std::move($2); }
|
||||
| definitions data { $$ = std::move($1); auto name = $2->name; $$.defs_data[name] = std::move($2); }
|
||||
| %empty { $$ = definition_group(); }
|
||||
;
|
||||
|
||||
defn
|
||||
|
@ -100,6 +99,12 @@ appBase
|
|||
| UID { $$ = ast_ptr(new ast_uid(std::move($1))); }
|
||||
| OPAREN aAdd CPAREN { $$ = std::move($2); }
|
||||
| case { $$ = std::move($1); }
|
||||
| let { $$ = std::move($1); }
|
||||
;
|
||||
|
||||
let
|
||||
: LET OCURLY definitions CCURLY IN OCURLY aAdd CCURLY
|
||||
{ $$ = ast_ptr(new ast_let(std::move($3), std::move($7))); }
|
||||
;
|
||||
|
||||
case
|
||||
|
|
|
@ -22,6 +22,8 @@ defn { return yy::parser::make_DEFN(); }
|
|||
data { return yy::parser::make_DATA(); }
|
||||
case { return yy::parser::make_CASE(); }
|
||||
of { return yy::parser::make_OF(); }
|
||||
let { return yy::parser::make_LET(); }
|
||||
in { return yy::parser::make_IN(); }
|
||||
\{ { return yy::parser::make_OCURLY(); }
|
||||
\} { return yy::parser::make_CCURLY(); }
|
||||
\( { return yy::parser::make_OPAREN(); }
|
||||
|
|
Loading…
Reference in New Issue
Block a user