|Developing/inventing a grammar... email@example.com (Oliver Bandel) (2005-07-11)|
|Re: Developing/inventing a grammar... cfc@shell01.TheWorld.com (Chris F Clark) (2005-07-12)|
|Re: Developing/inventing a grammar... firstname.lastname@example.org (makc.the.great) (2005-07-12)|
|Re: Developing/inventing a grammar... email@example.com (2005-07-12)|
|Date:||12 Jul 2005 05:21:09 -0400|
|Organization:||Department of Computer Science, University of Copenhagen|
|Posted-Date:||12 Jul 2005 05:21:09 EDT|
Oliver Bandel <firstname.lastname@example.org> writes:
> Any hints for effectively developing a grammar for a tool where I have
> an idea about how the language could/should look like?
> I use lex & yacc, have an idea about what the tool/language should do.
> But how to clearly develop a grammar for this?
> It's a different task to develop a grammar from scratch then using an
> already existing grammar and implementing it with lex & yacc.
> Any hints on how to go that way? Any tools? Tips & Tricks?
> Where to start? Starting with the keywords and the precedences?
First write the grammer down as you would in the user documentation
(assuming users understand grammars). Don't worry (at this stage)
about ambiguity, and allow yourself to use shorthand such as "id *" or
Then write this grammer in the form required for the parsing tool,
naming lexical items and introducing auxiliary nonterminals for the
shorthand used above. Still don't worry about ambiguity.
Add operator precedence declarations for the obvious cases (arithmetic
The run the parser generator with verbose output. Identify the causes
for conflicts and add more precedence declarations or rewrite to avoid
ambiguity. In most cases, precedence declarations will suffice, but
be careful to not exclude valid strings.
If you have some freedom in the exact look of the language, it may be
useful to add delimiting symbols (semicolons etc.) or keywords
("endif" etc.) to resolve ambiguities. But only add these where
necessary, or people will hate your language for being too verbose.
Return to the
Search the comp.compilers archives again.