[antlr-interest] Syntactic predicate not being generated

Olivier Dragon dragonoe at mcmaster.ca
Fri Jul 29 08:54:37 PDT 2005


Hi.

I have this problem where I put a syntactic predicate inside the lexer
and no code is being generated for it. I get no warnings or errors (it's
inside an alternative block with more than one). Here is the lexer rule:

// numeral literal
ICON {int counter=0;} :
	// plain integer
	counter=INTVAL
	
	(
	// code label
		{getColumn()<=6}? {_ttype=LABEL;}
		|
	// hollerith
		'h' ({counter>0}? . {counter--;})* {counter==0}?
		{_ttype=HOLLERITH;}
		|
	// real
		 // avoid tokenizing the . from an operator (eg. "1.eq.2")
		('.' (NUM | EXPON | ~('n'|'a'|'o'|'e'|'x'|'l'|'g'|'t'|'f')))=>
		'.' (NUM)* (EXPON)?   // 123. or 123.456
		{_ttype=RCON;}
		|
	// X format descriptor
		'x'
		{_ttype=XCON;}
		|
	// P format descriptor
		'p'
		{_ttype=PCON;}
	)?
	;

The problem is with the real (RCON) identification. I need to make sure
that the '.' really belongs to the real number and not to an operator.
And here is the code generated:

	switch(LA(1)) {
	...
		case '.':
		{
			match('.');
			{
			_loop437:
			do {
				if (((LA(1) >= '0' && LA(1) <= '9'))) {
					mNUM(false);
				}
				else {
					break _loop437;
				}
				
			} while (true);
			}
			{
			if ((LA(1)=='d'||LA(1)=='e')) {
				mEXPON(false);
			}
			else {
			}
			
			}
			if ( inputState.guessing==0 ) {
				_ttype=RCON;
			}
			break;
		}
	...

I've tried rebuilding the files from the grammar multiple times. I have
a syntactic predicate in another rule which works right so it is
possible to have them inside the lexer... Could it be because the part
after the integer (INTVAL) is optional (?)?

I really appreciate your help.

-Olivier

-- 
          __-/|    ? ?     |\-__
     __--/  /  \   (^^)   /  \  \--__
  _-/   /   /  /\ / ( )  /\  \   \   \-_
 /  /   /  /  /  (   ^^ ~  \  \  \   \  \
 / Oli Dragon    ( dragonoe at mcmaster.ca \
/  B.Eng. Sfwr   (     )    \    \  \    \
/  /  /    /__--_ (   ) __--__\    \  \  \
|  /  /  _/        \_ \_       \_  \  \  |
 \/  / _/            \_ \_       \_ \  \/
  \_/ /                -\_\        \ \_/
    \/                    )         \/
                        *~
        ___--<***************>--___
       [http://dragon.homelinux.org]
        ~~~--<***************>--~~~
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20050729/7c2f29ac/attachment.bin


More information about the antlr-interest mailing list