Skip to content

Commit

Permalink
Added annotations for visitor
Browse files Browse the repository at this point in the history
  • Loading branch information
KyrylR committed Oct 25, 2024
1 parent 4322ae9 commit e8627d0
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions grammar/CircomParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -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
;

/*//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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
;

/*//////////////////////////////////////////////////////////////
Expand Down

0 comments on commit e8627d0

Please sign in to comment.