fuck me
This commit is contained in:
parent
16cac369ee
commit
47c455a73c
1 changed files with 11 additions and 0 deletions
11
src/parser.y
11
src/parser.y
|
|
@ -56,6 +56,7 @@
|
|||
%type <std::unique_ptr<Stmt>> stmt
|
||||
%type <std::vector<std::unique_ptr<Expr>>> args
|
||||
%type <std::vector<std::unique_ptr<Stmt>>> stmt_list
|
||||
%type <std::vector<std::string>> params
|
||||
|
||||
|
||||
%%
|
||||
|
|
@ -80,6 +81,10 @@ stmt:
|
|||
| KW_FOR IDENTIFIER KW_IN expr COLON NEWLINE INDENT stmt_list DEDENT {
|
||||
$$ = std::make_unique<For> ($2, std::move($4), std::move($8));
|
||||
}
|
||||
| KW_DEF IDENTIFIER L_PAREN params R_PAREN COLON NEWLINE INDENT stmt_list DEDENT {
|
||||
$$ = std::make_unique<FunctionDef>($2, std::move($4), std::move($9));
|
||||
}
|
||||
| KW_RETURN expr NEWLINE { $$ = std::make_unique<Return>(std::move($2));}
|
||||
;
|
||||
|
||||
expr:
|
||||
|
|
@ -95,6 +100,7 @@ expr:
|
|||
| L_PAREN expr R_PAREN {$$ = std::move($2); /* #todo: test for precedence*/}
|
||||
| expr L_PAREN args R_PAREN { $$ = std::make_unique<Call>(std::move($1), std::move($3));}
|
||||
| expr DOT IDENTIFIER { $$ = std::make_unique<Attribute>(std::move($1), $3);}
|
||||
| L_BRACKET args R_BRACKET { $$ = std::make_unique<List>(std::move($2));}
|
||||
;
|
||||
|
||||
args:
|
||||
|
|
@ -103,6 +109,11 @@ args:
|
|||
$$.push_back(std::move($1)); }
|
||||
| args COMMA expr { $1.push_back(std::move($3)); $$ = std::move($1); }
|
||||
;
|
||||
|
||||
params:
|
||||
{ $$ = std::vector<std::string>();}
|
||||
| IDENTIFIER { $$ = std::vector<std::string>(); $$.push_back($1); }
|
||||
| params COMMA IDENTIFIER {$1.push_back($3); $$ = std::move($1);}
|
||||
%%
|
||||
namespace yy {
|
||||
void parser::error(const std::string& msg)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue