Hi

I started learning flex/bison some days ago to write a parser. Nearly
all my parser works well, but I've a problem with a rule which matches
well but gives a wrong result in $n. I checked the lexer (flex) did
extract right token. The input is like this:

action close shell:Shell

'action' is a keyword, 'close' too (an option), 'shell' is an
identifier, ':' the identifier separator and 'Shell' a label. I
provided a testset, but to resume, here's what happen:

The syntax is:

action close|okcancel [help] [<button id>:<button text>]

The production rules and defiinition for this kind of line is (DPRINT
is a macro'ed printf) like this:

%token ACTION ACTION_CLOSE ACTION_OKCANCEL OPTION_HELP
%token STRING QSTRING ID

action_line:
        ACTION
        { DPRINT(("* add an action line\n")); }
        action_type action_help_button action_add_button
        ;

action_type:
        ACTION_CLOSE
        { DPRINT(("  - close button\n")); }
        | ACTION_OKCANCEL
        { DPRINT(("  - ok and cancel buttons\n")); }
        ;

action_help_button:
        /* empty */
        | OPTION_HELP
        { DPRINT(("  - help button\n")); }
        ;

action_add_button:
        /* empty */
        | ID
        { DPRINT(("new button id: %s\n", $1)); }
        ':' string
        { DPRINT(("  - additional button #%s '%s'\n", $1, $4));
          DPRINT(("id separator: %s\n", $<str>3)); }
        ;

And string is defined like this (QSTRING refers to quoted strings):

string:
        STRING
        | QSTRING
        ;

The result is perturbing, because in the action_add_button rule, I
have this behaviour:

action_add_button:
        /* empty */
        | ID
        { DPRINT(("new button id: %s\n", $1)); }
>>> $1 = 'shell' ($1 is ok for now)
        ':' string
        { DPRINT(("  - additional button #%s '%s'\n", $1, $4)); }
>>> $1 = 'shell:Shell' (should be 'shell')
>>> $3 = 'shell:Shell' (should be ':')
>>> $4 = 'Shell' (this one is ok)
        ;

To use the test set:

tar zxf testset.tar.gz
cd testset
make
cat test.nds | ./ndlg

I enabled debug output for flex (-d).

Anyone has an idea ?
Regards

-- 
Richard 'riri' GILL
jabber: [EMAIL PROTECTED]
http://riri.houbathecat.info
http://nasgaia.org
« Frimousse en excessivité émousse son expressivité »

Attachment: testset.tar.gz
Description: GNU Zip compressed data

_______________________________________________
[email protected] http://lists.gnu.org/mailman/listinfo/help-bison

Reply via email to