Merge pull request #19 from KrisKennaway/master

Support parsing '?' tokens, which is a shorthand for 'PRINT'.
This commit is contained in:
A2 Geek 2019-09-01 14:58:42 -05:00 committed by GitHub
commit cc12f7ccba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 1 deletions

View File

@ -108,7 +108,12 @@ public class TokenReader {
.filter(t -> opt.get().parts.get(1).equals(t.text)) .filter(t -> opt.get().parts.get(1).equals(t.text))
.orElseThrow(() -> new IOException("Expecting: " + opt.get().parts)); .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 // Check if we found a directive
if (tokenizer.sval.startsWith("$")) { if (tokenizer.sval.startsWith("$")) {

View File

@ -71,6 +71,7 @@ public enum ApplesoftKeyword {
DEF(0xB8, "DEF"), DEF(0xB8, "DEF"),
POKE(0xB9, "POKE"), POKE(0xB9, "POKE"),
PRINT(0xBA, "PRINT"), PRINT(0xBA, "PRINT"),
questionmark(0xBA, "?"), // Alternate form of PRINT
CONT(0xBB, "CONT"), CONT(0xBB, "CONT"),
LIST(0xBC, "LIST"), LIST(0xBC, "LIST"),
CLEAR(0xBD, "CLEAR"), CLEAR(0xBD, "CLEAR"),
@ -178,6 +179,7 @@ public enum ApplesoftKeyword {
tokenizer.resetSyntax(); tokenizer.resetSyntax();
tokenizer.wordChars('a', 'z'); tokenizer.wordChars('a', 'z');
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 string marker
tokenizer.wordChars('%', '%'); // Experiment to pull in integer marker tokenizer.wordChars('%', '%'); // Experiment to pull in integer marker
tokenizer.wordChars(128 + 32, 255); tokenizer.wordChars(128 + 32, 255);

View File

@ -0,0 +1,2 @@
10 REM Test case to validate that the '?' shorthand form of PRINT is accepted
20 ? "PASS"