impl - * // /
This commit is contained in:
parent
bf44d84e17
commit
1a46130b1d
2 changed files with 30 additions and 4 deletions
|
@ -5,10 +5,10 @@ describe("expr", () => {
|
|||
test.each([
|
||||
["1", "1"],
|
||||
["1 + 2", "3"],
|
||||
// ["1 - 2", "-1"],
|
||||
// ["1 * 2", "2"],
|
||||
// ["1 / 2", "0.5"],
|
||||
// ["1 // 2", "0"],
|
||||
["1 - 2", "-1"],
|
||||
["1 * 2", "2"],
|
||||
["1 / 2", "0.5"],
|
||||
["1 // 2", "0"],
|
||||
// TODO: operator precedence
|
||||
// TODO: parentheses
|
||||
// TODO; eror reporting
|
||||
|
|
|
@ -66,6 +66,32 @@ const Operators: TokenHandler[] = [
|
|||
parse: ({ value: left }, matched, parser) =>
|
||||
map(parser.parseSubExpression(11), (right) => ({ value: left + right })),
|
||||
},
|
||||
{
|
||||
leftBindingPower: 10,
|
||||
token: MINUS_TOKEN,
|
||||
parse: ({ value: left }, matched, parser) =>
|
||||
map(parser.parseSubExpression(11), (right) => ({ value: left - right })),
|
||||
},
|
||||
{
|
||||
leftBindingPower: 20,
|
||||
token: TIMES_TOKEN,
|
||||
parse: ({ value: left }, matched, parser) =>
|
||||
map(parser.parseSubExpression(11), (right) => ({ value: left * right })),
|
||||
},
|
||||
{
|
||||
leftBindingPower: 20,
|
||||
token: FLOOR_TOKEN,
|
||||
parse: ({ value: left }, matched, parser) =>
|
||||
map(parser.parseSubExpression(11), (right) => ({
|
||||
value: Math.floor(left / right),
|
||||
})),
|
||||
},
|
||||
{
|
||||
leftBindingPower: 20,
|
||||
token: DIV_TOKEN,
|
||||
parse: ({ value: left }, matched, parser) =>
|
||||
map(parser.parseSubExpression(11), (right) => ({ value: left / right })),
|
||||
},
|
||||
];
|
||||
|
||||
const ZERO = { value: 0 };
|
||||
|
|
Loading…
Reference in a new issue