help-bison
[Top][All Lists]
Advanced

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

text is not parsed correctly due to shift/reduce conflict


From: Guenther Sohler
Subject: text is not parsed correctly due to shift/reduce conflict
Date: Sat, 24 Jul 2021 16:34:15 +0200

Hi Folks,

When trying to code a c language parser I got a issue with shift/reduce
conflict in bison, which actually hurts me.

It happens when parsing this:

int main( int a,[XXX] int b)

[XXX] is the pointer of the issue:
When reading the comma it does not know wether to continue iterating in
vardeclarationlist or in identifierlist.
If the software looked one token ahead to see if after the ',' there is a
type it should proceed iterating the vardeclarationlist, else proceed with
the identifierlist.
How can i improve my situation ?

best regards Günther

Rules below



my rules are like this:

functiondefinition:
type_ptr identifier '(' vardeclarationlist ')' compound_statement ;

vardeclarationlist :
vardeclaration |
vardeclarationlist ',' vardeclaration  ;
example: int a, int b=2

vardeclaration:
type_ptr identifierlist  ;
example: int *b

identifierlist :
identifierwithdefault |
identifierlist ',' identifierwithdefault

identifierwithdefault:
identifier |
identifier '=' expression |
identifier '[' INTNUM ']'


type_ptr :
type_ptr '*' |
type ;
example: int


reply via email to

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