- float numbers, basic operators(+, -, *, /, (, ))
- enhanced error handling with indication of problem position in input
- tokenizer is enough smart to proccess arbitrary formatted expressions
- parser upgraded to work with unary operators
- variables
- simple functions (one line formulas, without subcalls)
- meta commands(show something and etc…)
- script mode, options
- uses readline library(interactive editing)
- autocomplete(functions and variables)
- can create config file with predefined functions and variables
- optimize(minimize) function expressions
- api to interact with interpreter objects from go code
go test .
go build -o calc ./cmd
./calc
– to run
go run ./cmd
-
identifier: starts with letter, can consist of letters and digits(case-sensetive)
-
number: floating point number (dot as fraction separator)
-
variable:
- variable_name: identifier
- assignment:
varable_name = expression
variablevariable_name
with value ofexpression
- example:
var = 2 * 2
variablevar
with value 4
- example:
- usage:
variable_name
=> gives value of variablevariable_name
- example:
var
=> 4
- example:
-
function:
- function_name: @identifier
- declaration:
function_name = (variable_name [,variable_name]): expression
function with namefunction_name
with zero or more parameters(separated with comma), that used for calculateexpression
- example:
@foo = (a, b): 2 * a - b
- example:
- usage:
function_name(expression [,expression])
call functionfunction_name
- example:
@foo(4 - 1, 2)
=> 4
- example:
-
expression: consists of numbers, operators, function calls, variables
- example
-(a - @bar(1, (2.34 + c) * b)) * 5.1 - d / (100 - 1)
- example
-
operators:
- unary:
+-
- binary:
+-/*
- parentheses:
()
- unary:
-
meta command: ;identifier
;mem
(show existing variables and functions)
-
instruction:
- variable assignment (create variable)
- function declaration (create function)
- expression (calculate and print value)
- meta command
-
interpreter: processes instructions
Leave a Reply