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 [[http://homepages.cwi.nl/~daybuild/daily-books/syntax/2-sdf/sdf.html][SDF]] or the [[Spoofax.TemplateLanguage][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 [[http://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html][reserved words in Java]].
%T% _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.
%T% _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.
---+++ Comments 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.
http://strategoxt.org/pub/Spoofax/Features/show-abstract-syntax.png
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 [[...]]