{"id":13779550,"url":"https://github.com/nanoflite/basic","last_synced_at":"2025-05-11T13:30:54.501Z","repository":{"id":54601831,"uuid":"52297073","full_name":"nanoflite/basic","owner":"nanoflite","description":":tv: A from-scratch BASIC interpreter with a focus on being easy to extend and port.","archived":false,"fork":false,"pushed_at":"2023-05-06T10:36:50.000Z","size":389,"stargazers_count":84,"open_issues_count":4,"forks_count":26,"subscribers_count":8,"default_branch":"develop","last_synced_at":"2024-07-12T04:37:19.222Z","etag":null,"topics":["basic","c","interpreter"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nanoflite.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}},"created_at":"2016-02-22T18:54:30.000Z","updated_at":"2024-06-02T09:03:30.000Z","dependencies_parsed_at":"2024-01-17T00:55:07.123Z","dependency_job_id":"d115a75b-5043-4838-8fa3-22552fade967","html_url":"https://github.com/nanoflite/basic","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/nanoflite%2Fbasic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoflite%2Fbasic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoflite%2Fbasic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoflite%2Fbasic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nanoflite","download_url":"https://codeload.github.com/nanoflite/basic/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":213837758,"owners_count":15645750,"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":["basic","c","interpreter"],"created_at":"2024-08-03T18:01:06.360Z","updated_at":"2024-08-03T18:06:26.635Z","avatar_url":"https://github.com/nanoflite.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"![BASIC](./basic.png)\n\nA from-scratch BASIC interpreter with a focus on being easy to extend and port.\n\n[![asciicast](https://asciinema.org/a/37018.png)](https://asciinema.org/a/37018)\n\n# Introduction\n\nThis is a BASIC interpreter written from scratch in C. For the moment two architectures are supported, POSIX and AVR XMega via the avr-gcc toolchain.\n\nMost of the common BASIC keywords are supported:\n\n  * PRINT expression-list [ ; ]\n  * IF relation-expression THEN statement\n  * GOTO expression\n  * INPUT variable-list\n  * LET variable = expression\n  * GOSUB expression\n  * RETURN\n  * FOR numeric\\_variable '=' numeric\\_expression TO numeric_expression [ STEP number ] \n  * CLEAR, NEW\n  * LIST\n  * RUN\n  * END\n  * DIM variable \"(\" expression \")\"\n  * ABS, AND, ATN, COS, EXP, INT, LOG, NOT, OR, RND, SGN, SIN, SQR, TAN\n  * LEN, CHR$, MID$, LEFT$, RIGHT$, ASC \n\n# Extend\n\nIt should be easy to register a new BASIC function, as shown here with a `sleep` function for the XMEGA.\n\n```C\nregister_function_1(basic_function_type_keyword, \"SLEEP\", do_sleep, kind_numeric);\n...\nint do_sleep(basic_type* delay, basic_type* rv)\n{\n  delay_ms(delay-\u003evalue.number);\n  \n  rv-\u003ekind = kind_numeric;\n  rv-\u003evalue.number = 0;\n\n  return 0;\n}\n```\n\nLet's use that new keyword.\n\n```REALbasic\n10 INPUT \"YOUR NAME?\", NAME$\n20 CLS\n30 FOR I=1 TO LEN(NAME$)\n40 PRINT MID$(NAME$,I,1); \n50 SLEEP(500)\n60 NEXT\n70 PRINT\n```\n\n# Port\n\nIt should be easy to port the interpreter to other architectures. As an example there is a port to an XMega 128A4U included using the [Batsocks breadmate board](http://www.batsocks.co.uk/products/BreadMate/XMega%20PDI%20AV.htm).\n\n# Use\n\nThere is a simple REPL for the BASIC interpreter. You can use it in an interactive way, just as you would do on a 80's era computer.\n\n```\n _               _\n| |__   __ _ ___(_) ___\n| '_ \\ / _` / __| |/ __|\n| |_) | (_| \\__ \\ | (__\n|_.__/ \\__,_|___/_|\\___|\n(c) 2015-2016 Johan Van den Brande\n10 PRINT \"HELLO\"\n20 GOTO 10\n```\n\nYou can give it a BASIC file on the command line.\n\n```\n$\u003e basic examples/diamond.bas\n         *\n        ***\n       *****\n      *******\n     *********\n    ***********\n   *************\n  ***************\n *****************\n  ***************\n   *************\n    ***********\n     *********\n      *******\n       *****\n        ***\n         *\n```\n\nYou can also use the shebang operator to make standalone BASIC scripts\n\n```\n#!/usr/bin/env basic\n\n10 RADIUS=10\n20 FOR I=1 TO RADIUS-1\n30 W=INT(RADIUS*SIN(180/RADIUS*I*3.1415/180))\n40 PRINT SPC(RADIUS-W);:FOR J=1 TO 2*W:PRINT \"*\";:NEXT J:PRINT\n50 NEXT I\n```\n\n```\n$\u003e ./examples/circle.bas\n       ******\n     **********\n  ****************\n ******************\n********************\n ******************\n  ****************\n     **********\n       ******\n```\n\nIt is easy to embed the interpreter into your own application.\n\n```C\n  basic_init(2048, 512); // memory size, stack size\n  basic_register_io(putchar, getchar);\n  basic_eval(\"10 PRINT \\\"HELLO\\\"\");\n  basic_eval(\"RUN\"); \n  basic_destroy();  \n```\n\nOn OSX/POSIX you can use the 'BASIC\\_PATH' environment variable to set the folder used for loading and saving BASIC programs. The 'BASIC\\_PATH' defaults to '.'.\nBASIC programs are expected to end with '.bas'. You can use LOAD, SAVE, DELETE and DIR.\n\n# Copyright\n\n(c) 2015 - 2016 Johan Van den Brande\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanoflite%2Fbasic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnanoflite%2Fbasic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanoflite%2Fbasic/lists"}