From f7b5b050dd9018db1fba64cdbd1dd8dee472d72e Mon Sep 17 00:00:00 2001 From: kris Date: Sat, 20 Jul 2019 15:52:01 -0500 Subject: [PATCH 1/2] Support parsing '?' tokens, which is a shorthand for 'PRINT'. --- .../io/github/applecommander/bastools/api/TokenReader.java | 7 ++++++- .../bastools/api/model/ApplesoftKeyword.java | 2 ++ tools/bt/src/test/resources/print.bas | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 tools/bt/src/test/resources/print.bas diff --git a/api/src/main/java/io/github/applecommander/bastools/api/TokenReader.java b/api/src/main/java/io/github/applecommander/bastools/api/TokenReader.java index c491874..bf23231 100644 --- a/api/src/main/java/io/github/applecommander/bastools/api/TokenReader.java +++ b/api/src/main/java/io/github/applecommander/bastools/api/TokenReader.java @@ -108,7 +108,12 @@ public class TokenReader { .filter(t -> opt.get().parts.get(1).equals(t.text)) .orElseThrow(() -> new IOException("Expecting: " + opt.get().parts)); } - return Optional.of(Token.keyword(line, opt.get())); + ApplesoftKeyword outKeyword = opt.get(); + // Special case - canonicalize '?' alternate form of 'PRINT' + if (opt.filter(kw -> kw == ApplesoftKeyword.questionmark).isPresent()) { + outKeyword = ApplesoftKeyword.PRINT; + } + return Optional.of(Token.keyword(line, outKeyword)); } // Check if we found a directive if (tokenizer.sval.startsWith("$")) { diff --git a/api/src/main/java/io/github/applecommander/bastools/api/model/ApplesoftKeyword.java b/api/src/main/java/io/github/applecommander/bastools/api/model/ApplesoftKeyword.java index 74c0825..ccb256e 100644 --- a/api/src/main/java/io/github/applecommander/bastools/api/model/ApplesoftKeyword.java +++ b/api/src/main/java/io/github/applecommander/bastools/api/model/ApplesoftKeyword.java @@ -71,6 +71,7 @@ public enum ApplesoftKeyword { DEF(0xB8, "DEF"), POKE(0xB9, "POKE"), PRINT(0xBA, "PRINT"), + questionmark(0xBA, "?"), // Alternate form of PRINT CONT(0xBB, "CONT"), LIST(0xBC, "LIST"), CLEAR(0xBD, "CLEAR"), @@ -178,6 +179,7 @@ public enum ApplesoftKeyword { tokenizer.resetSyntax(); tokenizer.wordChars('a', 'z'); tokenizer.wordChars('A', 'Z'); + tokenizer.wordChars('?', '?'); // For '?' form of PRINT tokenizer.wordChars('$', '$'); // Experiment to pull in string marker tokenizer.wordChars('%', '%'); // Experiment to pull in integer marker tokenizer.wordChars(128 + 32, 255); diff --git a/tools/bt/src/test/resources/print.bas b/tools/bt/src/test/resources/print.bas new file mode 100644 index 0000000..f83962b --- /dev/null +++ b/tools/bt/src/test/resources/print.bas @@ -0,0 +1 @@ +10 ? "PASS" From 7939985f89001773e0f3c6fe15cf4f54ac771b32 Mon Sep 17 00:00:00 2001 From: kris Date: Sat, 20 Jul 2019 15:54:34 -0500 Subject: [PATCH 2/2] Add a comment explaining what is going on --- tools/bt/src/test/resources/print.bas | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/bt/src/test/resources/print.bas b/tools/bt/src/test/resources/print.bas index f83962b..75b995a 100644 --- a/tools/bt/src/test/resources/print.bas +++ b/tools/bt/src/test/resources/print.bas @@ -1 +1,2 @@ -10 ? "PASS" +10 REM Test case to validate that the '?' shorthand form of PRINT is accepted +20 ? "PASS"