Wow! finished function table, almost finished with lexing as a whole
This commit is contained in:
parent
bb070592a6
commit
8643824bb6
5 changed files with 97 additions and 116 deletions
|
|
@ -4,24 +4,37 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
type token_t int
|
||||
const (
|
||||
LIST token_t = iota
|
||||
STRING token_t = iota
|
||||
NUMBER token_t = iota
|
||||
VARIABLE token_t = iota
|
||||
FUNCTION token_t = iota
|
||||
)
|
||||
|
||||
type Token struct {
|
||||
next *Token
|
||||
tag parse_tag
|
||||
int position
|
||||
_inner interface{}
|
||||
}
|
||||
|
||||
func Lex(input string) Token {
|
||||
func Lex(input string) *Token {
|
||||
ret := new(Token)
|
||||
iter := &ret
|
||||
delim := ' '
|
||||
var tok strings.Builder
|
||||
iter_alloced := false
|
||||
is_list = false;
|
||||
is_list = false
|
||||
is_str = false
|
||||
is_num = true
|
||||
|
||||
for pos, char := range input {
|
||||
switch char {
|
||||
// TODO: User configurable delimiters
|
||||
case '\'', '"', '`':
|
||||
is_str = true
|
||||
delim = char
|
||||
case '(':
|
||||
is_list = true
|
||||
|
|
@ -29,22 +42,41 @@ func Lex(input string) Token {
|
|||
|
||||
case delim:
|
||||
*iter = new(Token)
|
||||
*iter.position = pos
|
||||
|
||||
if is_list {
|
||||
// TODO: Pass a pointer out of Lex and store a pointer
|
||||
*iter._inner = Lex(tok.String())
|
||||
*iter.tag = LIST_T
|
||||
is_list = false
|
||||
|
||||
if (*iter._inner.tag == FUNCTION) {
|
||||
*iter.tag = CALL
|
||||
} else {
|
||||
*iter.tag = LIST
|
||||
}
|
||||
|
||||
} else {
|
||||
// TODO: Store a pointer to the contents of the stringbuilder
|
||||
*iter._inner = tok.String()
|
||||
*iter.tag = OPERAND_T
|
||||
if is_string {
|
||||
*iter.tag = STRING
|
||||
is_str = false
|
||||
|
||||
} else if is_num {
|
||||
*iter.tag = NUMBER
|
||||
|
||||
} else if () {
|
||||
// TODO: Detect VARIABLE
|
||||
|
||||
} else {
|
||||
*iter.tag = FUNCTION
|
||||
}
|
||||
}
|
||||
|
||||
iter_alloced = true
|
||||
delim = ' '
|
||||
|
||||
default:
|
||||
is_num = is_num && IsDigit(char)
|
||||
tok.WriteRune(char)
|
||||
}
|
||||
|
||||
|
|
@ -54,10 +86,7 @@ func Lex(input string) Token {
|
|||
tok.Reset()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func eval(Token *tree) *Token {
|
||||
// Find operations
|
||||
// Simplify operations deepest first
|
||||
// return tree of final Tokens
|
||||
// TODO: Throw parsing error here if there is leftover in tok
|
||||
return ret
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue