Compare commits
1 Commits
2025-predr
...
line-symbo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de2522c28c |
24
grammar.txt
24
grammar.txt
@@ -70,27 +70,3 @@ initializer -> INTCONST intconstmult | CHARCONST | STRINGCONST .
|
||||
intconstmult -> MUL const | .
|
||||
|
||||
const -> INTCONST | CHARCONST | STRINGCONST .
|
||||
|
||||
|
||||
--------------------------------------------------------------------
|
||||
|
||||
//LEFT ASOC.
|
||||
exp0 = exp0 op other | other
|
||||
|
||||
|
|
||||
v
|
||||
|
||||
exp0 = other exp0'
|
||||
exp0' = op other exp0' | .
|
||||
|
||||
|
||||
|
||||
|
||||
//RIGHT ASOC.
|
||||
exp0 = other op exp0 | other
|
||||
|
||||
|
|
||||
v
|
||||
|
||||
exp0 = other exp0'
|
||||
exp0' = op exp0 | .
|
||||
@@ -1,5 +1,4 @@
|
||||
// line1 --
|
||||
line2 -----x
|
||||
line3
|
||||
fun putint(n)
|
||||
|
||||
fun main() = 0
|
||||
fun main() =
|
||||
putint(__LINE__)
|
||||
@@ -148,7 +148,11 @@ public record Token(Report.Location location, Symbol symbol, String lexeme) impl
|
||||
/**
|
||||
* Simbol {@code )}.
|
||||
*/
|
||||
RPAREN;
|
||||
RPAREN,
|
||||
/**
|
||||
* Simbol {@code __LINE__}.
|
||||
*/
|
||||
LINE
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -247,13 +247,7 @@ public class LexAn implements AutoCloseable {
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
while (buffChar != -1) {
|
||||
if (buffChar == '\n' && !builder.toString().endsWith("--")) {
|
||||
break;
|
||||
}
|
||||
builder.append((char) buffChar);
|
||||
while (buffChar != '\n' && buffChar != -1) {
|
||||
nextChar();
|
||||
}
|
||||
|
||||
@@ -325,6 +319,7 @@ public class LexAn implements AutoCloseable {
|
||||
case "let" -> Token.Symbol.LET;
|
||||
case "in" -> Token.Symbol.IN;
|
||||
case "end" -> Token.Symbol.END;
|
||||
case "__LINE__" -> Token.Symbol.LINE;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
@@ -457,6 +452,15 @@ public class LexAn implements AutoCloseable {
|
||||
symbol = Token.Symbol.IDENTIFIER;
|
||||
}
|
||||
|
||||
if (symbol == Token.Symbol.LINE) {
|
||||
buffToken = new Token(
|
||||
new Report.Location(startLocation, endLocation),
|
||||
Token.Symbol.INTCONST,
|
||||
Integer.toString(startLocation.begLine())
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
buffToken = new Token(
|
||||
new Report.Location(startLocation, endLocation),
|
||||
symbol,
|
||||
|
||||
Reference in New Issue
Block a user