From 7a6345e2a4068de676e879e79f8c31965ecd0771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Zrounba?= Date: Thu, 23 Nov 2023 18:26:52 +0000 Subject: Temporarily fix small issue in parser MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change the way unary signs are handled (e.g., "+1e9", "-15"): - instead of lexer, it is not the job of the parser - due to how positional arguments chain together, expressions now need to be grouped using curly brackets in positional arguments list in order to avoid ambiguous netlists (e.g., `wg1 in out 100e-9 +2`) - `-` appearing in net names could also pose issue but I think it's ok now ? Now: - `wg1 in out {2 - 1}` → one positional arg (= 2-1 = 1) - `wg1 in out 2 - 1` → two positional args (2 and -1) - `wg1 in out-abc + 1` → one positional args (1) (output net name: `out-abc`) - `wg1 in out - abc + 1` → one positional args (1) (output net name: `out-abc`) Ultimately this should be revamped in a better way, but the way the parser works, it was the best minimal change fix. It should hold for now. --- src/parser/parser.l | 6 ++++-- src/parser/parser.y | 9 ++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/parser/parser.l b/src/parser/parser.l index 3519d0d..ad86569 100644 --- a/src/parser/parser.l +++ b/src/parser/parser.l @@ -336,13 +336,15 @@ string convert_special_char(char c) return '"'; } -[+-]?{D}+ { +(?# [+-]?{D}+) +{D}+ { /* signed integer number */ yylval_param->i_val = from_string(yytext); return T_INT; } -[+-]?{DOUBLE} { +(?# [+-]?{DOUBLE}+) +{DOUBLE} { /* signed floating point number */ yylval_param->d_val = from_string(yytext); return T_NUM; diff --git a/src/parser/parser.y b/src/parser/parser.y index 855277e..e8602a7 100644 --- a/src/parser/parser.y +++ b/src/parser/parser.y @@ -415,7 +415,7 @@ atomdirective: directive.options { $$ = $1; } ; directive.with_args: - directive.with_args variable + directive.with_args variable.delimited_expr { // cout << "found positional arg: " << $2->get_str() << endl; if (!cur_pt->directives[$1]->kwargs.empty()) @@ -460,7 +460,7 @@ atomelement: element.wg { $$ = $1; } ; element.with_args: - element.with_args variable + element.with_args variable.delimited_expr { // cout << "found positional arg: " << $2->get_str() << endl; if (!cur_pt->elements[$1]->kwargs.empty()) @@ -554,7 +554,7 @@ atomanalysis: analysis.op { $$ = $1; } ; analysis.with_args: - analysis.with_args variable + analysis.with_args variable.delimited_expr { // cout << "found positional arg: " << $2->get_str() << endl; if (!cur_pt->analyses[$1]->kwargs.empty()) @@ -729,6 +729,7 @@ net_name.base.str: } | net_name.base.str '-' T_STR { + // FIXME: this rule is problematic (overlap with -expr) $$ = $1; *$1 += "-" + *$3; delete $3; @@ -881,6 +882,8 @@ constant: variable_base { $$ = $1; } expr: expr '+' term { $$ = $1; *$$ += *$3; delete $3; } | expr '-' term { $$ = $1; *$$ -= *$3; delete $3; } +| '+' term { $$ = $2; } +| '-' term { $$ = $2; *$$ *= -1; } | term { $$ = $1; } ; -- cgit v1.2.3