Saturday, December 27, 2008

OWL BASIC parser and abstract syntax tree

The first programming language I ever used was a version of BASIC on the BBC Microcomputer (over 20 years ago and counting). It did use line numbers, but had procedures and subroutines and allowed you to do structured programming including recursion. Having a programming language built into the machine made it incredibly simple to start hacking - and it even included an assembler so you could embed assembly language in basic programs. A lot of games on the machine started with a shell of basic that would bootstrap the game actually written in assembler.

Robert Smallshire has been working on an implementation of BBC Basic written in IronPython:
"Other personal projects, of both a software and familial nature have taken priority lately over my project to implement a BBC BASIC-a-like compiler for the .NET CLR, now called OWL BASIC in honour of the owl logo of the BBC’s Computer Literacy Project."

This blog entry is mainly focused on the front end parser which uses the Python PLY (Python Lex and Yacc) parser toolkit. This works very well with IronPython and is what we use at Resolver Systems for our spreadsheet formula language. As well as describing the grammar, Robert goes into the details of working with the AST (Abstract Syntax Tree) of parsed BASIC.

"Once the AST has been created by the parser, it can be analysed or manipulated by a visitor. One such visitor, which is an aid to debugging, transcribes each AST node into an XML representation. This is useful since it allows the AST to be conveniently examined using standard XML capable tools (e.g. a web browser) to aid debugging."

No comments:

Post a Comment

Note: only a member of this blog may post a comment.