Percentage

This commit is contained in:
2025-09-14 14:13:14 +08:00
parent 6590c33732
commit 5cf66cd1f2
3 changed files with 147 additions and 1 deletions

View File

@@ -17,7 +17,15 @@ class Parser {
}
}
Expr parse() => parseAdd();
Expr parse() {
var expr = parseAdd();
skipSpaces();
if (!isEnd && current == '%') {
eat();
expr = PercentExpr(expr);
}
return expr;
}
Expr parseAdd() {
var expr = parseMul();
@@ -46,6 +54,12 @@ class Parser {
}
skipSpaces();
}
// Handle percentage operator
skipSpaces();
if (!isEnd && current == '%') {
eat();
expr = PercentExpr(expr);
}
return expr;
}