attribute
This commit is contained in:
parent
f732e16c3a
commit
415dfb6a0e
1 changed files with 9 additions and 3 deletions
12
src/parser.y
12
src/parser.y
|
|
@ -52,9 +52,9 @@
|
|||
%right ASSIGN PLUS_ASSIGN MINUS_ASSIGN MULTIPLY_ASSIGN DIVIDE_ASSIGN MODULO_ASSIGN
|
||||
%right BIT_AND_ASSIGN BIT_OR_ASSIGN BIT_XOR_ASSIGN LSHIFT_ASSIGN RSHIFT_ASSIGN
|
||||
|
||||
// Add types for your grammar rules:
|
||||
%type <std::unique_ptr<Expr>> expr
|
||||
%type <std::unique_ptr<Stmt>> stmt
|
||||
%type <std::vector<std::unique_ptr<Expr>>> args
|
||||
%type <std::vector<std::unique_ptr<Stmt>>> stmt_list
|
||||
|
||||
|
||||
|
|
@ -84,10 +84,16 @@ expr:
|
|||
BinaryOperator(BinaryOperator::MUL),
|
||||
std::move($1), std::move($3)); }
|
||||
| L_PAREN expr R_PAREN {$$ = std::move($2); /* #todo: test for precedence*/}
|
||||
| expr L_PAREN R_PAREN { $$ = std::make_unique<Call>(std::move($1), std::vector<std::unique_ptr<Expr>>());}
|
||||
|
||||
| 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);}
|
||||
;
|
||||
|
||||
args:
|
||||
/* empty */ { $$ = std::vector<std::unique_ptr<Expr>>(); }
|
||||
| expr { $$ = std::vector<std::unique_ptr<Expr>>();
|
||||
$$.push_back(std::move($1)); }
|
||||
| args COMMA expr { $1.push_back(std::move($3)); $$ = std::move($1); }
|
||||
;
|
||||
%%
|
||||
namespace yy {
|
||||
void parser::error(const std::string& msg)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue