From e8627d04c0ae4446deaa3cbde8d093110ffc5fbc Mon Sep 17 00:00:00 2001 From: Kyryl R Date: Fri, 25 Oct 2024 23:38:38 +0300 Subject: [PATCH] Added annotations for visitor --- grammar/CircomParser.g4 | 60 ++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/grammar/CircomParser.g4 b/grammar/CircomParser.g4 index 3601649..0321439 100644 --- a/grammar/CircomParser.g4 +++ b/grammar/CircomParser.g4 @@ -104,30 +104,34 @@ statments ; ifStatments - : 'if' '(' cond=expression ')' ifStatments - | 'if' '(' cond=expression ')' regularStatmetns - | 'if' '(' cond=expression ')' regularStatmetns 'else' ifStatments - | 'if' '(' cond=expression ')' regularStatmetns 'else' regularStatmetns + : 'if' '(' cond=expression ')' ifStatments #IfWithFollowUpIf + | 'if' '(' cond=expression ')' regularStatmetns #IfRegular + | 'if' '(' cond=expression ')' regularStatmetns 'else' ifStatments #IfRegularElseWithFollowUpIf + | 'if' '(' cond=expression ')' regularStatmetns 'else' regularStatmetns #IfRegularElseRegular ; regularStatmetns - : body - | expression ';' - | substitutions ';' - | lhs=expression '===' rhs=expression ';' - | 'for' '(' declarations ';' cond=expression ';' step=substitutions ')' forBody=regularStatmetns - | 'for' '(' substitutions ';' cond=expression ';' step=substitutions ')' forBody=regularStatmetns - | 'while' '(' cond=expression ')' stmt=regularStatmetns - | 'return' value=expression ';' + : body #RStatmentBody + | expression ';' #RStatmentExpression + | substitutions ';' #RStatmentSucstitutions + | cycleStatments #RStatmentCycles + | lhs=expression '===' rhs=expression ';' #RStatmentEqConstraint + | 'return' value=expression ';' #RStatmentReturn + ; + +cycleStatments + : 'for' '(' declarations ';' cond=expression ';' step=substitutions ')' forBody=regularStatmetns #CycleForWithDeclaration + | 'for' '(' substitutions ';' cond=expression ';' step=substitutions ')' forBody=regularStatmetns #CycleForWithoutDeclaration + | 'while' '(' cond=expression ')' stmt=regularStatmetns #CycleWhile ; substitutions - : lhs=expression op=(ASSIGNMENT | LEFT_ASSIGNMENT | LEFT_CONSTRAINT) rhs=expression - | lhs=expression op='-->' variable=expression - | lhs=expression op='==>' variable=expression - | identifierStatment op=ASSIGNMENT_WITH_OP rhs=expression - | identifierStatment SELF_OP - | SELF_OP identifierStatment + : lhs=expression op=(ASSIGNMENT | LEFT_ASSIGNMENT | LEFT_CONSTRAINT) rhs=expression #SubsLeftAssignmet + | lhs=expression op='-->' variable=expression #SubsRightSimpleAssignmet + | lhs=expression op='==>' variable=expression #SubsRightConstrAssignmet + | identifierStatment op=ASSIGNMENT_WITH_OP rhs=expression #SubsAssignmetWithOperation + | identifierStatment SELF_OP #SubsIcnDecOperation + | SELF_OP identifierStatment #SubsInvalidOperation ; /*////////////////////////////////////////////////////////////// @@ -160,19 +164,19 @@ expression // Literal, parentheses, function call, array inline, anonymous component call primaryExpression - : identifierStatment - | '_' - | NUMBER - | '(' expressionList ')' - | '[' expressionList ']' - | ID '(' expressionList? ')' - | ID '(' expressionList? ')' '(' (expressionList | expressionListWithNames)? ')' + : identifierStatment #PIdentifierStatment + | '_' #PUnderscore + | NUMBER #PNumber + | '(' expressionList ')' #PParentheses + | '[' expressionList ']' #PArray + | ID '(' expressionList? ')' #PCall + | ID '(' expressionList? ')' '(' (expressionList | expressionListWithNames)? ')' #PAnonymousCall ; assignmentExpression - : '<==' rhs=expression - | '<--' rhs=expression - | '=' rhs=expression + : '<==' rhs=expression #AssignExprConstraint + | '<--' rhs=expression #AssignExprSimple + | '=' rhs=expression #AssignExprRegular ; /*//////////////////////////////////////////////////////////////