sola-script is an interpreted programming language that I built to learn more about how programming languages are designed and implemented. It was developed while working through the material in the book Crafting Interpreters by Robert Nystrom.
program := declaration* EOF ;
declaration := funDecl | varDecl | valDecl | statement ;
funDecl := "fun" function ;
varDecl := "var" IDENTIFIER ( "=" expression )? ";" ;
valDecl := "val" IDENTIFIER "=" expression ";" ;
function := IDENTIFIER "(" parameters? ")" block ;
parameters := IDENTIFIER ( "," IDENTIFIER )* ;
statement := exprStmt | ifStmt | returnStmt | whileStmt | block ;
exprStmt := expression ";" ;
forStmt
ifStmt := "if" "(" expression ")" statement ( "else" statement )? ;
returnStmt := "return" expression? ";" ;
whileStmt := "while" "(" expression ")" statement ;
block := "{" declaration* "}" ;
expression := assignment ;
assignment := ( call ".")? IDENTIFIER "=" assignment | ternary | nullish_coalescence ;
ternary := nullish_coalescence "?" nullish_coalescence ":" nullish_coalescence ;
nullish_coalescence := logic_or ( "??" logic_or )* ;
logic_or := logic_and ( "||" logic_and )* ;
logic_and := equality ( "&&" equality )* ;
equality := comparison ( ( "!=" | "==" ) comparison )* ;
comparison := term ( ( ">" | ">=" | "<" | "<=" ) term )* ;
term := factor ( ( "-" | "+" ) factor )* ;
factor := unary ( ( "/" | "*" ) unary )* ;
unary := ( "!" | "-" ) unary | call ;
call := primary ( "(" arguments? ")" ) | "." IDENTIFIER )* ;
primary := "false" | "true" | "null" | NUMBER | STRING | "(" expression ")" | IDENTIFIER ;
arguments := expression ( "," expression )* ;
STRING := \".*\"
NUMBER := [1-9][0-9]*(\.[0-9]+)?
IDENTIFIER := [a-zA-Z_][a-zA-Z0-9_]*
EOF := special for end of the file
# declarations
"class" | "fun" | "var" | "val"
# statements
"else" | "for" | "if" | "while"
# values
"false" | "null" | "true"
# etc
"and" | "or" | "return"
repositories {
maven {
url = uri("https://jitpack.io")
}
}
dependencies {
implementation("com.github.iamdudeman:sola-script:0.1.0")
}
sola-script jar downloads hosted on GitHub releases.
Run the following gradle command
.\gradlew.bat distFatJar
The output will be at dist/sola-script-<version>.jar
. Users will need to have Java 17 installed to run the jar
via java -jar dist/sola-script-<version>.jar
.