Kjetil's Information Center: A Blog About My Projects

TinyBasic in Lex/Yacc

Lex and Yacc are two wonderful Unix tools that can create lexical analyzers and parsers for interpreters or compilers of programming languages. I used the modern counterparts from the GNU project; Flex and Bison to create an interpreter for TinyBasic, a simple dialect of BASIC.

The reference implementation for TinyBasic can be found in the first issue of the computer magazine Doctor Dobb's Journal. The implementation I have made differs a little, and has some extensions. More information can be found in the README file in the source tarball.

Although using BASIC is considered harmful, it is very easy to learn, and therefore easy to write an interpreter for.

Here is some sample BASIC code that will work with the interpreter:
(Same program that I provided for the Attoscript interpreter earlier.)

10 LET C = 10
20 PRINT "There are ", C, " bottles of prune juice on the wall."
30 LET C = C - 1
40 IF C <> 0 THEN GOTO 20

The source code can be downloaded here. (Licenced under GNU GPL version 3.)

Topic: Open Source, by Kjetil @ 20/09-2008, Article Link