{"id":16602942,"url":"https://github.com/leonardpepa/jlox","last_synced_at":"2026-04-17T21:32:04.716Z","repository":{"id":68737469,"uuid":"520939623","full_name":"Leonardpepa/jlox","owner":"Leonardpepa","description":"JLOX is an interpreted scripting programming language implemented by reading the book Crafting intepreters","archived":false,"fork":false,"pushed_at":"2022-08-17T18:00:35.000Z","size":213,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-09T12:56:02.735Z","etag":null,"topics":["crafting-interpreters","jlox","lexical-analysis","parser","programming-language","scripting-language","semantic-analysis","walk-tree"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Leonardpepa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-03T15:40:31.000Z","updated_at":"2024-06-25T22:13:16.000Z","dependencies_parsed_at":"2023-04-01T06:35:28.214Z","dependency_job_id":null,"html_url":"https://github.com/Leonardpepa/jlox","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Leonardpepa/jlox","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Leonardpepa%2Fjlox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Leonardpepa%2Fjlox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Leonardpepa%2Fjlox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Leonardpepa%2Fjlox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Leonardpepa","download_url":"https://codeload.github.com/Leonardpepa/jlox/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Leonardpepa%2Fjlox/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31947522,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T17:29:20.459Z","status":"ssl_error","status_checked_at":"2026-04-17T17:28:47.801Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crafting-interpreters","jlox","lexical-analysis","parser","programming-language","scripting-language","semantic-analysis","walk-tree"],"created_at":"2024-10-12T00:46:01.339Z","updated_at":"2026-04-17T21:32:04.701Z","avatar_url":"https://github.com/Leonardpepa.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JLOX is an interpreted scripting programming language implemented by reading the book [Crafting intepreters](https://craftinginterpreters.com/)\n\n## Syntax Of JLOX\nJLox is a high-level scripting interpreted garbage collected language with dynamic typing.\nFunctions are first class in Lox, which just means they are real values that you can get a reference to, store in variables, pass around.\n\n### Variables\n```console\n    var x = 15; // number\n    var name = \"your name\"; // string\n    var yes = true; // booleans\n    var no = false; // booleans\n    var nullable = nil;\n```\n\n### Logical operators\n```console\n!true;  // false.\n!false; // true.\ntrue and false; // false.\ntrue and true;  // true.\nfalse or false; // false.\ntrue or false;  // true.\n```\n\n### Control flow\n```console\n    var x = 15;\n    if(x \u003e 0){\n        print \"x \u003e 0\";\n    }else {\n        print \"x \u003c= 0\";    \n    }\n```\n\n### Loops\n```console\n    var i = 0;\n    while(i \u003c 10){\n        print i;\n        i = i + 1;\n    }\n    \n    for(var j=0; j\u003c5; j = j + 1){\n        print j;\n    }\n```\n\n### Functions\n```console\n    fun greetings(name){\n        print \"hello \" + name;\n    }\n    \n    greetings(\"leonard\");\n```\n\n### Closures\n```console\nfun addPair(a, b) {\n  return a + b;\n}\n\nfun identity(a) {\n  return a;\n}\n\nprint identity(addPair)(1, 2); // Prints \"3\".\n\nfun makeCounter(){\n    var c = 0;\n    fun counter(){\n        c = c + 1;\n        print c;\n    }\n    return counter;\n}\n\nvar counter1 = makeCounter();\nvar counter2 = makeCounter();\n\ncounter1(); // 1\ncounter2(); // 1\n```\n\n### Classes\n```console\n    class Animal {\n        \n        init(aname){\n            this.name = aname;\n        }\n        \n        makeNoise(){\n            print \"animal noise\";\n        }\n        \n        printDetails(){\n            print this.name;\n        }\n    }\n    \n    var animal = Animal(\"something\");\n    print animal;\n    animal.makeNoise();\n    animal.printDetails();\n```\n### Inheritance\n```console\n    class Dog \u003c Animal {\n        init(aname, age){\n            super.init(aname);\n            this.age = age;\n        }\n        \n        makeNoise(){\n            print \"woof woof\";\n        }\n        \n        printDetails(){\n            super.printDetails();\n            print this.age;\n        }\n    }\n    var dog = Dog(\"doggo\", 2);\n    print dog;\n    dog.makeNoise();\n    dog.printDetails();\n```\n## File Strucure\n* Lox.java [entry point of the program]\n* AST [classes to represent the ast nodes]\n* Enviroment [classes for semantic analysis and runtime representation of the functions and classes in lox]\n* Intepreter [classes for the interpreter implemented with the visitor pattern]\n* Parser [classes for parsing the code in to a syntax tree]\n* Scanner [classes for lexical analysis]\n* Utils [utility classes]\n* Error [error handlers]\n* tests [lox program's to test the interpreter]\n\n## Topics Covered\n* tokens and lexing\n* abstract syntax trees\n* recursive descent parsing\n* prefix and infix expressions\n* runtime representation of objects\n* interpreting code using the Visitor pattern\n* lexical scope\n* environment chains for storing variables\n* control flow\n* functions with parameters\n* closures\n* static variable resolution and error detection\n* classes\n* constructors\n* fields\n* methods\n* inheritance\n\n\n## Lexical Grammar\n```console\nNUMBER → DIGIT+ ( \".\" DIGIT+ )? ;\nSTRING → \"\\\"\" \u003cany char except \"\\\"\"\u003e* \"\\\"\" ;\nIDENTIFIER → ALPHA ( ALPHA | DIGIT )* ;\nALPHA → \"a\" ... \"z\" | \"A\" ... \"Z\" | \"_\" ;\nDIGIT → \"0\" ... \"9\" ;\n```\n\n## Context Free Grammar\n```console\nprogram → declaration* EOF ;\n\ndeclaration → classDecl\n | funDecl\n | varDecl\n | statement ;\n\nclassDecl → \"class\" IDENTIFIER ( \"\u003c\" IDENTIFIER )?\n \"{\" function* \"}\" ;\n\nfunDecl → \"fun\" function ;\n\nvarDecl → \"var\" IDENTIFIER ( \"=\" expression )? \";\" ;\n\nstatement → exprStmt\n | forStmt\n | ifStmt\n | printStmt\n | returnStmt\n | whileStmt\n | block ;\n\nexprStmt → expression \";\" ;\n\nforStmt → \"for\" \"(\" ( varDecl | exprStmt | \";\" ) expression? \";\" expression? \")\" statement ;\n\nifStmt → \"if\" \"(\" expression \")\" statement ( \"else\" statement )? ;\n\nprintStmt → \"print\" expression \";\" ;\n\nreturnStmt → \"return\" expression? \";\" ;\n\nwhileStmt → \"while\" \"(\" expression \")\" statement ; \n\nblock → \"{\" declaration* \"}\" ;\n\nexpression → assignment ;\n\nassignment → ( call \".\" )? IDENTIFIER \"=\" assignment | logic_or ;\n\nlogic_or → logic_and ( \"or\" logic_and )* ;\n\nlogic_and → equality ( \"and\" equality )* ;\n\nequality → comparison ( ( \"!=\" | \"==\" ) comparison )* ;\n\ncomparison → term ( ( \"\u003e\" | \"\u003e=\" | \"\u003c\" | \"\u003c=\" ) term )* ;\n\nterm → factor ( ( \"-\" | \"+\" ) factor )* ;\n\nfactor → unary ( ( \"/\" | \"*\" ) unary )* ;\n\nunary → ( \"!\" | \"-\" ) unary | call ;\n\ncall → primary ( \"(\" arguments? \")\" | \".\" IDENTIFIER )* ;\n\nprimary → \"true\" | \"false\" | \"nil\" | \"this\" | NUMBER | STRING | IDENTIFIER | \"(\" expression \")\"\n | \"super\" \".\" IDENTIFIER ;\n \nfunction → IDENTIFIER \"(\" parameters? \")\" block ;\n\nparameters → IDENTIFIER ( \",\" IDENTIFIER )* ;\n\narguments → expression ( \",\" expression )* ;\n\n```\n\n## How to run\nif you don't provide a source file then the program opens the REPL and you can type and interpret your code line by line.\n* clone the repo with git clone https://github.com/Leonardpepa/jlox\n* cd into the project\n* run the jar with java -jar JLOX.jar [file]\n* or open with intellij and run the project\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleonardpepa%2Fjlox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleonardpepa%2Fjlox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleonardpepa%2Fjlox/lists"}