Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!mcvax!kth!sunic!dkuug!iesd!fischer From: fischer@iesd.dk (Lars P. Fischer) Newsgroups: comp.lang.c++ Subject: Re: Using OO Languages for Compilers/Interpreters Message-ID: <1706@iesd.dk> Date: 12 Apr 89 00:13:25 GMT References: <16915@cup.portal.com> <3690007@wdl1.UUCP> Sender: fischer@iesd.dk Organization: Dept. of Computer Science, University of Aalborg Lines: 41 In-reply-to: rme@wdl1.UUCP's message of 11 Apr 89 23:26:16 GMT In article <3690007@wdl1.UUCP> rme@wdl1.UUCP (Richard M Emberson) writes: > A small (but by far the most important point) has been missed. > Simply to have yacc or bison produce C++ code is not important, > but what is important is that their outputs are c++ classes. > This allows one to have multiple bnf grammers in the same > executable. (Try linking the output of two yacc grammers in the > same program - the yacc/bison drivers don't allow multiple > grammar tables). From the BISON manual: Most programs that use Bison parse only one language and therefore contain only one Bison parser. But what if you want to parse more than one language with the same program? Here is what you must do: * Make each parser a pure parser (*note Pure Decl::.). This gets rid of global variables such as `yylval' which would otherwise conflict between the various parsers, but it requires an alternate calling convention for `yylex' (*note Pure Calling::.). * In each grammar file, define `yyparse' as a macro, expanding into the name you want for that parser. Put this definition in the C declarations section (*note C Declarations::.). For example: %{ #define yyparse parse_algol ..... The same could be done for (f)lex. This is not to say that a C++ parser object would be a bad thing, only to point out that it can be done with ordinary function, and that bison can do it, now. /Lars -- Copyright 1989 Lars Fischer; you can redistribute only if your recipients can. Lars Fischer, fischer@iesd.dk, {...}!mcvax!iesd!fischer Any sufficiently advanced technology is indistinguishable from magic. -- Arthur C. Clarke