[Ometa] Translation problem in OMeta/JS (was: timeout problem)
Alessandro Warth
alexwarth at gmail.com
Thu Mar 25 09:55:36 PDT 2010
Hi Rudiger,
Here's an excerpt from
http://tinlizzie.org/ometa-js/#Things_You_Should_Knowthat you might
find helpful. (You can also get to this page by selecting
"Things You Should Know" from the "important info" pull-down menu in the
OMeta/JS workspace.)
Note #2: In the version of OMeta described in the paper, semantic actions
and predicates were written in COLA (kind of a mix between Scheme and
Smalltalk). In OMeta/JS, they are written in JavaScript. More specifically,
they are either primary expressions, e.g.,
123
x
foo.bar()
new Person()
(x + y) // note that you need parentheses around "x + y" in order to
make it into a primary expression
or something I made up called "statement expressions", which have the form
"{" <statement>* <expr> "}"
For example,
{ x +=3D 2; y =3D "foo"; f(x) }
The value of a statement expression is equal to that of its last expression.
So the immediate solution to the problem you're having is for you to put
parentheses (or even curly brackets, as you did) around the "x + y" in your
grammar.
Without the parentheses, the OMeta parser recognizes the "+" as a Kleene-+
operator that's being applied to the semantic action "x", and "y" as a rule
application. Having said that, I can't think of any cases in which you would
actually want to apply an iteration operator to a semantic action, so this
suggests that I should change the OMeta parser a little bit so that this is
not allowed. Once this is done, your original grammar will cause a parse
error, but that's much better than the mysterious behavior you experienced.
:)
I'll give you an update once this is done.
Thanks,
Alex
p.s. A few weeks ago I made a bunch improvements and added a couple of new
features to OMeta/JS. These are already in the OMeta/JS svn repository (and
on the workspace page), and I'll send an e-mail explaining them pretty soon.
On Thu, Mar 25, 2010 at 7:36 AM, R=FCdiger Plantiko <
ruediger.plantiko at astrotexte.ch> wrote:
> Der OMeta friends,
>
> I could bring the problem to the point (it has nothing to do with
> negation):
>
> Go to the OMeta/JS workspace http://www.tinlizzie.org/ometa-js/.
>
> Then define the following simple oMeta object:
>
> ometa M {
> test =3D 'x':x 'y':y -> x + y
> }
>
> Now try to match the string 'xy':
>
> M.matchAll( 'xy', 'test' )
>
> >>> You will get an endless loop !
>
> The JS transcript shows that for some unknown reasons the "->" is
> swallowed. The test rule is treated as if I had written
>
> test =3D 'x':x 'y':y x+ y
>
> Since the "rule" x always retrieves the character 'x', the expression x+
> blows up the result array with 'x' characters and never takes an end.
>
> Here is the generated transcript of the above rule:
>
> "test":function(){
> var $elf=3Dthis,_fromIdx=3Dthis.input.idx,x,y;
> return
> (function(){
> x=3Dthis._applyWithArgs("exactly","x");
> y=3Dthis._applyWithArgs("exactly","y");
> this._many1((function(){return x}));
> return this._apply("y")
> }).call(this)}
>
> The rule can easily be saved by enclosing the semantic action into braces
> like so:
>
> ometa M {
> test =3D 'x':x 'y':y -> { x + y }
> }
>
> But I don't understand why the first way is not transcribed as I expected
> (and probably all of you would expect).
>
> Regards,
> R=FCdiger
>
>
>
>
>
> ~~~~~~~~~~~~~~~~~~~~~~~~
> Dr. R=FCdiger Plantiko
> Bachwiesenstrasse 28
> CH-8405 Winterthur-Seen
>
> http://ruediger-plantiko.net
>
>
> _______________________________________________
> OMeta mailing list
> OMeta at vpri.org
> http://vpri.org/mailman/listinfo/ometa
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://vpri.org/pipermail/ometa/attachments/20100325/d2a321b3/attachme=
nt.htm
More information about the OMeta
mailing list