Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Define sub ranges in Pascal style cause problems
Define sub ranges in Pascal style cause problems [message #635839] Thu, 28 October 2010 10:45 Go to next message
Bodo is currently offline BodoFriend
Messages: 27
Registered: August 2010
Junior Member
The grammar rule for sub ranges in Pascal is like: Value ".." Value.

If values are integer and real numbers, one can write sentences like 6..9 or 8.2..9.7


But specifying the grammar this will cause the problem, that 6..9 is recognized as 6. .9, not as 6 .. 9.

The grammar I used is:

Expression:
    "[" from=Value UpTo ro=Value"]"
    ;
    
Value:
      integer=Integer
    | fixedPoint=FixedPoint
    ;

terminal UpTo:
    '.' '.'
    ;

terminal Integer : 
    '0'..'9' ('_' | '0'..'9')*
    ;

terminal FixedPoint : 
    '0'..'9' ('_' | '0'..'9')* '.' '0'..'9' ('_' | '0'..'9')*
    ;

Because, the order of terminal definitions may be important, I tried all 9 permutations - but in vain.

Does any body can give me a hint how to solve this problem?
Re: Define sub ranges in Pascal style cause problems [message #635853 is a reply to message #635839] Thu, 28 October 2010 11:29 Go to previous messageGo to next message
Pierre-Alain BOURDIL is currently offline Pierre-Alain BOURDILFriend
Messages: 25
Registered: September 2010
Junior Member
Hi,

why did you define
 terminal UpTo:
    '.' '.';


given the example of your message, i'll write something like :

 terminal UpTo : 
    '..'

because the token of range definition is '..' .

you can try to define fixed point as :

INT '.' INT // or (INT) ? '.' INT


[Updated on: Thu, 28 October 2010 12:26]

Report message to a moderator

Re: Define sub ranges in Pascal style cause problems [message #635862 is a reply to message #635839] Thu, 28 October 2010 11:59 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

don't define terminal rules that are not really necessary. In most cases datatype rules are better. By convention (readability) terminals rules are completely capitalised wheres parser rules have only a initial capital letter.

Expression:
"[" from=Value ".." to=Value"]"
;

Value:
integer=INTEGER
| fixedPoint=FixedPoint
;

FixedPoint :
INTEGER '.' INTEGER
;

terminal INTEGER:
'0'..'9' ('_' | '0'..'9')*
;

It may well be that the rest of your grammar causes your and this snippet not to work properly.

Alex
Re: Define sub ranges in Pascal style cause problems [message #635991 is a reply to message #635862] Thu, 28 October 2010 20:29 Go to previous messageGo to next message
Bodo is currently offline BodoFriend
Messages: 27
Registered: August 2010
Junior Member
Thank you all for your reply.

I think '..', '.' '.', and ".." are the same definition of one token. Of cause one do not introduce a named token for things, one can easily define in line. My grammar has more than 100 rules and I wanted to make my problem as obvious as possible.

Describing fixed point numbers by three tokens don't help because no one would like to write pi like
3
.
14


For describing the problem this 3 tokens are needed. The automaton should recognize, that
('0'..'9')+ '.' ('0'..'9')+
and
 '..' 
are two tokens and when the character sequence '1' '.' '.' came along, than after reading the 1st '.' it shall recognize, that a 2nd '.' is not a digit and remember, that stopping after the '1' gave a legal state (just put one character back and return INT). That behavior could programmatically specified with a precedence rule, but I don't know how one can do this for antlr and the lexer.

Trying all 6 permutations for ordering the 3 tokens didn't help.

Does any body know how to get rid of this problem (or at least where I can find the generated code for the lexer)?

Thanks...
Re: Define sub ranges in Pascal style cause problems [message #636001 is a reply to message #635991] Thu, 28 October 2010 21:24 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Bodo,

it does not make a difference in your in memory model whether you use
terminal rules or data type rules to define fixed points. However, the
lexer / parser stuff is working much better with less terminal rules.
Use the hidden() clause on your rule to suppress whitespace between the
integers and the comma.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 28.10.10 22:29, schrieb Bodo:
> Thank you all for your reply.
>
> I think '..', '.' '.', and ".." are the same definition of one token. Of
> cause one do not introduce a named token for things, one can easily
> define in line. My grammar has more than 100 rules and I wanted to make
> my problem as obvious as possible.
>
> Describing fixed point numbers by three tokens don't help because no one
> would like to write pi like
> 3
Re: Define sub ranges in Pascal style cause problems [message #636062 is a reply to message #636001] Fri, 29 October 2010 08:41 Go to previous messageGo to next message
Bodo is currently offline BodoFriend
Messages: 27
Registered: August 2010
Junior Member
Hi Sebastian,

the hidden() clause was the precedence rule I looked for! Thank you very much.

By the Way. In my grammar there shall be a part, where one can specify in a assembler like manner. So line formats matter, especial the end of line. Can I define a terminal like:

terminal EOL:
    (' ' | '\t')* ('\r'? '\n')
    ;


Thanks ...
Re: Define sub ranges in Pascal style cause problems [message #636071 is a reply to message #636062] Fri, 29 October 2010 08:48 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Bodo,

yes that's possible. You'll have to be careful to not collide with the
default WS rule.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 29.10.10 10:41, schrieb Bodo:
> Hi Sebastian,
>
> the hidden() clause was the precedence rule I looked for! Thank you very
> much.
> By the Way. In my grammar there shall be a part, where one can specify
> in a assembler like manner. So line formats matter, especial the end of
> line. Can I define a terminal like:
>
> terminal EOL:
> (' ' | '\t')* ('\r'? '\n')
> ;
>
> Thanks ...
Previous Topic:problems with EcoreDsl example
Next Topic:Parser not locating the end of a rule
Goto Forum:
  


Current Time: Thu Apr 18 04:50:20 GMT 2024

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

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

Back to the top