actually commit TP2
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
grammar ITE;
|
||||
|
||||
prog: stmt EOF;
|
||||
|
||||
stmt : ifStmt | ID ;
|
||||
|
||||
ifStmt : 'if' ID 'then' thenstmt=stmt ('else' elsestmt=stmt)?;
|
||||
|
||||
|
||||
ID : [a-zA-Z]+;
|
||||
WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines
|
||||
@@ -0,0 +1,17 @@
|
||||
MAINFILE = main
|
||||
PACKAGE = ITE
|
||||
|
||||
ifndef ANTLR4
|
||||
$(error variable ANTLR4 is not set)
|
||||
endif
|
||||
|
||||
default: $(PACKAGE)Parser.py
|
||||
|
||||
$(PACKAGE)Parser.py: $(PACKAGE).g4
|
||||
$(ANTLR4) $^ -Dlanguage=Python3
|
||||
|
||||
run: $(MAINFILE).py $(PACKAGE)Parser.py
|
||||
python3 $<
|
||||
|
||||
clean:
|
||||
rm -rf *~ $(PACKAGE)*.py $(PACKAGE)*.pyc *.interp *.tokens __pycache*
|
||||
@@ -0,0 +1,21 @@
|
||||
from antlr4 import InputStream
|
||||
from antlr4 import CommonTokenStream
|
||||
|
||||
# include to use the generated lexer and parser
|
||||
from ITELexer import ITELexer
|
||||
from ITEParser import ITEParser
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
lexer = ITELexer(InputStream(sys.stdin.read()))
|
||||
stream = CommonTokenStream(lexer)
|
||||
parser = ITEParser(stream)
|
||||
parser.prog()
|
||||
print("Finished")
|
||||
|
||||
|
||||
# warns pb if py file is included in others
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user