help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to implement optional semicolon rules


From: Hans Aberg
Subject: Re: How to implement optional semicolon rules
Date: Sat, 15 Nov 2014 18:32:00 +0100

> On 15 Nov 2014, at 15:25, Matthias Simon <address@hidden> wrote:

> I am struggling with some semicolon rules for some time now. In this language 
> (TTCN3) statements end with an mandatory semicolon, except there is a curly 
> bracket around. Example:
> 
> // -------------8<-------------[SNIP!]
>    {
>        var integer a;
>        var integer b[2] := { 23, 5 }
>        var integer c
>    }
> // ------------->8-------------[SNAP!]
> 
> 
> Declaration for variable b does not require a terminating semicolon, due to 
> closing bracket of its initialization. Also declaration of variable c needs 
> no semicolon due to the closing block.
> 
> TTCN3's grammar is already quite complex, therefore I made semicolon _always_ 
> mandatory and patched the lexer to `inject' semicolons when they were 
> expected by bison. This turned out to be quite hacky, so I am a little 
> clueless here. Perhaps you have some ideas how to solve this nicely?

The grammar for the Bison language, also a Bison grammar, used to admit 
optional commas (perhaps still at least in the Yacc-compatible part), and I 
think it may have used the same method. (Setting a context variable in the 
grammar before optional commas, telling the lexer to generate two tokens in 
succession via some variable it reads before lexing.)

Alternatively, you might be able to use the GLR parser, writing an ambiguous 
grammar that is resolved when the right lookahead arrives. No actions are 
executed during a split parse, imposing some limitations.

Also, with C++, one can do the opposite: writing a grammar for a more general 
language, and do a check in the actions.

And you might ask in the Usenet newsgroup comp.compilers, as somebody may have 
written a grammar for it before.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]