This commit is contained in:
parent
856618d113
commit
27b4e89694
@ -229,6 +229,10 @@ export class Parser {
|
|||||||
const value = Number(this.current.value);
|
const value = Number(this.current.value);
|
||||||
this.step();
|
this.step();
|
||||||
return ast.Node.create(loc, "IntExpr", { value });
|
return ast.Node.create(loc, "IntExpr", { value });
|
||||||
|
} else if (this.eat("(")) {
|
||||||
|
const expr = this.parseExpr();
|
||||||
|
this.mustEat(")");
|
||||||
|
return expr;
|
||||||
} else {
|
} else {
|
||||||
this.mustEat("<expression>");
|
this.mustEat("<expression>");
|
||||||
throw new Error();
|
throw new Error();
|
||||||
|
|||||||
@ -5,6 +5,8 @@
|
|||||||
// expect: 2
|
// expect: 2
|
||||||
// expect: -5
|
// expect: -5
|
||||||
// expect: 123
|
// expect: 123
|
||||||
|
// expect: 10
|
||||||
|
// expect: 14
|
||||||
|
|
||||||
fn main()
|
fn main()
|
||||||
{
|
{
|
||||||
@ -23,5 +25,8 @@ fn main()
|
|||||||
if not c {
|
if not c {
|
||||||
print_int(123);
|
print_int(123);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print_int(2 * 3 + 4);
|
||||||
|
print_int(2 * (3 + 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user