-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add toString() method to all classes in the AST.
- Loading branch information
1 parent
00e4f9a
commit e9111ad
Showing
19 changed files
with
142 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
10 LET X = 1 | ||
20 PRINT X * X | ||
30 LET X = X + 1 | ||
40 IF X > 10 THEN END | ||
50 GOTO 20 |
20 changes: 18 additions & 2 deletions
20
src/main/java/com/grahamedgecombe/tinybasic/TinyBasicCompiler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,25 @@ | ||
package com.grahamedgecombe.tinybasic; | ||
|
||
public final class TinyBasicCompiler { | ||
import com.grahamedgecombe.tinybasic.ast.Program; | ||
import com.grahamedgecombe.tinybasic.parser.Parser; | ||
import com.grahamedgecombe.tinybasic.tokenizer.Tokenizer; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
public static void main(String[] args) { | ||
public final class TinyBasicCompiler { | ||
|
||
public static void main(String[] args) throws IOException { | ||
Path path = Paths.get(args[0]); | ||
try (Tokenizer tokenizer = new Tokenizer(Files.newBufferedReader(path, StandardCharsets.UTF_8))) { | ||
try (Parser parser = new Parser(tokenizer)) { | ||
Program program = parser.parse(); | ||
System.out.println(program.toString().trim()); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 11 additions & 1 deletion
12
src/main/java/com/grahamedgecombe/tinybasic/ast/BinaryOperator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
package com.grahamedgecombe.tinybasic.ast; | ||
|
||
public enum BinaryOperator { | ||
PLUS, MINUS, MULT, DIV | ||
PLUS('+'), MINUS('-'), MULT('*'), DIV('/'); | ||
|
||
private final char character; | ||
|
||
private BinaryOperator(char character) { | ||
this.character = character; | ||
} | ||
|
||
public String toString() { | ||
return String.valueOf(character); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,9 @@ public int hashCode() { | |
return 0; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "END"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 11 additions & 1 deletion
12
src/main/java/com/grahamedgecombe/tinybasic/ast/RelationalOperator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
package com.grahamedgecombe.tinybasic.ast; | ||
|
||
public enum RelationalOperator { | ||
EQ, NE, GT, GTE, LT, LTE | ||
EQ("="), NE("<>"), GT(">"), GTE(">="), LT("<"), LTE("<="); | ||
|
||
private final String string; | ||
|
||
private RelationalOperator(String string) { | ||
this.string = string; | ||
} | ||
|
||
public String toString() { | ||
return string; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,9 @@ public int hashCode() { | |
return 0; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "RETURN"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 11 additions & 1 deletion
12
src/main/java/com/grahamedgecombe/tinybasic/ast/UnaryOperator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
package com.grahamedgecombe.tinybasic.ast; | ||
|
||
public enum UnaryOperator { | ||
PLUS, MINUS | ||
PLUS('+'), MINUS('-'); | ||
|
||
private final char character; | ||
|
||
private UnaryOperator(char character) { | ||
this.character = character; | ||
} | ||
|
||
public String toString() { | ||
return String.valueOf(character); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,9 @@ public int hashCode() { | |
return name.hashCode(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return name; | ||
} | ||
|
||
} |