An evaluator of a stripped down version of JS, aiming to replicate REPL of Node.js.
You can run this project in 2 ways:
- Install the
.jarfrom the releases section, and then runjava -jar jseval-v1.0.jar [-gui | -help] - Clone the repo and open the project in IntelliJ. Then simply run the
Main.ktfile located insrc/main/kotlin/Main.kt.
- Statements:
- Variable Declarations
- Function Declarations
- Pure functions defined like:
-
function double(x) { return x * 2; }
- Loops/Conditional Statements are yet to be implemented.
- Expressions
- Arithmetic operations of +, -, *, /
- Comparison operations of >, <, ==, >=, <=
- Logical operations of &&, ||, !
- Assignment
- Function call expressions
- Variable References
- Literals (values)
Tests are contained in src/test/ directory. The tests are:
EvalTests.kt- Tests core evaluation functionality
ParseTests.kt- Tests core parsing functionality
You can use the following commands in the interactive session:
info: displays information about all the variables, their modifier types, and their values.assign [varname] [varvalue]:- assigns a variable to a value (NOTE: the variable should be declared first)
varvaluecan also be an expression (e.g.assign a c+4)
evalLine [lineno]: evaluates the given line number and returns the result if it is an expressioninvoke [funcname] [args separated by comma]: invokes a function with the given arguments and returns the result
- conditional / loop statement support
- Implement support for ES named imports:
import { foo, bar } from "/modules/my-module.js"; let x = 1 + foo; let y = 2 * bar; x + y
