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-Editor
with 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
Console
view in Eclipse (Window: Show View: Other...
). -
Click on
Finish
to 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-Editor
project has been successfully built; some warnings (e.g., about overloaded constructors in SDF3 files) may remain, but can be ignored.
-
Clean the
CD-cbs
project -
Open
CD-cbs/CD/CD-Start/CD-Start.cbs
-
Select
Spoofax: Generate: Language editor
The 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.esv
to import firstMenus
- Edit
trans/cd.str
to import the generated Stratego modulegenerate
- Delete the file
syntax/Common.sdf3
, which is not used by CBS
- Edit
-
Clean the
CD-Editor
project(Ignore any warnings or error reports regarding files in
src-gen/ds-signatures
) -
Build the
CD-Editor
projectIt 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-Tests
inCBS-Demo
- Check that the
Spoofax (meta)
menu indicates that analysis is enabled - Add the Spoofax nature to the
CD-Tests
project:- Right-click on the project
- Select
Spoofax: Add Spoofax nature
- Create a folder named
CD-1
in theCD-Tests
project - Create the following files in the
CD-1
folder:int.cd
:42
identity.cd
:let f = lambda x. x in (f(42))
let.cd
:let m = 42 in let n = m in n
ski.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-Tests
project - Check that:
- There are no parse errors or ambiguities
- CD keywords are highlighted
Translate programs to funcons
- Focus on the
int.cd
editor window - Select
Spoofax: Generation: Generate funcons
- Check that the generated file
int.fct
contains: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 configuration
then enter the following settings:- Name
Run funcons
- Main
- Location:
YOUR-PATH-TO/runfct
- Arguments:
${resource_loc}
- Build
- Build before launch: unchecked
Click
Apply
thenClose
-
Select
Run: External Tools: Organize Favorites...
- Click
Add
- Select
Run funcons
- Click
OK
Click
OK
- Click
Execute funcon terms
- Focus on the
int.fct
editor 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