Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » how to define a Dummy Block in Grammar?
how to define a Dummy Block in Grammar? [message #556674] Thu, 02 September 2010 10:03 Go to next message
No real name is currently offline No real nameFriend
Messages: 16
Registered: September 2010
Junior Member
Hello, I want to build a grammar iteratively for a subset of an existing language.

The key problem is to be able to define a dummy part - I don't care what's in right now.

for example:

Model:
loop=ForLoop;

ForLoop:
'for' type=Type varname=ID ';' cond=Condition; incr=Increment
dummy=Dummy // dummy can contain another for-loop
'end for'


Is it possible?

Best regars, Anatoli
Re: how to define a Dummy Block in Grammar? [message #556679 is a reply to message #556674] Thu, 02 September 2010 10:28 Go to previous messageGo to next message
Bodo is currently offline BodoFriend
Messages: 27
Registered: August 2010
Junior Member
Just introduce a new grammar rule like:

Dummy:
forLoop=ForLoop
|
;
Re: how to define a Dummy Block in Grammar? [message #556684 is a reply to message #556674] Thu, 02 September 2010 10:40 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

to be a bit more verbose (yet untested). Note the changes in the ForLoop-Definition. It is to be preferred not to have white spaces within keywords.

ForLoop:
'for' type=Type varname=ID ';' cond=Condition; incr=Increment
dummy+=Dummy*
'end' 'for';

Dummy: ForLoop| content=Anything;

//pipe separated List of any terminal rule or keyword that may appear there
Anything: (ID|INT|STRING|';'|...);

Alex
Re: how to define a Dummy Block in Grammar? [message #556707 is a reply to message #556679] Thu, 02 September 2010 12:13 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 16
Registered: September 2010
Junior Member
Thank you very much for your answeres: I'm one step further now, but there are still some problems:

@Bodo: is it a special construct or just a pattern how you would do that?

Dummy:
forLoop=ForLoop
|
; is not a valid syntax

@Alexander

I could skip lots of stuff going this way before I came across the following, let's stick to my example:

Model:
loop=ForLoop;

ForLoop:
for1=FOR type=Type varname=ID ';' cond=Condition; incr=Increment
dummy=Dummy // dummy can contain another for-loop
end=END for2=FOR

END:
end='end';

FOR:
for='for';

Dummy: ForLoop| content=Anything;

Anything: (ID|INT|STRING|';');

now I can have something like:

for int i; i < 10; i++

if a > 3

end if

end for

where I do not have the "if"-construct yet - it should be covered by Dummy, but it is not valid to have 'end' between 'for' and 'end' 'for'

so I extended Anything to:

Anything: {Anything}(ID|INT|STRING|';'|end=END);

but then I get a warning:

the decision cannot distinguish between alternative(s) 1,2 for at least one input sequence

full warning:

0 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Registering platform uri 'C:\Users\bar\workspace'
627 [main] INFO ipse.emf.mwe.utils.DirectoryCleaner - Cleaning C:\Users\bar\workspace\org.xtext.example.mydsl\..\org.xtext. example.mydsl\src-gen
639 [main] INFO ipse.emf.mwe.utils.DirectoryCleaner - Cleaning C:\Users\bar\workspace\org.xtext.example.mydsl\..\org.xtext. example.mydsl.ui\src-gen
791 [main] INFO ipse.xtext.generator.LanguageConfig - generating infrastructure for org.xtext.example.mydsl.MyDsl with fragments : ImplicitRuntimeFragment, ImplicitUiFragment, GrammarAccessFragment, EcoreGeneratorFragment, ParseTreeConstructorFragment, ResourceFactoryFragment, XtextAntlrGeneratorFragment, JavaValidatorFragment, ImportNamespacesScopingFragment, QualifiedNamesFragment, BuilderIntegrationFragment, FormatterFragment, LabelProviderFragment, TransformerFragment, OutlineNodeAdapterFactoryFragment, QuickOutlineFragment, QuickfixProviderFragment, JavaBasedContentAssistFragment, XtextAntlrUiGeneratorFragment
warning(202): ../org.xtext.example.mydsl/src-gen/org/xtext/example/mydsl/p arser/antlr/internal/InternalMyDsl.g:707:1: the decision cannot distinguish between alternative(s) 1,2 for at least one input sequence
7650 [main] INFO or.validation.JavaValidatorFragment - executing generate for org.eclipse.xtext.generator.validation.JavaValidatorFragment
warning(202): ../org.xtext.example.mydsl.ui/src-gen/org/xtext/example/myds l/ui/contentassist/antlr/internal/InternalMyDsl.g:1098:32: the decision cannot distinguish between alternative(s) 1,2 for at least one input sequence
8910 [main] INFO .emf.mwe2.runtime.workflow.Workflow - Done.

Re: how to define a Dummy Block in Grammar? [message #556714 is a reply to message #556707] Thu, 02 September 2010 12:29 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 16
Registered: September 2010
Junior Member
fyi:

the for loop was a simplified example:

this is my actual (still simple) code, which throws the warning,

the warning is not there, when I remove end=END from rule Anything

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
header=PackageHeader body=PackageBody;

PackageHeader:
literal=CreateOrReplacePackage packagename=ID is=IS content=PackageHeaderContent end=END

packegename=ID ';' ('/')?;

PackageHeaderContent:
dummy=Dummy;

PackageBody:
literal1=CreateOrReplacePackage literal2=Body packagename1=ID is=IS content=Dummy end=END

packagename2=ID ';' ('/')?;

CreateOrReplacePackage:
sentence='CREATE OR REPLACE PACKAGE';

Body:
sentence='BODY';


Dummy:
{Dummy}(dummy+=Anything)*;

IS:
is='IS';

END:
end='END';

Anything: {Anything}(ID|INT|STRING|';'|'('|')'|'*'|'/'|'-'|':'|'='|',' |is=IS|end=END);
Re: how to define a Dummy Block in Grammar? [message #556718 is a reply to message #556714] Thu, 02 September 2010 12:49 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
The ANTLR warning (actually, it's more of an error) is there because the alternatives in your Anything rule overlap. I.e., there are two alternatives which consume the same token. It's quite easy to spot which one: 'IS' and 'END' both are consumed by the ID terminal rule as well.

In fact, I'm completely mystified why the IS and END rules exist at all, as they simply correspond to (the presence of) keywords. So, you can "inline" them and get rid of the ANTLR warning in one go.


Re: how to define a Dummy Block in Grammar? [message #556743 is a reply to message #556718] Thu, 02 September 2010 13:57 Go to previous message
No real name is currently offline No real nameFriend
Messages: 16
Registered: September 2010
Junior Member
Hello Meinte,

thanks for the explanation: I understand what you are saying.

I removed is=IS and end=END from Anything rule, but then I get a problem with the following at the subsequent IS belonging to FUNCTION (which I don't want to declare, because I don't want to have to declare everything at once, but iteratively) - I don't want to care what's inside the package body.



CREATE OR REPLACE PACKAGE sysstat IS
...
END sysstat;
/

CREATE OR REPLACE PACKAGE BODY sysstat IS

...

FUNCTION hour(hourx IN NUMBER DEFAULT 1) RETURN VARCHAR2 IS
BEGIN
RETURN '0';
END hour;

END sysstat;
Previous Topic:Java extensions for Xpand, editor support
Next Topic:Validation-Error "An object may not circularly contain itself" validating an gmf-diagram
Goto Forum:
  


Current Time: Thu Apr 25 15:09:50 GMT 2024

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

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

Back to the top