Validation
This page illustrates how to validate a language specification by generating a translator from programs to funcons, and checking the outcomes of executing translations of test programs.
Generate an editor and translator
You should specify your language before proceeding with the following steps.
Create an editor project
-
Create a Spoofax language project named
CD-Editorwith the following settings:- Project name
CD-Editor- Use default location
- unchecked
- Location
YOUR-PATH-TO/My-Languages/CBS-Demo- Identifier
CD-Editor(notCDEditor!)- Name
CD(notCD-Editor!)- Version
- (e.g.)
0.1.0-SNAPSHOT - Group identifier
- (e.g.)
org.example - Extensions
cd
and the following language options settings:
- Syntax type
SDF3- Analysis type
NaBL2 (deprecated)
The optional generation options settings determine whether extra projects will be created, e.g., for examples and automated tests
-
Open the
Consoleview in Eclipse (Window: Show View: Other...). -
Click on
Finishto create the language project. It can take about a minute. The progress is logged in the Spoofax Console.
Generate the editor and translator implementation
Next, use the CBS IDE to generate Spoofax meta-language files in the CD-Editor project.
Eclipse may initially flag various errors and warnings in the generated files. The errors should all disappear when the
CD-Editorproject has been successfully built; some warnings (e.g., about overloaded constructors in SDF3 files) may remain, but can be ignored.
-
Clean the
CD-cbsproject -
Open
CD-cbs/CD/CD-Start/CD-Start.cbs -
Select
Spoofax: Generate: Language editorThe Spoofax console window should report something like the following:
- Generating CD-Start components... - Generating CD-Start - Finished
(Ignore errors regarding LanguageIdentifierService.)
The CD-Editor project should now include the following files:
```
editor
- Menus.esv
lib
- StrategoMix.def
syntax
- Funcons.sdf3
- Stratego-CD.sdf
- cbs-gen
- CD-Start.sdf3
trans
- generate.meta
- generate.str
- cbs-gen
- CD-Start.meta
- CD-Start.str
```
Do not edit the files generated by the CBS IDE
-
Update the following files generated by Spoofax:
- Edit
editor/Main.esvto import firstMenus - Edit
trans/cd.strto import the generated Stratego modulegenerate - Delete the file
syntax/Common.sdf3, which is not used by CBS
- Edit
-
Clean the
CD-Editorproject(Ignore any warnings or error reports regarding files in
src-gen/ds-signatures) -
Build the
CD-EditorprojectIt may take about a minute. The console should not show any warnings or error reports.
Create a project with some test programs
- Create a general project named
CD-TestsinCBS-Demo - Check that the
Spoofax (meta)menu indicates that analysis is enabled - Add the Spoofax nature to the
CD-Testsproject:- Right-click on the project
- Select
Spoofax: Add Spoofax nature
- Create a folder named
CD-1in theCD-Testsproject - Create the following files in the
CD-1folder:int.cd:42identity.cd:let f = lambda x. x in (f(42))let.cd:let m = 42 in let n = m in nski.cd:let s = lambda x. lambda y. lambda z. (x(z)(y(z))) in let k = lambda x. lambda y. x in let i = lambda x. x in (s(s(k(s))(k)))
- Clean the
CD-Testsproject - Check that:
- There are no parse errors or ambiguities
- CD keywords are highlighted
Translate programs to funcons
- Focus on the
int.cdeditor window - Select
Spoofax: Generation: Generate funcons - Check that the generated file
int.fctcontains:initialise-binding finalise-failing decimal "42" - Generate funcons for all the other programs in
CD-Tests
Add a funcon interpreter
- Install the funcons-tools package
- Select
Run: External Tools: External Tools Configurations... -
Click
New launch configurationthen enter the following settings:- Name
Run funcons- Main
- Location:
YOUR-PATH-TO/runfct - Arguments:
${resource_loc} - Build
- Build before launch: unchecked
Click
ApplythenClose -
Select
Run: External Tools: Organize Favorites...- Click
Add - Select
Run funcons - Click
OK
Click
OK - Click
Execute funcon terms
- Focus on the
int.fcteditor window - Select
Run: External Tools: Run funcons - Check that the Spoofax console reports:
Result: 42 - Execute the funcons for all the other programs in
CD-Tests