I want to write a parser for C++ which can extract methods and members pertaining to a particular class(es) in a CPP file. I used Parser Generattor tool by BumbleBee softwares and did all the project settings as required by them but still keep on getting fatal errors in Exception Class(of Visual Studio 6 Library).

Is there a proper tool wherein I can integrate lex and yacc with VC++ 6.0.

Urgent Help Required. Please help

Dani AI

Generated

Brief, practical guidance for the two problems shown in this thread (the scanner/input-type mismatch and the "untyped $$" semantic-value warnings), plus a few compatibility tips that actually work when you must stay on VC++ 6.0.

The input-type mismatch

  • The generated lexer in this thread appears to use a C++ stream pointer for its input while the caller is passing a C FILE. If the scanner's header declares an std::istream input, open the source with an std::ifstream and pass its address (matching the member name in the generated header). Do not try to cast a FILE to an istream; that is undefined and will fail to compile on VC6.
  • If you cannot change call sites, regenerate or reconfigure the generator to produce a C-style interface (FILE*), or edit the generated header to expose the input type you need. Also inspect the generated header first to confirm the exact member name and type before changing code.

Example (illustrative):

#include <fstream>

std::ifstream in("file.cpp");
if (!in.is_open()) { /* handle error */ }

/* If the scanner's API expects a C++ stream pointer, pass &in.
   Replace 'scanner.inputPtr' with the actual member name from the header. */
scanner.inputPtr = &in;
parser.parse();

The "untyped $$" / semantic-value problem

  • That warning means the parser has no declared semantic value type for the productions you use with $n/$$. Define a union (or use your generator's C++-value mechanism) and tag tokens/nonterminals with their field names so $$ is typed.
  • For old toolchains avoid putting non-POD C++ objects directly into a C union; use pointers (or switch to the parser's C++ API if available).

Example Bison/Yacc sketch:

%union {
  char *sval;
  ASTNode *node;
}

%token <sval> IDENT
%type  <node> class_decl member_decl

class_decl:
    CLASS IDENT '{' member_list '}' { $$ = new ClassNode($2, $4); }
;

Additional tips

  • Check the generated header for the exact names/types (input pointer, YYSTYPE/%union) before changing code. was correct to point at a stream-vs-FILE mismatch; 's suggestion to try a more modern compiler is pragmatic—VC6 has many STL/ABI quirks. If upgrading is impossible, prefer generating C-style lex/yacc code or use pointers for semantic values to keep things compatible.

Recommended Answers

All 10 Replies

Why not code in linux/unix env?

I can't shift to Linux becoz my existing project is in VC++ 6.0 and I've to add parsing functionality to it. Hence you can see the problem here.

maybe you should contact BumbleBee. Also possible that VC++ 6.0 is too old. You might try a more current compiler such as the free VC++ 2005 Express.

Perhaps you could use the Spirit parser combinator library instead.

Well the problem is not with Bumblebee. When I used a sample project from then also I faced the same error as mentioned below.

error C2440: '=' : cannot convert from 'struct _iobuf *' to 'class std::basic_istream<char,struct std::char_traits<char> > *'

for the code line

FILE   *temp,
         *f;
lexer.yyin = f;

lexer is the object of the class CLexRC wherein CLexRC loks like this in first line of the class

class YYEXPLEXER YYFAR CLexRC : public _YL yyclexer {

please help.

It's assigning an uninitialized FILE* to another value? There's something wrong with that picture. Anyway, it looks like the yyin member is of type std::basic_istream<char, struct std::char_traits<char> >*, and the code is trying to assign a FILE* to it. At least, that's what the error message says.

so how to type cast it. I'm understanding the error but as a matter of fact the CPP file is not manually written. it gets generated by Bumblebee Parser Generator. I saw this kind of file stream assignment to most of the projects

What shall I do ?:sweat:

I'm now able to run lex files fine but while utilizing the yacc stack descriptors like '$$' it is giving the following error:

warning Y4003: '$$' : attribute is untyped

thought this is a warning now. If I'm assigning anything to it or trying to use string copy then it is throwing an error.

please help.

please help. I'm not able to $$ at all. the error Untyped Attribute is repeated at any case.

PLease help me it is kind of urgent.

Member Avatar for Member #46692

Urgent, I'm sure. Maybe you should have started your homework earlier. He he.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.