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.
$ swift build
Compile Swift Module 'foobarbas' (6 sources)
Linking ./.build/debug/foobarbas
$ ./.build/debug/foobarbas example-bas/factorial.bas
120
$ swift package generate-xcodeproj
generated: ./foobarbas.xcodeproj
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