From 641fd5413f26d7cc90a2c3e8e919c2905780d9cd Mon Sep 17 00:00:00 2001
From: Kyryl Riabov <kyryl.ryabov@gmail.com>
Date: Sun, 11 Aug 2024 18:50:08 +0300
Subject: [PATCH] Fixed bug and added basic operations to lexer

---
 grammar/Circom.g4      |  3 +-
 grammar/LexerCircom.g4 | 99 ++++++++++++++++++++++--------------------
 2 files changed, 54 insertions(+), 48 deletions(-)

diff --git a/grammar/Circom.g4 b/grammar/Circom.g4
index 82eb6f5..876adaf 100644
--- a/grammar/Circom.g4
+++ b/grammar/Circom.g4
@@ -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) ';'
diff --git a/grammar/LexerCircom.g4 b/grammar/LexerCircom.g4
index 1ef4a22..466c52c 100644
--- a/grammar/LexerCircom.g4
+++ b/grammar/LexerCircom.g4
@@ -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' ;
@@ -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_$] ;