bug-bison
[Top][All Lists]
Advanced

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

Re: Strange behavior


From: Laurent Deniau
Subject: Re: Strange behavior
Date: Mon, 29 Mar 2004 09:34:02 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031107 Debian/1.5-3

Hans Aberg wrote:
At 12:35 +0100 2004/03/25, Laurent Deniau wrote:

I am using Bison 1.35 and 1.875 to parse the ISO C99 grammar and I found
a strange behavior on a very simple case:


This is not really a Bison question, but a question of implementing a
language using the LALR(1) parsing algorithm. As your language is
well-known, it might be worthwhile asking around in the newsgroup
comp.compilers, or in some of the C newsgroups to see if somebody already
has done it. Some C compilers might already have it (GNU C?).

My question has nothing to do with the C99 grammar. It was just to fix the background, nothing more.

Also, it is really a Help-Bison <address@hidden>, question, not a
Bug-Bison question.


If I use the rule:

direct_abstract_declarator
 : '(' abstract_declarator ')'
 | direct_abstract_declarator_opt '[' assignment_expression_opt ']'
 | direct_abstract_declarator_opt '[' '*' ']'
 | '(' parameter_type_list_opt ')'
 | direct_abstract_declarator '(' parameter_type_list_opt ')'
 ;

I have only one shift/reduce conflict for all the grammar (the IF ELSE
one). But if I use the rule


You can resolve the dangling else problem by setting token precedences on
the THEN and ELSE tokens (using say %nonassoc).

This is what I use. But before dealing with precedence, I wanted to remove all the shift/reduce I had except the well know IF ELSE one.

 In C, one should probably
set a precedence on ")" then.

Tip: It is might be better to avoid the single quote ')' constructs, and
instead use
%token LP "("
%token RP ")"
...
%%
...>direct_abstract_declarator
   : "(" abstract_declarator ")"

Using string here is quite dangerous since you replace the character ASCII value by a string literal address. No a good idea...

Then your Flex grammart must have lines
"("   { return RP; }
etc.

Nothing about my question?

Thanks.

ld.





reply via email to

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