|
Class Common
|
CSLite /CSLite
Using Scribbler to Learn Compiler BasicsIn 91.204 Computer IV, we will use Scribbler robot devices as the system target to learn compiler basics. To program the Scribbler robots, we have designed a new language: Chirp-Scribbler. Chirp-Scribbler has C-like syntax, and includes both common and specialized language features to program Scribbler. The full specificiation of Chirp-Scribbler is described in this PDF spec. Chirp-Scribbler Lite (CSLite)To make it possible to build a Chirp-Scribbler compiler project in a short time frame, we will implement a simplified subset of the Chirp-Scribbler language, called CSLite. The sample compiler demonstrates the basics of lexing, parsing, and code generation to compile CSLite to target Scribbler. CSLite FeaturesCSLite is a subset of Chirp-Scribbler, you should first read the above Chirp-Scribbler language spec PDF. Comparing to the full language, CSLite provides only the following language features:
What CSLite does NOT have:
Implementation of these features will be done in the student's project. Using CSLite features, CSLite program can be written as a collection of variable definitions and statements. The following program demonstrates the use of CSLite: hello.csl sample program:
int a;
byte b;
int c;
int led1;
int led2;
int led3;
a = 3;
b = 4;
c = a+b*5;
System.print("hello, world");
System.print("a=", a);
System.print("b=", b);
System.print("c=", c);
if (a%2) {
led1 = 1;
} else {
led1 = 0;
}
a = a/2;
if (a%2) {
led2 = 1;
} else {
led2 = 0;
}
a = a/2;
if (a%2) {
led3 = 1;
} else {
led3 = 0;
}
Scribbler.setLED(led3, led2, led1);
System.print("Done demo.");
CSLite Sample Compiler: cscTo help you build the CSLite compiler, we will give you a working CSLite sample compiler csc. In the student's project, you will study the source code of csc and extended to implement the required language features. You can download the csc source code using this link: download csc Eclipse project .zip file. The easiest way to run it is using Eclipse: select file menu Import->Existing Project->Choose archive file and select your downloaded .zip file, then Eclipse will import the CSLite project in your workspace and you should be able to run the Test classes. The following are information and directions to use csc.
ReferencesDownload FilesThe csctool.jar has the XMLTreeView class which can be used to display the JDOM Document or Element tree. |