alias is a developer console with multiple implementations
The lexer is a function that when passed a string it will output an array-like structure of tokens.
When passed a string it should split it with spaces being the separator, however if there are double quotes they sould not be split, insted bbeing considered one token. The output will be stored in an array-like structure. The quotes should not be visable in the output.
Example:
input: 'a b c "a b c"'
output ['a', 'b', 'c', 'abc']
The interpreter is a function that takes in an array-like structure of strings (generated by the lexer) and performs an operation based on those tokens.
The first item is used to tell the interpreter what operation to perform, all of the other items are used as arguments. For example if we make an echo operation that outputs the second argument to the standard output if we pass the interpreter these tokens:
['echo', 'Hello, World!']
in the standard output we will see:
Hello, World!
The interpreter's operations should be extensible.
The heap is simple, just store valuses and get values by string. An example would be a dictonary
An alias is a group of commands that are stored under one name.
They can be executed by simply referencing them like a normal command (e.g. echo
).
The way they execute is one command at a time, execute one, then go to the next in the alias.
They are stored in a second heap called aliascmds, each alias is an array-like structure with each command in it.
"echo"
"setvar"
"calcvar"
"quit"
"alias"
prints the second argument to the screen
assigns a variable (2nd argument) in the heap a value (3rd argument)
syntax:
setvar [var1] [operation] [var2] [var3]
performs operation on var1 and var2 then puts a value into var3
addition
subtraction
multiplication
division
(returns boolean 1 or 0) is equal
(returns boolean 1 or 0) is not equal
quit the program
assigns a alias a value
If we make a variable called "usrin" and we set it to contain a command, for example echo "Hello, World!"
.
We would pass the "usrin" variable to the lexer function, after the lexer has completed we would pass the tokens from the lexer function into the interpreter function.