BDFD-style scripting language implemented in Rust for general PC automation and scripting.
- Everything is a function call prefixed with
$ - Function arguments separated by semicolon
; - Function calls use brackets:
$functionName[arg1;arg2] - Strings must be quoted:
"Hello"notHello - Variable names are bare identifiers:
$xis a variable reference - Comments start with
#
$toNumber- Convert string/number/bool to number$toString- Convert any value to string
$add,$sub,$mul,$div,$mod,$pow,$sqrt$floor,$ceil,$round,$abs$rand,$randInt,$min,$max
$if(lazy),$and(lazy),$or(lazy)$eq,$neq,$gt,$lt,$gte,$lte,$not
$print,$input,$readFile,$writeFile,$appendFile$fileExists,$deleteFile,$mkdir$listDir,$isDir,$isFile,$copyFile,$moveFile,$cd
$strLen,$strSub,$strConcat,$strSplit,$strReplace$strLower,$strUpper,$strTrim,$strContains$startsWith,$endsWith,$repeat,$join,$slice,$padStart,$padEnd$chr,$ord
$env,$args,$exit,$sleep,$pwd,$exec
$arrayCreate,$arrayGet,$arrayLen,$arrayPush,$arraySort$arrayMap(com callbacks!),$arrayFilter(com callbacks!),$arrayReduce(com callbacks!)$arrayRange,$arrayReverse,$arrayFlatten,$arrayUnique$arrayJoin,$arrayFind,$arrayIndexOf,$arrayContains,$arraySlice$dictCreate,$dictGet,$dictSet,$dictKeys,$dictValues$dictHas,$dictRemove,$dictEntries,$dictMerge$jsonParse,$jsonStringify$typeOf,$isNull,$isArray,$isObject,$isString,$isNumber,$isBool$len,$noop,$identity,$return
$httpGet,$httpPost,$httpPut,$httpDelete,$downloadFile$encodeUrl,$decodeUrl
$now,$timestamp,$formatDate,$timestampToDate
$base64Encode,$base64Decode,$hash(sha256, md5)
$regexMatch,$regexReplace,$regexFind,$regexSplit
$def[name;params;body]- Define a function. Params are space-separated, e.g.,$def[add;a b;$add[$a;$b]]$set[varname;value]- Set a variable$if[cond;then;else]- Conditional (lazy: only evaluates chosen branch)$and[a;b;...]- Short-circuit AND$or[a;b;...]- Short-circuit OR$for[var;start;end;body]- For loop with range$while[cond;body]- While loop$break[]- Break out of loop$continue[]- Skip to next iteration$try[body;catch...]- Try/catch error handling (sets$errorvar)$throw[message]- Throw an error with message$return[value]- Early return from user function$arrayMap[arr;"funcName"]- Map with user-defined function callback$arrayFilter[arr;"funcName"]- Filter with user-defined function callback$arrayReduce[arr;initial;"funcName"]- Reduce with user-defined function callback
# For loop
$for[i;0;10;$print[$i]]
# While loop
$set[x;0]
$while[$lt[$x;5];
$print[$x]
$set[x;$add[$x;1]]
]
# Break and Continue
$for[i;0;100;
$if[$gte[$i;5];$break[];$noop[]]
$print[$i]
]
# Try/Catch
$try[
$readFile["missing.txt"]
;
$print["File not found!"]
$print[$error]
]
# Throw
$throw["Something went wrong"]
# Return
$def[safeDiv;a b;
$if[$eq[$b;0];
$return["Cannot divide by zero"]
;
$div[$a;$b]
]
]
$def[double;x;$mul[$x;2]]
$def[is_even;x;$eq[$mod[$x;2];0]]
$def[sum;a b;$add[$a;$b]]
$set[nums;$arrayCreate[1;2;3;4;5]]
$arrayMap[$nums;"double"] # [2, 4, 6, 8, 10]
$arrayFilter[$nums;"is_even"] # [2, 4]
$arrayReduce[$nums;0;"sum"] # 15
$def[double;x;$mul[$x;2]]
$def[fib;n;$if[$lt[$n;2];$n;$add[$fib[$sub[$n;1]];$fib[$sub[$n;2]]]]]
Important: Function parameters are space-separated inside the $def, not semicolon-separated:
# CORRECT:
$def[add;a b;$add[$a;$b]]
# WRONG:
$def[add;a;b;$add[$a;$b]]
$set[x;10]
$print[$x]
# Evaluate expression
cargo run -- -e '$print["Hello"]'
# Run script file
cargo run -- script.eterSee examples/ directory:
hello.eter- Hello Worldmath.eter- Math operationsfactorial.eter- Recursive factorialfibonacci.eter- Recursive Fibonaccivariables.eter- Variable assignmentfizzbuzz.eter- FizzBuzz with conditionalsstrings.eter- String manipulationcalculadora.eter- Interactive calculator (single operation)calculadora_loop.eter- Interactive calculator with looploops.eter- For and while loopserror_handling.eter- Try/catch and throwcollections.eter- ArrayMap/Filter/Reduce with callbacksdictionaries.eter- Dict operations
src/lexer.rs- Tokenizer and parsersrc/evaluator.rs- Expression evaluator with special forms, loops, error handling, stack traces, callbackssrc/value.rs- Value types, expressions, RuntimeError with stack traces, ControlFlow enumsrc/functions/- Built-in function implementationssrc/main.rs- CLI entry point
- Semicolon handling - Parser skips semicolons between expressions
- Empty-arg function calls -
$xresolves to variable values - String interpolation -
$varnameinside strings replaced with values - Lazy evaluation -
$if,$and,$oronly evaluate needed branches - Recursive functions - Now work correctly with lazy evaluation
- Comment support -
#comments skip to end of line - EOF handling - Empty-arg calls at end-of-input work
- Function params - Space-separated in
$def, e.g.,$def[foo;a b;$add[$a;$b]] - Loops -
$for,$while,$break,$continueimplemented as special forms - Error handling -
$try,$throwwith stack traces - Early return -
$returnfrom user functions - Callbacks funcionais -
$arrayMap,$arrayFilter,$arrayReducecom funções definidas pelo usuário - Array utilities -
$arrayRange,$arrayReverse,$arrayFlatten,$arrayUnique,$arrayJoin,$arrayContains,$arraySlice - Dict utilities -
$dictSet,$dictKeys,$dictValues,$dictHas,$dictRemove,$dictEntries,$dictMerge
- Variables are function-scoped (no closures)
- Error messages could be more descriptive in some edge cases