mirror of
https://github.com/AppleCommander/bastools.git
synced 2025-01-03 01:29:28 +00:00
Adding comments.
This commit is contained in:
parent
731930b56e
commit
42b0f90931
@ -10,6 +10,7 @@ import java.util.List;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
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 {
|
public enum ApplesoftKeyword {
|
||||||
END(0x80, "END"),
|
END(0x80, "END"),
|
||||||
FOR(0x81, "FOR"),
|
FOR(0x81, "FOR"),
|
||||||
|
@ -6,6 +6,7 @@ import java.io.PrintStream;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/** An AppleSoft BASIC Line representation. */
|
||||||
public class Line {
|
public class Line {
|
||||||
public final int lineNumber;
|
public final int lineNumber;
|
||||||
public final List<Statement> statements = new ArrayList<>();
|
public final List<Statement> statements = new ArrayList<>();
|
||||||
|
@ -4,6 +4,7 @@ import java.io.FileNotFoundException;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
|
/** A simple driver for the tokenizer for a sample and rudimentary test. */
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) throws FileNotFoundException, IOException {
|
public static void main(String[] args) throws FileNotFoundException, IOException {
|
||||||
if (args.length != 1) {
|
if (args.length != 1) {
|
||||||
|
@ -5,6 +5,10 @@ import java.util.Queue;
|
|||||||
|
|
||||||
import net.sf.applecommander.bastokenizer.Token.Type;
|
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 {
|
public class Parser {
|
||||||
private final Queue<Token> tokens;
|
private final Queue<Token> tokens;
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import java.io.PrintStream;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/** A Program is a series of lines. */
|
||||||
public class Program {
|
public class Program {
|
||||||
public final List<Line> lines = new ArrayList<>();
|
public final List<Line> lines = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import java.io.PrintStream;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/** A Statement is simply a series of Tokens. */
|
||||||
public class Statement {
|
public class Statement {
|
||||||
public final List<Token> tokens = new ArrayList<>();
|
public final List<Token> tokens = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -5,6 +5,11 @@ import java.io.IOException;
|
|||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.util.Optional;
|
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 class Token {
|
||||||
public final int line;
|
public final int line;
|
||||||
public final Type type;
|
public final Type type;
|
||||||
|
@ -9,6 +9,12 @@ import java.util.LinkedList;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Queue;
|
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 {
|
public class TokenReader {
|
||||||
private boolean hasMore = true;
|
private boolean hasMore = true;
|
||||||
// Internal flag just in case we consume the EOL (see REM for instance)s
|
// 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 Reader reader;
|
||||||
private StreamTokenizer tokenizer;
|
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 {
|
public static Queue<Token> tokenize(String filename) throws FileNotFoundException, IOException {
|
||||||
try (FileReader fileReader = new FileReader(filename)) {
|
try (FileReader fileReader = new FileReader(filename)) {
|
||||||
TokenReader tokenReader = new TokenReader(fileReader);
|
TokenReader tokenReader = new TokenReader(fileReader);
|
||||||
|
Loading…
Reference in New Issue
Block a user