Joel E. Denny ha scritto:
On Fri, 19 Jun 2009, Ewa Rom wrote:
%{
int yylex();
void yyerror(char *s);
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <fstream>
#include <windows.h>
#include <Shellapi.h>
#include "parser.hpp"
#include "resource.h"
nodeType *v(char s);
nodeType *in(int i);
nodeType *oper(char s,nodeType l,nodeType r);
void printToFile(char *s);
using namespace std;
%}
>From the above block, try moving everything that the %union below depends
upon to a %code requires. I believe that's just:
%code requires {
#include "resource.h"
}
This is right.
%union {
int iValue;
char sIndex;
nodeType *nPtr;
}
flex -olex.cpp CoProveLexer.lex
bison -v -d --language=C++ -oparser.cpp CoProveParser.y
Which generates me lex.cpp parser.cpp and parser.hpp files that I have
included into my Visual C++ project.
Then I try to build the project and I get the following error:
1>CoProveParser.y(28) : error C2143: syntax error : missing ';' before '*'
1>CoProveParser.y(28) : error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
1>CoProveParser.y(28) : error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
It seems like the %union does not know about the definition of the
nodeType structure defined in the resource.h file even if I include it
in the first part of the y file enclosed by %{ %}
%{ %} does not generate code into the parser.hpp file. Based on the
information you've provided, I believe that's the problem you've
encountered. If so, the %code suggestion I gave above should fix it.
In general, you ought to consider using %code instead of the old %{ %} to
avoid these kinds of issues. See the %code entries in the section "Bison
Declaration Summary" in the Bison manual for a summary of its
functionality. See the section "Prologue Alternatives" for a detailed
discussion including the advantages of %code over %{ %}.
However, %code is not available in Bison 2.3a and earlier, so your
grammars would only work with more recent versions of Bison.
In this case, you have always to include "resource.h" BEFORE y.tab.h.
You can put them in a common header.
If
compatibility is a concern for you, we can discuss other solutions, but
please try %code first to see if that fixes your problem.
_______________________________________________
help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison
_______________________________________________
help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison