help-bison
[Top][All Lists]
Advanced

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

Re: Resolving shift/reduce conflict in Bison grammar


From: Panayiotis Karabassis
Subject: Re: Resolving shift/reduce conflict in Bison grammar
Date: Sat, 31 Jul 2010 17:23:45 +0300
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.10) Gecko/20100620 Icedove/3.0.5

Hi!

Use the -v (verbose) flag on bison to generate the xxx.output file that contains more information about the parser automaton (including where the conflicts appear). Then please post it here.

You may also want to read the debugging section from:

info bison

Regards,
    Panayiotis

On 07/31/2010 04:54 PM, anandvn wrote:
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




reply via email to

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