Article View: gnu.gcc.help
Article #81Two-pass frontend: hints?
From: Tor Lillqvist
Date: Wed, 08 Apr 1992 22:49
Date: Wed, 08 Apr 1992 22:49
36 lines
1996 bytes
1996 bytes
I am writing a PL/M frontend to GCC 2.1. I have now come to realize that PL/M needs a two-pass compiler because you can use procedures/functions before their declaration (and it's a strongly typed language with parameter type and number checking). (Actually, the Intel PL/M manual seems to say that you cannot use procedures before their declaration, but their compiler works otherwise.) I thought of implementing the two passes like this: In the compiler proper, the first pass scans the source with a grammar that just recognizes the block structure and procedure/function declarations, and inserts "forward" declarations at the beginning of the appropriate block. This pass stores the pre-lexed source in a internal data structure (basically, a linked list of obstacks or something like that). The first pass also handles the peculiar "declare literally" concept in PL/M -- a kind of textual macro (without parameters) that has block-structured scope. The "real" 2nd pass parser gets tokens from this pre-lexed structure. Because of the inserted forward declarations, there is no problem with using procedures/functions before declaration. The 1st pass is automatically run throught the whole source the first time (the 2nd pass) yylex is called. Does this sound like a reasonable idea? (Actually, at the very first there is a preprocessor, like cpp, that handles conditional compilation etc. This is easy.) -- Tor Lillqvist, working, but not speaking, for the Technical Research Centre of Finland
Technical Details
Message-ID:
<TML.92Apr8174951@tiuhti.tik.vtt.fi>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!hemuli.tik.vtt.fi!tik.vtt.fi!tmlShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!hemuli.tik.vtt.fi!tik.vtt.fi!tml From: tml@tik.vtt.fi (Tor Lillqvist) Newsgroups: gnu.gcc.help Subject: Two-pass frontend: hints? Message-ID: <TML.92Apr8174951@tiuhti.tik.vtt.fi> Date: 8 Apr 92 22:49:51 GMT Sender: news@hemuli.tik.vtt.fi Distribution: gnu Organization: Technical Research Centre of Finland, Laboratory for Information Processing (VTT/TIK) Lines: 36