From 37b9da32d3b911091deb254f6cba2a137c471287 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Thu, 12 Oct 2023 10:51:58 +0200 Subject: move to a direct byte code compiler (#8) * chore: refactor to keep only the new parser and bytecode vm * scanner: remove Token.value field * scanner: remove scanner.kind field * chore: move language specification in lang package This avoid a cyclic dependency in scanner_test which can now use the golang/GoSpec language specification for Go. * clean code * scanner: export scanner fields Also parser now generate function calls, including externals. * chore: fix lint issues * parser: handle strings * wip * parser: implement support for 'if, else, else if' statements Resolving labels in the compiler still in progress. * parser: support if statements, improve compiler * improve handling of functions * improve support of local variables * scanner: trim leading and trailing spaces * fixes to make fibonacci work * parser: improve README, fix function parameters parsing --- parser/kind.go | 56 -------------------------------------------------------- 1 file changed, 56 deletions(-) delete mode 100644 parser/kind.go (limited to 'parser/kind.go') diff --git a/parser/kind.go b/parser/kind.go deleted file mode 100644 index d004471..0000000 --- a/parser/kind.go +++ /dev/null @@ -1,56 +0,0 @@ -package parser - -import "fmt" - -// kind defines the AST node kind. Its name is the concatenation -// of a category (Block, Decl, Expr, Op, Stmt) and an instance name. -type Kind int - -const ( - Undefined = Kind(iota) - BlockParen - BlockStmt - Comment - DeclFunc - ExprCall - Ident - LiteralNumber - LiteralString - OpAdd - OpAssign - OpDefine - OpDot - OpInferior - OpMultiply - OpSubtract - StmtIf - StmtReturn -) - -var kindString = [...]string{ - Undefined: "Undefined", - BlockParen: "BlockParen", - BlockStmt: "BlockStmt", - Comment: "Comment", - DeclFunc: "DeclFunc", - ExprCall: "ExprCall", - Ident: "Ident", - LiteralString: "LiteralString", - LiteralNumber: "LiteralNumber", - OpAdd: "OpAdd", - OpAssign: "OpAssign", - OpDefine: "OpDefine", - OpDot: "OpDot", - OpInferior: "OpInferior", - OpMultiply: "OpMultiply", - OpSubtract: "OpSubtract", - StmtIf: "StmtIf", - StmtReturn: "StmtReturn", -} - -func (k Kind) String() string { - if int(k) < 0 || int(k) > len(kindString) { - return fmt.Sprintf("unknown kind %d", k) - } - return kindString[k] -} -- cgit v1.2.3