Repository navigation
examples: add tiny_basic compiler - #60
Merged
Merged
Conversation
Addresses issue #9 by specifying a single-file BASIC-subset compiler in examples/tiny_basic.rs (lexer + parser + codegen -> qbe::Module). Spec nails down language scope, codegen strategy (stack slots, line-numbered blocks), error handling, and explicit out-of-scope items. Made-with: Cursor
Bite-sized TDD-flavored task list (10 tasks) that builds the example incrementally: scaffolding -> lexer -> parser -> expressions -> codegen skeleton -> LET/PRINT -> IF/GOTO -> END -> end-to-end factorial -> docs. Each task ends in a verification step (round-trip through qbe + cc) and a commit. Made-with: Cursor
Made-with: Cursor
Made-with: Cursor
Made-with: Cursor
Made-with: Cursor
Made-with: Cursor
Made-with: Cursor
Made-with: Cursor
Made-with: Cursor
The lexer already skips REM-line content (so arbitrary characters in comments don't produce lex errors), making the parser's REM bump-loop dead code. Inline the parser arm. Update the README pipe to include the cc step (matching the file-level doc comment) and update the design spec to record that REM-line skipping happens at lex time. Made-with: Cursor
Cargo auto-detects examples/<name>/main.rs, so the compiler itself stays a single ~600 LOC file but now lives next to runnable .bas sample programs (hello, factorial, fibonacci) and a README with a copy-pasteable run recipe. Top-level README links to that README so users land on a working how-to instead of a raw shell pipe. Made-with: Cursor
Made-with: Cursor
These were workflow scaffolding for the original implementation pass and don't belong on main. Made-with: Cursor
Made-with: Cursor
garritfra
marked this pull request as ready for review
April 27, 2026 12:39
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9
Description
Adds a small but complete compiler example under
examples/tiny_basic/thatdemonstrates the qbe crate end-to-end: a BASIC subset → AST →
qbe::Module→QBE IL on stdout. Pipe through
qbeand a C compiler to get a runnablebinary.
The compiler itself is a single ~600 LOC
main.rswith no externaldependencies, organized as three sequential passes (lexer → parser →
codegen). It exercises the parts of the API
hello_world.rsdoesn't reach:stack-slot variables (
Alloc4/Store/Load), branching (Jnz,Jmp),Cmpwith all six comparison codes, callingprintfvia a privateDataDef, and per-line block labels.Changes proposed in this pull request
examples/tiny_basic/:main.rs— lexer, recursive-descent parser with precedence climbing,codegen with line-number target validation.
factorial.bas,fibonacci.bas,hello.bas— runnable sample programs.README.md— language reference and copy-pasteable run recipe.README.mdreorganized into a list of examples linking to theper-example README.
CHANGELOG.md: newUnreleasedsection with the addition.Tiny BASIC at a glance
ToDo
qbe+ccand produce expected output;cargo test(48 tests) andcargo clippy --all-targets -- -D warningsare clean)