Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!know!zaphod.mps.ohio-state.edu!usc!apple!snorkelwacker!husc6!spdcc!esegue!compilers-sender From: meissner@osf.org Newsgroups: comp.compilers Subject: Re: Two pass compiler using YACC? Keywords: yacc, design, parse Message-ID: <9008271732.AA20407@curley.osf.org> Date: 27 Aug 90 17:32:01 GMT Sender: compilers-sender@esegue.segue.boston.ma.us Reply-To: meissner@osf.org Organization: Compilers Central Lines: 35 Approved: compilers@esegue.segue.boston.ma.us In-Reply-To: bart@videovax.tv.tek.com's message of 25 Aug 90 04:41:58 GMT In terms of ways of having two or more parsers within a program, one way that I haven't seen mentioned is the way I did it when implementing Data General's AOS/VS C compiler. I implemented the compiler and preprocessor as one integrated program, and was left with the decision on how to handle #if. I didn't particularly want to have two sets of parser tables in the compiler, because of difficulities in convincing the parser generator to cooperate (this was a home grown parser generator that had it's own share of problems). The solution I came up with was to make the top level rule, something like: top: grammar1 | SPECIAL_TOKEN grammar2 ; That is, having the lexer spit out a special token to go to second grammar rather than the first. Of course if you have a recursive parser (such as my case processing #if's within the normal handling of the grammar), you have to save all of the parser state and restore it when you exit the parser. Given that the parser generator I used just spit out the tables, and I had to write the parser skeleton, it was easy to do. With YACC where the skeleton is provided for you, and it doesn't support multiple grammars like BISON does, you have some work to do.... -- Michael Meissner email: meissner@osf.org phone: 617-621-8861 Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142 [Good point, I once did that too. Making yacc support recursive parsing isn't very hard, you just have to make a bunch of static arrays and variables automatics. -John] -- Send compilers articles to compilers@esegue.segue.boston.ma.us {ima | spdcc | world}!esegue. Meta-mail to compilers-request@esegue.