2 ms·
The example I was thinking of when I mentioned performance was Lua. Instead of generating a syntax tree the recursive descent parser directly spits out bytecode
by ufo 12y ago
The example I was thinking of when I mentioned performance was Lua. Instead of generating a syntax tree the recursive descent parser directly spits out bytecode as it goes, which ends up being a big performance win on large source files.
- barrkel 12y agoTaking the other side of the argument in my sibling comment to yours: using a parser generator does not preclude directly spitting out bytecode. You can do that in the parse actions instead of building an AST. A bottom-up parser like that produced by LALR parser generator could make this slightly more awkward, depending on what you need to generate the bytecode, but an LL(k) parser generator (e.g. Antlr) should let you do most of what you'd do with recursive descent, and in a similar way.
- mamcx 12y agoI wonder if exists other ways, and find a obscure reference to "slim binaries": (Asked here) https://www.reddit.com/r/Compilers/comments/2o78hd/exist_a_sample_code_for_the_slim_binaries/ https://www.reddit.com/r/Compilers/comments/2o78hd/exist_a_s... Also, I wonder how NOT lost the info that already have the AST in the bytecode conversion, I even have the crazy idea to store everything in a sqlite database, but I suspect will be slow (to read later in the VM...)
- barrkel 12y agoEvaluate code for a stack machine symbolically, and you'll end up with an expression tree. RPN bytecode is a post-order traversal of the underlying expression. Things get a bit more wrinkly with control flow, but you can design bytecode to make it easier to rehydrate that too.