You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> The tokenizer is implemented using [Ragel State Machine Compiler](https://www.colm.net/open-source/ragel/).
120
-
121
-
**The Syntax Tree Builder** generates a syntax tree from tokens:
122
-
```
123
-
EXIT
124
-
|-- CALL(join)
125
-
|-- STR(",")
126
-
|-- ARR
127
-
|-- STR("a")
128
-
|-- STR("b")
129
-
```
130
-
131
-
> A schema of the syntax tree is described by [Protocol Buffers 3](https://developers.google.com/protocol-buffers/) to make it easy traversable by any programming language.
132
-
133
-
**The Compiler** makes a bytecode from the syntax tree to make it executable by **a stack-based virtual machine**:
134
-
```
135
-
PUSH_STR ","
136
-
PUSH_STR "a"
137
-
PUSH_STR "b"
138
-
PUSH_VECTOR 2
139
-
SYS_CALL "join" 2
140
-
RET
118
+
ARR 2
119
+
INVOKE join 2
141
120
```
121
+
> The lexer is implemented using [Ragel State Machine Compiler](https://www.colm.net/open-source/ragel/).
142
122
123
+
**The compiler** makes a bytecode from the syntax tree to make it executable by **a stack-based virtual machine**.
143
124
> The bytecode is described by [Flatbuffers](https://google.github.io/flatbuffers/flatbuffers_guide_use_go.html) to achieve high-throughput with low memory consumption.
144
125
145
126
## Usage
146
127
147
128
Compilation:
148
129
```go
149
-
import"github.com/regeda/expr/asm"
130
+
import (
131
+
"github.com/regeda/expr/compiler"
132
+
"github.com/regeda/expr/lexer"
133
+
)
150
134
151
135
code:=`join(",", ["a", "b"])`
152
136
153
-
a:= asm.New()
154
-
bytecode, err:= a.Assemble([]byte(code))
137
+
tokens, err:= lexer.Parse([]byte(code))
155
138
if err != nil {
156
139
panic(err)
157
140
}
158
141
142
+
bytecode:= compiler.Compile(tokens)
143
+
159
144
// save `bytecode` to be executed by the virtual machine
0 commit comments