Home > Archive > Compilers > February 2008 > (E)BNF Grammar to XML for LALR(1) parse table?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
(E)BNF Grammar to XML for LALR(1) parse table?
|
|
| Cox.Jason@gmail.com 2008-01-15, 4:31 am |
| I have created a grammar for a little calculator language my company
created (literally takes constants, variables, parenthesis, and basic
arithmetic). We work exclusively in C# and I am having a difficult
time finding tools to generate a business-class, maintainable lexer
and parser. I have evaluated:
* Gold [http://devincook.com/goldparser/]
* C#Cup [http://www.infosys.tuwien.ac.at/cuplex/cup.htm]
* And GPLEX/GPPG [http://www.plas.fit.qut.edu.au/gppg/]
My requirements are:
* Efficiency is paramount as this will be iterated over many times.
* The code must be readable/maintainable.
GPLEX/GPPG was probably the best one, but it still fell short of my
expectations.
I figured the most expeditious route to get a working parser would be
to write my own, but I am not having fun manually generating the parse
tables. In this light, are there any tools which will examine a
grammar and spit out the parse table in XML so I can generate code
based on that?
Any magic bullet parser generators welcome as well :)
[If it really is just an expression language, an operator precedence parser,
which is easy to hand-code, should be all you need. -John]
| |
| Cox.Jason@gmail.com 2008-01-15, 7:24 pm |
| On Jan 14, 4:28 pm, Cox.Ja...@gmail.com wrote:
> I have created a grammar for a little calculator language my company
> created (literally takes constants, variables, parenthesis, and basic
> arithmetic). We work exclusively in C# and I am having a difficult
> time finding tools to generate a business-class, maintainable lexer
> and parser. ...
>
> Any magic bullet parser generators welcome as well :)
> [If it really is just an expression language, an operator precedence
> parser, which is easy to hand-code, should be all you need. -John]
There is a possibility that the "language" may be expanded in the
future to include things like max and min functions as well as
functions that do some proprietary things. You are probably right that
I could do an operator precedence parser and be done with, but I worry
about future scalability.
| |
|
| On Jan 14, 5:28 pm, Cox.Ja...@gmail.com wrote:
> I have created a grammar for a little calculator language my company
> created (literally takes constants, variables, parenthesis, and basic
> arithmetic). We work exclusively in C# and I am having a difficult
> time finding tools to generate a business-class, maintainable lexer
> and parser.
There's also ANTLR, of course. And COCO/R, which has a well written
book that describes how to use it with C# and Java, authored by Pat
Terry. I had to order the book from Amazon UK because Amazon in the US
didn't carry it: "Compiling with C# and Java".
I like Pat's explation of attributed grammars using C# specific code.
There's also a good book on ANTLR but I haven't had the time to read
it. My quick glances showed that it seems to be better than it has any
right to be, which is quite good. The book focuses on Domain Specific
Languages, which is what I understand yours to be.
These are both recursive decent tools: LL(k) and LL(1), instead of
LALR.
There's also the Gardens Point Parser Generator (GPPG). I've looked at
their Pascal compiler, and I simply can't say enough good things about
it. Those folks are simply brilliant.
Eric
| |
| Paul B Mann 2008-02-15, 10:17 pm |
| > I have created a grammar for a little calculator language my company
> created. We work exclusively in C# and I am having a difficult
> time finding tools to generate a business-class, maintainable lexer
> and parser.
>
> * Efficiency is paramount as this will be iterated over many times.
> * The code must be readable/maintainable.
>
> In this light, are there any tools which will examine a
> grammar and spit out the parse table in XML so I can generate code
> based on that?
Why do you want the parser tables in XML? Parser tables don't usually
get generated in XML.
Why do you want to hand code the parser tables, when they are usually
generated automatically?
I know of one tool that can generate very fast parsers and lexers in
C++ from a BNF grammar and it's possible to re-write the parser
skeleton and have the parser tables generated in C#.
It's called LRGen 8.3 at http://lrgen.com
Wikipedia has a long list of parser generators here:
http://en.wikipedia.org/wiki/List_of_parser_generators
Paul B Mann
| |
| scooter.phd@gmail.com 2008-02-17, 10:30 pm |
| On Jan 14, 2:28 pm, Cox.Ja...@gmail.com wrote:
> I figured the most expeditious route to get a working parser would be
> to write my own, but I am not having fun manually generating the parse
> tables. In this light, are there any tools which will examine a
> grammar and spit out the parse table in XML so I can generate code
> based on that?
XML? Parse table in XML? I can see expressing the grammar in XML,
perhaps, although that'd be the most loquacious looking description of
a grammar. But the parse table in XML?
Maybe I'm missing something.
-scooter
[It sorta kinda makes sense if you had a family of parse table generators
feeding into a family of parsers, but given how tightly the table format
has to be tied to the parser, it does seem like a wee bit of overkill,
doesn't it? -John]
|
|
|
|
|