Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. Expression ::= AdditionExpression
  2.  
  3. AdditionExpression ::=
  4. MultiplicationExpression
  5. | AdditionExpression '+' MultiplicationExpression
  6. | AdditionExpression '-' MultiplicationExpression
  7.  
  8. MultiplicationExpression ::=
  9. Term
  10. | MultiplicationExpression '*' Term
  11. | MultiplicationExpression '/' Term
  12.  
  13. Term ::=
  14. Number
  15. | '(' AdditionExpression ')'
  16.  
  17. Number ::=
  18. [+-]?[0-9]+(.[0-9]+)?
  19.  
  20. function parse_addition_expression() {
  21. num = parse_multiplication_expression()
  22. while (has_token()) {
  23. get_token()
  24. if (current_token_type == PLUS)
  25. num += parse_multiplication_expression()
  26. else if (current_token_type == MINUS)
  27. num -= parse_multiplication_expression()
  28. else {
  29. unget_token()
  30. return num
  31. }
  32. }
  33. return num
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement