varaq-interpreter-go/varaq/token.go

230 lines
6.9 KiB
Go
Raw Normal View History

2022-09-03 23:15:35 -04:00
package varaq
type TokenType int64
const (
2024-12-07 21:19:43 -05:00
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 //
2022-09-03 23:15:35 -04:00
)
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",
2024-12-07 21:19:43 -05:00
MEASURE: "MEASURE",
2022-09-03 23:15:35 -04:00
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",
2023-03-18 22:26:32 -04:00
SERVEHTTP: "SERVEHTTP",
2023-03-22 22:26:58 -04:00
READALL: "READALL",
2022-09-03 23:15:35 -04:00
}
func (me TokenType) String() string {
return tokens[me]
}
type Token struct {
Toktype TokenType
Lexeme string
Literal any
Line int
}