help-bison
[Top][All Lists]
Advanced

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

grammar problem


From: Steffen Schuemann
Subject: grammar problem
Date: Wed, 6 Mar 2002 13:49:28 +0100

Hello!

I'm trying to implement a language, which was formerly parsed by a
handmade interpreter. There are some flaws in the syntax. Some of
them exist due to the fact that the language is mixed with another
one and so has to adopt some rules.

Problems arise from the following base rules of the language:

* The language is normally line oriented

* It is possible to combine statements on one line by seperating them
  with a colon (':')

* Parameters of commands are seperated by whitespace (not newline),
  therefore expressions are not allowed to contain whitespace

* Control statements have their substatements enclosed in curly
  brackets

* Only at those brackets, newlines are allowed to break up control
  statements for better readability

At the moment I'm fighting a problem with 'if' statements, so here
is some hoepefully relevant cut down of my grammer (comments are not
in the real source):


stmtblk
    : '{' olb stmtlist olb '}'
    ;

stmtlist
    :
    | stmtseq
    ;

stmtseq
    : stmt
    | stmtseq ':' stmt
    | stmtseq lnbrk stmt
    | stmtseq lnbrk
    ;

stmt
    : expr
    | selstmt
    ;

selstmt
    : CMD_IF expr olb stmtblk
    | CMD_IF expr olb stmtblk olb CMD_ELSE olb stmtblk
    ;

olb             /* This rule shoul handle optional line breaks */
    :
    | lnbrk
    ;

lnbrk
    : NEWLINE
    | lnbrk NEWLINE
    ;

 
My (actual) problem is, that this grammar accepts 'if'/'else'
combinations, but rejects a pure 'if' in code like

{
  if 26+2>27
  {
     do stuff
  }
  do more stuff
}

because after '}' it matches an 'NEWLINE', reduces to 'olb' and
thinks it has to be the 'if'/'else' rule. I hoped the matched NEWLINE,
also allowed through rule 'stmtseq lnbrk stmt' without following 'else'
would reduce to 'stmtseq'.

I played around some hours with the grammar and searched some books and
search engines, but I wasn't able to come up with a solution.

Is it possible?

(I fear the moment where I come to the whitespace problem with args
and expressions, but that is another story ;-))

Thanks for help in any directions.

                    Steffen Schuemann




reply via email to

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