{"id":19163066,"url":"https://github.com/federicobruzzone/smaller-basic","last_synced_at":"2026-01-18T10:02:17.237Z","repository":{"id":176832434,"uuid":"657497323","full_name":"FedericoBruzzone/smaller-basic","owner":"FedericoBruzzone","description":" A Python interpreter using ANTLR4 as a parser generator for a version of Microsoft's Small Basic language renamed \"Smaller Basic.\"","archived":false,"fork":false,"pushed_at":"2024-08-12T16:08:48.000Z","size":6684,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-04T07:33:55.364Z","etag":null,"topics":["basic","compiler","interpreter","language","python","smallbasic","smallbasic-lang"],"latest_commit_sha":null,"homepage":"","language":"Python","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/FedericoBruzzone.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":"2023-06-23T07:34:08.000Z","updated_at":"2024-08-12T16:08:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"20a65ecf-4b9c-4921-a33a-d8ada4234ce8","html_url":"https://github.com/FedericoBruzzone/smaller-basic","commit_stats":null,"previous_names":["federicobruzzone/smaller-basic"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/FedericoBruzzone/smaller-basic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FedericoBruzzone%2Fsmaller-basic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FedericoBruzzone%2Fsmaller-basic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FedericoBruzzone%2Fsmaller-basic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FedericoBruzzone%2Fsmaller-basic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FedericoBruzzone","download_url":"https://codeload.github.com/FedericoBruzzone/smaller-basic/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FedericoBruzzone%2Fsmaller-basic/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28534203,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T00:39:45.795Z","status":"online","status_checked_at":"2026-01-18T02:00:07.578Z","response_time":98,"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":["basic","compiler","interpreter","language","python","smallbasic","smallbasic-lang"],"created_at":"2024-11-09T09:14:08.344Z","updated_at":"2026-01-18T10:02:17.193Z","avatar_url":"https://github.com/FedericoBruzzone.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Smaller Basic\n\nA Python interpreter using ANTLR4 as a parser generator for a version of Microsoft's Small Basic language renamed \"Smaller Basic.\"\n\n## Examples of source code\n\nLocation of this source code: `source_code/source.sb`.\n\n```python\nSub x_as_int\n    If (x = \"1\") Then x = 1 EndIf\n    If (x = \"2\") Then x = 2 EndIf\n    If (x = \"3\") Then x = 3 EndIf\n    If (x = \"4\") Then x = 4 EndIf\n    If (x = \"5\") Then x = 5 EndIf\n    If (x = \"6\") Then x = 6 EndIf\n    If (x = \"7\") Then x = 7 EndIf\n    If (x = \"8\") Then x = 8 EndIf\n    If (x = \"9\") Then x = 9 EndIf\nEndSub\n\nSub main\n    While (true)\n        IO.WriteLine(\"Enter a number from 0 to 9: \")\n        x = IO.ReadLine()\n        x_as_int()\n\n        IO.WriteLine(\"Enter your name: \")\n        name = IO.ReadLine()\n\n        For i = 0 To x Step 2\n            IO.WriteLine(\"Hello \" + name)\n        EndFor\n    EndWhile\nEndSub\n\nmain()\n```\n\n\n\u003cdetails\u003e\n  \u003csummary\u003eAST\u003c/summary\u003e\n\n  ![ast](https://github.com/FedericoBruzzone/smaller-basic/blob/main/img_readme/ast-source.png)\n\u003c/details\u003e\n\nThe output of this source code is:\n\n```bash\n+---------------------------------------+\n| ----- Run source_code/source.sb ----- |\n+---------------------------------------+\n\nEnter a number from 0 to 9:\n|\u003e 8\nEnter your name:\n|\u003e Federico\nHello Federico\nHello Federico\nHello Federico\nHello Federico\n```\n\n\u003cdetails\u003e\n  \u003csummary\u003e\u003cb\u003eExample using Library, Array and Goto statements\u003c/b\u003e [source_code/first_prog.sb] \u003c/summary\u003e\n\n  ```python\nSub init_value_as_int\n    If (init_value = \"1\") Then init_value = 1 EndIf\n    If (init_value = \"2\") Then init_value = 2 EndIf\n    If (init_value = \"3\") Then init_value = 3 EndIf\n    If (init_value = \"4\") Then init_value = 4 EndIf\n    If (init_value = \"5\") Then init_value = 5 EndIf\n    If (init_value = \"6\") Then init_value = 6 EndIf\n    If (init_value = \"7\") Then init_value = 7 EndIf\n    If (init_value = \"8\") Then init_value = 8 EndIf\n    If (init_value = \"9\") Then init_value = 9 EndIf\nEndSub\n\nSub ArrayInit\n    For i = 0 To 3\n        For j = 0 To 3\n            my_vec[i][j] = init_value\n        EndFor\n    EndFor\nEndSub\n\nSub ArrayIncrement\n    For i = 0 To 3\n        For j = 0 To 3\n            my_vec[i][j] = my_vec[i][j] + 1\n        EndFor\n    EndFor\nEndSub\n\nSub Main\n    my_vec[2][2] = 0\n    IO.WriteLine(my_vec)\n\n    count = 0\n    LabelFor5:\n    IO.WriteLine(count)\n\n    IO.WriteLine(\"Enter the value with which you want to initialize the array: \")\n    init_value = IO.ReadLine()\n    If (String.Length(init_value) \u003e 1) Then\n        IO.WriteLine(\"You entered more than one character. Only the first character will be used.\")\n        init_value = String.Substr(init_value, 0, 1)\n    EndIf\n    init_value_as_int()\n\n    ArrayInit()\n    IO.WriteLine(my_vec)\n\n    ArrayIncrement()\n    IO.WriteLine(my_vec)\n\n    count = count + 1\n    If (count \u003c 5) Then\n        Goto LabelFor5\n    EndIf\n\n    Goto End\n\n    While (my_vec[2][2] \u003c 10)\n        ArrayIncrement()\n        IO.WriteLine(my_vec)\n    EndWhile\nEndSub\n\nMain()\n\nEnd:\n    IO.WriteLine(\"End of program.\")\n  ```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003e\u003cb\u003eExample using nested Goto\u003c/b\u003e [source_code/second_prog.sb]\u003c/summary\u003e\n\n  ```python\n  a = 1\n\nLoop1:\n    IO.WriteLine(\"Loop1\")\n\n    Loop2:\n        IO.WriteLine(\"Loop2\")\n        a = a + 1\n        If (a \u003c 10) Then\n            Goto Loop2\n        EndIf\n\n    IO.WriteLine(a)\n    a = a + Math.Sqrt(a)\n    IO.WriteLine(a)\n\n    If (a \u003e 100) Then\n        Goto End\n    EndIf\n\nGoto Loop1\n\n\nEnd:\n    IO.WriteLine(\"End\")\n  ```\n\u003c/details\u003e\n\nParsing errors and warnings are displayed as follows:\n\n![warning_error](https://github.com/FedericoBruzzone/smaller-basic/blob/main/img_readme/warning_error.png)\n\n## Project directory structure\n\n```\n.\n├── source_code\n│   ├── ...\n└── src\n    ├── abstract_syntax_tree\n    │   ├── ...\n    ├── error\n    │   ├── ...\n    ├── grammar\n    │   ├── SmallerBasic.g4\n    │   └── ...\n    ├── interpreter\n    │   ├── dispatch_table.py\n    │   ├── global_memory.py\n    │   ├── interpreter.py\n    │   └── library\n    │       └── ...\n    ├── main.py\n    └── utils\n        └── ...\n```\n\n### Overview\n\n- `source_code`: This directory contains the source code files of SmallerBasic programming language.\n\n- `src`: The main source code directory containing various subdirectories and files related to the interpreter and language implementation.\n\n    - `abstract_syntax_tree`: This directory hold files related to constructing and manipulating the abstract syntax tree.\n\n    - `error`: This directory there are files related to error handling and reporting within the interpreter.\n\n    - `grammar`: This directory contain the grammar definition files, such as `SmallerBasic.g4`, which define the syntax and structure of the SmallerBasic language using ANTLR grammar notation.\n\n    - `interpreter`: This is a crucial directory containing the implementation of the interpreter for the SmallerBasic language.\n\n        - `dispatch_table.py`: This file contains the implementation of a dispatch table used for efficiently executing different language constructs.\n\n        - `global_memory.py`: This file contains the code related to managing the global memory and variables within the interpreter.\n\n        - `interpreter.py`: This is the main interpreter implementation that executes SmallerBasic programs by traversing the abstract syntax tree and performing actions based on the language constructs.\n\n        - `library`: This directory contain the library files that provide built-in functions or utilities for SmallerBasic programs, for example `IO`, `Math` and `String` libraries.\n\n- `main.py`: This is the entry point of your interpreter, where execution starts when running the interpreter.\n\n- `utils`: This directory could hold utility files that are used throughout the project, for example the metaclass that colors prints.\n\n## Starting point working locally\n\n**Create and start a new virtual environment**\n\n`source create_venv.sh venv`\n\n**Start current virtual environment**\n\n`source venv/bin/activate`\n\n**Deactivate the current virtual environment**\n\n`deactivate`\n\n## Usage\n\n```\nUsage: smallbasic [OPTION] [FILE]\nRun Smaller Basic program\n\nOptions:\n  -h      display this help and exit\n  -g      generate grammar\n  -gas    generate grammar and run all files in source_code folder\n  -as     run all files in source_code folder\n```\n\n## Interpreter\n\n### Run a file\n\n`smallbasic \u003cfile\u003e.sb`\n\nFor example, you can ri-generate the grammar and run a file in `source_code` directory in the following way:\n\n`smallbasic -g source_code/source.sb`\n\n### Generate grammar\n\n`antlr4 -Dlanguage=Python3 -visitor src/grammar/SmallerBasic.g4`\n\n- **Requirements**: the same or greater java version used to compile the antlr4 jar. (in our case **java-18-openjdk-amd64**)\n\n- Change version of java: `update-alternatives --config java`.\n\n- `antlr4` is an alias generated by the `create_venv.sh` file.\n\n### Run a file using `python3` interpreter\n\n`python3 -m src.main source_code/\u003cfile\u003e.sb`\n\n## Contributing\n\nContributions to this project are welcome! If you have any suggestions, improvements, or bug fixes, feel free to submit a pull request.\n\n## License\n\nThis repository is licensed under the [GNU General Public License (GPL)](https://www.gnu.org/licenses/gpl-3.0.html). Please review the license file provided in the repository for more information regarding the terms and conditions of the GPL license.\n\n## Contact\n\nIf you have any questions, suggestions, or feedback, do not hesitate to [contact me](https://federicobruzzone.github.io/).\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffedericobruzzone%2Fsmaller-basic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffedericobruzzone%2Fsmaller-basic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffedericobruzzone%2Fsmaller-basic/lists"}