[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Resolving shift/reduce conflict in Bison grammar
From: |
anandvn |
Subject: |
Resolving shift/reduce conflict in Bison grammar |
Date: |
Sat, 31 Jul 2010 06:54:41 -0700 (PDT) |
Hi,
Could any one please help me in resolving the shift/reduce in the following
grammar?
%{
#include <stdio.h>
extern char yytext[];
extern int column;
void yyerror(char const *s);
%}
%union
{
unsigned int tokVal;
unsigned char *tokValStr;
}
/* C operators */
%token <tokVal> STATIC CONST VOLATILE EXTERN INT UNSIGNED VARNAME EQUAL
COLON OP_BRACE CL_BRACE IDENTIFIER
%type <tokVal> declaration translation_unit declaration_specifiers
storage_class_specifier type_specifier type_qualifier init_declarator_list
/* Parsing starts with this transalation unit */
%start translation_unit
%%
translation_unit
: external_declaration
| translation_unit external_declaration
;
external_declaration
: function_definition
| declaration
;
function_definition
: declaration_specifiers declarator compound_statement
;
declarator
: IDENTIFIER
;
compound_statement
: OP_BRACE CL_BRACE
;
declaration
: init_dec declaration_specifiers COLON
| init_dec declaration_specifiers init_declarator_list COLON
;
init_dec
: {printf("*** Process for Initialization ***\n\n");}
init_declarator_list
: EQUAL VARNAME
;
declaration_specifiers
: storage_class_specifier
| storage_class_specifier declaration_specifiers
| type_specifier
| type_specifier declaration_specifiers
| type_qualifier
| type_qualifier declaration_specifiers
;
storage_class_specifier
: EXTERN
| STATIC
;
type_specifier
: INT
| UNSIGNED
;
type_qualifier
: CONST
| VOLATILE
;
%%
void yyerror(char const *s)
{
fflush(stdout);
printf("\n%*s\n%*s\n", column, "^", column, s);
}
In the rule "declaration", I want to perform initalization activities using
the empty rule "init_dec" (original code here
http://old.nabble.com/file/p29313133/Test.zip Test.zip ). But i'm getting
shift/reduce conflict. Since I'm new to this bison, i need help from you to
resolve this conflict. I tried by i felt very difficult.
Thanks
Anand V
--
View this message in context:
http://old.nabble.com/Resolving-shift-reduce-conflict-in-Bison-grammar-tp29313133p29313133.html
Sent from the Gnu - Bison - Help mailing list archive at Nabble.com.
- Resolving shift/reduce conflict in Bison grammar,
anandvn <=