feat: replace AST-based parser with single-pass bytecode compiler and VM

Replace the recursive-descent parser that built an AST (Node* tree) with a single-pass compiler that emits bytecode directly into a Block structure. Remove the parser.c/parser.h files and their AST node types (NodeLiteral, NodeCall, NodeBinaryOp, etc.), add new compiler.c/compiler.h with a Compiler struct and Pratt-style precedence parsing that outputs CODE_CONSTANT and CODE_END instructions, and introduce vm.c/vm.h containing a Fiber-based interpreter with a stack, interpret() loop, and printValue() for OBJ_INT. Update main.c to call compile() then interpret() instead of parse(), remove TOKEN_INDENT/TOKEN_OUTDENT from token.h and dumpTokens(), and adjust the Xcode project to include the new source files while excluding the old parser.
This commit is contained in:
Bob Nystrom
2013-10-22 19:16:39 +00:00
parent 8d29decb14
commit 9bb2ca308e
10 changed files with 512 additions and 457 deletions
+1 -1
View File
@@ -1 +1 @@
123(1, true, "a string".whatevs)
2