diff options
| author | Marc Vertes <mvertes@free.fr> | 2023-11-03 19:05:14 +0100 |
|---|---|---|
| committer | Marc Vertes <mvertes@free.fr> | 2023-11-03 19:05:14 +0100 |
| commit | 6e2349e875e77d8af8b7d6f00f718db6813b40c1 (patch) | |
| tree | 74b476bc508264378fcb11bc7849658d76955f68 /parser/symbol.go | |
| parent | 20d331813cf05f42961f0f6df531c2880f753a07 (diff) | |
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.
Diffstat (limited to 'parser/symbol.go')
| -rw-r--r-- | parser/symbol.go | 21 |
1 files changed, 12 insertions, 9 deletions
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...) }}, } } |
