Improve trees generated by arithmetic grammar
This work should inform how to implement operator precedence helper functions
This commit is contained in:
parent
7adb0bf34f
commit
99817a38c1
6 changed files with 1666 additions and 719 deletions
|
|
@ -10,7 +10,8 @@ recovers from errors inside parenthesized expressions
|
|||
=====================================================
|
||||
x + (y * + z) * 5
|
||||
---
|
||||
(expression
|
||||
(expression (sum
|
||||
(variable)
|
||||
(plus)
|
||||
(term (factor (ERROR)) (times) (number)))
|
||||
(product
|
||||
(grouping (ERROR))
|
||||
(number))))
|
||||
|
|
@ -17,9 +17,8 @@ parses products
|
|||
===================
|
||||
x * x
|
||||
---
|
||||
(expression (term
|
||||
(expression (product
|
||||
(variable)
|
||||
(times)
|
||||
(variable)))
|
||||
|
||||
===================
|
||||
|
|
@ -27,28 +26,28 @@ parses sums
|
|||
===================
|
||||
x + x
|
||||
---
|
||||
(expression
|
||||
(expression (sum
|
||||
(variable)
|
||||
(plus)
|
||||
(variable))
|
||||
(variable)))
|
||||
|
||||
====================
|
||||
parses complex trees
|
||||
====================
|
||||
x * y + z * a
|
||||
x * y + z / a
|
||||
---
|
||||
(expression
|
||||
(term (variable) (times) (variable))
|
||||
(plus)
|
||||
(term (variable) (times) (variable)))
|
||||
(expression (sum
|
||||
(product (variable) (variable))
|
||||
(quotient (variable) (variable))))
|
||||
|
||||
=================================
|
||||
handles parenthesized expressions
|
||||
=================================
|
||||
x * (y + z)
|
||||
============================
|
||||
parses exponents
|
||||
============================
|
||||
x + y * z^(a + b)
|
||||
---
|
||||
(expression (term
|
||||
(expression (sum
|
||||
(variable)
|
||||
(times)
|
||||
(factor (expression (variable) (plus) (variable)))))
|
||||
|
||||
(product
|
||||
(variable)
|
||||
(exponent
|
||||
(variable)
|
||||
(grouping (sum (variable) (variable)))))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue