Skip to content

Commit 70c1592

Browse files
authored
Introduce scope statements (#8)
1 parent aab109a commit 70c1592

10 files changed

+146
-90
lines changed

MyParser.g4

+15-15
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ options {
99
}
1010

1111
program
12-
: (codeBlock)* EOF
12+
: statement* EOF
1313
;
1414

15-
codeBlock
16-
: OPEN_BRACKET_CURLY (codeBlock)* CLOSE_BRACKET_CURLY
17-
| ifThenElse
18-
| forLoop
19-
| whileLoop
20-
| assignment
21-
| print
22-
| return
23-
| break
24-
| continue
15+
statement
16+
: OPEN_BRACKET_CURLY statement* CLOSE_BRACKET_CURLY # scopeStatement
17+
| ifThenElse # scopeStatement
18+
| forLoop # scopeStatement
19+
| whileLoop # scopeStatement
20+
| assignment # simpleStatement
21+
| print # simpleStatement
22+
| return # simpleStatement
23+
| break # simpleStatement
24+
| continue # simpleStatement
2525
;
2626

2727
ifThenElse
@@ -33,23 +33,23 @@ if
3333
;
3434

3535
then
36-
: codeBlock
36+
: statement
3737
;
3838

3939
else
40-
: ELSE codeBlock
40+
: ELSE statement
4141
;
4242

4343
forLoop
44-
: FOR id ASSIGN range codeBlock
44+
: FOR id ASSIGN range statement
4545
;
4646

4747
range
4848
: expression RANGE_OP expression
4949
;
5050

5151
whileLoop
52-
: WHILE OPEN_BRACKET_ROUND comparison CLOSE_BRACKET_ROUND codeBlock
52+
: WHILE OPEN_BRACKET_ROUND comparison CLOSE_BRACKET_ROUND statement
5353
;
5454

5555
comparison

generated/MyParser.interp

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generated/MyParser.py

+87-54
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)