Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Expression ::= AdditionExpression
- AdditionExpression ::=
- MultiplicationExpression
- | AdditionExpression '+' MultiplicationExpression
- | AdditionExpression '-' MultiplicationExpression
- MultiplicationExpression ::=
- Term
- | MultiplicationExpression '*' Term
- | MultiplicationExpression '/' Term
- Term ::=
- Number
- | '(' AdditionExpression ')'
- Number ::=
- [+-]?[0-9]+(.[0-9]+)?
- function parse_addition_expression() {
- num = parse_multiplication_expression()
- while (has_token()) {
- get_token()
- if (current_token_type == PLUS)
- num += parse_multiplication_expression()
- else if (current_token_type == MINUS)
- num -= parse_multiplication_expression()
- else {
- unget_token()
- return num
- }
- }
- return num
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement