-
Notifications
You must be signed in to change notification settings - Fork 8
/
grammar.txt
87 lines (64 loc) · 3.51 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
Program -> {Block}
| Procedure
| Function
Block -> {Expression}*
Function -> FUNCTION IDENTIFIER [LPRN [BYREF | BYVAL] IDENTIFIER : (DataType | IDENTIFIER) {, [BYREF | BYVAL] IDENTIFIER : (DataType | IDENTIFIER)} RPRN] RETURNS (DataType | IDENTIFIER) Block ENDPROCEDURE
Procedure -> PROCEDURE IDENTIFIER [LPRN [BYREF | BYVAL] IDENTIFIER : (DataType | IDENTIFIER) {, [BYREF | BYVAL] IDENTIFIER : (DataType | IDENTIFIER)} RPRN] Block ENDPROCEDURE
Expression -> EvaluationExpression
| DeclareStatement
| CONSTANT IDENTIFIER = INTEGER | -INTEGER | REAL | -REAL | BOOLEAN | CHAR | STRING
| TYPE IDENTIFIER = (LPRN {IDENTIFIER}* RPRN) | ^DataType
| CompositeType
| IfCondition
| CaseStatement
| WhileLoop
| ForLoop
| CALL IDENTIFIER[LPRN EvaluationExpression {, EvaluationExpression} RPRN]
| RETURN EvaluationExpression
| BREAK
| CONTINUE
| (OUTPUT | PRINT) EvaluationExpression {, EvaluationExpression}
| (INPUT | READ) IdentifierExpression
| OPENFILE StringExpression FOR (READ | WRITE | APPEND | RANDOM)
| READFILE StringExpression, IDENTIFIER
| WRITEFILE StringExpression, EvaluationExpression
| SEEK StringExpression, EvaluationExpression
| GETRECORD StringExpression, IDENTIFIER
| PUTRECORD StringExpression, IDENTIFIER
| CLOSEFILE StringExpression
CompositeType -> TYPE IDENTIFIER {DeclareStatement}* ENDTYPE
DeclareStatement -> DECLARE IDENTIFIER{, IDENTIFIER} : [ARRAY LSQRB EvaluationExpression:EvaluationExpression {EvaluationExpression:EvaluationExpression} RSQRB OF] (DataType | IDENTIFIER)
ForLoop -> FOR IDENTIFIER <- ArithmeticExpression TO ArithmeticExpression [STEP ArithmeticExpression] Block NEXT [IDENTIFIER]
RepeatUntilLoop -> REPEAT Block UNTIL EvaluationExpression
WhileLoop -> WHILE EvaluationExpression DO Block ENDWHILE
CaseStatement -> CASE OF EvaluationExpression {EvaluationExpression[ TO EvaluationExpression] : Block} [OTHERWISE : Block] ENDCASE
IfCondition -> IF EvaluationExpression THEN Block {ELSE IF EvaluationExpression THEN Block} [ELSE Block] ENDIF
DataType -> L_INTEGER | L_REAL | L_BOOLEAN | L_CHAR | L_STRING
EvaluationExpression -> LogicalExpression {(= | <>) LogicalExpression}
LogicalExpression -> ComparisonExpression {(AND | OR) ComparisonExpression}
ComparisonExpression -> ArithmeticExpression {(> | < | >= | <= | = | <>) ArithmeticExpression}
| NOT ComparisonExpression
StringExpression -> ArithmeticExpression {& ArithmeticExpression}
ArithmeticExpression -> Term {(+ | -) Term}
Term -> Factor {(* | / | DIV | MOD) Factor}
Factor -> Atom | -Atom
Atom -> INTEGER
| REAL
| TRUE
| FALSE
| CHAR
| STRING
| (MOD | DIV) LPRN EvaluationExpression, EvaluationExpression RPRN
| DataType LPRN EvaluationExpression RPRN
| LPRN EvaluationExpression RPRN
| IdentifierExpression
| IdentifierExpression <- EvaluationExpression | ^IdentifierExpression
| IDENTIFIER LPRN [EvaluationExpression {, EvaluationExpression}] RPRN
IdentifierExpression -> SingleIdentifier{.SingleIdentifier | ^ | LSQRB ArithmeticExpression {, ArithmeticExpression} RSQRB}
---- Definitions ----
X | Y - X or Y
[X] - Optional
{X} - Zero or many
{X}* - One or many
LPRN/RPRN - Left/Right parentheses
LSQRB/RSQRB - Left/Right square brackets