1

I cannot seem to resolve the ambiguity contained in the following rule:

InitializerList_a →,[Initializer][InitializerList_a]

It is causing a shift/reduce conflict in my parser (I'm using Bison). The following is its closure:

InitializerList_a → ε

Initializer → [Constant]

Initializer → {[InitializerList][Initializer_a]

Initializer_a → }

Initializer_a → ,}

InitializerList → [Initializer][InitializerList_a]

Any help would be appreciated. I can post the bison output file if needed.

Here is the same grammar written in a more readable way:

L → IT

T → ,IT | ε

I → [Constant] | {LA

A → } | ,}

where [Constant] is a terminal
too honest for this site
  • 12,050
  • 4
  • 30
  • 52

1 Answers1

0

This should cover it. YACC like grammars prefer head recursion over tail recursion in the grammar.

%start I
%token CONSTANT
%%
I: CONSTANT | '{' L '}' ;
L: J | J ',' ;
J: I | J ',' I ;
jxh
  • 69,070
  • 8
  • 110
  • 193
  • Thank you but which non-terminal from the original grammar does J correspond to? Or is it a new non-terminal? – Jarri Abidi Apr 14 '16 at 06:28
  • Probably `T`. I was just winging it. – jxh Apr 14 '16 at 06:37
  • this isn't correct.. could you try again? The grammar is for the initilization of a variable/array. e.g. i = 1 or i = { 1, 2, 3, 4 } – Jarri Abidi Apr 15 '16 at 05:45
  • Oh my apologies. I thought it wouldn't work because you didn't use one of the original non-terminals but I guess that doesn't matter. It works. Thanks! – Jarri Abidi Apr 15 '16 at 06:07