Compare commits
1 Commits
add-right-
...
2025-predr
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
352085b499 |
29
grammar.txt
29
grammar.txt
@@ -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
|
||||
@@ -71,3 +70,27 @@ 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,3 +1,5 @@
|
||||
// line1 --
|
||||
line2 -----x
|
||||
line3
|
||||
|
||||
fun main() =
|
||||
3 - 2 - 1
|
||||
fun main() = 0
|
||||
@@ -247,7 +247,13 @@ public class LexAn implements AutoCloseable {
|
||||
return;
|
||||
}
|
||||
|
||||
while (buffChar != '\n' && buffChar != -1) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
while (buffChar != -1) {
|
||||
if (buffChar == '\n' && !builder.toString().endsWith("--")) {
|
||||
break;
|
||||
}
|
||||
builder.append((char) buffChar);
|
||||
nextChar();
|
||||
}
|
||||
|
||||
|
||||
@@ -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