Improve trees generated by arithmetic grammar

This work should inform how to implement operator
precedence helper functions
This commit is contained in:
Max Brunsfeld 2014-03-29 18:37:51 -07:00
parent 7adb0bf34f
commit 99817a38c1
6 changed files with 1666 additions and 719 deletions

View file

@ -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))))

View file

@ -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)))))))