This commit is contained in:
Gašper Dobrovoljc 2025-03-23 14:00:35 +01:00
parent b8545a143b
commit ffcb50c707
No known key found for this signature in database
GPG Key ID: 0E7E037018CFA5A5
5 changed files with 27 additions and 28 deletions

View File

@ -2,7 +2,7 @@ fun noarg()
fun onearg(a) fun onearg(a)
fun multargs(a, b) fun multargs(a, b)
fun funcassign(a) = fun funcassign(a) =
a = 1 a = 1
var a = 1 var a = 1
var b = 'a' var b = 'a'
@ -14,23 +14,23 @@ var h = 4 * "aaa"
var i = var i =
fun a() = fun a() =
1, 'a', "a", 1, 'a', "a",
a, neki(a, 1, 'a', "a"), a, neki(a, 1, 'a', "a"),
a^, a^^, a^, a^^,
+a, -a, !a, ^a, +-!^a, +a, -a, !a, ^a, +-!^a,
a * b, a / b, a % b, a * b / c % d, a * b, a / b, a % b, a * b / c % d,
a + b, a - b, a + b, a - b,
a == b, a != b, a < b, a > b, a <= b, a >= b, a == b, a != b, a < b, a > b, a <= b, a >= b,
a && b, a && b && c, a && b, a && b && c,
a || b, a || b || c, a || b, a || b || c,
(1), (a + b), (a - (!(1) * 2)), (1), (a + b), (a - (!(1) * 2)),
a + 1 = b - 1, a + 1 = b - 1,
if a then b end, if a then b end,
if a == 3 then b = 1, !c end, if a == 3 then b = 1, !c end,
if !a then b else a = 3 * a end, if !a then b else a = 3 * a end,
if a then b else a, b end, if a then b else a, b end,
while a <= 10 do a + 1 end, while a <= 10 do a + 1 end,
while a <= 10 do a + 1, ^c end, while a <= 10 do a + 1, ^c end,
let fun a(b, c) in !b end, let fun a(b, c) in !b end,
let fun a(b, c) var e = 'o' in !b end, let fun a(b, c) var e = 'o' in !b end,
let fun a(b, c) in !b, 4 end let fun a(b, c) in !b, 4 end

View File

@ -1 +1,2 @@
var fun a() =
1 +

View File

@ -1,7 +1,5 @@
package pins25.common; package pins25.common;
import java.util.HashMap;
/** /**
* Leksikalni simbol. * Leksikalni simbol.
* *
@ -152,7 +150,8 @@ public record Token(Report.Location location, Symbol symbol, String lexeme) impl
*/ */
RPAREN; RPAREN;
public String prettyPrint() { @Override
public String toString() {
return switch (this) { return switch (this) {
case INTCONST -> "integer constant"; case INTCONST -> "integer constant";
case CHARCONST -> "character constant"; case CHARCONST -> "character constant";
@ -192,7 +191,6 @@ public record Token(Report.Location location, Symbol symbol, String lexeme) impl
} }
} }
@Override @Override
public String toString() { public String toString() {
String lexeme = switch (symbol) { String lexeme = switch (symbol) {

View File

@ -130,7 +130,7 @@ public class LexAn implements AutoCloseable {
Report.Location start = currentLocation(); Report.Location start = currentLocation();
switch (buffChar) { switch (buffChar) {
case -1: // EOF case -1: // EOF
buffToken = new Token(start, Token.Symbol.EOF, null); buffToken = new Token(start, Token.Symbol.EOF, "EOF");
return; return;
case '\'': case '\'':

View File

@ -38,7 +38,7 @@ public class SynAn implements AutoCloseable {
private Token check(Token.Symbol symbol) { private Token check(Token.Symbol symbol) {
final Token token = lexAn.takeToken(); final Token token = lexAn.takeToken();
if (token.symbol() != symbol) if (token.symbol() != symbol)
throw new Report.Error(token, "Unexpected symbol '" + token.lexeme() + "', expected " + symbol.prettyPrint() + "."); throw new Report.Error(token, "Unexpected symbol '" + token.lexeme() + "', expected " + symbol + ".");
return token; return token;
} }