Reputation: 27
I'm getting this problem "%Header is not a valid directive".
This is the .y :
%header{
#include "yystype.h"
#include<stdio.h>
#include"analex.h"
extern int yylex(void);
extern char *yytext;
extern int linea;
extern FILE *yyin;
void yyerror(const char *);
%}
%token ESCRIBIR
%token <valor> NUMERO
%type <valor> expr term fact
%define PURE
%define STYPE YY_parse_STYPE
%%
entrada : instrucciones
;
instrucciones : instruccion | instrucciones instruccion
;
instruccion : escritura
;
escritura : ESCRIBIR '(' expr ')' ';'
{printf("La expresion vale: %i\n",$3);}
;
expr : expr '+' term
{$$ = $1+$3;}
| expr '-' term
{$$ = $1-$3;}
| term {$$ = $1;}
;
term : term '*' fact
{$$=$1*$3;}
| term '/' fact
{$$ = $1/$3;}
| fact
{$$=$1;}
;
fact : '(' expr ')'
{$$=$2;}
| NUMERO
{$$=$1;}
;
%%
void yyerror(char *s)
{
printf("ERROR: (%s)\n",yytext);
}
The .l
%header{
#include "yystype.h"
%}
%{
#include <stdlib.h>
#include "anasint.h"
%}
letra [A-Za-z]
digito [0-9]
numero {digito}+
blanco [ \t\n]
%define LEX_PARAM YY_parse_STYPE *yylval
%%
{blanco}* {;}
{numero} {yylval->valor=atoi(yytext); return(NUMERO);}
escribir {return(ESCRIBIR);}
. {return(yytext[0]);}
%%
And the yystype.h
#ifndef _YYSTYPE_H
#define _YYSTYPE_H
typedef union{
int valor;} YY_parse_STYPE;
#endif
Please if someone knows what's the error here, feel free to tell me. The bison version is the 2.4.1 and flex 2.5
Upvotes: 0
Views: 515
Reputation: 5893
I think the reason you are getting the message:
"%Header is not a valid directive".
Is because "%Header is not a valid directive".
Checking the manual for flex and bison I see no %Header
directive described. It is not in the manual, it is not valid.
If you remove the text header
so that you have %{
you will no longer get the message.
I am puzzled why you thought there might be one; where did that information come from....
Upvotes: 1