The Language
In the following table are presented the icons of the language, labeled with the correspondent meta-grammar symbols.
|
|
|
LeftSymbol |
Nonterminal |
Terminal |
|
|
|
InhAttribute |
SyntAttribute |
IntrinsicValueAttribute |
|
|
|
InhConnection |
SyntConnection |
IntrinsicValueConnection |
|
|
|
Function |
FunctionArg |
FunctionOut |
|
|
|
Identity |
|
TreeBranch |
These symbols are dragged to the edition area of the prodsView and rulesView. Then are assembled together creating a syntactic and semantic valid sentence.
Regard the following example for a better understand of how to use VisualLISA to specify an Attribute Grammar.
You can also see the Movie Tutorial of this example.
In this example, the attribute grammar will be used to create a processor for a list of students (described by their name and their age) in a school and to sum the total of ages of the students in the list given. Formally, the attribute grammar is defined as follows:
p1: Students -> Student Students
{ Students.sum = Students.sum + Student.age; }
p2: Students -> Student
{ Students.sum = Student.age; }
p3: Student -> name age
{ Student. age = ToInt(age.value); }
In VisualLISA:
|
Defining the base layout of production p1: The tree layout of the production is defined by dragging the LeftSymbol and the Nonterminal icons to the edition area of prodsView. The connections between the symbols are generated automatically.
|
Associating attributes: The attributes, no matter they are inherited, synthesized or intrinsic, are dragged into the edition area of prodsView along with the respective connection lines. Then the start point of the line (the leftmost point) is dragged upon the parent symbol, and the end point of the line (the rightmost point) is dragged upon the attribute.
|
|
|
Specifying a semantic rule: After declaring a computation rule in the prodsView, the
rulesView can be opened and the semantic rule can be specified. For p1, the need for a sum between two attributes, implies the creation of a function.
The Function icon is dragged to the edition area, in the
rulesView, along with the output and the several argument connections. These lines are connected to the function and the attributes, inducing the dependencies between the attributes.
The operation is declared textually:
$1 op1 ... opN $i, where i≥1 , and $i is the ith attribute (argument) connected to the function.
|
The three semantic productions of the example attribute grammar are shown below, completely defined. Production 2 copies the value of the attribute age to the attribute sum. Production 3, in its turn, transforms the textual value of the intrinsic attribute of the terminal age into an integer data-type, and assigns it to the attribute age of the symbol Student.
Production 1
|
Production 2
|
Production 3
|