{"id":22873309,"url":"https://github.com/frederiktobner/jbasic","last_synced_at":"2025-03-31T12:22:51.407Z","repository":{"id":107177245,"uuid":"581948913","full_name":"FrederikTobner/JBASIC","owner":"FrederikTobner","description":"Simple Interpreter for the JBASIC programming language","archived":false,"fork":false,"pushed_at":"2023-06-09T05:57:02.000Z","size":1212,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-06T18:03:30.576Z","etag":null,"topics":["antlr4","basic","interpreter","programming-language","scripting-language"],"latest_commit_sha":null,"homepage":"https://frederiktobner.github.io/JBASIC/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FrederikTobner.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-12-25T02:05:08.000Z","updated_at":"2023-02-24T10:26:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"914aa9d5-b442-4565-93a2-6759dcb7c1ed","html_url":"https://github.com/FrederikTobner/JBASIC","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FrederikTobner%2FJBASIC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FrederikTobner%2FJBASIC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FrederikTobner%2FJBASIC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FrederikTobner%2FJBASIC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FrederikTobner","download_url":"https://codeload.github.com/FrederikTobner/JBASIC/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246465812,"owners_count":20782038,"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","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":["antlr4","basic","interpreter","programming-language","scripting-language"],"created_at":"2024-12-13T14:18:31.895Z","updated_at":"2025-03-31T12:22:51.400Z","avatar_url":"https://github.com/FrederikTobner.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JBASIC\n\n[![Maven CI](https://github.com/FrederikTobner/JBASIC/actions/workflows/maven.yml/badge.svg)](https://github.com/FrederikTobner/JBASIC/actions/workflows/maven.yml)\n[![Code QL](https://github.com/FrederikTobner/JBASIC/actions/workflows/codeql.yml/badge.svg)](https://github.com/FrederikTobner/JBASIC/actions/workflows/codeql.yml)\n[![Java 11+](https://img.shields.io/badge/java-11+-4c7e9f.svg)](http://java.oracle.com)\n[![ANTLR v4](https://img.shields.io/badge/Antlr-v4-4c7e9f)](https://github.com/antlr/antlr4)\n\nSimple Interpreter for the JBASIC programming language written in Java using [ANTLR](https://www.antlr.org/).\n\nJBASIC is a simple general purpose, high-level scripting language heavily inspired\nby the earliest dialects of [BASIC](https://en.wikipedia.org/wiki/BASIC).\n\n## Table of Contents\n\n* [Overview](#overview)\n* [Operators](#operators)\n* [Keywords](#keywords)\n* [Functions](#functions)\n* [Building](#building)\n* [How it works](#how-it-works)\n* [License](#license)\n\n## Overview\n\nJBASIC is dialect of 'BASIC' (Beginners' All-purpose Symbolic Instruction Code) a family of general-purpose, high-level\nprogramming languages, that focus on ease of use. \nThe original version of BASIC was created in 1963 at the Dartmouth College, by  John G. Kemeny and Thomas E. Kurtz.\n\nJBASIC combines traits of the first and the second generation of basic languages. \n\nUsage:\n\n    java -jar JBASIC.jar \u003cfilePath\u003e\n\n## Operators\n\n### Binary operators\n\n| Operator | Description                                                           | Example      |\n|----------|-----------------------------------------------------------------------|--------------|\n| +        | Computes the sum of two numerical values or concatenates two strings. | 1 + 2   // 3 |\n| -        | Subtracts the second value from the first value.                      | 2 - 1   // 1 |\n| *        | Multiplies the two values.                                            | 3 * 3   // 9 |\n| /        | Divides the first value with the second value.                        | 9 / 3   // 3 |\n| \u003c        | Less than                                                             | 1 \u003c 2   // 1 |\n| \u003c=       | Less than equal.                                                      | 1 \u003c= 2  // 1 |\n| \u003e        | Greater than                                                          | 1 \u003e 2   // 0 |\n| \u003e=       | Greater than equal.                                                   | 1 \u003e= 2  // 0 |\n| =        | Comparison for equality of two values. 1 if they are equal 0 if not   | 9 = 3   // 0 |\n| \u003c\u003e       | Comparison for equality of two values. 0 if they are equal 1 if not   | 9 \u003c\u003e 3  // 1 |\n\n### Unary operators\n\n| Operator | Description                | Example |\n|----------|----------------------------|---------|\n| -        | Negates a numerical value. | -5      |\n\n## Keywords\n\nThe language features the following keywords\n\n### Data manipulation\n\n| Keyword  | Description                                                                                                                                                                                                           | Example            |\n|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------|\n| DATA ... | holds a list of values which are assigned sequentially using the READ command                                                                                                                                         | DATA 1, 2, 3, 4, 5 |\n| DIM      | Creates a new array with the specified dimensions                                                                                                                                                                     | DIM array[3]       |\n| LET      | Assigns a value (which may be the result of an expression) to a variable.                                                                                                                                             | LET I = 1          |\n| READ ... | Reads a value from a DATA statement and assigns it to a variable and moves it one position forward with each READ.\u003cbr\u003eMultiple variables can be specified as parameters to read several values in a single operation. | READ A, B          |\n| RESTORE  | Resets to the DATA statement to the specified index, allowing the program to begin READing from the value at the specified index.                                                                                     | RESTORE 0          |\n\nIf the variable name in a Let statement ends with '$' the assigned value needs to be a string and if it ends with '%' a numerical value.\n\n```\nLET ASTRING$ = \"Hello World\"\nLET ANUMBER% = 10\n```\n\nAn array in JBASIC can be either one-, two- or three-dimensional.\nA specific value in the array can be accessed or altered by specifying the index. \nThe first element in an array has the index '1', like in most other dialects of BASIC.\n\n```\nDIM array[3]\narray[1] = \"Hello\"\narray[2] = \" World!\"\nPRINT array[1] + array[2]\n```\n\nIf the array name in a DIM statement ends with '$' it can only store strings and if it ends with '%' it can only store numerical values.\n\n### Input and output\n\n| Keyword | Description                                                                                   | Example              |\n|---------|-----------------------------------------------------------------------------------------------|----------------------|\n| CLS     | Clears the screen                                                                             | CLS                  |\n| INPUT   | Asks the user to enter the value of a variable.\u003cbr\u003eThe statement may include a prompt message | INPUT \"NAME= \", name |\n| PRINT   | Displays a message on the screen or other output device                                       | PRINT \"Hello World!\" |\n\n### Logical\n\n| Keyword | Description                                                                   | Example              |\n|---------|-------------------------------------------------------------------------------|----------------------|\n| NOT     | Inverts a logical value.                                                      | NOT 1 // 0           |\n\n### Mathematical\n\n| Keyword | Description                                                                    | Example      |\n|---------|--------------------------------------------------------------------------------|--------------|\n| MOD     | Returns the remainder of the division of the first value with the second value | 5 MOD 3 // 2 |\n\n### Miscellaneous\n\n| Keyword | Description                                                                                             | Example                        |\n|---------|---------------------------------------------------------------------------------------------------------|--------------------------------|\n| REM     | holds a programmer's comment or remark\u003cbr\u003e used to help identify the purpose of a given section of code | REM This is a remark / comment |\n\n### Program flow control\n\n| Keyword(s)                                                           | Description                                                                                                    | Example                                                                                     |\n|----------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------|\n| IF ... THEN \u003cbr\u003e...\u003cbr\u003e {ELSE IF} \u003cbr\u003e...\u003cbr\u003e {ELSE} \u003cbr\u003e...\u003cbr\u003e END | Used to perform comparisons or make decisions.                                                                 | IF 1 \u003c 2 THEN\u003cbr\u003e\u0026emsp;print \"true\"\u003cbr\u003eELSE\u003cbr\u003e\u0026emsp;print \"false\"\u003cbr\u003eEND                   |\n| FOR ... TO ... {STEP} \u003cbr\u003e...\u003cbr\u003e NEXT                               | Repeats a section of code a given number of times.                                                             | FOR I = 0 TO 5\u003cbr\u003e\u0026emsp;print I\u003cbr\u003eNEXT                                                     |\n| WHILE ... \u003cbr\u003e ...\u003cbr\u003e END                                           | Repeats a section of code a given number of times.                                                             | WHILE I \u003c 2 \u003cbr\u003e\u0026emsp;print I\u003cbr\u003e\u0026emsp;I = I + 1\u003cbr\u003eEND                                     |\n| REPEAT \u003cbr\u003e ... \u003cbr\u003e UNTIL ...                                       | Repeats a section of code a given number of times.                                                             | REPEAT \u003cbr\u003e\u0026emsp;print I\u003cbr\u003e\u0026emsp;I = I + 1 \u003cbr\u003eUNTIL I \u003e 4                                 |\n| DO \u003cbr\u003e ... \u003cbr\u003e WHILE ...                                           | Repeats a section of code a given number of times,\u003cbr\u003e but at least once.                                      | DO \u003cbr\u003e\u0026emsp;print I\u003cbr\u003e\u0026emsp;I = I + 1\u003cbr\u003eWHILE I \u003c 2                                      |\n| DO \u003cbr\u003e ... \u003cbr\u003e UNTIL ...                                           | Repeats a section of code a given number of times,\u003cbr\u003e but at least once.                                      | DO 1 \u003c 2 \u003cbr\u003e\u0026emsp;print I\u003cbr\u003e\u0026emsp;I = I + 1 \u003cbr\u003eUNTIL I \u003e 4                               |\n| SWITCH ...\u003cbr\u003e (CASE ... : ...)+\u003cbr\u003e END                             | Allows the use of the value of a variable or\u003cbr\u003eexpression to change the program execution via search and map. | SWITCH 1 + 2 \u003cbr\u003e\u0026emsp;CASE 1: \"one\"\u003cbr\u003e\u0026emsp;CASE 2: \"two\"\u003cbr\u003e\u0026emsp;CASE 3: \"three\"\u003cbr\u003eend |\n| GOTO                                                                 | Jumps to a numbered or labelled line in the program.                                                           | 10: PRINT \"Hi\" \u003cbr\u003e20: GOTO 10                                                              |\n\n### Subroutine specific\n\nJBASIC allows the definition of subroutines to accomplish a particular task.\n\n| Keyword(s)           | Description              | Example                                         |\n|----------------------|--------------------------|-------------------------------------------------|\n| CALL(...)            | Calls a subroutine       | CALL printSum(1, 2)                             |\n| SUB(...) ... END SUB | Defines a new subroutine | SUB printSum(a, b) \u003cbr\u003e\u0026emsp;PRINT a + b\u003cbr\u003eEND |\n\nAn example for a simple subroutine would\nbe:\n\n```\nSUB Greet()\n   INPUT \"Name=\" name\n   PRINT \"Hi my name is \" + name\nEND SUB\n\nCALL Greet()\n```\n\nThe SUB keyword marks the definition of a subroutine. \nAfter that the name of the subroutine and the arguments of the\nsubroutine are specified. Then the body of the subroutine follows. \nThe end of the subroutine is marked with the END and the SUB keyword. \nSubroutines are then invoked using the call keyword.\n\n## Functions\n\nJBASIC offers numerous built-in functions to perform various tasks.\n\n### Mathematical\n\n| FunctionName | Description                | Example Usage                                                                |\n|--------------|----------------------------|------------------------------------------------------------------------------|\n| ABS          | Absolute value             | ABS(-2)                                 // 2                                 |\n| ACS          | Arc cosine                 | ACS(0)                                  // 1.5707963267949                   |\n| ASH          | Arc sine hyperbolicus      | ASH(1.1752011936438)                    // 1                                 |\n| ASN          | Arc sine                   | ASN(1)                                  // 1.5707963267949                   |\n| ATH          | Area tangent hyperbolicus  | ATH(1)                                  // ∞                                 |\n| ATN          | Arc tangent                | ATN(1)                                  // 0.78539816339745                  |\n| AVG          | Average                    | AVG(1, 2, 3)                            // 2                                 |\n| COS          | Cosine                     | COS(1.5707963267949)                    // 0                                 |\n| EXP          | Exponential function       | EXP(1)                                  // 2,7182818284590452353602874713527 |\n| LOG          | Natural logarithm          | LOG(2,7182818284590452353602874713527)  // 1                                 |\n| MAX          | Maximum value              | MAX(1, 2, 3)                            // 3                                 |\n| MIN          | Minimum value              | MIN(1, 2, 3)                            // 1                                 |\n| SIN          | Sine (argument in radians) | SIN(1.5707963267949)                    // 1                                 |\n| SQR          | Square root                | SQR(9)                                  // 3                                 |\n| SUM          | Summation                  | SUM(1, 2, 3)                            // 6                                 |\n| TAN          | Tangent                    | TAN(0.78539816339745)                   // 1                                 |\n\n### Miscellaneous\n\n| Function | Description                                                                | Example Usage           |\n|----------|----------------------------------------------------------------------------|-------------------------|\n| LIST     | Creates a string that contains the full source code of the current program | LIST()      // LIST()   |\n| NUM      | Converts a string to a numerical value                                     | NUM(\"3\")    // 3        |\n| RND      | Creates a random number in the specified range                             | RND(1, 3)   // [1 .. 3] |\n| STR      | Converts a numerical value to a string                                     | STR(3)      // \"3\"      |\n\n### Strings\n\n| FunctionName | Description        | Example Usage   |\n|--------------|--------------------|-----------------|\n| LEN          | Length of a string | LEN(\"123\") // 3 |\n\n## Building\n\nThe interpreter is built using maven and uses the JDK version 11.\n\n## How it works\n\nThe interpretation of a program is performed in the following stages:\n\n* Lexical analysis: We iterate over all the characters in the source code and group them together to tokens\n* Parsing: Next we parse the linear sequence of tokens we have created in the previous step to create an abstract syntax\n  tree\n* Execution: To execute a JBASIC program we visit all the nodes in our abstract syntax tree and evaluate them\n\nMore information about the interpreter can be found at the [technical documentation](https://frederiktobner.github.io/JBASIC/).\n\n## License\n\nThis project is licensed under the [GNU General Public License](LICENSE)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrederiktobner%2Fjbasic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrederiktobner%2Fjbasic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrederiktobner%2Fjbasic/lists"}