From 6e2349e875e77d8af8b7d6f00f718db6813b40c1 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Fri, 3 Nov 2023 19:05:14 +0100 Subject: feat: add support for control flow operators in expressions Logical operators `&&` (and), `||` (or) are now parsed in expressions. The control flow tokens (labels, conditional jumps) are added accordingly. --- parser/symbol.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'parser/symbol.go') diff --git a/parser/symbol.go b/parser/symbol.go index f83ec4e..d32bb59 100644 --- a/parser/symbol.go +++ b/parser/symbol.go @@ -1,6 +1,7 @@ package parser import ( + "fmt" "reflect" "strings" ) @@ -51,15 +52,17 @@ func (p *Parser) getSym(name, scope string) (sym *symbol, sc string, ok bool) { func initUniverse() map[string]*symbol { return map[string]*symbol{ - "any": {kind: symType, Type: reflect.TypeOf((*any)(nil)).Elem()}, - "bool": {kind: symType, Type: reflect.TypeOf((*bool)(nil)).Elem()}, - "error": {kind: symType, Type: reflect.TypeOf((*error)(nil)).Elem()}, - "int": {kind: symType, Type: reflect.TypeOf((*int)(nil)).Elem()}, - "string": {kind: symType, Type: reflect.TypeOf((*string)(nil)).Elem()}, + "any": {kind: symType, index: -1, Type: reflect.TypeOf((*any)(nil)).Elem()}, + "bool": {kind: symType, index: -1, Type: reflect.TypeOf((*bool)(nil)).Elem()}, + "error": {kind: symType, index: -1, Type: reflect.TypeOf((*error)(nil)).Elem()}, + "int": {kind: symType, index: -1, Type: reflect.TypeOf((*int)(nil)).Elem()}, + "string": {kind: symType, index: -1, Type: reflect.TypeOf((*string)(nil)).Elem()}, - "nil": {}, - "iota": {value: 0}, - "true": {value: true}, - "false": {value: false}, + "nil": {index: -1}, + "iota": {index: -1, value: 0}, + "true": {index: -1, value: true, Type: reflect.TypeOf(true)}, + "false": {index: -1, value: false, Type: reflect.TypeOf(false)}, + + "println": {index: -1, value: func(v ...any) { fmt.Println(v...) }}, } } -- cgit v1.2.3