Adding comments.

This commit is contained in:
Rob Greene 2018-05-08 20:25:09 -05:00
parent 731930b56e
commit 42b0f90931
8 changed files with 21 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import java.util.List;
import java.util.Objects;
import java.util.Optional;
/** All elements of AppleSoft that are tokenized in some manner. "Keyword" was picked as it is not the word token. ;-) */
public enum ApplesoftKeyword {
END(0x80, "END"),
FOR(0x81, "FOR"),

View File

@ -6,6 +6,7 @@ import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
/** An AppleSoft BASIC Line representation. */
public class Line {
public final int lineNumber;
public final List<Statement> statements = new ArrayList<>();

View File

@ -4,6 +4,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Queue;
/** A simple driver for the tokenizer for a sample and rudimentary test. */
public class Main {
public static void main(String[] args) throws FileNotFoundException, IOException {
if (args.length != 1) {

View File

@ -5,6 +5,10 @@ import java.util.Queue;
import net.sf.applecommander.bastokenizer.Token.Type;
/**
* The Parser will read a series of Tokens and build a Program.
* Note that this is not a compiler and does not "understand" the program.
*/
public class Parser {
private final Queue<Token> tokens;

View File

@ -6,6 +6,7 @@ import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
/** A Program is a series of lines. */
public class Program {
public final List<Line> lines = new ArrayList<>();

View File

@ -6,6 +6,7 @@ import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
/** A Statement is simply a series of Tokens. */
public class Statement {
public final List<Token> tokens = new ArrayList<>();

View File

@ -5,6 +5,11 @@ import java.io.IOException;
import java.io.PrintStream;
import java.util.Optional;
/**
* A Token in the classic compiler sense, in that this represents a component of the application.
*
* @author rob
*/
public class Token {
public final int line;
public final Type type;

View File

@ -9,6 +9,12 @@ import java.util.LinkedList;
import java.util.Optional;
import java.util.Queue;
/**
* The TokenReader, given a text file, generates a series of Tokens (in the compiler sense,
* not AppleSoft) for the AppleSoft program.
*
* @author rob
*/
public class TokenReader {
private boolean hasMore = true;
// Internal flag just in case we consume the EOL (see REM for instance)s
@ -16,6 +22,7 @@ public class TokenReader {
private Reader reader;
private StreamTokenizer tokenizer;
/** A handy method to generate a list of Tokens from a file. */
public static Queue<Token> tokenize(String filename) throws FileNotFoundException, IOException {
try (FileReader fileReader = new FileReader(filename)) {
TokenReader tokenReader = new TokenReader(fileReader);