-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.py
52 lines (44 loc) · 1.6 KB
/
parser.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# importing yacc module from ply
import ply.yacc as yacc
from lexer import tokens
# precedence rules
precedence = (
("left", "COMMA"),
("right", "ASSIGN"),
("left", "OR"),
("left", "AND"),
("left", "EQUALS"),
("left", "LT", "LTE", "GT", "GTE"),
("left", "PLUS", "MINUS"),
("left", "EXP"),
("left", "PRODUCT", "DIVIDE"),
("right", "NOT"),
("right", "INCREMENT", "DECREMENT"),
)
# importing grammar rules -- productions
from Productions.Program import *
from Productions.Statements.Declaration.Struct import *
from Productions.Statements.Declaration.Variable import *
from Productions.Statements.Declaration.Function import *
from Productions.Statements.Declaration.List import *
from Productions.Statements.Declaration.VariableList import *
from Productions.Statements.Type import *
from Productions.Statements.Generic import *
from Productions.Statements.List import *
from Productions.Functions.Call import *
from Productions.Statements.Conditional.If import *
from Productions.Statements.Iterative.For import *
from Productions.Statements.Iterative.DoWhile import *
from Productions.Statements.Iterative.While import *
from Productions.Statements.Compound import *
from Productions.Statements.Expression import *
from Productions.Statements.Print import *
from Productions.Functions.Arguments import *
from Productions.Statements.Assignment import *
from Productions.Expression import *
from Productions.Term import *
from Productions.Factor import *
from Productions.Literal import *
from Productions.Error import *
from Productions.Empty import *
parser = yacc.yacc(start="program")