Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » parsing OCL as a pure abstract syntax tree
parsing OCL as a pure abstract syntax tree [message #54705] Fri, 02 May 2008 14:29 Go to next message
Jean-Marc Vanel is currently offline Jean-Marc VanelFriend
Messages: 23
Registered: July 2009
Junior Member
Hi

Is it possible to parse syntically an OCL expression, i.e. without a
reference to a Class context, obtaining a pure abstract syntax tree ?
Re: parsing OCL as a pure abstract syntax tree [message #54804 is a reply to message #54705] Sun, 04 May 2008 01:56 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: give.a.damus.gmail.com

Hi, Jean-Marc,

The OCL language's abstract syntax is fundamentally dependent on the
contextual classifier for construction of the abstract syntax tree.

Perhaps the concrete-syntax tree will suit your needs? See the
OCLAnalyzer::parseConcreteSyntax() API.

HTH,

Christian


On Friday 05-02-2008 (10:29), Jean-Marc Vanel wrote:
> Hi

> Is it possible to parse syntically an OCL expression, i.e. without a
> reference to a Class context, obtaining a pure abstract syntax tree ?


--

I'm trying a new usenet client for Mac, Nemo OS X.
You can download it at http://www.malcom-mac.com/nemo
Re: parsing OCL as a pure abstract syntax tree [message #54993 is a reply to message #54804] Tue, 06 May 2008 13:32 Go to previous messageGo to next message
Jean-Marc Vanel is currently offline Jean-Marc VanelFriend
Messages: 23
Registered: July 2009
Junior Member
Christian W. Damus wrote:
> Hi, Jean-Marc,
>
> The OCL language's abstract syntax is fundamentally dependent on the
> contextual classifier for construction of the abstract syntax tree.
>
> Perhaps the concrete-syntax tree will suit your needs? See the
> OCLAnalyzer::parseConcreteSyntax() API.

Thanks Christian.
I did this:

Environment env = EcoreEnvironmentFactory.INSTANCE.createEnvironment();
OCLAnalyzer a = new OCLAnalyzer( env, oclSource );
CSTNode csTree = a.parseConcreteSyntax();

Then csTree is null in almost all cases, except that a name alone is
interpreted as a variable.

Note that everything is templatized by:
<EPackage, EClassifier, EOperation, EStructuralFeature, EEnumLiteral,
EParameter, EObject, CallOperationAction, SendSignalAction, Constraint,
EClass, EObject>

>
> HTH,
>
> Christian
>
> On Friday 05-02-2008 (10:29), Jean-Marc Vanel wrote:
>
>> Hi
>
>> Is it possible to parse syntactically an OCL expression, i.e. without a
>> reference to a Class context, obtaining a pure abstract syntax tree ?
Re: parsing OCL as a pure abstract syntax tree [message #55020 is a reply to message #54993] Tue, 06 May 2008 15:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: give.a.damus.gmail.com

Hi, Jean-Marc,

You are probably getting nulls because your input text is not one of
the top expressions defined by the OCL concrete-syntax grammar
(Chapter 9 of the spec).

You must supply text conforming to one of these productions:

packageDeclarationCS
invOrDefCS
prePostOrBodyDeclCS
initOrDerValueCS
variableCS

This last one (which worked for you) isn't really supposed to be a top
expression, but the API needs it for its own reasons.

Have a look in the test_constraints.ocl file in the
org.eclipse.ocl.ecore.tests project for an example of valid top
expressions. In all cases, the "package <qname> ... endpackage"
context is optional; the contents are also top expressions.

HTH,

Christian


On Tuesday 05-06-2008 (09:32), Jean-Marc Vanel wrote:
> Christian W. Damus wrote:
>> Hi, Jean-Marc,
>>
>> The OCL language's abstract syntax is fundamentally dependent on
>> the contextual classifier for construction of the abstract syntax
>> tree.
>>
>> Perhaps the concrete-syntax tree will suit your needs? See the
>> OCLAnalyzer::parseConcreteSyntax() API.

> Thanks Christian.
> I did this:

> Environment env =
> EcoreEnvironmentFactory.INSTANCE.createEnvironment();OCLAnal yzer a =
> new OCLAnalyzer( env, oclSource );
> CSTNode csTree = a.parseConcreteSyntax();

> Then csTree is null in almost all cases, except that a name alone is
> interpreted as a variable.

> Note that everything is templatized by:
> <EPackage, EClassifier, EOperation, EStructuralFeature,
> EEnumLiteral, EParameter, EObject, CallOperationAction,
> SendSignalAction, Constraint, EClass, EObject>

-----8<-----


--

I'm trying a new usenet client for Mac, Nemo OS X.
You can download it at http://www.malcom-mac.com/nemo
Re: parsing OCL as a pure abstract syntax tree [message #55047 is a reply to message #55020] Tue, 06 May 2008 17:39 Go to previous messageGo to next message
Jean-Marc Vanel is currently offline Jean-Marc VanelFriend
Messages: 23
Registered: July 2009
Junior Member
Christian W. Damus wrote:

> Hi, Jean-Marc,
>
> You are probably getting nulls because your input text is not one of
> the top expressions defined by the OCL concrete-syntax grammar
> (Chapter 9 of the spec).
>
> You must supply text conforming to one of these productions:
>
> packageDeclarationCS
> invOrDefCS
> prePostOrBodyDeclCS
> initOrDerValueCS
> variableCS

It works much better now, prefixing my stuff with inv: or body: .
But is there a way to get the error messages ?
Re: parsing OCL as a pure abstract syntax tree [message #55074 is a reply to message #55047] Tue, 06 May 2008 17:53 Go to previous messageGo to next message
Jean-Marc Vanel is currently offline Jean-Marc VanelFriend
Messages: 23
Registered: July 2009
Junior Member
I forgot to ask:

Now that I have a root CSNode object, is there some code to recursively
iterate on it ?
Would need to distinguish plain identifiers and collection mathods.
Re: parsing OCL as a pure abstract syntax tree [message #55099 is a reply to message #55047] Tue, 06 May 2008 18:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: give.a.damus.gmail.com

Hi, Jean-Marc,

As you're using an EcoreEnvironment, it will have an OCLProblemHandler
installed.

Have a look at the OCLUtil::checkForErrors(...) methods to see how you
can get Diagnostics describing any syntactic problems found by the
parser.

HTH,

Christian

On Tuesday 05-06-2008 (01:39), Jean-Marc Vanel wrote:
> Christian W. Damus wrote:
>> Hi, Jean-Marc,
>>
>> You are probably getting nulls because your input text is not one
>> of the top expressions defined by the OCL concrete-syntax grammar
>> (Chapter 9 of the spec).
>>
>> You must supply text conforming to one of these productions:
>>
>> packageDeclarationCS
>> invOrDefCS
>> prePostOrBodyDeclCS
>> initOrDerValueCS
>> variableCS

> It works much better now, prefixing my stuff with inv: or body: .
> But is there a way to get the error messages ?


--

I'm trying a new usenet client for Mac, Nemo OS X.
You can download it at http://www.malcom-mac.com/nemo
Re: parsing OCL as a pure abstract syntax tree [message #55154 is a reply to message #55074] Tue, 06 May 2008 18:37 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: give.a.damus.gmail.com

Hi, Jean-Marc,

I'm thinking that the Abstract Syntax Tree will be more useful to you
for this purpose. The CST cannot distinguish between constructs that
look similar but are semantically different. For example, a reference
to a static attribute and an enumeration literal look identical; the
difference in semantics can only be determined by looking at the model
to see whether the named element is an attribute or an enumeration
literal. Likewise, what looks in the concrete syntax like a variable
could be a reference to an operation parameter, let-variable,
attribute, or type.

Using the AST, you also get a handy visitor framework in the
org.eclipse.ocl.utilities.AbstractVisitor class.

If you prefer to work with the CST, then you can use a popular pattern
to implement a visitor-like iteration: create a subclass of the
CSTSwitch class, and override the defaultCase(EObject) method to
iterate the eContents of the object and call doSwitch on each in turn.
Then, for any caseXyz(Xyz) method that you override, ensure that the
last thing it does is to call the defaultCase explicitly to continue
the recursion.HTH,

Christian

On Tuesday 05-06-2008 (01:53), Jean-Marc Vanel wrote:
> I forgot to ask:

> Now that I have a root CSNode object, is there some code to
> recursively iterate on it ?
> Would need to distinguish plain identifiers and collection mathods.


--

I'm trying a new usenet client for Mac, Nemo OS X.
You can download it at http://www.malcom-mac.com/nemo
Re: parsing OCL as a pure abstract syntax tree [message #55180 is a reply to message #55099] Wed, 07 May 2008 10:07 Go to previous messageGo to next message
Jean-Marc Vanel is currently offline Jean-Marc VanelFriend
Messages: 23
Registered: July 2009
Junior Member
Christian W. Damus wrote:

> Hi, Jean-Marc,
>
> As you're using an EcoreEnvironment, it will have an OCLProblemHandler
> installed.
>
> Have a look at the OCLUtil::checkForErrors(...) methods to see how you
> can get Diagnostics describing any syntactic problems found by the
> parser.

Thanks.

To get the error messages, I did:

env = EcoreEnvironmentFactory.INSTANCE.createEnvironment();
OCLAnalyzer a = new OCLAnalyzer( env, oclSource );
CSTNode csTree = a.parseConcreteSyntax();
if( csTree == null )
try {
Diagnostic errors = OCLUtil.checkForErrors( env );
if( errors != null )
System.err.println( errors ); // line not reached
} catch (SyntaxException e) {
System.err.println( oclSource + "\n" + e.getDiagnostic() ); //
line reached
} catch (SemanticException e) {
System.err.println( oclSource + "\n" + e.getDiagnostic() );
}


Note that the other method checkForErrors() doesn't bring anything :

handler = new OCLProblemHandler( a.getParser() );
OCLUtil.checkForErrors( handler );
Re: parsing OCL as a pure abstract syntax tree [message #55207 is a reply to message #55180] Wed, 07 May 2008 19:53 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: give.a.damus.gmail.com

Hi, Jean-Marc,

Right, a new problem-handler wouldn't have any problems in it. You
would have to use the problem-handler already associated with your
OCLAnalyzer.

In any case, your solution seems to work, so that's good!

Cheers,

Christian


Jean-Marc Vanel wrote:
> Christian W. Damus wrote:
>
>> Hi, Jean-Marc,
>>
>> As you're using an EcoreEnvironment, it will have an OCLProblemHandler
>> installed.
>>
>> Have a look at the OCLUtil::checkForErrors(...) methods to see how you
>> can get Diagnostics describing any syntactic problems found by the
>> parser.
>
> Thanks.
>
> To get the error messages, I did:
>
> env = EcoreEnvironmentFactory.INSTANCE.createEnvironment();
> OCLAnalyzer a = new OCLAnalyzer( env, oclSource );
> CSTNode csTree = a.parseConcreteSyntax();
> if( csTree == null )
> try {
> Diagnostic errors = OCLUtil.checkForErrors( env );
> if( errors != null )
> System.err.println( errors ); // line not reached
> } catch (SyntaxException e) {
> System.err.println( oclSource + "\n" + e.getDiagnostic() ); // line
> reached
> } catch (SemanticException e) {
> System.err.println( oclSource + "\n" + e.getDiagnostic() );
> }
>
>
> Note that the other method checkForErrors() doesn't bring anything :
>
> handler = new OCLProblemHandler( a.getParser() );
> OCLUtil.checkForErrors( handler );
Re: parsing OCL as a pure abstract syntax tree [message #540956 is a reply to message #54705] Thu, 17 June 2010 19:09 Go to previous messageGo to next message
Victorino  is currently offline Victorino Friend
Messages: 21
Registered: June 2010
Junior Member
I found this page is too late,
because I meet the same problem for a few months ago,
and I still can not solve.
I write the code belowed:
============================================================ ===
OCL<?,EClassifier,?,?,?,?,?,?,?,Constraint,EClass,EObject> ocl;
ocl=OCL.newInstance(env);//EcoreEnvironmentFactory.INSTANCE) ;
OCLInput input=new OCLInput("inv: size>0");
List<Constraint> constraints=ocl.parse(input);

============================================================ ===
but I always got an SemanticException.
It says "expected parser to return PackageDeclarationCS but got InvCS"

if I changed input to "pre: size>0" or "post: size>0",
It says "expected parser to return PackageDeclarationCS but got PrePostOrBodyDeclCS"

And how can I use the parser result to continued my work ???
I am almost newer to OCL,
and found it can improve diagrams (either Ecore or UML),
but I am stuck at parse.
Please help me ! Please ~~~

[Updated on: Thu, 17 June 2010 19:10]

Report message to a moderator

Re: parsing OCL as a pure abstract syntax tree [message #540963 is a reply to message #540956] Thu, 17 June 2010 19:31 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Victorino

The OCL.parse method is for parsing OCL Documents.

See
help/topic/org.eclipse.ocl.doc/references/overview/parsingCo nstraints.html
in the OCL Developer Guide for
instrctions on using e.g. ocl.createHelper().createPostCondition();

If you're using OCL to enrich Ecore, ytou might want to check out
the OCLinEcore tutorial in the Helios OCL documentation and see
the much improved OCL and Ecore integration.

[Helios is officially released on June 23rd; RC4 is available now.]

Regards

Ed Willink

On 17/06/2010 20:09, Victorino wrote:
> I found this page is too late,
> because I meet the same problem for a few months ago,
> and I still can not solve.
> I write the code belowed:
> ============================================================ ===
> OCL<?,EClassifier,?,?,?,?,?,?,?,Constraint,EClass,EObject> ocl;
> ocl=OCL.newInstance(env);//EcoreEnvironmentFactory.INSTANCE) ;
> OCLInput input=new OCLInput("inv: size>0");
> List<Constraint> constraints=ocl.parse(input);
> ============================================================ ===
> but I always got an SemanticException.
> It says "expected parser to return PackageDeclarationCS but got InvCS"
>
> if I changed input to "pre: size>0",
> It says "expected parser to return PackageDeclarationCS but got
> PrePostOrBodyDeclCS"
>
> And how can I use the parser result to continued my work ???
> I am almost newer to OCL,
> and found it can improve diagrams (either Ecore or UML),
> but I am stuck at parse.
> Please help me ! Please ~~~
Re: parsing OCL as a pure abstract syntax tree [message #540966 is a reply to message #54705] Thu, 17 June 2010 20:03 Go to previous messageGo to next message
Victorino  is currently offline Victorino Friend
Messages: 21
Registered: June 2010
Junior Member
Hi, Ed Willink.
Thx for your reply, and I found that page :
" http://help.eclipse.org/galileo/index.jsp?nav=/26 ",
I am trying to do the same thing with that page says.
Look that page carefully I guest ocl constraint can be evaluate,
and where is the result put after evaluated ???
Is result only can presented boolean type ???
Sorry to bothered you.
But I still wonder how can I use the "result" ???
Like how can I get the token(s) in the constraint or somewhat ???
Re: parsing OCL as a pure abstract syntax tree [message #541017 is a reply to message #540966] Fri, 18 June 2010 05:20 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Victorino

You need to be much clearer about your problems fot a reply to address them.

The result of ocl.createHelper().createPostCondition() is an AST that is
returned. Your email is titled AST so I presume that is what you want.
The result is a postcondition so of course it is Boolean. Use a
different method such as createQuery() if you want a different behaviour.

I referred you to the "Parsing Constraints and Queries" page in the OCL
documentation that you can find via Help->Help Contents->OCL Developer
Guide; it should already be on your machine and so be a bit quicker than
the web.

If you want to evaluate look at the "Evaluating Constraints and Queries"
page.

Regards

Ed Willink



On 17/06/2010 21:03, Victorino wrote:
> Hi, Ed Willink.
> Thx for your reply, and I found that page :
> " http://help.eclipse.org/galileo/index.jsp?nav=/26 ",
> I am trying to do the same thing with that page says.
> Look that page carefully I guest ocl constraint can be evaluate,
> and where is the result put after evaluated ???
> Is result only can presented boolean type ???
> Sorry to bothered you.
> But I still wonder how can I use the "result" ???
> Like how can I get the token(s) in the constraint or somewhat ???
>
Re: parsing OCL as a pure abstract syntax tree [message #541057 is a reply to message #54705] Fri, 18 June 2010 08:06 Go to previous messageGo to next message
Victorino  is currently offline Victorino Friend
Messages: 21
Registered: June 2010
Junior Member
I met a problem again,
Since I can got AST Tree, is it means I can evaluated ?
Like " perform " the query is satisfied or not ?
I wrote the code (even followed the guide still has some problem):
============================================================ =====

OCL<?,EClassifier,?,?,?,?,?,?,?,Constraint,EClass,EObject> ocl;
ocl=OCL.netInstance(EcoreEnvironmentFactory.INSTANCE);
OCLHelper<EClassifier,?,?,Constraint> helper=ocl.createOCLHelper();
Constraint invariant=helper.createInvariant("books->forAll(b1, b2 | b1 <> b2 implies b1.
title <> b2.title)");

============================================================ =====
I got org.eclipse.ocl.ParserException as below:
org.eclipse.ocl.ParserException
at org.eclipse.ocl.internal.helper.OCLHelperImpl.propagate(OCLH elperImpl.java:403)
at org.eclipse.ocl.internal.helper.OCLHelperImpl.createInvarian t(OCLHelperImpl.java:218)
at pkg.Test.main(Test.java:135)
Caused by: java.lang.NullPointerException
at org.eclipse.ocl.AbstractEnvironment.getContextClassifier(Abs tractEnvironment.java:206)
at org.eclipse.ocl.parser.AbstractOCLAnalyzer.invOrDefCS(Abstra ctOCLAnalyzer.java:1405)
at org.eclipse.ocl.parser.OCLAnalyzer.parseInvOrDefCS(OCLAnalyz er.java:266)
at org.eclipse.ocl.internal.helper.HelperUtil.parseInvariant(He lperUtil.java:206)
at org.eclipse.ocl.internal.helper.OCLHelperImpl.createInvarian t(OCLHelperImpl.java:215)
... 1 more
Would you mind hint me where is going wrong?
And Would you write an simplest code example me,
only include created inv, pre, post and evaluate them.
Best Regards.

[Updated on: Fri, 18 June 2010 08:15]

Report message to a moderator

Re: parsing OCL as a pure abstract syntax tree [message #541079 is a reply to message #541057] Fri, 18 June 2010 09:23 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

The example works fine for me.

But I can reproduce your error by deleting:

helper.setContext(EXTLibraryPackage.Literals.LIBRARY);

Try getting the example to work before you improve it.

Regards

Ed Willink


On 18/06/2010 09:06, Victorino wrote:
> I met a problem again,
> Since I can got AST Tree, is it means I can evaluated ?
> Like " perform " the query is satisfied or not ?
> I wrote the code (even followed the guide still has some problem):
> ============================================================ =====
> OCLHelper<EClassifier,?,?,Constraint> helper=ocl.createOCLHelper();
> Constraint invariant=helper.createInvariant("books->forAll(b1, b2 | b1
> <> b2 implies b1.title <> b2.title)");
> ============================================================ =====
> I got org.eclipse.ocl.ParserException as below:
> org.eclipse.ocl.ParserException
> at org.eclipse.ocl.internal.helper.OCLHelperImpl.propagate(OCLH
> elperImpl.java:403)
> at org.eclipse.ocl.internal.helper.OCLHelperImpl.createInvarian
> t(OCLHelperImpl.java:218)
> at pkg.Test.main(Test.java:135)
> Caused by: java.lang.NullPointerException
> at org.eclipse.ocl.AbstractEnvironment.getContextClassifier(Abs
> tractEnvironment.java:206)
> at org.eclipse.ocl.parser.AbstractOCLAnalyzer.invOrDefCS(Abstra
> ctOCLAnalyzer.java:1405)
> at org.eclipse.ocl.parser.OCLAnalyzer.parseInvOrDefCS(OCLAnalyz
> er.java:266)
> at org.eclipse.ocl.internal.helper.HelperUtil.parseInvariant(He
> lperUtil.java:206)
> at org.eclipse.ocl.internal.helper.OCLHelperImpl.createInvarian
> t(OCLHelperImpl.java:215)
> ... 1 more
> Would you mind hint me where is going wrong?
> And Would you write an simplest code example me,
> only include created inv, pre, post and evaluate them.
Re: parsing OCL as a pure abstract syntax tree [message #541087 is a reply to message #54705] Fri, 18 June 2010 09:46 Go to previous messageGo to next message
Victorino  is currently offline Victorino Friend
Messages: 21
Registered: June 2010
Junior Member
hi,
-> helper.setContext(EXTLibraryPackage.Literals.LIBRARY);
Is necessory to import " org.eclipse.emf.examples.extlibrary.EXTLibraryPackage ", right ?
I guest this is right.
But if I wanna have my EMF model(to make a new ecore file),
Is it the same ?
Or I have to doing something different from "EXTLibraryPackage" ?
And, by the way,
when I import org.eclipse.emf.examples.extlibrary.EXTLibraryPackage, and including org.eclipse.emf.example.installer in my building path,
this program is still wrong and have read line below EXTLibraryPackage.
How it's happen on my mechine ?
Best Regards

[Updated on: Fri, 18 June 2010 09:52]

Report message to a moderator

Re: parsing OCL as a pure abstract syntax tree [message #541094 is a reply to message #541087] Fri, 18 June 2010 10:17 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

EXTLibraryPackage is the meta-model for the example; it defines Library
and books.

For Java code you must import your meta-model.

Regards

Ed Willink

On 18/06/2010 10:46, Victorino wrote:
> hi,
> -> helper.setContext(EXTLibraryPackage.Literals.LIBRARY);
> Is necessory to import "
> org.eclipse.emf.examples.extlibrary.EXTLibraryPackage ", right ?
> I guest this is right.
> But if I wanna have my EMF model(to make a new ecore file),
> Is it the same ?
> Or I have to doing something different from "EXTLibraryPackage" ?
> Best Regards
Re: parsing OCL as a pure abstract syntax tree [message #541103 is a reply to message #54705] Fri, 18 June 2010 11:21 Go to previous messageGo to next message
Victorino  is currently offline Victorino Friend
Messages: 21
Registered: June 2010
Junior Member
But how can I import my own meta-model of EPackage ?
I know use the setContext (<=is that ?),
but how can I generate my own meta-model ?
What is the meta-model looks like ?
Best Regards.
Re: parsing OCL as a pure abstract syntax tree [message #541111 is a reply to message #541103] Fri, 18 June 2010 11:55 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
On 18/06/2010 12:21, Victorino wrote:
> But how can I import my own meta-model of EPackage ?
> I know use the setContext (<=is that ?),
> but how can I generate my own meta-model ?
> What is the meta-model looks like ?
> Best Regards.

Please follow the EMF tutorials before attempting to use OCL.

Regards

Ed Willink
Re: parsing OCL as a pure abstract syntax tree [message #541125 is a reply to message #54705] Fri, 18 June 2010 12:35 Go to previous messageGo to next message
Victorino  is currently offline Victorino Friend
Messages: 21
Registered: June 2010
Junior Member
About you mentioned " EMF tutorials ",
I have seen that and do some works on it already.
Actually, I done work which is using EMF to generating *.genmodel and defining another model,
and using this model to drawing(describing) my new model.
But I still don't understand how import my meta-model very well.
Now, I have problem on the OCL expression is not in the *.ecore file, but in the new model(This is happened in my environment).
I can't parsing this OCL expression, because I don't know how to give the resource at all except the OCL expression let OCL parser to using parse the OCL expression.
That why I need to learning how to parse OCL independent.
Re: parsing OCL as a pure abstract syntax tree [message #541150 is a reply to message #541125] Fri, 18 June 2010 13:09 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

If you used genmodel then you have an XXXPackage that you can use
instead of ExtLibraryPackage.

Regards

Ed Willink

On 18/06/2010 13:35, Victorino wrote:
> About you mentioned " EMF tutorials ",
> I have seen that and do some works on it already.
> Actually, I done work which is using EMF to generating *.genmodel and
> defining another model,
> and using this model to drawing(describing) my new model.
> But I still don't understand how import my meta-model very well.
> Now, I have problem on the OCL expression is not in the *.ecore file,
> but in the new model(This is happened in my environment).
> I can't parsing this OCL expression, because I don't know how to give
> the resource at all except the OCL expression let OCL parser to using
> parse the OCL expression.
> That why I need to learning how to parse OCL independent.
Re: parsing OCL as a pure abstract syntax tree [message #541167 is a reply to message #54705] Fri, 18 June 2010 14:11 Go to previous messageGo to next message
Victorino  is currently offline Victorino Friend
Messages: 21
Registered: June 2010
Junior Member
============================================================ ========
If you used genmodel then you have an XXXPackage that you can use
instead of ExtLibraryPackage.
============================================================ ========
Sorry, I don't understand and what is this means ?
I didn't find any XXXPackage in my genmodel.
Maybe I have to describing more detail.
I use that genmodel to drawing and definition new one.
(It means this genmodel is basic type, and use this genmodel you can drawing lots of diagram according to your mind. Like EMF done, you can drawing any kind of class diagram you want.)
Now, after I use EMF to generating the new diagram, it will have three addition folder on my "Package Explorer" automatically, there are "Parttimejob", "Parttimejob.diagram", "Parttimejob.edit".
These three is the basic component when I am drawing new diagram.
It's means I use the EMF definition some basic node,
and using these basis node to describing new diagram.
(Imagine Parttimejob define some basic "node", and use these node to drawing new class diagram, state diagram or some others diagram, and OCL expression is a EString on your newest drawing diagram, in this situation, how can I parsing single OCL expression ? Called "single", just because they are not in the *.ecore, and they don't know any source to helping OCLParser.)

[Updated on: Fri, 18 June 2010 14:16]

Report message to a moderator

Re: parsing OCL as a pure abstract syntax tree [message #541172 is a reply to message #541167] Fri, 18 June 2010 14:21 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I am sorry but I have to prepare for a symposium next week.

Perhaps someone else could explain how genmodel produces a Package.

Regards

Ed Willink

On 18/06/2010 15:11, Victorino wrote:
> ============================================================ ========
> If you used genmodel then you have an XXXPackage that you can use
> instead of ExtLibraryPackage.
> ============================================================ ========
> Sorry, I don't understand and what is this means ?
> I didn't find any XXXPackage in my genmodel.
> Maybe I have to describing more detail.
> I use that genmodel to drawing and definition new one.
> (It means this genmodel is basic type, and use this genmodel you can
> drawing lots of diagram according to your mind. Like EMF done, you can
> drawing any kind of class diagram you want.)
> Now, after I use EMF to generating the new diagram, it will have three
> addition folder on my "Package Explorer" automatically, there are
> "Parttimejob", "Parttimejob.diagram", "Parttimejob.edit".
> Looks these three is the basic component when I am drawing new diagram.
> It's means I use the EMF definition some basic node,
> and using these basis node to describing new diagram.
> (Imagine EMF define some basic "node", and use these node to drawing new
> class diagram, state diagram or some others diagram, and OCL expression
> is a EString on your newest drawing diagram, in this situation, how can
> I parsing single OCL expression ? Called "single", just because they are
> not in the *.ecore.)
>
Re: parsing OCL as a pure abstract syntax tree [message #541177 is a reply to message #54705] Fri, 18 June 2010 14:43 Go to previous messageGo to next message
Victorino  is currently offline Victorino Friend
Messages: 21
Registered: June 2010
Junior Member
I have to say thank you at all.
It's my problem,
but you give me lots of suggestion.
Any way,
wish your symposium everything going fine.
And if you have time,
you can answer "expected parser to return PackageDeclarationCS but got InvCS" for me.
Even a little bit hint, I will very appreciated.
Best Regards

[Updated on: Fri, 18 June 2010 14:46]

Report message to a moderator

Re: parsing OCL as a pure abstract syntax tree [message #541203 is a reply to message #541177] Fri, 18 June 2010 16:31 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Victorino,

This means that you supplied the parser with text that consists only of
an OCL invariant constraint:

inv <name>: <expression>

omitting the context declaration that indicates to which classifier,
operation, or attribute the constraint pertains and (optionally) in
which package to resolve unqualified names.

Successful use of the OCL APIs with EMF-based models really requires:

(a) Familiarity with Ecore and the EMF run-time framework.
There are good introductory tutorials on EMF's homepage:
http://www.eclipse.org/modeling/emf/

(b) Reading the OCL Programmer's Guide on-line help that Ed
already indicated, and in particular, working through the
tutorial and the examples provided in the SDK

HTH,

Christian


On 18/06/10 10:43 AM, Victorino wrote:
> I have to say thank you at all.
> It's my problem,
> but you give me lots of suggestion.
> Any way,
> Wish your symposium everything going fine.
> And if you have time you can answer "expected parser to return
> PackageDeclarationCS but got InvCS" for me.
> Even a little bit hint, I will very appreciated.
> Best Regards
Re: parsing OCL as a pure abstract syntax tree [message #541375 is a reply to message #54705] Sun, 20 June 2010 15:16 Go to previous messageGo to next message
Victorino  is currently offline Victorino Friend
Messages: 21
Registered: June 2010
Junior Member
Thx for helping and sorry to reply so late,
I will following your suggestion to do.
And if I use analyzer to parse Concrete Syntax,
I will got a CSTNode return,
how can I get or managed the result?
Like to reading token or distinguishing what type is this node ...etc ?
Best Regard

[Updated on: Sun, 20 June 2010 20:08]

Report message to a moderator

Re: parsing OCL as a pure abstract syntax tree [message #541518 is a reply to message #541375] Mon, 21 June 2010 12:40 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Victorino,

I'm afraid I don't understand your question.

The API methods that parse OCL text (in the OCL facade class and the
OCLHelper) return the ASTs, be they Constraints or OCLExpressions.
These are the results.

What kind of type information are you trying to extract from the parsed
results?

- the kind of OCL object that it is? The API distinguishes these
via the Constraint and OCLExpression interfaces
- the kind of context classifier? This is simply the type of the
"self" variable owned by the constraint
- the kind of expression that it is (e.g., operation call, let, etc.)?
These are distinguished as subtypes of the OCLExpression interface

Have you read the tutorial and other documentation? Have you played
with the examples to see how the API works? Have you used the debugger
to inspect a parsed OCLExpression to see what the structure of the AST
is like?

Cheers,

Christian

On 20/06/10 11:16 AM, Victorino wrote:
> Thx for helping,
> I will following your suggestion to do.
> And if I use analyzer to parse Concrete syntax,
> how can I get or managed the result?
> Like to reading token or distinguishing what type is this?
> Best Regard
Re: parsing OCL as a pure abstract syntax tree [message #541543 is a reply to message #54705] Mon, 21 June 2010 13:58 Go to previous messageGo to next message
Victorino  is currently offline Victorino Friend
Messages: 21
Registered: June 2010
Junior Member
Hi, Christian W. Damus.
I readed the document but I don't practiced it.
Because I wanna parse the single sentence,
not the whole ocl document,
and ocl single sentence like "a>b" "a<100" (I tried it),
and return CSTNode,
but I can't traversal this CSTNode.
Is there some way can help me ?
Best Regards

[Updated on: Mon, 21 June 2010 13:58]

Report message to a moderator

Re: parsing OCL as a pure abstract syntax tree [message #541569 is a reply to message #541543] Mon, 21 June 2010 15:17 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Victorino,

You don't want to generate a Concrete Syntax Tree, but rather an
Abstract Syntax Tree. Perhaps you should try practising the tutorial in
addition to simply reading it. For example, if you emulate the code in
the "Parsing OCL Expressions" section of this page:

http://help.eclipse.org/galileo/topic/org.eclipse.ocl.doc/tu torials/oclInterpreterTutorial.html

then you may find something like what you need.

Christian


On 21/06/10 09:58 AM, Victorino wrote:
> I readed the document but I don't practiced it.
> Because I wanna parse the single sentence,
> not the whole ocl document,
> and ocl single sentence like "a>b" "a<100" (I tried it),
> and return CSTNode,
> but I can't traversal this CSTNode.
> Is there some way can help me ?
> Best Regards
Re: parsing OCL as a pure abstract syntax tree [message #541590 is a reply to message #54705] Mon, 21 June 2010 16:56 Go to previous messageGo to next message
Victorino  is currently offline Victorino Friend
Messages: 21
Registered: June 2010
Junior Member
Hi, Christian W. Damus,
Really thanks your suggestion,
I will tried it.
And if I have something got,
I will report.
At last, allow me to say "Thanks" again.
^^
Best Regards
Re: parsing OCL as a pure abstract syntax tree [message #545498 is a reply to message #541569] Thu, 08 July 2010 05:06 Go to previous message
Victorino  is currently offline Victorino Friend
Messages: 21
Registered: June 2010
Junior Member
Hi, Christian W. Damus.
I just tried your suggestion and visited that page again.
And I found some error happened in my program even I just copy and paste from that page,
that is simply code:
============================================================ ====
@SuppressWarnings({"unchecked","hiding"})
public static <EClassifier, Constraint, EClass, EObject> void main(String[] args) {
boolean valid;
org.eclipse.ocl.expressions.OCLExpression<EClassifier> query = null;
try {
// create an OCL instance for Ecore
OCL< EPackage,org.eclipse.emf.ecore.EClassifier,EOperation,EStruc turalFeature,EEnumLiteral,EParameter,org.eclipse.emf.ecore.E Object,CallOperationAction,SendSignalAction,org.eclipse.ocl. ecore.Constraint,org.eclipse.emf.ecore.EClass,org.eclipse.em f.ecore.EObject > ocl;
ocl=OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);
// create an OCL helper object
OCLHelper< org.eclipse.emf.ecore.EClassifier,EOperation,EStructuralFeat ure,org.eclipse.ocl.ecore.Constraint > helper=ocl.createOCLHelper();
// set the OCL context classifier
helper.setContext(EXTLibraryPackage.Literals.WRITER);
query=(org.eclipse.ocl.expressions.OCLExpression<EClassifier >) helper.createQuery("self.books->collect(b : Book | b.category)->asSet()");
// record success
valid=true;
}
catch (ParserException e) {
// record failure to parse
valid=false;
System.err.println(e.getLocalizedMessage());
}
}
============================================================ ====
And in " helper.setContext(EXTLibraryPackage.Literals.WRITER); " that line,
It's always happened error and have a red line below it.
I know is missing package - " EXTLibraryPackage ",
but I don't wanna to use EXTLibraryPackage.
So, let me represented my question now:
How can I replace that package?
Does I created one package from my *.ecore at first?
And how to created?
I tried your way to passing this problem. (Trust me, I have worked this way more than one week.)
But I still stock at this " begin " problem.
If possible, please tell me how to do in detail.
Best Regard

Christian W. Damus wrote on Mon, 21 June 2010 11:17
Hi, Victorino,

You don't want to generate a Concrete Syntax Tree, but rather an
Abstract Syntax Tree. Perhaps you should try practising the tutorial in
addition to simply reading it. For example, if you emulate the code in
the "Parsing OCL Expressions" section of this page:

http://help.eclipse.org/galileo/topic/org.eclipse.ocl.doc/tu torials/oclInterpreterTutorial.html

then you may find something like what you need.

Christian


On 21/06/10 09:58 AM, Victorino wrote:
> I readed the document but I don't practiced it.
> Because I wanna parse the single sentence,
> not the whole ocl document,
> and ocl single sentence like "a>b" "a<100" (I tried it),
> and return CSTNode,
> but I can't traversal this CSTNode.
> Is there some way can help me ?
> Best Regards

Previous Topic:OCL in drawing tool!!
Next Topic:ocl in profile uml
Goto Forum:
  


Current Time: Fri Mar 29 06:23:06 GMT 2024

Powered by FUDForum. Page generated in 0.04216 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top