Compare commits
1 Commits
add-right-
...
line-symbo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de2522c28c |
@@ -39,9 +39,8 @@ restcmp -> EQU addexpr
|
||||
| .
|
||||
|
||||
addexpr -> multexpr restadd .
|
||||
restadd -> ADD addexpr
|
||||
| SUB addexpr
|
||||
| .
|
||||
restadd -> ADD multexpr restadd
|
||||
| SUB multexpr restadd | .
|
||||
|
||||
multexpr -> prefixexpr restmult .
|
||||
restmult -> MUL prefixexpr restmult
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
fun putint(n)
|
||||
|
||||
fun main() =
|
||||
3 - 2 - 1
|
||||
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
|
||||
|
||||
@@ -319,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;
|
||||
};
|
||||
}
|
||||
@@ -451,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,
|
||||
|
||||
@@ -540,20 +540,20 @@ public class SynAn implements AutoCloseable {
|
||||
Token token = lexAn.peekToken();
|
||||
switch (token.symbol()) {
|
||||
case ADD: {
|
||||
// restadd -> ADD addexpr
|
||||
// restadd -> ADD multexpr restadd
|
||||
check(Token.Symbol.ADD);
|
||||
AST.Expr right = parseAdditionExpression();
|
||||
AST.Expr right = parseMultiplicationExpression();
|
||||
AST.Expr binExpr = new AST.BinExpr(AST.BinExpr.Oper.ADD, left, right);
|
||||
attrLoc.put(binExpr, new Report.Location(attrLoc.get(left), attrLoc.get(right)));
|
||||
return binExpr;
|
||||
return parseRestAdditionExpressions(binExpr);
|
||||
}
|
||||
case SUB: {
|
||||
// restadd -> ADD addexpr
|
||||
// restadd -> SUB multexpr restadd
|
||||
check(Token.Symbol.SUB);
|
||||
AST.Expr right = parseAdditionExpression();
|
||||
AST.Expr right = parseMultiplicationExpression();
|
||||
AST.Expr binExpr = new AST.BinExpr(AST.BinExpr.Oper.SUB, left, right);
|
||||
attrLoc.put(binExpr, new Report.Location(attrLoc.get(left), attrLoc.get(right)));
|
||||
return binExpr;
|
||||
return parseRestAdditionExpressions(binExpr);
|
||||
}
|
||||
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user