Code:
typedef union 
{
  int ival;
  char *sval;
} YYSTYPE;
;

compiler error says too many in declration. do you know how is that happening?

actually, i'm working on YACC and LEX right now, so if ever you are knowledgeable about that, then you must already know that. The code above is contained in YYTAB.H. My yacc file contains the following union code:

Code:
%union
{
  int ival;
  char *sval;
}
well, i really don't know why it is having an error regarding too many different types in union. as far as i know (and from what online tutorials say), that's how you create a union for your yyval.

anyways, if you are indeed good at lex and yacc, then you may view these codes:

lex file
[hide]
Code:
%{
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "yytab.h"

static int line=1;
%}

comment_single  "//".* 
comment_multi   "%%"([^%]|\n)*"%%"

letter	[a-zA-Z]
digit	[0-9]
alphanum {letter}|{digit}

esc \\([abfnrtv'?\\]|(o|O)[0-7]{1,3}|(x|X)[0-9A-F]{1,2}) 

whitespace [ \t\r]
newline [\n]
others 	.

%%

character                   {return CHARACTER;}  
if                          {return IF;}
continue                    {return CONTINUE;}
function                    {return FUNCTION;}
integer                     {return INTEGER;}
else                        {return ELSE;}
break                       {return BREAK;}
begin_t                     {return BEGIN_T;}
string                      {return STRING;}
while                       {return WHILE;}
return                      {return RETURN;}
end                         {return END;}
let                         {return LET;}
for                         {return FOR;}
void                        {return VOID;}
repeat                      {return REPEAT;}
to                          {return TO;}
by                          {return BY;}

"+"       					{return ADDOP;}
"-"       					{return ADDOP;}
"*"       					{return MULTOP;}
"/"       					{return MULTOP;}

and       					{return AND;}
or       					{return OR;}
not       					{return NOT;}

"=="       					{return RELOP;}
"<"       					{return RELOP;}
">"       					{return RELOP;}
"<="       					{return RELOP;}
">="       					{return RELOP;}
"!="       					{return RELOP;}

"<--"      					{return ASSIGN;}

","       					{return COMMA;}
":"       					{return COLON;}
"("       					{return OPENPAREN;}
")"       					{return CLOSEPAREN;}
"["       					{return OPENSQUARE;}
"]"       					{return CLOSESQUARE;}


0|[1-9]{digit}*|(([1-9]{digit}*)?|0)\.{digit}{1,6}   {return INTLITERAL;}

\'([^'\\]|{esc})?\'                {return CHARLITERAL;}
\"([^"\\\n]|{esc})*\"              {return STRINGLITERAL;}

({letter}|"_")({alphanum}|"_")*    {yylval.sval=strdup(yytext); return IDENTIFIER;}

{whitespace}+                      {;}

{newline}       {line++;}

%%
[/hide]

yacc file
[hide]
Code:
%{
#define YYSTYPE int
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "lexyy.c"

  extern int line;
  
  static int symbol_value[1024];
  static char symbol_table[1024][33];
  static int symbols = 0;
  
  void yyerror(char * s);
  void print_error(char * s);
  int add_sym(char * name);
  int get_sym_idx(char * name);
  int get_sym_val(int idx);
  void save_sym_val(int idx, int value);
%}

%union
{
  int ival;
  char *sval;
}

%token CHARACTER INTEGER STRING FUNCTION BEGIN_T END LET
%token IF ELSE WHILE FOR CONTINUE REPEAT BREAK RETURN VOID TO BY

%token INTLITERAL CHARLITERAL STRINGLITERAL
%token ADDOP MULTOP RELOP AND OR NOT
%token COMMA COLON OPENPAREN CLOSEPAREN OPENSQUARE CLOSESQUARE ASSIGN
%token <sval> IDENTIFIER

%start varDecl

%%

varDecl 	
    : LET varDefn
    ;

varDefn	
    : varDefn COMMA varList COLON type
    | varDefn COMMA varList COLON error {print_error("Invalid type!");}
    | varList COLON type
    | varList COLON error {print_error("Invalid type!");}
	  ;

varList 
    : varList COMMA var
    | var
    ;

type 
    : INTEGER
    | CHARACTER
    | STRING
    ;

var 	
    : array
    | IDENTIFIER varInit {add_sym($1);}
    | error varInit {print_error("Invalid ID of non-array!");}
    ;

array	
    : IDENTIFIER OPENSQUARE INTLITERAL CLOSESQUARE arrayInit {add_sym($1);} 
    | IDENTIFIER OPENSQUARE error CLOSESQUARE arrayInit {print_error("Array index must be INTEGER!");}
    | error OPENSQUARE INTLITERAL CLOSESQUARE arrayInit {print_error("Invalid ID of array!");}
    ;

arrayInit	
    : ASSIGN OPENPAREN literalList CLOSEPAREN
    | ASSIGN OPENPAREN error CLOSEPAREN {print_error("Invalid literal list inside the parenthesis!");}
    | ASSIGN STRINGLITERAL 
    | ASSIGN error {print_error("Assigned value must be STRINGLITERAL!");}
    | 
    ;

varInit 	
    : ASSIGN literal
    | ASSIGN error {print_error("Invalid literal in assignment!");}
    |
	  ;
	
literalList 	
    : literalList COMMA literal
    | literal
    ;

literal 	
    : INTLITERAL
    | CHARLITERAL
    | STRINGLITERAL
    ;
	
%%

  int main(void)
	{
	yyin=fopen("input.txt", "rt");
	yyout=fopen("output.txt", "wt");
	yyparse();
	return 0;
	}
	
	void yyerror(){
	}
	
	void print_error(char *s) /*Error reporting function*/
  {
	fprintf(stdout, "Line: %d : Error:%s\n",line,s);
  }
  
  int find_symbol(char * name)
  {
    int i;
    for (i = 0; i < symbols; i++)
	     if (strncmp(name, symbol_table[i], 32) == 0)
	         break;
    if (i == symbols)
	       i = -1;
	  else
	     print_error("Redeclaration of ID!");
    return i;
  }

  int add_sym(char * name)
  {
    int i = find_symbol(name);
    if (i < 0) {
	   i = symbols++;
	   strncpy(symbol_table[i], name, 32);
    }
    printf("u%s\n", name);
    return i;
  }

  int get_sym_idx(char * name)
  {
    return find_symbol(name);
  }

  int get_sym_val(int idx)
  {
    return symbol_value[idx];
  }

  void save_sym_val(int idx, int value)
  {
    symbol_value[idx] = value;
  }
[/hide]

yytab.h result
[hide]
Code:
typedef union 
{
  int ival;
  char *sval;
} YYSTYPE;
extern YYSTYPE yylval;
#define CHARACTER 257
#define INTEGER 258
#define STRING 259
#define FUNCTION 260
#define BEGIN_T 261
#define END 262
#define LET 263
#define IF 264
#define ELSE 265
#define WHILE 266
#define FOR 267
#define CONTINUE 268
#define REPEAT 269
#define BREAK 270
#define RETURN 271
#define VOID 272
#define TO 273
#define BY 274
#define INTLITERAL 275
#define CHARLITERAL 276
#define STRINGLITERAL 277
#define ADDOP 278
#define MULTOP 279
#define RELOP 280
#define AND 281
#define OR 282
#define NOT 283
#define COMMA 284
#define COLON 285
#define OPENPAREN 286
#define CLOSEPAREN 287
#define OPENSQUARE 288
#define CLOSESQUARE 289
#define ASSIGN 290
#define IDENTIFIER 291
[/hide]