diff --git a/TP02/ariteval/tests/hello02.txt b/TP02/ariteval/tests/hello02.txt new file mode 100644 index 0000000..62cfe6d --- /dev/null +++ b/TP02/ariteval/tests/hello02.txt @@ -0,0 +1 @@ +(2*4+3)+(4+3*2) diff --git a/TP02/demo_files/exo6/Exercice6.g4 b/TP02/demo_files/exo6/Exercice6.g4 new file mode 100644 index 0000000..bc3cf4e --- /dev/null +++ b/TP02/demo_files/exo6/Exercice6.g4 @@ -0,0 +1,18 @@ +//define a lexical analyser called Exercice6 + +grammar Exercice6; + +full_expr: expr ';' EOF ; + +expr: + | LBRA expr RBRA expr + | LPAR expr RPAR expr + | + ; + +LPAR: '(' ; +RPAR: ')' ; +LBRA: '[' ; +RBRA: ']' ; +CHARS: ~[()[\]] -> skip; +WS: [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines diff --git a/TP02/demo_files/exo6/Makefile b/TP02/demo_files/exo6/Makefile new file mode 100644 index 0000000..685ef14 --- /dev/null +++ b/TP02/demo_files/exo6/Makefile @@ -0,0 +1,17 @@ +MAINFILE = main +PACKAGE = Exercice6 + +ifndef ANTLR4 +$(error variable ANTLR4 is not set) +endif + +default: $(PACKAGE).py + +$(PACKAGE).py: $(PACKAGE).g4 + $(ANTLR4) $^ -Dlanguage=Python3 + +run: $(MAINFILE).py $(PACKAGE)*.py + python3 $< + +clean: + rm -rf *~ $(PACKAGE)*.py $(PACKAGE)*.pyc *.interp *.tokens __pycache* diff --git a/TP02/demo_files/exo6/main.py b/TP02/demo_files/exo6/main.py new file mode 100644 index 0000000..dc0d5d2 --- /dev/null +++ b/TP02/demo_files/exo6/main.py @@ -0,0 +1,22 @@ +from antlr4 import InputStream +from antlr4 import CommonTokenStream + +# include to use the generated lexer and parser +from Exercice6Lexer import Exercice6Lexer +from Exercice6Parser import Exercice6Parser + +import sys + + +def main(): + input_stream = InputStream(sys.stdin.read()) + lexer = Exercice6Lexer(input_stream) + stream = CommonTokenStream(lexer) + parser = Exercice6Parser(stream) + parser.full_expr() # We want to recognize full_expr in grammar Exercice6 + print("Finished") + + +# warns pb if py file is included in others +if __name__ == '__main__': + main() diff --git a/TP02/requirements.txt b/TP02/requirements.txt new file mode 100644 index 0000000..4b7031c --- /dev/null +++ b/TP02/requirements.txt @@ -0,0 +1,6 @@ +antlr-python3-runtime==4.13.1 +pyright +pytest +pytest-cov +pytest-xdist +graphviz