|Compiler 101 email@example.com (Jon Masterson) (2005-01-22)|
|Re: Compiler 101 firstname.lastname@example.org (2005-01-24)|
|Re: Compiler 101 email@example.com (Laurence Finston) (2005-01-24)|
|Re: Compiler 101 firstname.lastname@example.org (Jon Masterson) (2005-01-24)|
|Re: Compiler 101 email@example.com (Jon Masterson) (2005-01-30)|
|Re: Compiler 101 firstname.lastname@example.org (Nobodyzhome) (2005-01-30)|
|Re: Compiler 101 email@example.com (2005-02-18)|
|Re: Compiler 101 firstname.lastname@example.org (email@example.com) (2005-02-28)|
|From:||Laurence Finston <firstname.lastname@example.org>|
|Date:||24 Jan 2005 10:58:58 -0500|
|Posted-Date:||24 Jan 2005 10:58:58 EST|
On Sun, 22 Jan 2005, Jon Masterson wrote:
> I am looking for pointers to starter information on building what is
> really an interpeter.
> I am working on a two stage interpeter -
> similar to Java - first stage which is with the code editor does
> syntax checking and analyes the code turning it into a series of
> tokens and associated data. The second stage runs on the users
> computer and executes the tokens.
I would call these two stages "scanning" and "parsing",
whereby I would describe them somewhat differently than
you have done.
> [...] and would appreciate and pointers to where I can read up
> on basic compiler/interpreter principles.
I recommend the GNU Bison manual. The moderator of this
newsgroup, John R. Levine, is also the author of the book
_Lex and Yacc_.
> At the moment, for example, I cannot allow nesting as I have no clue
> as to how to handle that now.
Nesting is easy. You just have to define a data structure
to represent your source of input. Let's call it
`Input_Struct'. An `Input_Struct' should have a data member
that references a source of input, i.e., a file descriptor,
a `FILE', an `istream', a `string', or whatever. You might
want to make this data member a pointer.
`Input_Struct' should also contain a data member of type
`Input_Struct*', which you might want to call `up'.
This is the basis for a linked list of `Input_Structs'.
When you need nesting, you allocate memory for a new
`Input_Struct' dynamically and push it onto the linked list.
When you're done reading from the input source it
represents, you pop it off.
If you want to see how I do this, my code is available at:
I do actually use the names `Input_Struct' and `up'.
If you do decide to use GNU Bison, you might want to look at
the archives of the `email@example.com' mailing list:
Return to the
Search the comp.compilers archives again.