-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.txt
88 lines (88 loc) · 3.73 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
<program> ===> <otherFunctions> <mainFunction> .
<mainFunction> ===> TK_MAIN <stmts> TK_END .
<otherFunctions> ===> <function> <otherFunctions> .
<otherFunctions> ===> e .
<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> ===> e .
<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> ===> e .
<stmts> ===> <typeDefinitions> <declarations> <otherStmts> <returnStmt> .
<typeDefinitions> ===> <typeDefinition> <typeDefinitions> .
<typeDefinitions> ===> e .
<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> ===> e .
<declarations> ===> <declaration> <declarations> .
<declarations> ===> e .
<declaration> ===> TK_TYPE <dataType> TK_COLON TK_ID <global_or_not> TK_SEM .
<global_or_not> ===> TK_COLON TK_GLOBAL .
<global_or_not> ===> e .
<otherStmts> ===> <stmt> <otherStmts> .
<otherStmts> ===> e .
<stmt> ===> <assignmentStmt> .
<stmt> ===> <iterativeStmt> .
<stmt> ===> <conditionalStmt> .
<stmt> ===> <ioStmt> .
<stmt> ===> <funCallStmt> .
<assignmentStmt> ===> <singleOrRecId> TK_ASSIGNOP <arithmeticExpression> TK_SEM .
<singleOrRecId> ===> TK_ID <new_24> .
<new_24> ===> e .
<new_24> ===> TK_DOT TK_FIELDID .
<funCallStmt> ===> <outputParameters> TK_CALL TK_FUNID TK_WITH TK_PARAMETERS <inputParameters> TK_SEM .
<outputParameters> ===> TK_SQL <idList> TK_SQR TK_ASSIGNOP .
<outputParameters> ===> e .
<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> ===> <var> .
<arithmeticExpression> ===> <term> <expPrime> .
<expPrime> ===> <lowPrecedenceOperators> <term> <expPrime> .
<expPrime> ===> e .
<term> ===> <factor> <termPrime> .
<termPrime> ===> <highPrecedenceOperator> <factor> <termPrime> .
<termPrime> ===> e .
<factor> ===> TK_OP <arithmeticExpression> TK_CL .
<factor> ===> <all> .
<highPrecedenceOperator> ===> TK_MUL .
<highPrecedenceOperator> ===> TK_DIV .
<lowPrecedenceOperators> ===> TK_PLUS .
<lowPrecedenceOperators> ===> TK_MINUS .
<all> ===> TK_NUM .
<all> ===> TK_RNUM .
<all> ===> TK_ID <temp> .
<temp> ===> TK_DOT TK_FIELDID .
<temp> ===> e .
<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 <new_24> .
<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> ===> e .
<idList> ===> TK_ID <more_ids> .
<more_ids> ===> TK_COMMA <idList> .
<more_ids> ===> e .