Documentation
¶
Overview ¶
tokenize includes functions to help create a list of tokens from a given string
Index ¶
- Constants
- func EVAL(e *EXPR) (TYPE int, VALUE interface{})
- func EVAL_ADD(e *EXPR) (TYPE int, VALUE interface{})
- func EVAL_DIVIDE(e *EXPR) (TYPE int, VALUE interface{})
- func EVAL_MINUS(e *EXPR) (TYPE int, VALUE interface{})
- func EVAL_MULTIPLY(e *EXPR) (TYPE int, VALUE interface{})
- func IS_VALID_NUMBER(s string) bool
- func Tokenize(s string) []string
- type ASTQUEUE
- type EXPR
Constants ¶
const ( ADD = iota MINUS MULTIPLY DIVIDE INT FLOAT LIST BOOLEAN UNKNOWN ERROR )
The expression might be several types, which are numericals, lists or operations.
const ( BEGIN_TOKEN = '(' END_TOKEN = ')' ADD_TOKEN = '+' MINUS_TOKEN = '-' MULTI_TOKEN = '*' DIV_TOKEN = '/' BEGIN_EXPR = "(" END_EXPR = ")" ADD_EXPR = "+" MINUS_EXPR = "-" MULTI_EXPR = "*" DIV_EXPR = "/" )
Variables ¶
This section is empty.
Functions ¶
func EVAL ¶
Eval function provides evaluation function for lisp expressions, currently the defini- tion is like this:
If the EXPR is numerical operation, the num- ber of operands must be >= 2, otherwise the interpreter stop evaluating and throw an er- ror
If the EXPR is numerical, the value and its type is returned.
If the EXPR is list, the string of the oper- ands are returned
func EVAL_ADD ¶
ADD function deals with add expressions. We first check if there are any floats in the operands, and if there is, we convert every- thing to float and return float result ***Allows single operands***
func EVAL_DIVIDE ¶
ADD function deals with add expressions. We first check if there are any floats in the operands, and if there is, we convert every- thing to float and return float result ***Allow Single Operands***
func EVAL_MINUS ¶
MINUS function deals with minus expressions. We first check if there are any floats in the operands, and if there is, we convert every- thing to float and return float result ***Allows single operands***
func EVAL_MULTIPLY ¶
ADD function deals with add expressions. We first check if there are any floats in the operands, and if there is, we convert every- thing to float and return float result ***Allow Single Operands***
func IS_VALID_NUMBER ¶
IS_VALID_NUMBER takes in a string and ch- eck if it is a valid number, i.e. there are no non-numerical letters with in and '.' only appear once
Types ¶
type ASTQUEUE ¶
type ASTQUEUE struct {
ASTELEM []string
}
func ASTQUEUEConstructer ¶
ASTQUEUE constructor using an existing token list, returns the pointer to the constructed astqueue
func (*ASTQUEUE) Pop ¶
Returns the first element in the queue and delete it afterwards. If pop from an empty queue, an empty string is re- turned with an error.
func (*ASTQUEUE) ReachedEnd ¶
return the result if there is no more elements in the queue