Update TP02
This commit is contained in:
parent
d8d7c45ad2
commit
5af1ff8677
1
TP02/ariteval/tests/hello02.txt
Normal file
1
TP02/ariteval/tests/hello02.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
(2*4+3)+(4+3*2)
|
18
TP02/demo_files/exo6/Exercice6.g4
Normal file
18
TP02/demo_files/exo6/Exercice6.g4
Normal 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
|
17
TP02/demo_files/exo6/Makefile
Normal file
17
TP02/demo_files/exo6/Makefile
Normal 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*
|
22
TP02/demo_files/exo6/main.py
Normal file
22
TP02/demo_files/exo6/main.py
Normal 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
6
TP02/requirements.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
antlr-python3-runtime==4.13.1
|
||||||
|
pyright
|
||||||
|
pytest
|
||||||
|
pytest-cov
|
||||||
|
pytest-xdist
|
||||||
|
graphviz
|
Loading…
Reference in New Issue
Block a user