Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] Parsing context-free language
[ATL] Parsing context-free language [message #35116] Sun, 29 April 2007 12:55 Go to next message
Lorenzo Dalla Vecchia is currently offline Lorenzo Dalla VecchiaFriend
Messages: 58
Registered: July 2009
Member
Hi.

I am currently working for a trasformation project using ATL framework.

As a first step, I am injecting the input XML file of my input model in a
ECore model by means of an ATL transformation between the XML model
(injected from the file) and my metamodel.

Now, all was proceeding well, until I encountered a problem. Some attributes
in the source XML file contain expressions meaningful for the model, and
that I would like to parse to generate model elements from them.
The problem is that the language of the expressions is a context-free
language (explointing features like nesting brackets, operator precedence,
etc.) and therefore cannot be parsed using a simple regular expression.

If I was using a programming language like C or Java I would have used a
parser generator to create a parser from the language grammar, but how can I
generate such parser in ATL code? Coding it by hand just doesn't seem right.
Is there a way to somehow connect to external java classes?

Thanks.

--
Lorenzo
Re: [ATL] Parsing context-free language [message #35153 is a reply to message #35116] Sun, 29 April 2007 13:22 Go to previous messageGo to next message
Frédéric Jouault is currently offline Frédéric JouaultFriend
Messages: 572
Registered: July 2009
Senior Member
Hello,

Parsing context-free languages is not a model transformation issue (at
least, not if you stay within the boundaries of the Model Engineering
technical space, or technology).

However, going from context-free (or Grammarware, or EBNF) to Model
Engineering is a kind of injection (i.e., a transformation from another
technology towards Model Engineering).

The AMMA platform offers a tool to perform exactly this kind of
injection: TCS. See:
http://wiki.eclipse.org/index.php/TCS

TCS is usually used to parse a single file into a single model. You may
write a transformation (or more likely a combination of transformations,
and ant scripts) that extracts all the XML attributes that you want to
parse in separate files. Then, you may use TCS the usual way. This can
be fully automated using ant scripts and the AM3 ant tasks. See:
http://wiki.eclipse.org/index.php/AM3_Ant_Tasks


However, there is an experimental feature of ATL that you may find
extremely useful: the ability to parse a String from within the current
transformation (e.g., read from an XML attribute) into the target model
of your choice. This works by calling the following operation on your
strings:

String.inject(targetModelName : String, kind : String, params : String)

where:
- targetModelName is the name of the target model in which to create the
elements (e.g., 'OUT').
- kind is the kind of injection you want to use (e.g., 'ebnf2' for the
current version of TCS, or 'xml' for XML).
- params is a list of parameters for the injector (e.g., 'KM3' to use
the KM3 TCS parser if kind is set to 'ebnf2').

Note that you will need to put the jar (i.e., the compiled TCS parser
generated by TCS from your TCS model and KM3 metamodel) into the current
Java classpath.


As you may have noticed, it is even possible to inject an XML-encoded
String, or use any other injector from within an ATL transformation.


This feature has been tested successfully to inject an XSLT file (i.e.,
XML + XPath, which is context-free, with operators and so on) with an
XML2XSTL.atl transformation calling the String.inject(...) operation
described above. This transformation scenario has not been published yet
(stay tuned :-)).


Regards,

Frédéric Jouault


Lorenzo Dalla Vecchia wrote:
> Hi.
>
> I am currently working for a trasformation project using ATL framework.
>
> As a first step, I am injecting the input XML file of my input model in
> a ECore model by means of an ATL transformation between the XML model
> (injected from the file) and my metamodel.
>
> Now, all was proceeding well, until I encountered a problem. Some
> attributes in the source XML file contain expressions meaningful for the
> model, and that I would like to parse to generate model elements from them.
> The problem is that the language of the expressions is a context-free
> language (explointing features like nesting brackets, operator
> precedence, etc.) and therefore cannot be parsed using a simple regular
> expression.
>
> If I was using a programming language like C or Java I would have used a
> parser generator to create a parser from the language grammar, but how
> can I generate such parser in ATL code? Coding it by hand just doesn't
> seem right.
> Is there a way to somehow connect to external java classes?
>
> Thanks.
>
> --
> Lorenzo
Re: [ATL] Parsing context-free language [message #35433 is a reply to message #35153] Mon, 30 April 2007 12:13 Go to previous messageGo to next message
Lorenzo Dalla Vecchia is currently offline Lorenzo Dalla VecchiaFriend
Messages: 58
Registered: July 2009
Member
Thanks for the detailed reply.

I'm checking out TCS, but I'm having problems running the Ant script. Is
there a place to get help about TCS issues?
Thanks.

--
Lorenzo
Re: [ATL] Parsing context-free language [message #36698 is a reply to message #35153] Wed, 09 May 2007 22:02 Go to previous messageGo to next message
Lorenzo Dalla Vecchia is currently offline Lorenzo Dalla VecchiaFriend
Messages: 58
Registered: July 2009
Member
Hi again.

> [...] there is an experimental feature of ATL that you may find extremely
> useful: the ability to parse a String from within the current
> transformation (e.g., read from an XML attribute) into the target model of
> your choice. This works by calling the following operation on your
> strings:
>
> String.inject(targetModelName : String, kind : String, params : String)
>
> where:
> - targetModelName is the name of the target model in which to create the
> elements (e.g., 'OUT').
> - kind is the kind of injection you want to use (e.g., 'ebnf2' for the
> current version of TCS, or 'xml' for XML).
> - params is a list of parameters for the injector (e.g., 'KM3' to use the
> KM3 TCS parser if kind is set to 'ebnf2').

I have prepared the TCS injector and I have its Jar ready to use.
After adding my TCS-populated model as a secondary output model in my ATL
file, and after adding the inject method call you described, I am getting
this exception during transformation.

[am3.atl] java.lang.reflect.InvocationTargetException

[am3.atl] ... 42 more

[am3.atl] Caused by: java.lang.NullPointerException

[am3.atl] at
org.atl.engine.vm.nativelib.ASMString.inject(ASMString.java: 258)

[am3.atl] ... 42 more


The exception is raised each time a call to the inject method is made.

> Note that you will need to put the jar (i.e., the compiled TCS parser
> generated by TCS from your TCS model and KM3 metamodel) into the current
> Java classpath.

It should be: I added it in the "Classpath" tab of the Ant task I am using
to run the transformation.
What could be causing the problem?

Thank you.

--
Lorenzo
Re: [ATL] Parsing context-free language [message #37210 is a reply to message #36698] Fri, 11 May 2007 13:17 Go to previous message
Frédéric Jouault is currently offline Frédéric JouaultFriend
Messages: 572
Registered: July 2009
Senior Member
Hello,

You did find a bug :-).

The String.inject(...) operation had never been tested from within
Eclipse. The current implementation depends on an object only present
when the ATL VM is launched from command line.


Best regards,

Frédéric Jouault


Lorenzo Dalla Vecchia wrote:
> Hi again.
>
>> [...] there is an experimental feature of ATL that you may find
>> extremely useful: the ability to parse a String from within the
>> current transformation (e.g., read from an XML attribute) into the
>> target model of your choice. This works by calling the following
>> operation on your strings:
>>
>> String.inject(targetModelName : String, kind : String, params : String)
>>
>> where:
>> - targetModelName is the name of the target model in which to create
>> the elements (e.g., 'OUT').
>> - kind is the kind of injection you want to use (e.g., 'ebnf2' for the
>> current version of TCS, or 'xml' for XML).
>> - params is a list of parameters for the injector (e.g., 'KM3' to use
>> the KM3 TCS parser if kind is set to 'ebnf2').
>
> I have prepared the TCS injector and I have its Jar ready to use.
> After adding my TCS-populated model as a secondary output model in my
> ATL file, and after adding the inject method call you described, I am
> getting this exception during transformation.
>
> [am3.atl] java.lang.reflect.InvocationTargetException
>
> [am3.atl] ... 42 more
>
> [am3.atl] Caused by: java.lang.NullPointerException
>
> [am3.atl] at
> org.atl.engine.vm.nativelib.ASMString.inject(ASMString.java: 258)
>
> [am3.atl] ... 42 more
>
>
> The exception is raised each time a call to the inject method is made.
>
>> Note that you will need to put the jar (i.e., the compiled TCS parser
>> generated by TCS from your TCS model and KM3 metamodel) into the
>> current Java classpath.
>
> It should be: I added it in the "Classpath" tab of the Ant task I am
> using to run the transformation.
> What could be causing the problem?
>
> Thank you.
>
> --
> Lorenzo
Previous Topic:[ATL] Tansformation a XML Document to another XML
Next Topic:[ATL] In-place injection
Goto Forum:
  


Current Time: Thu Jan 21 15:48:20 GMT 2021

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

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

Back to the top