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