SkillAgentSearch skills...

Foobarbas

Tiny Tiny Basic Interpreter in under 500 LOC of Swift

Install / Use

/learn @jdmoreira/Foobarbas
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

foobarbas

Tiny Tiny BASIC Interpreter in under 500 LOC of Swift. Implements a subset of the already Tiny BASIC.

If you are looking for sample code on how to implement a simple parser or DSL in swift, this code should suit you. The only dependencies are The Swift Standard Library and a Unix libc. Pull requests are welcome.

Build

$ swift build
Compile Swift Module 'foobarbas' (6 sources)
Linking ./.build/debug/foobarbas

Run

$ ./.build/debug/foobarbas example-bas/factorial.bas
120

Generate Xcode Project

$ swift package generate-xcodeproj
generated: ./foobarbas.xcodeproj

Grammar

program ::= line*

line ::= number statement CR

statement ::= PRINT expression
              IF expression relop expression THEN statement
              GOTO expression
              LET var = expression
              END

relop ::= < (>|=|ε) | > (=|ε) | =

expression ::= term | term (+|-) term

term ::= factor | factor (*|/) factor

factor ::= (-|ε)value | (expression)

value ::= var | number

var ::= A | B | C ... | Y | Z

number ::= digit digit*

digit ::= 0 | 1 | 2 | 3 | ... | 8 | 9
View on GitHub
GitHub Stars29
CategoryDevelopment
Updated1y ago
Forks2

Languages

Swift

Security Score

75/100

Audited on Nov 14, 2024

No findings