mirror of
https://github.com/Noratrieb/GRSBPL.git
synced 2026-01-14 11:45:02 +01:00
character error message
This commit is contained in:
parent
9c3d9a2dd9
commit
44ded882c3
2 changed files with 25 additions and 8 deletions
|
|
@ -1,9 +1,19 @@
|
||||||
10 factorial 1 goto exit
|
1 &i # init loop counter
|
||||||
|
:start # set start label
|
||||||
|
@i 100 - not goto finished # if i is 100, finish
|
||||||
|
@i 15 % not goto print_fizz_buzz # fizzbuzz
|
||||||
|
@i 5 % not goto print_buzz # buzz
|
||||||
|
@i 3 % not goto print_fizz # fizz
|
||||||
|
@i nout '\n' out # normal number
|
||||||
|
:end # go back here after printing
|
||||||
|
@i 1 + &i # increment i
|
||||||
|
1 goto start # go back to the start
|
||||||
|
|
||||||
function factorial 1
|
:print_fizz_buzz
|
||||||
dup not goto isZero
|
"Fizzbuzz\n" out goto end
|
||||||
pop dup 1 - factorial * return
|
:print_fizz
|
||||||
:isZero
|
"Fizz\n" out goto end
|
||||||
1 pop return
|
:print_buzz
|
||||||
|
"Buzz\n" out goto end
|
||||||
|
|
||||||
:exit pop dup nout
|
:finished 0
|
||||||
|
|
@ -92,7 +92,7 @@ public class Lexer {
|
||||||
value = escape();
|
value = escape();
|
||||||
}
|
}
|
||||||
add(CHAR, value);
|
add(CHAR, value);
|
||||||
consume();
|
expect('\'');
|
||||||
}
|
}
|
||||||
|
|
||||||
private void string() {
|
private void string() {
|
||||||
|
|
@ -194,6 +194,13 @@ public class Lexer {
|
||||||
advance();
|
advance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void expect(char c) {
|
||||||
|
if (peek() != c) {
|
||||||
|
lexException("Excepted character '" + c + "' but found '" + peek() + "'");
|
||||||
|
}
|
||||||
|
advance();
|
||||||
|
}
|
||||||
|
|
||||||
private char last() {
|
private char last() {
|
||||||
return program[position - 1];
|
return program[position - 1];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue