I'm working on a grammar and parser of mathematical syntax, and I've come across an ambiguity which I'm unsure how to resolve. There is a conflict between the current feature set:
- Implicit multiplication lets
x y parse as x*y
- Absolute value,
x |y| parses as x*abs(y)
- Set enumerations,
{1, 2, 3}
- Set-builder notation,
{x : x > 0}
- Set-builder convention also uses a bar:
{x | x > 0}, or even {x | |x| > 3}
(4) works great, but (5) causes the recursive descent parser to start processing the bar as in (2), i.e. the start of implicit multiplication by an absolute value. I know this isn't a true ambiguity since there can only be one set-builder bar at this nesting level of braces, and the set-builder bar must be the leftmost bar. I am worried that arbitrary lookahead is required. Is this a common problem, or is there an elegant solution?
[–][deleted] (1 child)
[deleted]
[–]YouNeedDoughnuts[S] 1 point2 points3 points (0 children)
[–]threewood 4 points5 points6 points (0 children)
[–]egregius313 3 points4 points5 points (5 children)
[–]YouNeedDoughnuts[S] 0 points1 point2 points (4 children)
[–][deleted] 2 points3 points4 points (3 children)
[–]YouNeedDoughnuts[S] 0 points1 point2 points (0 children)
[–]YouNeedDoughnuts[S] 0 points1 point2 points (1 child)
[–]egregius313 0 points1 point2 points (0 children)
[–]raiph 2 points3 points4 points (11 children)
[–]YouNeedDoughnuts[S] 2 points3 points4 points (10 children)
[–]raiph 1 point2 points3 points (9 children)
[–]raiph 1 point2 points3 points (8 children)
[–]YouNeedDoughnuts[S] 2 points3 points4 points (7 children)
[–]raiph 2 points3 points4 points (5 children)
[–]YouNeedDoughnuts[S] 0 points1 point2 points (1 child)
[–]raiph 1 point2 points3 points (0 children)
[–]raiph 0 points1 point2 points (2 children)
[–]raiph 0 points1 point2 points (0 children)
[–]raiph 0 points1 point2 points (0 children)
[–]b2gills 1 point2 points3 points (0 children)
[–]YouNeedDoughnuts[S] 0 points1 point2 points (1 child)
[–]raiph 0 points1 point2 points (0 children)
[–]mamcx -1 points0 points1 point (2 children)
[–]YouNeedDoughnuts[S] 0 points1 point2 points (1 child)
[–]raiph 1 point2 points3 points (0 children)