while
This commit is contained in:
parent
16378e5d48
commit
5f560f079b
5 changed files with 30 additions and 5 deletions
|
|
@ -32,7 +32,7 @@
|
|||
%left KW_OR
|
||||
%left KW_AND
|
||||
%right KW_NOT // unary logical NOT
|
||||
%token KW_DEF KW_IF KW_RETURN KW_FOR KW_IN KW_PASS KW_ELSE KW_ELIF KW_CLASS
|
||||
%token KW_DEF KW_IF KW_RETURN KW_FOR KW_IN KW_PASS KW_ELSE KW_ELIF KW_CLASS KW_WHILE
|
||||
|
||||
%token L_PAREN R_PAREN L_BRACKET R_BRACKET L_BRACE R_BRACE
|
||||
%token DOT COLON SEMICOLON COMMA
|
||||
|
|
@ -94,6 +94,9 @@ stmt:
|
|||
| KW_RETURN expr NEWLINE {
|
||||
$$ = std::make_unique<Return>(std::move($2));
|
||||
}
|
||||
| KW_WHILE expr COLON NEWLINE INDENT stmt_list DEDENT {
|
||||
$$ = std::make_unique<While>(std::move($2), std::move($6));
|
||||
}
|
||||
;
|
||||
|
||||
expr:
|
||||
|
|
@ -102,6 +105,7 @@ expr:
|
|||
| STRING { $$ = std::make_unique<String>($1); }
|
||||
| expr PLUS expr { $$ = std::make_unique<BinOp>( BinaryOperator(BinaryOperator::ADD), std::move($1), std::move($3)); }
|
||||
| expr MULTIPLY expr { $$ = std::make_unique<BinOp>( BinaryOperator(BinaryOperator::MUL), std::move($1), std::move($3)); }
|
||||
| expr MINUS expr { $$ = std::make_unique<BinOp>( BinaryOperator(BinaryOperator::SUB), std::move($1), std::move($3)); }
|
||||
| expr LT expr { $$ = std::make_unique<BinOp>( BinaryOperator(BinaryOperator::LT) , std::move($1), std::move($3)); }
|
||||
| expr KW_AND expr { $$ = std::make_unique<BinOp>( BinaryOperator(BinaryOperator::AND) , std::move($1), std::move($3)); }
|
||||
| expr KW_OR expr { $$ = std::make_unique<BinOp>( BinaryOperator(BinaryOperator::OR) , std::move($1), std::move($3)); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue