-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.txt
92 lines (92 loc) · 3.42 KB
/
grammar.txt
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
program ===> otherFunctions mainFunction
mainFunction ===> TK_MAIN stmts TK_END
otherFunctions ===> function otherFunctions
otherFunctions ===> eps
function ===> TK_FUNID input_par output_par TK_SEM stmts TK_END
input_par ===> TK_INPUT TK_PARAMETER TK_LIST TK_SQL parameter_list TK_SQR
output_par ===> TK_OUTPUT TK_PARAMETER TK_LIST TK_SQL parameter_list TK_SQR
output_par ===> eps
parameter_list ===> dataType TK_ID remaining_list
dataType ===> primitiveDatatype
dataType ===> constructedDatatype
primitiveDatatype ===> TK_INT
primitiveDatatype ===> TK_REAL
constructedDatatype ===> TK_RECORD TK_RECORDID
remaining_list ===> TK_COMMA parameter_list
remaining_list ===> eps
stmts ===> typeDefinitions declarations otherStmts returnStmt
typeDefinitions ===> typeDefinition typeDefinitions
typeDefinitions ===> eps
typeDefinition ===> TK_RECORD TK_RECORDID fieldDefinitions TK_ENDRECORD TK_SEM
fieldDefinitions ===> fieldDefinition fieldDefinition moreFields
fieldDefinition ===> TK_TYPE primitiveDatatype TK_COLON TK_FIELDID TK_SEM
moreFields ===> fieldDefinition moreFields
moreFields ===> eps
declarations ===> declaration declarations
declarations ===> eps
declaration ===> TK_TYPE dataType TK_COLON TK_ID global_or_not TK_SEM
global_or_not ===> TK_COLON TK_GLOBAL
global_or_not ===> eps
otherStmts ===> stmt otherStmts
otherStmts ===> eps
stmt ===> assignmentStmt
stmt ===> iterativeStmt
stmt ===> conditionalStmt
stmt ===> ioStmt
stmt ===> funCallStmt
assignmentStmt ===> singleOrRecId TK_ASSIGNOP arithmeticExpression TK_SEM
singleOrRecId ===> TK_ID new24
new24 ===> TK_DOT TK_FIELDID
new24 ===> eps
funCallStmt ===> outputParameters TK_CALL TK_FUNID TK_WITH TK_PARAMETERS inputParameters TK_SEM
outputParameters ===> TK_SQL idList TK_SQR TK_ASSIGNOP
outputParameters ===> eps
inputParameters ===> TK_SQL idList TK_SQR
iterativeStmt ===> TK_WHILE TK_OP booleanExpression TK_CL stmt otherStmts TK_ENDWHILE
conditionalStmt ===> TK_IF TK_OP booleanExpression TK_CL TK_THEN stmt otherStmts elsePart
elsePart ===> TK_ELSE stmt otherStmts TK_ENDIF
elsePart ===> TK_ENDIF
ioStmt ===> TK_READ TK_OP singleOrRecId TK_CL TK_SEM
ioStmt ===> TK_WRITE TK_OP allVar TK_CL TK_SEM
allVar ===> TK_ID newVar
allVar ===> TK_NUM
allVar ===> TK_RNUM
newVar ===> TK_DOT TK_FIELDID
newVar ===> eps
arithmeticExpression ===> term expPrime
expPrime ===> lowPrecedenceOperators term expPrime
expPrime ===> eps
term ===> factor termPrime
termPrime ===> highPrecedenceOperators factor termPrime
termPrime ===> eps
factor ===> TK_OP arithmeticExpression TK_CL
factor ===> all
highPrecedenceOperators ===> TK_MUL
highPrecedenceOperators ===> TK_DIV
lowPrecedenceOperators ===> TK_PLUS
lowPrecedenceOperators ===> TK_MINUS
all ===> TK_NUM
all ===> TK_RNUM
all ===> TK_ID temp
temp ===> TK_DOT TK_FIELDID
temp ===> eps
booleanExpression ===> TK_OP booleanExpression TK_CL logicalOp TK_OP booleanExpression TK_CL
booleanExpression ===> var relationalOp var
booleanExpression ===> TK_NOT TK_OP booleanExpression TK_CL
var ===> TK_ID
var ===> TK_NUM
var ===> TK_RNUM
logicalOp ===> TK_AND
logicalOp ===> TK_OR
relationalOp ===> TK_LT
relationalOp ===> TK_LE
relationalOp ===> TK_EQ
relationalOp ===> TK_GT
relationalOp ===> TK_GE
relationalOp ===> TK_NE
returnStmt ===> TK_RETURN optionalReturn TK_SEM
optionalReturn ===> TK_SQL idList TK_SQR
optionalReturn ===> eps
idList ===> TK_ID more_ids
more_ids ===> TK_COMMA idList
more_ids ===> eps