-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgrammar.txt
More file actions
49 lines (47 loc) · 863 Bytes
/
Copy pathgrammar.txt
File metadata and controls
49 lines (47 loc) · 863 Bytes
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
# Terminals
## Operators
+, −, ∗, /, =, >, ==, (, )
## Delimiters
`;', `,', `{', `}'
## Keywords
`for', `write', `read', `int'
## <variable>
<variable> = {a - z}+
## <constant>
<constant> = {0-9}+
# Variables
+ P - program (start variable)
+ S - statement
+ D - declaration
+ F - for loop
+ A - assignment
+ R - read
+ W - write
+ E - expression
+ T1, T2, T3 - helper variables for expression
# Productions
## Constant
N -> <constant>
## Variable
I -> <variable>
## Variable list
L -> I | I, L
## Declaration
D -> int L
## Read
R -> read I
## Write
W -> write I | write N
## Expression
E -> E > T1 | E == T1 | T1
T1 -> T1 + T2 | T1 − T2 | T2
T2 -> T2 ∗ T3 | T2/T3 | T3
T3 -> (E) | I | N
## Assignment
A -> I = E
## Loop
F -> for(A; E; A){S}
## Statement
S -> A; | R; | W; | F; | A; S | R; S | W; S | F; S
## Program
P -> D; | D; S | S