From 7dd139671b4ee276d9273c1bcf2026cf7a2b22cd Mon Sep 17 00:00:00 2001 From: olivame Date: Mon, 23 Mar 2026 20:35:47 +0800 Subject: [PATCH] fix(frontend): tighten grammar to match sysy2022 --- src/antlr4/SysY.g4 | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/antlr4/SysY.g4 b/src/antlr4/SysY.g4 index 5f6b0c8..3af810a 100644 --- a/src/antlr4/SysY.g4 +++ b/src/antlr4/SysY.g4 @@ -83,7 +83,7 @@ fragment BINARY_EXPONENT: [pP] [+-]? DEC_DIGIT+; /*===-------------------------------------------===*/ compUnit - : topLevelItem* EOF + : topLevelItem (topLevelItem)* EOF ; topLevelItem @@ -206,13 +206,12 @@ floatConst unaryExp : primaryExp | ID LPAREN funcRParams? RPAREN - | unaryOp unaryExp + | addUnaryOp unaryExp ; -unaryOp +addUnaryOp : ADD | SUB - | NOT ; funcRParams @@ -247,8 +246,8 @@ eqExp ; lAndExp - : eqExp - | lAndExp AND eqExp + : condUnaryExp + | lAndExp AND condUnaryExp ; lOrExp @@ -256,6 +255,11 @@ lOrExp | lOrExp OR lAndExp ; +condUnaryExp + : eqExp + | NOT condUnaryExp + ; + constExp : addExp ;