SHS/pkg/shsh/token.go

68 lines
1.3 KiB
Go
Raw Normal View History

2019-11-12 12:24:45 -08:00
package token;
import (
"strings"
2019-11-12 13:02:06 -08:00
"bytes"
2019-11-12 12:24:45 -08:00
)
type operation func(Token) Token
2019-11-12 13:25:53 -08:00
/*
* LIST: a list of elements
2019-11-12 14:10:07 -08:00
* OPERAND: a string or number
* OPERATOR: an entry in a symtable
* OPERATION: a list starting with an operator
2019-11-12 13:25:53 -08:00
*/
type parse_tag enum {
LIST_T iota
OPERAND_T iota
OPERATOR_T iota
OPERATION_T iota
}
2019-11-12 12:24:45 -08:00
type Token struct {
Token *next
interface{} *_inner
}
2019-11-12 13:02:31 -08:00
func lex(string input) string {
2019-11-12 12:24:45 -08:00
ret := new(Token)
iter := &ret
2019-11-12 13:02:06 -08:00
// buffered reader via new or make i dunno
2019-11-12 13:09:31 -08:00
bool buff_is_dirty = false;
2019-11-12 12:24:45 -08:00
2019-11-12 13:02:06 -08:00
for pos, char := range input {
2019-11-12 13:09:31 -08:00
switch char {
case ' ', '\t', '\n', '\f', '\r':
// parse new token
case '\'', '\"', '`':
// parse new token
case '(':
// match paren
// parse list
case ')':
// SHOULDNT HAPPEN
default:
// add to buffer
buf_is_dirty = true
}
if buf_is_dirty {
// clear buffer
buf_is_dirty = false
}
2019-11-12 13:02:06 -08:00
}
2019-11-12 12:24:45 -08:00
}
2019-11-12 13:09:31 -08:00
func parse(Token *arg) {
2019-11-12 13:25:53 -08:00
// if operand determine if operator
// determine operator precense in symbol table
// Determine if a list is an operation or a list
2019-11-12 13:09:31 -08:00
}
func eval(Token *tree) Token* {
2019-11-12 13:25:53 -08:00
// Find operations
// Simplify operations deepest first
// return tree of final Tokens
2019-11-12 13:09:31 -08:00
}