Skip to content

Commit

Permalink
Fixed bug and added basic operations to lexer
Browse files Browse the repository at this point in the history
  • Loading branch information
KyrylR committed Aug 11, 2024
1 parent 99e313a commit 641fd54
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 48 deletions.
3 changes: 2 additions & 1 deletion grammar/Circom.g4
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ templateStmt
| signalDeclaration ';'
| componentDeclaration ';'
| blockInstantiation ';'
| identifier (ASSIGNMENT | CONSTRAINT_EQ) expression ';'
| (identifier ('.' ID)?) ASSIGNMENT expression ';'
| expression CONSTRAINT_EQ expression ';'
| (primary | (identifier '.' identifier)) (LEFT_ASSIGNMENT | ASSIGNMENT_OP) expression ';'
| expression RIGHT_ASSIGNMENT primary ';'
| '_' (ASSIGNMENT | LEFT_ASSIGNMENT) (expression | blockInstantiation) ';'
Expand Down
99 changes: 52 additions & 47 deletions grammar/LexerCircom.g4
Original file line number Diff line number Diff line change
@@ -1,78 +1,54 @@
lexer grammar LexerCircom;

VERSION
: NUMBER '.' NUMBER '.' NUMBER
;
VERSION: NUMBER '.' NUMBER '.' NUMBER ;

PACKAGE_NAME: STRING ;

SIGNAL_TYPE: INPUT | OUTPUT ;

SIGNAL
: 'signal' ;
SIGNAL: 'signal' ;

INPUT
: 'input' ;
INPUT: 'input' ;

OUTPUT
: 'output' ;
OUTPUT: 'output' ;

PUBLIC
: 'public' ;
PUBLIC: 'public' ;

TEMPLATE
: 'template' ;
TEMPLATE: 'template' ;

COMPONENT
: 'component' ;
COMPONENT: 'component' ;

VAR
: 'var' ;
VAR: 'var' ;

FUNCTION
: 'function' ;
FUNCTION: 'function' ;

RETURN
: 'return' ;
RETURN: 'return' ;

IF
: 'if' ;
IF: 'if' ;

ELSE
: 'else' ;
ELSE: 'else' ;

FOR
: 'for' ;
FOR: 'for' ;

WHILE
: 'while' ;
WHILE: 'while' ;

DO
: 'do' ;
DO: 'do' ;

LOG
: 'log' ;
LOG: 'log' ;

ASSERT
: 'assert' ;
ASSERT: 'assert' ;

INCLUDE
: 'include' ;
INCLUDE: 'include' ;

CUSTOM
: 'custom' ;
CUSTOM: 'custom' ;

PRAGMA
: 'pragma' ;
PRAGMA: 'pragma' ;

CIRCOM
: 'circom' ;
CIRCOM: 'circom' ;

CUSTOM_TEMPLATES
: 'custom_templates' ;
CUSTOM_TEMPLATES: 'custom_templates' ;

MAIN
: 'main' ;
MAIN: 'main' ;

PARALLEL
: 'parallel' ;
Expand Down Expand Up @@ -102,6 +78,35 @@ RIGHT_ASSIGNMENT: '-->' | '==>' ;

CONSTRAINT_EQ: '===' ;

NOT: '!' ;
BNOT: '~' ;

POW: '**' ;

MUL: '*' ;
DIV: '/' ;
QUO: '\\' ;
MOD: '%' ;

ADD: '+' ;
SUB: '-' ;

SHL: '<<' ;
SHR: '>>' ;

BAND: '&' ;
BXOR: '^' ;
BOR: '|' ;

EQ: '==' ;
NE: '!=' ;
GT: '>' ;
LT: '<' ;
LE: '>=' ;
GE: '<=' ;
AND: '&&' ;
OR: '||' ;

ID : LETTER (LETTER|DIGIT)*;
fragment
LETTER : [a-zA-Z\u0080-\u00FF_$] ;
Expand Down

0 comments on commit 641fd54

Please sign in to comment.