[ATL] De Morgan with ATL (Calling called rules) [message #506326] |
Wed, 06 January 2010 20:11 |
Shannon Messages: 6 Registered: December 2009 Location: Wellington, NZ |
Junior Member |
|
|
Hi,
I am trying to perform de Morgans laws as a transformation. My current problem is that I don't know how to execute called rules.
For a simple start, I just want to achieve the simple transform A and B becomes A or B. Later I want to achieve an actual law eg :
not (A and B) becomes not A or not B.
Here is my metamodel, developed with xText (grammar follows):
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="prop"
nsURI="http://www.xtext.org/example/Prop" nsPrefix="prop">
<eClassifiers xsi:type="ecore:EClass" name="Prop" eSuperTypes="#//SubProp">
<eStructuralFeatures xsi:type="ecore:EReference" name="left" eType="#//SubProp"
containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="op" eType="#//BinOp" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="UnOp" eSuperTypes="#//SubProp">
<eStructuralFeatures xsi:type="ecore:EReference" name="right" eType="#//SubProp"
containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="SubProp">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="BinOp">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="right" eType="#//SubProp"
containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="op" eType="#//BinOp" containment="true"/>
</eClassifiers>
</ecore:EPackage>
xText Grammar:
grammar org.xtext.example.Prop with org.eclipse.xtext.common.Terminals
generate prop "http://www.xtext.org/example/Prop"
Prop : left=SubProp op=BinOp
;
UnOp : name='not'
;
SubProp : '(' Prop ')'
| name=ID
| UnOp right=SubProp
;
BinOp : (name=('and' | 'or' | 'impl' | 'eq') right=SubProp op=BinOp)?
;
Finally, here is my attempt at the first transformation:
module PropATL;
create OUT : Prop from IN : Prop;
rule newOp (s : String){
to t : Prop!Op (
name <- s
)
}
helper context Prop!Prop def: isAnd() : Boolean =
if self.op.name = 'and' then
true
else
false
endif;
rule And2Or {
from s : Prop!Prop (s.isAnd())
to t : Prop!Prop (
left <- s.left
)
do {
t.op <- newOp('or');
t.op.right <- s.op.right;
}
}
Currently I am having trouble calling the called rule, newOp.
Any help appreciated.
Cheers,
Shannon
[Updated on: Thu, 07 January 2010 01:15] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03205 seconds