> Hi Nicolas,
>
> I must admit, I was impressed when I traversed the code for the NekoVm
> and compiler, but numerous keywords stood out that made me feel you had
> certainly used a parser generator before. If you had to use a parser
> for compiler development, which one would be your preference?
The NekoML one. It's inspired by CamlP4 stream parsers, which are an
syntactical extension of OCaml. LL(1) parser don't need "generators"
since you can directly express your grammar in terms of patterns.
For exemple if you have a BNF :
parent := '(' expr ')'
you can encode it this way :
function parent(s) {
match s {
| [< ParentOpen; e = expr s; ParentClose >] -> ....
}
}
Where 's' is your token stream and 'ParentOpen' and 'ParentClose' are
two tokens. Neko and NekoML lexer tokens are pairs of (token,position)
so this make the parser a bit more verbose, such as :
function parent(s) {
match s {
| [< (ParentOpen,p1); e = expr s; (ParentClose,p2) >] -> ....
}
}
Then in '...' you can build the expression EParenthesis(e) with
position delimiters p1 and p2, hence punion(p1,p2)
> Also, I
> can quite clearly see the path to building a compiler that executed the
> code as it went along, but how did you go about planning the bytecode
> structure for Neko? Did you use the same conventions when planning your
> parsers from script -> bytecode and from bytecode -> execution?
Neko comes from a previous VM called "MotionScript". Usually you first
develop a small lexer+parser, then an toy interpreter that will just
execute the AST (very slow !). When it comes to writing a VM, the goal
is to have a linear representation of the AST with fewest opcodes
possible, then add some opcodes for optimizing the things that you do often.
I'm not sure I understand your question about "using the same
conventions". Surely, the bytecode generator (written in NekoML) and the
bytecode loader (written in C) must share the same format. As for
bootstrapping, the compiler was first written in OCaml then rewritten in
NekoML, since you can't self-boostrap a language.
Nicolas
--
Neko : One VM to run them all
(http://nekovm.org)