help-bison
[Top][All Lists]
Advanced

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

How to get rid of "expecting" message?


From: Arijit Das
Subject: How to get rid of "expecting" message?
Date: Thu, 9 Aug 2007 11:11:54 +0530

Greetings All,

I have a Bison defined Parser on which if I am feeding:

block ral_top {
        bytes 1
        field fld1
        field fld2
}

And the parser definition looks somewhat like this:

global_block_definition
    : BLOCK IDENTIFIER '{' block_properties '}'


block_properties
    : block_property
    | block_properties block_property
    ;

block_property
        : BYTES INTEGER
                {
                        /* .. Some code ...*/
                }

        | REGISTER IDENTIFIER
                {
                        /* .. Some code ...*/
                }

        |       { 
                        /* ...some code...*/ 
                }
         constraint_definition
                {
                        /* ... some more code ... */
                }
        ;

constraint_definition
    : CONSTRAINT IDENTIFIER
        {
                /* .. Some code ...*/
        }
      '{'  constraint_body '}'
    ;


Lets assume for this analysis, flex will generate tokens like this:

"block" will generate BLOCK token
"field" will generate FIELD token
"register" will generate REGISTER token
"bytes" will generate BYTES token
"1" will generate INTEGER token
"fld1", "fld2" and "ral_top" will generated IDENTIFIER


If you notice, in the above-shown Bison code, you will see that FIELD
token is not allowed inside the BLOCK. So, an error message should be
spitted for this example. And so, the following msg is coming:

syntax error, unexpected FIELD, expecting CONSTRAINT

ISSUE: The first part of the error message i.e. "syntax error,
unexpected FIELD" is perfect. But the 2nd part i.e. "expecting
CONSTRAINT", doesn't make sense in my application's context. Why is that
coming by the way? Where did I specify that?

A better message in the 2nd part would have been: ", expecting REGISTER"

Question:
        1) How can I instruct Bison to get me ", expecting REGISTER" as
the 2nd part of its error message?
        2) If there is no way I can achieve (1), is there is any way I
can suppress the 2nd part of the message i.e. I want only " syntax
error, unexpected FIELD" as my entire error message.

I can hack the generated C code for achieving all these, but I was just
wondering, if Bison has its own/better way of achieving this.

Thanks for your time,

Regards,
Arijit




reply via email to

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