Download User's guide + Reference manual - CodeWorker
Transcript
false, there is no return type (void),
LINE 36: a parameter declaration is expected after the comma,
LINE
43:
about
parsing,
parameters
are
modeled
into
node
myMethod.listOfParameters[sParameterName],
LINE 52: about parsing, myType.isArray contains true if type is an array,
LINE 54: about parsing, myType.name contains the name of basic type,
LINE 58: about parsing, myType.isAggregation contains true if the object is aggregated,
LINE 59: about parsing, myType.isObject contains true because this type is a class specifier,
LINE 61: the lexical clause IDENT recognizes identifiers and might be replaced by the predefined
clause #readIdentifier, which does the same work,
The first version of the script was just able to read a well-formed design file written in the simple
modeling language. The second version validates the file and populates the parse tree:
parseAsBNF("GettingStarted/SimpleML-parsing.cwp",
project, "GettingStarted/SolarSystem0.sml");
Output:
file parsed successfully
3.3 Decorating the parse tree
Once our design file has been parsed (either procedure-driven or BNF-driven, we don’t care), there
is sometimes a little more work to acomplish on the parse tree. It may be verifying consistency of
the whole, as checking existence of each class referenced as association or parent. It may also be
reorganizing the graph differently, so as to simplify tasks of source code generation. We call it decorating
the parse tree in the C ODE W ORKER vocabulary.
The next script proposes to check the existence of each class specifier types and to keep a reference
to the node that describes this class specifier. Some nodes change their nature (myClass.parent
becomes a reference to the parent node, for example), some other are added (for object types, the new
node myType.class keeps a reference to the class):
// file "GettingStarted/TreeDecoration.cws":
1 foreach myClass in project.listOfClasses {
2
if myClass.parent {
3
if !findElement(myClass.parent, project.listOfClasses)
4
error("class ’" + myClass.parent + "’ doesn’t exist
while class ’"
5
+ myClass.name + "intends to inherit from it");
6
ref myClass.parent = project.listOfClasses[myClass.parent];
7
}
8
foreach myAttribute in myClass.listOfAttributes {
9
local myType;
10
ref myType = myAttribute.type;
11
if myType.isObject {
12
if !findElement(myType.name, project.listOfClasses)
13
error("class ’" + myType.name + "’ doesn’t exist
while attribute ’"
14
+ myClass.name + "::" + myAttribute.name +
"’ refers to it");
3.3. Decorating the parse tree
27