bug-bison
[Top][All Lists]
Advanced

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

Bison 3.0.2 - "bison -d Grammar.y" generates duplicate entries in the YY


From: Hammad Rauf
Subject: Bison 3.0.2 - "bison -d Grammar.y" generates duplicate entries in the YYSTYPE union (In Header file only)
Date: Mon, 24 Nov 2014 07:16:37 -0500

Hi,

Bison is generating duplicate entries the union in header "basava.tab.h".

My grammer is listeted below, and also attached in the attached Zip file.

Thanks,

Hammad Rauf

-----
Basava.tab.h (Excrept Only)

-------

union YYSTYPE
{

#line 102 "basava.tab.h" /* yacc.c:1909  */
  /* CHAR_LITERAL  */
  char CHAR_LITERAL;
  /* STRING_LITERAL  */
  char * STRING_LITERAL;
  /* DOUBLE_LITERAL  */
  double DOUBLE_LITERAL;
  /* num_exp  */
  double num_exp;
  /* LONG_LITERAL  */
  long LONG_LITERAL;
  /* CHAR_LITERAL  */
  char CHAR_LITERAL;
  /* STRING_LITERAL  */
  char * STRING_LITERAL;
  /* DOUBLE_LITERAL  */
  double DOUBLE_LITERAL;
  /* num_exp  */
  double num_exp;
  /* LONG_LITERAL  */
  long LONG_LITERAL;
};

----

Grammar "Basava.y".( $ bison -d basava.y)

---

%{
#include <stdio.h>     /* C declarations used in actions */
#include <stdlib.h>
//extern char yytext[];
extern int column;
extern int yylex();      // the scanner routine - returns one token (int) a
time
extern int yylineno;     // Line no for debugging messages
extern char* yytext;

void yyerror (const char *s);
//int symbols[52];
//int symbolVal(char symbol);
//void updateSymbolVal(char symbol, int val);
%}

/* Yacc definitions */
%define api.value.type union     /*   Generate YYSTYPE from these types */
/*%union
{
    char char_literal;
    char* string_literal;
    double double_literal;
    long long_literal;
}
*/
%token IDENTIFIER
%token PROGRAM
%token INT FLOAT CHAR STRING
%token B_BEGIN B_END S_TERMINATOR
%token VOID MAIN
%token IF ELSE DO WHILE GOTO
%token ELLIPSIS RIGHT_ASSIGN LEFT_ASSIGN
%token ADD_ASSIGN SUB_ASSIGN MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN
%token AND_ASSIGN XOR_ASSIGN OR_ASSIGN RIGHT_OP LEFT_OP
%token INC_OP DEC_OP PTR_OP AND_OP OR_OP LE_OP GE_OP EQ_OP NE_OP
%token TYPEDEF_NAME ENUMERATION_CONSTANT
%token <long> LONG_LITERAL
%token <double> DOUBLE_LITERAL
%token <char> CHAR_LITERAL
%token <char *> STRING_LITERAL
%type <double> num_exp
%start basava

%%

/* descriptions of expected inputs     corresponding actions (in C) */

basava:
            PROGRAM IDENTIFIER '{' body '}' {exit(EXIT_SUCCESS);}
| error ';'   { exit(EXIT_FAILURE); }
| error '}'   { exit(EXIT_FAILURE); }
;

body:
            %empty   { ;}
            | body line
            ;
line:
            ';'
            | num_exp ';'
            ;

num_exp:
            DOUBLE_LITERAL          { $$ = $1; }
            | LONG_LITERAL          { $$ = $1; }
            ;


%%                     /* C code */
/*
int computeSymbolIndex(char token)
{
int idx = -1;
if(islower(token)) {
idx = token - 'a' + 26;
} else if(isupper(token)) {
idx = token - 'A';
}
return idx;
}

// returns the value of a given symbol
int symbolVal(char symbol)
{
int bucket = computeSymbolIndex(symbol);
return symbols[bucket];
}

// updates the value of a given symbol
void updateSymbolVal(char symbol, int val)
{
int bucket = computeSymbolIndex(symbol);
symbols[bucket] = val;
}


int main (void) {
printf("Sizeof Unsigned Int: %d\n",sizeof(unsigned int));
return yyparse ( );
}
*/

void yyerror (const char *s) {
fflush(stdout);
fprintf(stderr, "*** %s. Line: %d, Column: %d\n", s, yylineno, column);
fprintf(stderr, "**** Problem Word: %s\n", yytext);
}



---------

Attachment: Basava.zip
Description: Zip archive


reply via email to

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