* Trash Web
Changes Index Search

Webs Book Compare GPCE06 Gmt Gpce Gpce04 Gpce05 IFIPWG211 IPA06 Main Octave PEPM07 PEPM08 PHP Sandbox Sdf Stratego Sts TWiki Tiger Tools Transform Variability default porn free porn

Day 3

On the third day, you define the concrete and abstract syntax for the MiniJava language.

Syntax Definition

You should build the syntax definition step by step. As a syntax definition formalism, you can choose either SDF or the Template Language.

Lexical Syntax

Start with the lexical syntax definition including identifiers, integer, and simple layout. First, define lexical syntax rules. Second, define follow restrictions to ensure longest matches. Finally, use rejection rules to rule out reserved words in Java.

TIP Tip: You need to define lexical syntax rules for INT and ID. For grading, it is required to comply with these sort names literally.

Context-free Syntax

Continue with the context-free syntax of the language. Use the context-free grammar from the book as a reference.

First, define context-free syntax rules. Next, add constructors for abstract syntax trees to your rules. Complete the definition with appropriate disambiguation rules.

TIP Tip: You need to define context-free syntax rules for the following sorts: Program, MainClass, ClassDecl, VarDecl, MethodDecl, Type, Statement and Exp. For grading, it is required to comply with these sort names literally.


Finally, you should add lexical syntax rules for comments to your syntax definition. Start with simple line comments. Continue with simple block comments and extend them to support nested comments. Do not forget to define follow restrictions.

Testing the Syntax Definition

After each step, you can check your progress by building the project and running your test cases. Therefor, you need to declare the same start symbols in your syntax definition as in your test suites. To also test your MiniJava editor interactively, you need to specify the start symbols also in the main editor description editor/MiniJava.main.esv. You can also use Show AST in the editor's Transform menu to test your abstract syntax definition interactively.


While you extend your syntax definition step by step, it is very handy to have multiple start symbols. But in the end, Program should be the only start symbol. This will break many of your test suites. You can fix this by removing start symbol declarations in these test suites. Instead, you need to specify a setup header and footer to embed your test cases into a complete MiniJava program.

module example
language MiniJava

setup MiniJava program header [[...]]

test ...
test ...

setup MiniJava program footer [[...]]

Trash.Day3 moved from CC.Day3 on 13 Mar 2014 - 08:17 by GuidoWachsmuth - put it back