delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/18/03:56:57

From: george AT george DOT org (Babylon7)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: HELP: Bison, Flex & C++ class support...
Date: Fri, 18 Apr 1997 03:13:40 GMT
Organization: Erol's Internet Services
Lines: 65
Message-ID: <335ce6e1.25872643@news.erols.com>
References: <97Apr17.164001gmt+0100 DOT 21892 AT internet01 DOT amc DOT de>
NNTP-Posting-Host: spg-as25s25.erols.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Thu, 17 Apr 1997 14:42:15 GMT, Chris Croughton <crough45 AT amc DOT de>
wrote:

>I haven't managed to get the C++ lexer class to work (or even compile).
>I think that what the original message was asking about was compiling
>the non-class lexer as C++ rather than creating a lexer class.

	exactly... to keep with lex and yacc compatibility

>The answer is that it can be done, but you have to add some
>declarations to make sure that everything is in the right form.
>Basically, this means making sure that functions are declared 
>before they're used, which is essential in C++ although it often
>doesn't matter in C (and therefore bison in particular is rather
>lax about declaring functions, often using the old K&R declarations
>to be compatible with old compilers).
>
>In this case, I added the following:
>
>At the top of cplus.y:
>
>  int yylex(void);
>
>At the top of cplus.l:
>
>  int yyerror(char *x);
>
>(both times within the %{ %} block).  That solved the problems
>
>Chris

	OK... problem solved :)

	hehe now my symbol table class works.
	iostream functions working.

I included the following file in both cplus.l and cplus.y

/////////////////////////////////////////////////
//
//     header.h
//

#include <iostream.h>
int yylex();
int yyerror( char* );


I altered cplus.l as follows:

%{
#include	"header.h"
#include	"y_tab.h"
%}


I altered cplus.y as follows:

%{
#include	<stdio.h>
#include	<math.h>
#include	<string.h>

#include	"header.h"
%}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019