Download An Eclipse-Based Integrated Development Environment for Curry
Transcript
4 Foundations
1 DataDeclaration:
’data’ name=TypeConstrID ’=’ ConstrDecl;
Now, Xtext automatically establishes the cross-references and produces an error, if for
a particular TypeConstrID within a Signature no target element can be found. For the
sample program from Listing 4.1, this is the case for the identifier ’AnotherDataType’.
So, the definition of cross-links implies semantic validation for references. The complete
Xtext-grammar for SimpleCurry including data model information and the cross-link
looks as follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Module hidden(ANY_OTHER):
’module’ name=ModuleID ’where’ body=Body;
Body:
{Block} ’{’
(declarations+=BlockDeclaration ’;’)*
’}’;
BlockDeclaration: DataDeclaration
| Signature;
DataDeclaration: ’data’ name=TypeConstrID
’=’ constructor=ConstrDecl;
ConstrDecl:
name=DataConstrID;
Signature:
name=FunctionID ’::’ type=TypeExpr;
TypeExpr:
type=[DataDeclaration|TypeConstrID]
(’->’ nextType=TypeExpr)?;
// Identifiers consist of any sequence of letters.
ModuleID:
ID;
TypeConstrID:
ID;
DataConstrID:
ID;
FunctionID:
ID;
terminal ID:
(’a’..’z’ | ’A’..’Z’)+;
terminal ANY_OTHER:
.;
The generated data model for SimpleCurry is presented in Figure 4.3. Figure 4.3a
shows the generated data types for SimpleCurry and their relations. As described,
Xtext takes care of implicit inheritance, hence, Signature and DataDeclaration have the
same super type BlockDeclaration.
Figure 4.3b depicts the AST that is constructed for the input program from Listing 4.1. The green line represents the cross-reference from the TypeExpr within the
Signature of ’myFunction’ to the DataDeclaration ’MyDataType’. On the contrary, the
red line is meant to demonstrate the broken cross-reference for the DataDeclaration ’AnotherDataType’ that does not exist. Indeed, this “AST” is no tree anymore, because the
cross-references create cycles in the undirected graph of objects. However, in the following we will still refer to this kind of data representation as an AST to indicate that we
36