Enable more syntax.
This commit is contained in:
parent
f00a6a7783
commit
579c7bad92
|
@ -18,6 +18,7 @@ using yyscan_t = void*;
|
|||
}
|
||||
|
||||
%token BACKSLASH
|
||||
%token BACKTICK
|
||||
%token PLUS
|
||||
%token TIMES
|
||||
%token MINUS
|
||||
|
@ -52,9 +53,10 @@ using yyscan_t = void*;
|
|||
%type <std::vector<branch_ptr>> branches
|
||||
%type <std::vector<constructor_ptr>> constructors
|
||||
%type <std::vector<parsed_type_ptr>> typeList
|
||||
%type <binop> anyBinop
|
||||
%type <definition_group> definitions
|
||||
%type <parsed_type_ptr> type nonArrowType typeListElement
|
||||
%type <ast_ptr> aEq aAdd aMul case let lambda app appBase
|
||||
%type <ast_ptr> aInfix aEq aAdd aMul case let lambda app appBase
|
||||
%type <definition_data_ptr> data
|
||||
%type <definition_defn_ptr> defn
|
||||
%type <branch_ptr> branch
|
||||
|
@ -76,7 +78,7 @@ definitions
|
|||
;
|
||||
|
||||
defn
|
||||
: DEFN LID lowercaseParams EQUAL OCURLY aEq CCURLY
|
||||
: DEFN LID lowercaseParams EQUAL OCURLY aInfix CCURLY
|
||||
{ $$ = definition_defn_ptr(
|
||||
new definition_defn(std::move($2), std::move($3), std::move($6), @$)); }
|
||||
;
|
||||
|
@ -86,6 +88,16 @@ lowercaseParams
|
|||
| lowercaseParams LID { $$ = std::move($1); $$.push_back(std::move($2)); }
|
||||
;
|
||||
|
||||
aInfix
|
||||
: aInfix BACKTICK LID BACKTICK aEq
|
||||
{ $$ = ast_ptr(new ast_app(
|
||||
ast_ptr(new ast_app(ast_ptr(new ast_lid(std::move($3))), std::move($1))), std::move($5))); }
|
||||
| aInfix BACKTICK UID BACKTICK aEq
|
||||
{ $$ = ast_ptr(new ast_app(
|
||||
ast_ptr(new ast_app(ast_ptr(new ast_uid(std::move($3))), std::move($1))), std::move($5))); }
|
||||
| aEq { $$ = std::move($1); }
|
||||
;
|
||||
|
||||
aEq
|
||||
: aAdd EQUALS aAdd { $$ = ast_ptr(new ast_binop(EQUALS, std::move($1), std::move($3), @$)); }
|
||||
| aAdd LESS_EQUALS aAdd { $$ = ast_ptr(new ast_binop(LESS_EQUALS, std::move($1), std::move($3), @$)); }
|
||||
|
@ -114,24 +126,35 @@ appBase
|
|||
: INT { $$ = ast_ptr(new ast_int($1, @$)); }
|
||||
| LID { $$ = ast_ptr(new ast_lid(std::move($1), @$)); }
|
||||
| UID { $$ = ast_ptr(new ast_uid(std::move($1), @$)); }
|
||||
| OPAREN aEq CPAREN { $$ = std::move($2); }
|
||||
| OPAREN aInfix CPAREN { $$ = std::move($2); }
|
||||
| OPAREN anyBinop CPAREN { $$ = ast_ptr(new ast_lid(op_name($2))); }
|
||||
| case { $$ = std::move($1); }
|
||||
| let { $$ = std::move($1); }
|
||||
| lambda { $$ = std::move($1); }
|
||||
;
|
||||
|
||||
anyBinop
|
||||
: PLUS { $$ = PLUS; }
|
||||
| MINUS { $$ = MINUS; }
|
||||
| TIMES { $$ = TIMES; }
|
||||
| DIVIDE { $$ = DIVIDE; }
|
||||
| MODULO { $$ = MODULO; }
|
||||
| EQUALS { $$ = EQUALS; }
|
||||
| LESS_EQUALS { $$ = LESS_EQUALS; }
|
||||
;
|
||||
|
||||
let
|
||||
: LET OCURLY definitions CCURLY IN OCURLY aAdd CCURLY
|
||||
: LET OCURLY definitions CCURLY IN OCURLY aInfix CCURLY
|
||||
{ $$ = ast_ptr(new ast_let(std::move($3), std::move($7), @$)); }
|
||||
;
|
||||
|
||||
lambda
|
||||
: BACKSLASH lowercaseParams ARROW OCURLY aAdd CCURLY
|
||||
: BACKSLASH lowercaseParams ARROW OCURLY aInfix CCURLY
|
||||
{ $$ = ast_ptr(new ast_lambda(std::move($2), std::move($5), @$)); }
|
||||
;
|
||||
|
||||
case
|
||||
: CASE aAdd OF OCURLY branches CCURLY
|
||||
: CASE aInfix OF OCURLY branches CCURLY
|
||||
{ $$ = ast_ptr(new ast_case(std::move($2), std::move($5), @$)); }
|
||||
;
|
||||
|
||||
|
@ -141,7 +164,7 @@ branches
|
|||
;
|
||||
|
||||
branch
|
||||
: pattern ARROW OCURLY aAdd CCURLY
|
||||
: pattern ARROW OCURLY aInfix CCURLY
|
||||
{ $$ = branch_ptr(new branch(std::move($1), std::move($4))); }
|
||||
;
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
% { return yy::parser::make_MODULO(drv.location); }
|
||||
== { return yy::parser::make_EQUALS(drv.location); }
|
||||
\<= { return yy::parser::make_LESS_EQUALS(drv.location); }
|
||||
` { return yy::parser::make_BACKTICK(drv.location); }
|
||||
[0-9]+ { return yy::parser::make_INT(atoi(yytext), drv.location); }
|
||||
defn { return yy::parser::make_DEFN(drv.location); }
|
||||
data { return yy::parser::make_DATA(drv.location); }
|
||||
|
|
Loading…
Reference in New Issue
Block a user