Skip to content

iamdudeman/sola-script

Repository files navigation

sola-script

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.

Java CI Javadocs Link

Sola grammar

program              := declaration* EOF ;

Declarations

declaration          := funDecl | varDecl | valDecl | statement ;
funDecl              := "fun" function ;
varDecl              := "var" IDENTIFIER ( "=" expression )? ";" ;
valDecl              := "val" IDENTIFIER "=" expression ";" ;

Declaration helpers

function             := IDENTIFIER "(" parameters? ")" block ;
parameters           := IDENTIFIER ( "," IDENTIFIER )* ;

Statements

statement            := exprStmt | ifStmt | returnStmt | whileStmt | block ;
exprStmt             := expression ";" ;
forStmt
ifStmt               := "if" "(" expression ")" statement ( "else" statement )? ;
returnStmt           := "return" expression? ";" ;
whileStmt            := "while" "(" expression ")" statement ;
block                := "{" declaration* "}" ;

Expressions

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 ;

Expression Helpers

arguments            := expression ( "," expression )* ;

Terminals

STRING               := \".*\"
NUMBER               := [1-9][0-9]*(\.[0-9]+)?
IDENTIFIER           := [a-zA-Z_][a-zA-Z0-9_]*
EOF                  := special for end of the file

Keywords

# declarations
"class" | "fun" | "var" | "val"

# statements
"else" | "for" | "if" | "while"

# values
"false" | "null" | "true"

# etc
"and" | "or" | "return"

Download

Gradle + Jitpack:

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.

Packaging fat jar for release

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.

About

A small interpreted language made to learn about programming language design

Topics

Resources

License

Stars

Watchers

Forks

Languages