MiniBasic - how to write a script interpreter
|
Publisher: Malcolm McLean
Copyright:
© 2006 by Malcolm McLean Standard Copyright License
Language: English
Country: United Kingdom
|
Download:
1 documents, 391 KB
Printed: 131 pages, 6" x 9", perfect binding, black and white interior ink Description:Implementation of a BASIC interpreter, with full language documentation and essay on how to write a script interpreter. Full ANSI C source included. A great resource for anyone doing a compilers and interpreters course at university, or for anyone needing to add scripting to their programs. A program BASICdraw is now available that adds a MiniBasic script interpreter to a graphics editor. The program is free, download here Keywords:Listed in: |
Stats:
Lulu Sales Rank: 19,502
Average customer rating:
Please log in or sign up to rate this item.
Have your own story to tell?
We've got publishing services to get you started.Reviews:
Please log in or sign up to post a review.
This little book on lulu.com caught my eye, and I purchased it via download. Malcolm clearly achieves what his strapline advertises - explaining to you "how to write a BASIC interpreter" - by writing a really good interpretor, and explaining it.
Don't be put off by the sketchy cover and lack of contents page and index - the content of this book is very well written and very accessible.
It sets the scene by showing a number of sample BASIC programs of increasing complexity, to get the reader into the context of BASIC and what can be expected of an interpretor. The BASIC is reminiscent of the early BASIC interpretors like Pet BASIC or 8052 BASIC, having no support for more advanced control structures that something like BBC BASIC introduced, but the fact there are only 39 keywords in the language makes it quick to learn, and makes the interpretor very tiny and fast. Tiny and fast is good if you were considering embedding this language inside a bigger containing application, e.g. as a scripting language.
Next, the book takes on a reference-style and explains the key syntax, followed by an alphabetical list of keywords and their function, each with small but useful examples of how to use them, followed by an error-message reference (there are only 25 errors and 39 keywords).
Next, and these next two sections are the most interesting from a design point of view, the author looks at how to write an interpreter, and specifically some of the design decisions made while writing MiniBasic. He carefully navigates from some of the initial issues such as expression parsing and evaluation and control structures, through to I/O. This is then followed by focussing on some of the key design decisions and design compromises of MiniBasic, with a number of complete example MiniBasic programs to illustrate.
Malcolm then completes the book with a 64 page listing of the C code that implements MiniBasic. While the code in some places has terse comments, the code is well written, well structured, and the accompanying notes in earlier text clearly describe the design and operation of the code. This is the right choice by Malcolm, because sometimes too many comments can clutter the code and make it hard to read. His programming style and layout style makes the code very clean to read and understand.
MiniBasic uses a recursive-descent parsing technique, and because of this, the book would suite anyone wanting to learn about parsing techniques without having to get too sucked into the intricate detail that one expects from books like Aho, Sethi and Ullman. Having a complete working BASIC interpretor that you can compile and run and change yourself is by far the best way to absorb the techniques - by looking at and using real code.
The choice of the author to put the whole interpretor in a single C file was the correct one I think, because although 64 A4 pages of code is quite long, this actually keeps the code simpler due to their being no need for module linkage and externals which would make the program much larger. An example driver module is provided that wraps the interpretor with a main(), and demonstrates the power of the fact that the BASIC program sent to the interpretor can come from anywhere - an external file, or even embedded inside the C program as a string.
I spent many happy hours pouring over the source code for MiniBasic and experimenting with it, and can highly recommend this book as both an interesting and useful resource.
David Whale,
www.thinkingbinaries.com,
February 2009.
Don't be put off by the sketchy cover and lack of contents page and index - the content of this book is very well written and very accessible.
It sets the scene by showing a number of sample BASIC programs of increasing complexity, to get the reader into the context of BASIC and what can be expected of an interpretor. The BASIC is reminiscent of the early BASIC interpretors like Pet BASIC or 8052 BASIC, having no support for more advanced control structures that something like BBC BASIC introduced, but the fact there are only 39 keywords in the language makes it quick to learn, and makes the interpretor very tiny and fast. Tiny and fast is good if you were considering embedding this language inside a bigger containing application, e.g. as a scripting language.
Next, the book takes on a reference-style and explains the key syntax, followed by an alphabetical list of keywords and their function, each with small but useful examples of how to use them, followed by an error-message reference (there are only 25 errors and 39 keywords).
Next, and these next two sections are the most interesting from a design point of view, the author looks at how to write an interpreter, and specifically some of the design decisions made while writing MiniBasic. He carefully navigates from some of the initial issues such as expression parsing and evaluation and control structures, through to I/O. This is then followed by focussing on some of the key design decisions and design compromises of MiniBasic, with a number of complete example MiniBasic programs to illustrate.
Malcolm then completes the book with a 64 page listing of the C code that implements MiniBasic. While the code in some places has terse comments, the code is well written, well structured, and the accompanying notes in earlier text clearly describe the design and operation of the code. This is the right choice by Malcolm, because sometimes too many comments can clutter the code and make it hard to read. His programming style and layout style makes the code very clean to read and understand.
MiniBasic uses a recursive-descent parsing technique, and because of this, the book would suite anyone wanting to learn about parsing techniques without having to get too sucked into the intricate detail that one expects from books like Aho, Sethi and Ullman. Having a complete working BASIC interpretor that you can compile and run and change yourself is by far the best way to absorb the techniques - by looking at and using real code.
The choice of the author to put the whole interpretor in a single C file was the correct one I think, because although 64 A4 pages of code is quite long, this actually keeps the code simpler due to their being no need for module linkage and externals which would make the program much larger. An example driver module is provided that wraps the interpretor with a main(), and demonstrates the power of the fact that the BASIC program sent to the interpretor can come from anywhere - an external file, or even embedded inside the C program as a string.
I spent many happy hours pouring over the source code for MiniBasic and experimenting with it, and can highly recommend this book as both an interesting and useful resource.
David Whale,
www.thinkingbinaries.com,
February 2009.
[Click the preview to close]




