commit c01463a300aee951bd8364979b23b9e6ea102f94 from: Omar Polo date: Wed Aug 04 16:44:38 2021 UTC add multiline consts now it's possible to do also things like const ( one = 1 two = 2 ... ) instead of const one = 1 const two = 2 ... commit - afb311959eec920dbda96d86b42aa30ac55f1662 commit + c01463a300aee951bd8364979b23b9e6ea102f94 blob - 9640f09cd4866ccc1202135638947c519d9954bd blob + 1f6f44dd273ab1a61844f7bff72279c7b9e6f5c3 --- np.y +++ np.y @@ -115,6 +115,8 @@ optnl : '\n' optnl /* zero or more newlines */ | /*empty*/ ; +nl : '\n' optnl ; + include : INCLUDE STRING { struct file *nfile; @@ -130,14 +132,21 @@ include : INCLUDE STRING { } ; -const : CONST SYMBOL '=' literal { - if (!global_set($2, $4)) { +const : CONST consti + | CONST '(' optnl mconst optnl ')' + ; + +mconst : consti nl | mconst consti nl ; + +consti : SYMBOL '=' expr { + if (!global_set($1, $3)) { yyerror("constant expression is not a literal"); - free($2); - free_op($4); + free($1); + free_op($3); YYERROR; } -}; + } + ; var : SYMBOL '=' expr { $$ = op_assign($1, $3); } ; varref : SYMBOL { $$ = op_var($1); } ;