varaq-interpreter-go/varaq/token.go

230 lines
6.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package varaq
type TokenType int64
const (
UNDEFINED TokenType = iota
IDENTIFIER // id
STRING // string
NUMBER // float
BOOLEAN // bool
LIST // list
SCRIPT // script
FUNCTION // function
ERROR // error
LEFTPAREN // (
RIGHTPAREN // )
LEFTBRACE // {
RIGHTBRACE // }
TILDE // The ~ operator is a special form, as it is not a postfix operator. When the interpreter encounters a ~, it pushes the next token on the stack as is regardless of whether it is a defined name.
SLASH // /
STAR // *
FALSE // false
TRUE // true
PI // 3.14159
E // 2.718
EOF // end of file
POP // Pops and discards the top item on the stack. The literal meaning is discard.
DUP // Duplicates the top object on the stack.
EXCH // Inverts the order of the top two objects on the stack.
CLEAR // Empties the stack.
REMEMBER // Puts a flag (like PostScripts mark) on the stack. The internal representation of the flag is not available to the programmer.
FORGET // Clears the stack down to the flag and pops the flag. If there is no flag present, the stack is emptied completely.
DUMP // Prints the contents of the operand stack to STDOUT without changing them.
NAME // Associates obj with id and places it in the system lookup space. Conventionally used to associate new operator names with procedure objects.
SET // Reassigns the value of a value already in the system lookup space. Used primarily for variable assignments.
IFYES //
IFNO //
CHOOSE //
EVAL //
ESCAPE //
REPEAT //
SPLIT //
CONS //
SHATTER //
MEASURE //
EMPTY //
COMPOSE //
STREQ //
STRCUT //
STRMEASURE //
STRTIE //
EXPLODE //
ADD //
SUB //
MUL //
DIV //
IDIV //
MOD //
POW //
SQRT //
ADD1 //
SUB1 //
SIN //
COS //
TAN //
ATAN //
LN //
LOG //
LOG3 //
CLIP //
SMOOTH //
HOWMUCH //
SETRAND //
RAND //
NUMBERIZE //
ISOLATE //
MIX //
CONTRADICT //
COMPL //
SHIFTRIGHT //
SHIFTLEFT //
GT //
LT //
EQ //
GE //
LE //
NE //
NULL //
NEGATIVE //
ISNULL //
ISINT //
ISNUMBER //
AND //
OR //
XOR //
DISP //
LISTEN //
COMPLAIN //
NEWLINE //
TAB //
WHEREAMI //
VERSION //
ARGV //
TIME //
GARBAGECOLLECT //
OVER //
ROT //
DEPTH //
SERVEHTTP //
READALL //
)
var tokens = [...]string{
UNDEFINED: "UNDEFINED",
IDENTIFIER: "IDENTIFIER",
STRING: "STRING",
NUMBER: "NUMBER",
LIST: "LIST",
ERROR: "ERROR",
SCRIPT: "SCRIPT",
FUNCTION: "FUNCTION",
LEFTPAREN: "LEFTPAREN",
RIGHTPAREN: "RIGHTPAREN",
LEFTBRACE: "LEFTBRACE",
RIGHTBRACE: "RIGHTBRACE",
TILDE: "TILDE",
SLASH: "SLASH",
STAR: "STAR",
FALSE: "FALSE",
TRUE: "TRUE",
PI: "PI",
E: "E",
EOF: "EOF",
POP: "POP",
DUP: "DUP",
EXCH: "EXCH",
CLEAR: "CLEAR",
REMEMBER: "REMEMBER",
FORGET: "FORGET",
DUMP: "DUMP",
NAME: "NAME",
SET: "SET",
IFYES: "YES?",
IFNO: "NO?",
CHOOSE: "CHOOSE",
EVAL: "EVAL",
ESCAPE: "ESCAPE",
REPEAT: "REPEAT",
SPLIT: "SPLIT",
CONS: "CONS",
SHATTER: "SHATTER",
MEASURE: "MEASURE",
EMPTY: "EMPTY?",
COMPOSE: "COMPOSE",
STREQ: "STREQ?",
STRCUT: "STRCUT",
STRMEASURE: "STRMEASURE",
STRTIE: "STRTIE",
EXPLODE: "EXPLODE",
ADD: "ADD",
SUB: "SUB",
MUL: "MUL",
DIV: "DIV",
IDIV: "IDIV",
MOD: "MOD",
POW: "POW",
SQRT: "SQRT",
ADD1: "ADD1",
SUB1: "SUB1",
SIN: "SIN",
COS: "COS",
TAN: "TAN",
ATAN: "ATAN",
LN: "LN",
LOG: "LOG",
LOG3: "LOG3",
CLIP: "CLIP",
SMOOTH: "SMOOTH",
HOWMUCH: "HOWMUCH?",
SETRAND: "SETRAND",
RAND: "RAND",
NUMBERIZE: "NUMBERIZE",
ISOLATE: "ISOLATE",
MIX: "MIX",
CONTRADICT: "CONTRADICT",
COMPL: "COMPL",
SHIFTRIGHT: "SHIFTRIGHT",
SHIFTLEFT: "SHIFTLEFT",
GT: "GT?",
LT: "LT?",
EQ: "EQ?",
GE: "GE?",
LE: "LE?",
NE: "NE?",
NULL: "NULL",
NEGATIVE: "NEGATIVE",
ISNULL: "NULL?",
ISINT: "INT?",
ISNUMBER: "NUMBER?",
AND: "AND",
OR: "OR",
XOR: "XOR",
DISP: "DISP",
LISTEN: "LISTEN",
COMPLAIN: "COMPLAIN",
NEWLINE: "NEWLINE",
TAB: "TAB",
WHEREAMI: "WHEREAMI",
VERSION: "VERSION",
ARGV: "ARGV",
TIME: "TIME",
GARBAGECOLLECT: "GARBAGECOLLECT",
OVER: "OVER",
ROT: "ROT",
DEPTH: "DEPTH",
SERVEHTTP: "SERVEHTTP",
READALL: "READALL",
}
func (me TokenType) String() string {
return tokens[me]
}
type Token struct {
Toktype TokenType
Lexeme string
Literal any
Line int
}