|Absolute beginner - Need some pointers email@example.com (NickCarlson) (2008-02-27)|
|Re: Absolute beginner - Need some pointers DrDiettrich1@aol.com (Hans-Peter Diettrich) (2008-02-28)|
|Re: Absolute beginner - Need some pointers firstname.lastname@example.org (Bartc) (2008-02-29)|
|Re: Absolute beginner - Need some pointers email@example.com (2008-03-02)|
|Re: Absolute beginner - Need some pointers firstname.lastname@example.org (2008-03-03)|
|Re: Absolute beginner - Need some pointers email@example.com (2008-03-04)|
|Re: Absolute beginner - Need some pointers firstname.lastname@example.org (glen herrmannsfeldt) (2008-03-05)|
|Re: Absolute beginner - Need some pointers email@example.com (Soeren Sandmann) (2008-03-07)|
|Date:||Fri, 29 Feb 2008 19:00:07 GMT|
|Posted-Date:||01 Mar 2008 12:14:00 EST|
"NickCarlson" <firstname.lastname@example.org> wrote in message
> (we'll call my new language Omega for now)
> i. Write a lexical analyzer to convert to Omega code into a tree
> structure that the parser can parse.
> 2. Write a parser to parse the tree structure into bytecode.
> C. Write a virtual machine that can execute the bytecode.
The parser retrieves tokens from the lexer, and analyses the symbols to
build the syntax tree.
The code generator turns the tree into possible bytecode.
In-between you may need to do further analysis (datatyping and so on).
You can actually execute this tree directly as has been mentioned (you will
of course need to set up the execution environment: variables, registers,
probably a stack, but you know all this).
But it is a little more satisfying to write the bytecode to a file. Then you
can distribute this without the compiler or source code.
Take this code snippet:
if x then
When written to bytecode you might end up with something like the following
(this uses a stack):
00019 %1: ;fred
00021 Pushm x
00023 Jumpf %2
00025 Pushm b
00027 Pushm c
00030 Popm a
00032 Jump %1
In other words, a linear sequence of opcodes reassuringly similar to
assembly language. The numbers indicate byte-offsets, and you can manipulate
your program counter very easily. But there are many ways of handling
Return to the
Search the comp.compilers archives again.