2023-12-27 23:11:30 +00:00
|
|
|
# Run it
|
2023-12-23 22:28:37 +00:00
|
|
|
`java -jar WHILEParser.jar <whileprogram> <x1Value> <x2Value> ...`
|
|
|
|
|
2023-12-27 23:11:30 +00:00
|
|
|
# Build it
|
2023-12-27 22:23:57 +00:00
|
|
|
## create parser with antlr
|
|
|
|
`antlr4 -package parser.grammar -o main/java/parser/grammar -no-listener -visitor Loop.g4`
|
2023-12-23 13:01:58 +00:00
|
|
|
|
2023-12-23 22:28:37 +00:00
|
|
|
## create executable
|
2023-12-27 23:11:30 +00:00
|
|
|
`mvn clean compile assembly:single`
|
|
|
|
|
|
|
|
# Language Example
|
|
|
|
```
|
|
|
|
//addWithWhile.txt
|
|
|
|
x0 = x2; // this is a comment
|
|
|
|
WHILE x1 != 0 DO
|
|
|
|
x0 = x0 +1;
|
|
|
|
x1 = x1 - 1;
|
|
|
|
END
|
|
|
|
```
|
|
|
|
```
|
|
|
|
//mulWithLoop.txt
|
|
|
|
z1 = x1;
|
|
|
|
z2 = x2;
|
|
|
|
x0 = 0;
|
|
|
|
y0 = 1;
|
|
|
|
LOOP z2 DO
|
|
|
|
x1 = z1;
|
|
|
|
x2 = y0 - 1;
|
|
|
|
x3 = x0;
|
|
|
|
y10 = y0;
|
|
|
|
z11 = x1;
|
|
|
|
z12 = x3;
|
|
|
|
x0 = x1;
|
|
|
|
y0 = 1;
|
|
|
|
LOOP z12 DO
|
|
|
|
x1 = z11;
|
|
|
|
x2 = y0 - 1;
|
|
|
|
x3 = x0;
|
|
|
|
x0 = x3 + 1;
|
|
|
|
y0 = y0 + 1;
|
|
|
|
END
|
|
|
|
y0 = y10;
|
|
|
|
y0 = y0 + 1;
|
|
|
|
END
|
|
|
|
```
|