-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar_rules.erp
57 lines (57 loc) · 2.5 KB
/
grammar_rules.erp
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
program : moduleDeclarations otherModules driverModule otherModules
moduleDeclarations : moduleDeclaration moduleDeclarations | EMPTY
moduleDeclaration : DECLARE MODULE ID SEMICOL
otherModules : module otherModules | EMPTY
driverModule : DRIVERDEF DRIVER PROGRAM DRIVERENDDEF moduleDef
module : DEF MODULE ID ENDDEF TAKES INPUT SQBO input_plist SQBC SEMICOL ret moduleDef
ret : RETURNS SQBO output_plist SQBC SEMICOL | EMPTY
input_plist : ID COLON dataType n1
n1 : COMMA ID COLON dataType n1 | EMPTY
output_plist : ID COLON type n2
n2 : COMMA ID COLON type n2 | EMPTY
type : INTEGER | REAL | BOOLEAN
dataType : type | ARRAY SQBO range_arrays SQBC OF type
moduleDef : START statements END
statements : statement statements | EMPTY
statement : ioStmt | simpleStmt | declareStmt | condionalStmt | iterativeStmt
ioStmt : GET_VALUE BO ID BC SEMICOL | PRINT BO var BC SEMICOL
whichId : SQBO index SQBC | EMPTY
index : NUM | ID
simpleStmt : assignmentStmt | moduleReuseStmt
assignmentStmt : ID whichStmt
moduleReuseStmt : optional USE MODULE ID WITH PARAMETERS idList SEMICOL
optional : SQBO idList SQBC ASSIGNOP | EMPTY
idList : ID n3
n3 : COMMA ID n3 | EMPTY
expression : arithmeticOrBooleanExpr | u
arithmeticOrBooleanExpr : anyTerm n7
n7 : logicalOp anyTerm n7 | EMPTY
anyTerm : arithmeticExpr n8 | boolConstt
n8 : relationalOp arithmeticExpr | EMPTY
arithmeticExpr : term n4
n4 : op1 term n4 | EMPTY
term : factor n5
n5 : op2 factor n5 | EMPTY
factor : BO arithmeticOrBooleanExpr BC | var_id_num
var : var_id_num | boolConstt
op1 : PLUS | MINUS
op2 : MUL | DIV
logicalOp : AND | OR
relationalOp : LT | LE | GT | GE | EQ | NE
declareStmt : DECLARE idList COLON dataType SEMICOL
condionalStmt : SWITCH BO ID BC START caseStmts default END
caseStmts : CASE value COLON statements BREAK SEMICOL n9
n9 : CASE value COLON statements BREAK SEMICOL n9 | EMPTY
value : NUM | TRUE | FALSE
default : DEFAULT COLON statements BREAK SEMICOL | EMPTY
iterativeStmt : FOR BO ID IN range BC START statements END | WHILE BO arithmeticOrBooleanExpr BC START statements END
range : NUM RANGEOP NUM
range_arrays : index RANGEOP index
boolConstt : TRUE | FALSE
var_id_num : ID whichId | NUM | RNUM
whichStmt : lvalueIDStmt | lvalueARRStmt
lvalueIDStmt : ASSIGNOP expression SEMICOL
lvalueARRStmt : SQBO index SQBC ASSIGNOP expression SEMICOL
u : unary_op new_NT
unary_op : PLUS | MINUS
new_NT : BO arithmeticExpr BC | var_id_num