{"id":20944364,"url":"https://github.com/amoshnin/typescript-programming.language","last_synced_at":"2026-05-06T19:33:54.299Z","repository":{"id":106313854,"uuid":"401197529","full_name":"amoshnin/TypeScript-Programming.Language","owner":"amoshnin","description":"⚡️ Small programming language and interpreter that supports fundamental programming concepts. Inspiration is heavily taken from the BASIC language and it is written in TypeScript","archived":false,"fork":false,"pushed_at":"2021-09-04T09:50:00.000Z","size":4486,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-13T04:16:21.025Z","etag":null,"topics":["interpreter","javascript","lexer","parser","programming-language","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/amoshnin.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}},"created_at":"2021-08-30T02:52:17.000Z","updated_at":"2024-07-08T23:37:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"46722fef-e2b2-4853-8048-201aaba51959","html_url":"https://github.com/amoshnin/TypeScript-Programming.Language","commit_stats":null,"previous_names":["amoshnin/typescript-programming.language"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/amoshnin/TypeScript-Programming.Language","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amoshnin%2FTypeScript-Programming.Language","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amoshnin%2FTypeScript-Programming.Language/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amoshnin%2FTypeScript-Programming.Language/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amoshnin%2FTypeScript-Programming.Language/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amoshnin","download_url":"https://codeload.github.com/amoshnin/TypeScript-Programming.Language/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amoshnin%2FTypeScript-Programming.Language/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28006407,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-24T02:00:07.193Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["interpreter","javascript","lexer","parser","programming-language","typescript"],"created_at":"2024-11-18T23:40:41.755Z","updated_at":"2025-12-24T19:11:12.350Z","avatar_url":"https://github.com/amoshnin.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lemo-Programming-Language and Interpreter\n\nLemo is a programming language and interpreter, which I developed during the Summer Holidays of 2021\u003cbr/\u003e\nMotivation for developing was pure interest/curiosity in learning how programming languages work under the hood\u003cbr/\u003e\nThe design of the language is heavily inspired by BASIC and the language it is written in is TypeScript\u003cbr/\u003e\n\n**Author**: Artem Moshnin \u003cbr/\u003e\n**Resources used**: [Gabriele Tomassetti's blog entries](https://tomassetti.me/resources-create-programming-languages/) with numerous useful resources (Books \u0026 Articles)\n\n## Overview\n\n### General information\n\nProgramming language supports various fundamental programming concepts such as variable-declaration,\nfunction calling, conditional statements, for and while loops, proper order of operations, recursion and much more.\n\n\u003e The language also includes the following built-in datatypes: Integers, Floats, Strings, Lists.\n\n\u003e Each datatype also has its own methods implemented that can be called on instances of these datatypes.\n\n\u003e The language also includes the following built-in global functions: print(), input(), clear().\n\n\u003e The language also includes a type-checking system.\n\n\u003e Multi-line support is integrated, as well as the ability to run external files of '.lemo' format.\n\nBelow is the language's EBNF-based grammar, and following that are some examples of programs that the language can run. Even further down is a link to a repl.it where the programs can be run.\n\n### Parser\n\nParser builds up a syntax tree of the program from the tokens created by the Lexer.\nThe parses has to figure out if the tokens match out language grammar. If it does, generate a tree accordingly.\nFor example: \"200 200 +\" makes no sense in our language. While \"123 + 456\" makes perfect sense.\n\nIn other words, order of operations are being followed and the parses construct the syntax tree accordingly to meet its requirements, as illustrated below:\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"./img/parser.png\" alt=\"Parser image (of mathematical expression)\" style=\"width:500px;\" /\u003e\n\u003c/p\u003e\n\nTo understand the source code of the parser, I below illustrated the grammar of a mathematical expression that is being analyzed while parsing to ensure that the order of operations are followed:\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"./img/parser_order_of_operations.jpeg\" alt=\"Parser image (of mathematical expression)\" style=\"width:500px;\" /\u003e\n\u003c/p\u003e\n\n### Interpreter\n\nThe role of the interpreter is to traverse through the AST (Abstract Syntax Tree) that the parser builds, look for different node types and determine what code should be executed. For example, if it comes across a binary operation node with a '+' operator - it will add its left and right child nodes together. The AST (Abstract Syntax Tree) will allow the interpreter to follow the order of operations correctly.\n\n### Steps for implementing new operators\n\n### Variables declaration\n\n\u003cdetails\u003e\n  \u003csummary style=\"fontWeight:bold;\"\u003eComparison, Logical Operators and Booleans\u003c/summary\u003e\n\n    \u003e\u003e Comparison Operators: =, !=, \u003c, \u003e, \u003c=, \u003e=\n\n    \u003e\u003e Logical Operators: and, or, not\n    - Example of Logical Operators:\n    - 5 == 5 and 6 == 6 =\u003e 1\n    - 1 + 1 == 2 or 2 + 2 == 5 =\u003e 1\n\n    \u003e\u003e Booleans: 0 = FALSE, 1 = TRUE\n\n\u003c/details\u003e\n\n## Grammar\n\n\u003cdetails\u003e\n  \u003csummary style=\"fontWeight:bold;\"\u003eGrammar (EBNF-based) of the Lemo-Programming Language\u003c/summary\u003e\n\n    -\u003e Grammar (EBNF-based) of the Lemo-Programming Language \u003c-\n\n    statements : NEWLINE* statement (NEWLINE+ statement)* NEWLINE\\*\n\n    statement : KEYWORD:RETURN expr?\n    : KEYWORD:CONTINUE\n    : KEYWORD:BREAK\n    : expr\n\n    expr : KEYWORD:VAR IDENTIFIER EQ expr\n    : comp-expr ((KEYWORD:AND|KEYWORD:OR) comp-expr)\\*\n\n    comp-expr : NOT comp-expr\n    : arith-expr ((EE|LT|GT|LTE|GTE) arith-expr)\\*\n\n    arith-expr : term ((PLUS|MINUS) term)\\*\n\n    term : factor ((MUL|DIV) factor)\\*\n\n    factor : (PLUS|MINUS) factor\n    : power\n\n    power : call (POW factor)\\*\n\n    call : atom (LPAREN (expr (COMMA expr)\\*)? RPAREN)?\n\n    atom : INT|FLOAT|STRING|IDENTIFIER\n    : LPAREN expr RPAREN\n    : list-expr\n    : if-expr\n    : for-expr\n    : while-expr\n    : func-def\n\n    list-expr : LSQUARE (expr (COMMA expr)\\*)? RSQUARE\n\n    if-expr : KEYWORD:IF expr KEYWORD:THEN\n    (statement if-expr-b|if-expr-c?)\n    | (NEWLINE statements KEYWORD:END|if-expr-b|if-expr-c)\n\n    if-expr-b : KEYWORD:ELIF expr KEYWORD:THEN\n    (statement if-expr-b|if-expr-c?)\n    | (NEWLINE statements KEYWORD:END|if-expr-b|if-expr-c)\n\n    if-expr-c : KEYWORD:ELSE\n    statement\n    | (NEWLINE statements KEYWORD:END)\n\n    for-expr : KEYWORD:FOR IDENTIFIER EQ expr KEYWORD:TO expr\n    (KEYWORD:STEP expr)? KEYWORD:THEN\n    statement\n    | (NEWLINE statements KEYWORD:END)\n\n    while-expr : KEYWORD:WHILE expr KEYWORD:THEN\n    statement\n    | (NEWLINE statements KEYWORD:END)\n\n    func-def : KEYWORD:FUN IDENTIFIER?\n    LPAREN (IDENTIFIER (COMMA IDENTIFIER)\\*)? RPAREN\n    (ARROW expr)\n    | (NEWLINE statements KEYWORD:END)\n\n\u003c/details\u003e\n\n## Examples of Fundamental Concepts of Programming Languages\n\n### Built-In Constants\n\n```javascript\nPRINT(NULL) // 0\nPRINT(FALSE) // 0\nPRINT(TRUE) // 1\nPRINT(MATH_PI) // 3.141592653589793\n```\n\n### Built-In Functions\n\n```javascript\n// \u003e General functins \u003c //\n'PRINT' =\u003e\nPRINT(\"Hello World\") // Hello World\n\n// \u003e Check if is corresponding type \u003c //\n'IS_NUMBER' =\u003e\nIS_NUMBER(123) // 1\nIS_NUMBER(\"Hello\") // 0\n\n'IS_STRING' =\u003e\nIS_STRING(\"Hello\") // 1\nIS_STRING(123) // 0\n\n'IS_LIST' =\u003e\nIS_LIST([1,2,3]) // 1\nIS_LIST(\"Hello\") // 0\n\n'IS_FUNCTION' =\u003e\nVAR x = FUN test(a) -\u003e a * 2 // \u003cfunction test\u003e\nIS_FUNCTION(x) // 1\n\n// \u003e List functions (mutable) \u003c //\n'APPEND' =\u003e\nVAR list = [1,2,3] // [1, 2, 3]\nAPPEND(list, 4)\nPRINT([1, 2, 3]) // [1, 2, 3, 4]\n\n'POP' =\u003e\nVAR list = [1,2,3] // [1, 2, 3]\nPOP(list, 0) // 1\nPRINT(list) // [2, 3]\n\n// \u003e List functions (immutable) \u003c //\n'EXTEND' =\u003e\nVAR list = [1, 2, 3]\nVAR extendedList = EXTEND(list, [1,2,3])\nPRINT(extendedList) // [1, 2, 3, 1, 2, 3]\nPRINT(list) // [1, 2, 3]\n```\n\n### Basic Variable Declaration\n\n### Basic Function Calling\n\n```javascript\nFUN add (a, b) -\u003e a + b // \u003cfunction add\u003e\nadd(5, 6) // 11\n```\n\n### Re-assigning function to a variable\n\n```javascript\nFUN add (a, b) -\u003e a + b // \u003cfunction add\u003e\nVAR someFunc = add // \u003cfunction add\u003e\nsomeFunc(1, 2) // 3\n```\n\n### Anonymous functions\n\n```javascript\nFUN (a) -\u003e a + 6 // function\u003canonymous\u003e\nVAR someFunc = FUN(a) -\u003e a + 6\nsomeFunc(12) // 12 + 6 = 18\n```\n\n### Structured Error Traceback when calling functions which throw some error\n\n```javascript\nFUN test(a) -\u003e a / 0 // function\u003ctest\u003e\ntest(12345)\n// Error output:\n// Traceback (most recent call last):\n//    File \u003cstdin\u003e, line: 1, in \u003cprogram\u003e\n//    File \u003cstdin\u003e, line: 1, in test\n// Runtime Error: Division by zero\n//\n// FUN test(a) -\u003e a / 0\n//                    ^\n```\n\n### Basic Conditional Statements\n\n### For Loop (positive step values)\n\n```javascript\nVAR result = 1\nFOR i = 1 TO 6 THEN VAR result = result * i\nresult // result =\u003e 120\n```\n\n### For Loop (negative step values)\n\n```javascript\nVAR result = 1\nFOR i = 5 TO 0 STEP -1 THEN VAR result = result * i\nresult // result =\u003e 120\n```\n\n### While Loop\n\n```javascript\nVAR result = 0\nWHILE result \u003c 100000 THEN VAR result = result + 1\nresult // result =\u003e 100000\n```\n\n### Order of Operations\n\n```javascript\nVAR result1 = (2 + 5) * 2 - (10 + 5) // -1\nVAR result2 = 5 == 5 OR 3 == 2 // 1 (TRUE)\n```\n\n## Examples of Advanced Concepts of Programming Languages (Multi-Line Statements \u0026 Reading from files)\n\n### Multi-Line Statements (if statements)\n\n```javascript\nIF \u003cexpr\u003e THEN \u003cexpr\u003e\n\nIF \u003cexpr\u003e THEN\n  \u003cexpr1\u003e\n  \u003cexpr2\u003e\n  \u003cexpr3\u003e\nEND\n```\n\n### Multi-Line Statements (for loops)\n\n```javascript\nFOR i = 0 to 10 THEN \u003cexpr\u003e\n\nFOR i = 0 TO 10 THEN\n  \u003cexpr1\u003e\n  \u003cexpr2\u003e\n  \u003cexpr3\u003e\nEND\n```\n\n### Multi-Line Statements (functions)\n\n```javascript\nFUN \u003cname\u003e() -\u003e \u003cexpr\u003e\n\nFUN \u003cname\u003e()\n  \u003cexpr1\u003e\n  \u003cexpr2\u003e\n  \u003cexpr3\u003e\nEND\n```\n\n## DataTypes\n\n### DataType: Integer (INT)\n\n```javascript\nVAR int = 25\n```\n\n### DataType: Floating number (FLOAT)\n\n```javascript\nVAR float = 23.2\n```\n\n### DataType: String\n\n```javascript\n'Text'\n\"Text with \\\"quotes\\\"\"\n'Text with \\\\ backslashes \\\\'\n'Text \\nwith \\nnewlines'\n```\n\n### DataType: Lists\n\n```javascript\n[] // List syntax\n[1, 2, 3] + 4 =\u003e [1, 2, 3, 4] // Add an element to the list\n[1, 2, 3] * [3, 4, 5] =\u003e [1, 2, 3, 3, 4, 5] // Concatenate two lists\n\n[1, 2, 3] - 1 =\u003e [1, 3] // Remove element from the list at index 1\n[1, 2, 3] - 0 =\u003e [2, 3] // Remove element from the list at index 0\n\n[1, 2, 3] - -1 =\u003e [1, 2] // Remove the last element from the list\n[1, 2, 3] - -2 =\u003e [1, 3] // Remove the before-last element from the list\n\n[1, 2, 3] / 0 =\u003e 1 // Retrieve an element from the array at index 0\n[1, 2, 3] / 1 =\u003e 2 // Retrieve an element from the array at index 1\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famoshnin%2Ftypescript-programming.language","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famoshnin%2Ftypescript-programming.language","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famoshnin%2Ftypescript-programming.language/lists"}