-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlara
executable file
·33 lines (29 loc) · 1011 Bytes
/
lara
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/python
import sys
from langtools.lexer.lexer import tokenize
from langtools.parser.cfg import CFG
from src.config.lexer import TOKENIZER
from src.config.parser import PRODUCTION_RULES, START
from src.eval import Evaluator
num_args = len(sys.argv)
if num_args > 1:
tokens = tokenize(open(sys.argv[1]), TOKENIZER, white_space_delimit=True)
lara_grammar = CFG(
production_rules=PRODUCTION_RULES,
alphabet=[chr(i) for i in range(128)],
start_symbol=START,
)
ast = lara_grammar.LL1_parse(tokens)
ast.flatten(
{
"STATEMENTS": {"STATEMENTS"},
"ARGUMENTS": {"ANOTHER_ARGUMENT", "ARGUMENTS"},
"ANOTHER_ARGUMENT": {"ARGUMENTS"},
"ARGUMENTS_DEF": {"ANOTHER_ARGUMENT_DEF", "ARGUMENTS_DEF"},
"ANOTHER_ARGUMENT_DEF": {"ARGUMENTS_DEF"},
"IF_BLOCK": {"IF_BLOCK_CONTINUE"},
# "EXPRESSION": {"TERM_OPERATOR"},
}
)
evaluator = Evaluator(ast)
evaluator.evaluate()