LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-13-2011, 09:49 AM   #1
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Lex and YACC C++ namespace issue


I have a C++ library project, and it includes a Lex lexer and a YACC parser. Everything in the project is under a common namespace, with some parts in other namespaces under that. I want all the code generated by Lex and YACC to be under the namespace "lexyacc" under the common namespace.

I did it by putting these lines in the header parts of the Lex and YACC files:

Code:
namespace LANG_NAMESPACE { namespace lexyacc {
Tge problem is that when compiling, the code generated by Lex and YACC throws a huge about of errors about using types that don't exist (even though their header files are included). What do I do?

EDIT: here's a snippet from YACC's output:

Code:
/* Line 189 of yacc.c  */
#line 1 "/home/michael/Projects/lang/lib/yacc_parser.y"

	#include "config.hh"
	#include "node_call_param_list.hh"
	#include "node_func_param_list.hh"
	#include "nodes.hh"
	#include <iostream>
	#include "y.tab.hh"
	namespace LANG_NAMESPACE { namespace lexyacc {
	
	int yylex();
	void yyerror(char*);
	FILE *input;
	extern char *yytext;
	
	char *__parser_filename__;
	int __parser_line__;


<snip>

#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
{

/* Line 214 of yacc.c  */
#line 19 "/home/michael/Projects/lang/lib/yacc_parser.y"

	Node *node;
	NodeFuncParamList *fParam;
	NodeCallParamList *cParam;
	char *str;
	struct {
		char *name;
		Node *node;
	} nameNodePair;



/* Line 214 of yacc.c  */
#line 179 "/home/michael/Projects/lang/build/lib/y.tab.cc"
} YYSTYPE;
First is says "#include "nodes.hh"", and then it uses Node in the declaration of YYSTYPE. Tell me, how could Node possibly not have been defined?

Last edited by MTK358; 04-13-2011 at 01:22 PM.
 
Old 04-13-2011, 02:18 PM   #2
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by MTK358 View Post
Code:
namespace LANG_NAMESPACE { namespace lexyacc {
Did you remember to add the extra closing "}" for each name space?

I would suggest creating the smallest file that can duplicate the problem and posts the entire contents here. I was unable to understand what was going on in the small piece you posted.
 
Old 04-13-2011, 02:42 PM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by David1357 View Post
Did you remember to add the extra closing "}" for each name space?
Of course.

Quote:
Originally Posted by David1357 View Post
I would suggest creating the smallest file that can duplicate the problem and posts the entire contents here. I was unable to understand what was going on in the small piece you posted.
Not really. This is purely a Lex/YACC issue. This kind of thing never happens when I write code manually.
 
Old 04-13-2011, 03:49 PM   #4
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Here are the Lex and YACC files, if that helps:
Attached Files
File Type: txt stuff.tar.xz.txt (1.7 KB, 44 views)
 
Old 04-14-2011, 02:07 PM   #5
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
I fixed it by explicitly specifying the namespaces in %union.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
lex and yacc aarsh Linux - Software 3 01-03-2011 08:58 AM
does ubuntu have lex and yacc,how to use them?? akshay_jp Linux - Software 4 05-26-2010 06:36 PM
LEX and YACC with C gr33ndata Programming 4 11-18-2007 05:12 PM
Lex and Yacc on Federo 2.0 vivekian Fedora 6 05-20-2006 09:09 AM
Lex and Yacc on Mandrake 9.2.2 Anuradha Linux - Software 0 07-02-2005 03:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration