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: Derek Clegg
Subject: Re: How to implement optional semicolon rules
Date: Sat, 15 Nov 2014 10:24:49 -0800

I’m certainly no bison expert, but something like the following might be a 
starting point:

start: semicolon_terminated_statements
  ;

semicolon_terminated_statements:
  /* empty */
  | semicolon_terminated_statements semicolon_terminated_statement
  | semicolon_terminated_statements block
  ;

block:
  '{' semicolon_terminated_statements '}'
  | '{' semicolon_terminated_statements decl '}'
  ;

semicolon_terminated_statement:
  decl ';'
  | array_decl ';'
  | array_decl
  ;

decl:
  VAR INTEGER NAME
  ;

array_decl:
  VAR INTEGER NAME '[' NUMBER ']' '=' braced_initializer
  ;

braced_initializer: '{' /* initialization */ '}'
  ;

Derek Clegg

> On Nov 15, 2014, at 6:25 AM, Matthias Simon <address@hidden> wrote:
> 
> Hi,
> 
> 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?
> 
> Cheers!
> 
> Matthias
> 
> _______________________________________________
> address@hidden https://lists.gnu.org/mailman/listinfo/help-bison




reply via email to

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