Update TP02

This commit is contained in:
augustin64 2024-10-08 08:25:14 +02:00
parent d8d7c45ad2
commit 5af1ff8677
5 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1 @@
(2*4+3)+(4+3*2)

View File

@ -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

View File

@ -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*

View File

@ -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()

6
TP02/requirements.txt Normal file
View File

@ -0,0 +1,6 @@
antlr-python3-runtime==4.13.1
pyright
pytest
pytest-cov
pytest-xdist
graphviz