Skip to content

Commit

Permalink
GOTO Parser & Interpreter added
Browse files Browse the repository at this point in the history
  • Loading branch information
Erlkoenig90 committed Sep 10, 2016
1 parent 39a2e4c commit 6b9bcff
Show file tree
Hide file tree
Showing 12 changed files with 582 additions and 164 deletions.
30 changes: 27 additions & 3 deletions README.md
Expand Up @@ -6,6 +6,7 @@ The features are:
* Usage of grammars specified in BNF
* Parsing & Interpreting WHILE programs
* Compiling WHILE programs into GOTO programs
* Interpreting GOTO programs
* Compiling GOTO programs into Java Bytecode and saving those as Java ".class" files by using the [ASM](http://asm.ow2.org) library. These can be run from any Java application or directly on the console. This is a true but simple compilation to the JVM without any interpreter.

This proves that it is possible to parse arbitrarily complex context-free grammars in a few hundred lines of code, and how WHILE & GOTO programs can serve as model languages for real-world ones.
Expand Down Expand Up @@ -49,6 +50,13 @@ where Args is:
* While2Goto InFile OutFile

Compile WHILE program to GOTO program
* RunGoto File Input...

Interpret GOTO program from file and print result

* Goto2Java InFile ClassName OutFile

Compile GOTO program to Java class
* While2Java InFile ClassName OutFile

Compile WHILE program to Java class
Expand All @@ -60,7 +68,11 @@ where Args is:
Print the BNF of the grammar used to parse BNF's
* ShowWhile

Print the BNF of the grammar used to parse while progams
Print the BNF of the grammar used to parse while programs

* ShowGoto

Print the BNF of the grammar used to parse goto programs

OutFile can also be "-" to print to the console.

Expand Down Expand Up @@ -152,10 +164,16 @@ $ java -jar whiler.jar While2Goto progs/mult.while -
011: GOTO 4
012: HALT$ cat test.while
X0:=0

```
Compiling the multiplication program into a Java program, analyzing the generated class file, and running it directly in Java:
Running the multiplication GOTO program:
```sh
$ java -jar whiler.jar While2Java progs/mult.while Mult progs/Mult.class
$ java -jar whiler.jar RunGoto progs/mult.goto 3 4
12
```
Compiling the multiplication goto program into a Java program, analyzing the generated class file, and running it directly in Java:
```sh
$ java -jar whiler.jar Goto2Java progs/mult.goto Mult progs/Mult.class
$ javap progs/Mult.class
public class Mult {
static {};
Expand All @@ -165,6 +183,12 @@ public class Mult {
$ java -cp progs Mult 3 4
12
```
Compiling the multiplication while program into a Java program, and running it directly in Java:
```sh
$ java -jar whiler.jar While2Java progs/mult.while Mult progs/Mult.class
$ java -cp progs Mult 3 4
12
```

## License
This is an open source project licensed under the terms of the BSD license. See the [LICENSE file](LICENSE) for details.
17 changes: 17 additions & 0 deletions launch/whiler RunGoto Mult.launch
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/whiler/src/whiler/Main.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
</listAttribute>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="whiler.Main"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="RunGoto progs/mult.goto 4 5"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="whiler"/>
</launchConfiguration>

0 comments on commit 6b9bcff

Please sign in to comment.