With a PEG, you can define it in non-recursive terms. As such: sum <- term ((PLUS / MINUS) term) * term <- value ((DIV / MUL / MOD) term) * valua <- float-constant / int-constant / POPEN sum PCLOSE
You can impose associativity on top of this as you desire. On Thu, Jun 3, 2010 at 10:45 AM, Marcus Nordenstam <mar...@exoticmatter.com>wrote: > Hello, > > I just saw this mailing list, and figured if there's anywhere people > may know the answer to this question, it would be here. > > I've been using the peg/leg parser generator tool to make C++ PEG > parsers (I modified it slightly so that it would generate C++ code > instead of ANSI C). > > I'm trying to write a simple expression grammar using PEG and, like > everyone else I guess, have run into the left recursion issue. The > primary issue I have is the simplest kind, e.g.: > > sum <- sum PLUS term > / sum MINUS term > / term > > term <- term DIV value > / term MUL value > / term MOD value > / value > > value <- float-constant > / int-constant > / POPEN sum PCLOSE > > note that I've written terminals in all caps above. > > Now I can rewrite the grammar to eliminate the left-recursion, but > doesn't that change the associativity of the parse? That would be > quite bad since this grammar is primarily for mathematical > expressions... > > So my question is: is anyone aware of an implementation (preferably in > C or C++) which could parse the above grammar? Even if it's not a > perfect tool, anything would be a better starting point for me than > having to implement one of the left-recursion PEG papers from scratch > :-) > > cheers > Marcus > > _______________________________________________ > PEG mailing list > PEG@lists.csail.mit.edu > https://lists.csail.mit.edu/mailman/listinfo/peg >
_______________________________________________ PEG mailing list PEG@lists.csail.mit.edu https://lists.csail.mit.edu/mailman/listinfo/peg