Skip to content

Commit

Permalink
Berry update grammar (#19129)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-hadinger authored Jul 16, 2023
1 parent 00249ac commit 410a6b9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/libesp32/berry/tools/grammar/berry.ebnf
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ block = {statement};
(* statement define *)
statement = class_stmt | func_stmt | var_stmt | if_stmt | while_stmt |
for_stmt | break_stmt | return_stmt | expr_stmt | import_stmt |
try_stmt | throw_stmt | ';';
try_stmt | throw_stmt | do_stmt | ';';
if_stmt = 'if' expr block {'elif' expr block} ['else' block] 'end';
while_stmt = 'while' expr block 'end';
do_stmt = 'do' block 'end';
for_stmt = 'for' ID ':' expr block 'end';
break_stmt = 'break' | 'continue';
return_stmt = 'return' [expr];
Expand All @@ -28,17 +29,19 @@ throw_stmt = 'raise' expr [',' expr];
var_stmt = 'var' ID ['=' expr] {',' ID ['=' expr]};
(* expression define *)
expr_stmt = expr [assign_op expr];
expr = suffix_expr | unop expr | expr binop expr | range_expr | cond_expr;
expr = suffix_expr | unop expr | expr binop expr | range_expr | cond_expr | walrus_expr;
cond_expr = expr '?' expr ':' expr; (* conditional expression *)
assign_op = '=' | '+=' | '-=' | '*=' | '/=' |
'%=' | '&=' | '|=' | '^=' | '<<=' | '>>=';
binop = '<' | '<=' | '==' | '!=' | '>' | '>=' | '||' | '&&' |
'<<' | '>>' | '&' | '|' | '^' | '+' | '-' | '*' | '/' | '%';
range_expr = expr '..' [expr]
unop = '-' | '!' | '~';
walrus_expr = expr ':=' expr
suffix_expr = primary_expr {call_expr | ('.' ID) | '[' expr ']'};
primary_expr = '(' expr ')' | simple_expr | list_expr | map_expr | anon_func | lambda_expr;
simple_expr = INTEGER | REAL | STRING | ID | 'true' | 'false' | 'nil';
simple_expr = INTEGER | REAL | STRING | ID | 'true' | 'false' | 'nil' | f_string;
f_string = 'f' STRING
call_expr = '(' [expr {',' expr}] ')';
list_expr = '[' {expr ','} [expr] ']';
map_expr = '{' {expr ':' expr ','} [expr ':' expr] '}';
Expand Down

0 comments on commit 410a6b9

Please sign in to comment.