Closed jacknugent1529 closed 3 years ago
After reading through the Bison library documentation provided on their site, I came up with a few pros and cons.
Pros
The following is an example of a case where GLR can be run while LR fails to run:
type subrange = (a) .. b;
type enum = (a);
In this case, both lines of code are seemingly identical until it encounters the '..' token. LR's one-token lookahead would not be able to determine what form '(a)
' should be parsed. GLR, on the other hand, would split the case into two branches, testing out each possible case, and merging in the end with the intended result.
Cons
An example of the grammar they support would be:
sum : NUM '+' NUM { $$ = std::stoi($1) + std::stoi($2); }
As you can see, the manipulation is within the brackets for this rule as compared to an example of a rule from ANTLR:
sum : NUM PLUS NUM ;
Sources: https://www.gnu.org/software/bison/manual/bison.pdf https://www.antlr.org/papers/allstar-techreport.pdf
I looked into using bison to write parsers in C. Since bison is just a parser and does not include a lexer, I used flex to create a lexer. I followed an example for a basic calculator with 4 operations, and then expanded on the example to create a scientific calculator with additional functions and parentheses (replit).
Pros:
Cons:
Additional Notes: Bison is a parser generator, not a parser combinator. This is not necessarily an advantage or disadvantage, but allows for slightly less flexibility in return for greater speed.
Issue Score: ✔️++
Comments: Great job on this really thorough research! In the future, it would be better to keep this kind of research documentation in a Wiki page for your team, so it is easier to reference in the future.
We plan on researching the bison library (https://www.gnu.org/software/bison/) and examining its usefulness for the CLI++ or DSL features. We aim to create a pros and cons list and some sample code using this library.
Assignees: John and Jack team: CLI++/DSL