Link Search Menu Expand Document

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

  1. 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 (not CDEditor!)
    Name
    CD (not CD-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

  2. Open the Console view in Eclipse (Window: Show View: Other...).

  3. 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.

  1. Clean the CD-cbs project

  2. Open CD-cbs/CD/CD-Start/CD-Start.cbs

  3. 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

  1. Update the following files generated by Spoofax:

    • Edit editor/Main.esv to import first Menus
    • Edit trans/cd.str to import the generated Stratego module generate
    • Delete the file syntax/Common.sdf3, which is not used by CBS
  2. Clean the CD-Editor project

    (Ignore any warnings or error reports regarding files in src-gen/ds-signatures)

  3. Build the CD-Editor project

    It may take about a minute. The console should not show any warnings or error reports.

Create a project with some test programs

  1. Create a general project named CD-Tests in CBS-Demo
  2. Check that the Spoofax (meta) menu indicates that analysis is enabled
  3. Add the Spoofax nature to the CD-Tests project:
    1. Right-click on the project
    2. Select Spoofax: Add Spoofax nature
  4. Create a folder named CD-1 in the CD-Tests project
  5. 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)))
      
  6. Clean the CD-Tests project
  7. Check that:
    1. There are no parse errors or ambiguities
    2. CD keywords are highlighted

Translate programs to funcons

  1. Focus on the int.cd editor window
  2. Select Spoofax: Generation: Generate funcons
  3. Check that the generated file int.fct contains:
    initialise-binding finalise-failing decimal
      "42"
    
  4. Generate funcons for all the other programs in CD-Tests

Add a funcon interpreter

  1. Install the funcons-tools package
  2. Select Run: External Tools: External Tools Configurations...
  3. 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 then Close

  4. Select Run: External Tools: Organize Favorites...

    1. Click Add
    2. Select Run funcons
    3. Click OK

    Click OK

Execute funcon terms

  1. Focus on the int.fct editor window
  2. Select Run: External Tools: Run funcons
  3. Check that the Spoofax console reports:
    Result:
    42
    
  4. Execute the funcons for all the other programs in CD-Tests


Table of contents