[antlr-interest] Warning(200) for k=1

Aurelian Melinte ame01 at gmx.net
Sat Jun 14 17:10:28 PDT 2008


Hello,

I am forced to use k=1 for a large C++ grammar - while the grammar has been designed for k=2, Antlr 3.0.1 will run out of memory for anything else but k=1. I

At k=1:  

1) I have a few "(200) alternative unreachable" that I am trying to fix. 
2) If I predicate the alternative, Antlr runs out of memory

I have isolated number 1) in a fragment pasted below, together with the warnings. But for the fragment, number 2) does not occur when I use the predicate, - it does not fixes the issue either. 

You can see the out of memory with the grammar here: http://www.freeshells.ch/~amelinte/CPP_parser.g

Any advice is appreciated.

Regards,
a.

---------------
ANTLR Parser Generator  Version 3.0.1 (August 13, 2007)  1989-2007
warning(200): ./test.g:12:25: Decision can match input such as "{EOF, SCOPE..ID, 'inline'}" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(201): ./test.g:12:25: The following alternatives are unreachable: 2
warning(200): ./test.g:18:3: Decision can match input such as "'inline'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ./test.g:23:3: Decision can match input such as "SCOPE" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ./test.g:32:3: Decision can match input such as "ID" using multiple alternatives: 1, 2, 3
As a result, alternative(s) 2,3 were disabled for that input
warning(201): ./test.g:32:3: The following alternatives are unreachable: 2


---------------


grammar test; 

options
	{
	language = 'C';
	k = 1; 
	}


translation_unit
	:	(external_declaration)*  EOF
	;

external_declaration
	:
		(('inline')? scope_override)=>
		('inline')? scope_override
	;

scope_override
	:
		(SCOPE)? 
		(	
			(ID LESSTHAN template_argument_list GREATERTHAN SCOPE)=>
			ID LESSTHAN template_argument_list GREATERTHAN SCOPE
			('template')?
		|	
			//(ID SCOPE)=> //still warnings
			ID SCOPE
			('template')?
		)*
	;

//template_argument_list
template_argument_list
	:	
		template_argument (COMMA template_argument)*
	;

//template_argument
template_argument
	:
		BITWISEXOREQUAL //just for the sake of example
	;



COMMA           : ',' ;
LESSTHAN        : '<' ;
GREATERTHAN     : '>' ;

LPAREN          : '(' ;
RPAREN          : ')' ;
LCURLY          : '{' ;
RCURLY          : '}' ;

BITWISEXOREQUAL : '^=' ;

SCOPE           : '::'  ;

Whitespace	
	:	
		(	// Ignore space
			Space
		|	// handle newlines
			(	'\r' '\n'	// MS
			|	'\r'		// Mac
			|	'\n'		// Unix 
			)	{newline(ACTX);}
		|	// handle continuation lines
			(	'\\' '\r' '\n'	// MS
			|	'\\' '\r'		// Mac
			|	'\\' '\n'		// Unix 
			)	{printf("CPP_parser.g continuation line detected on line \%d\n",g_SupportData.lineNo);
				deferredNewline(ACTX);}
		)	
		{$channel = HIDDEN;}
	;


Comment  
	:   '/*' (options {greedy=false;} : .)* '*/' {$channel=HIDDEN;}
	;

fragment  
Space
	:	
			(' '|'\t' {tab(ACTX);}|'\f')
	;

CharLiteral
	:	
		'\'' ( Escape | UniversalCharacterName | ~('\''|'\\'|'\n'|'\r') ) '\''
	;

WCharLiteral
	:
		'L' CharLiteral
	;

StringLiteral
	:	
		'"'
		(	Escape
		|	UniversalCharacterName
		|	~('"'|'\\'|'\n'|'\r')
		)*
		'"'
	;

WStringLiteral
	:
		'L' StringLiteral
	;

fragment  
EndOfContinuedLine
	:
		(//options{generateAmbigWarnings = false;}:
			'\\' '\r' '\n'	// MS
		|	'\\' '\r'		// Mac
		|	'\\' '\n'		// Unix 
		)	{deferredNewline(ACTX);}
	;

fragment  
EndOfLine
	:	
		(	//options{generateAmbigWarnings = false;}:
			'\r\n'  // MS
		|	'\r'    // Mac
		|	'\n'    // Unix
		)
	;

fragment  
Escape  
	:	
		'\\'
		( //options{warnWhenFollowAmbig=false;}:
		  'a'
		| 'b'
		| 'f'
		| 'n'
		| 'r'
		| 't'
		| 'v'
		| '"'
		| '\''
		| '\\'
		| '?'
		| ('0'..'3') (/*options{warnWhenFollowAmbig=false;}:*/ Digit (/*options{warnWhenFollowAmbig=false;}:*/ Digit)? )?
		| ('4'..'7') (/*options{warnWhenFollowAmbig=false;}:*/ Digit)?
		| 'x' (/*options{warnWhenFollowAmbig=false;}:*/ HexadecimalDigit)+ //Digit | 'a'..'f' | 'A'..'F')+
		)
	;

// Numeric Constants: 


fragment  
Digit
	:	
		'0'..'9'
	;

fragment  
Decimal
	:	
		('0'..'9')+
	;

fragment  
LongSuffix
	:	'l'
	|	'L'
	;

fragment  
UnsignedSuffix
	:	'u'
	|	'U'
	;

//fragment  
//FloatSuffix
//	:	'f'
//	|	'F'
//	;

fragment  
Exponent
	:	
		('e'|'E') ('+'|'-')? (Digit)+
	;

fragment  
UniversalCharacterName
	:
		'\\u' HexQuad
	|	'\\U' HexQuad HexQuad
	;

fragment  
HexQuad
	:
		HexadecimalDigit HexadecimalDigit HexadecimalDigit HexadecimalDigit 
	;

fragment  
HexadecimalDigit
	:
		('0'..'9'|'a'..'f'|'A'..'F')
	;

fragment  
Vocabulary
	:	
		'\u0003'..'\u0377'
	;

ELLIPSIS
	:
		('...')=> '...'
	;

DECIMALINT
	:
		'1'..'9' (Digit)* (IntegerSuffix)?
	;

OCTALINT
	:
		'0' ('0'..'7')* (IntegerSuffix)?
	;

HEXADECIMALINT
	:
		'0' ('x' | 'X') (HexadecimalDigit)+ (IntegerSuffix)?
	;

FLOATONE
	:
		( (Digit)+ ('.' | 'e' | 'E') )=> 
		(Digit)+
		( '.' (Digit)* (Exponent)?
		| Exponent	// should be FLOATTWO?
		)
	;

FLOATTWO
	:
		'.' (Digit)+ (Exponent)? (FloatSuffix)?
	;

IntegerSuffix
	:
		LongSuffix (UnsignedSuffix)
		UnsignedSuffix (LongSuffix)
	;

FloatSuffix
	:
		('f' | 'F' | 'l' | 'L' )
	;

ID
	//options {testLiterals = true;}
	:	
		(('asm'|'_asm'|'__asm') Whitespace )=>

		('asm'|'_asm'|'__asm') 
			(EndOfLine {deferredNewline(ACTX);}
			|Space
			)+
		(
			LPAREN
				(	EndOfLine {deferredNewline(ACTX);}	
				|	~(')' | '\r' | '\n')
				)*	
			RPAREN {$channel = HIDDEN;}
		|
			LCURLY
				(	EndOfLine {deferredNewline(ACTX);}	
				|	~('}' | '\r' | '\n')
				)*	
			RCURLY {$channel = HIDDEN;}
		|
			// Single line asm statement
			(~('(' | ')' | '{' | '}' | '\n' | '\r' | ' ' | '\t' | '\f'))
			(~('(' | ')' | '{' | '}' | '\n' | '\r'))* (EndOfLine {newline(ACTX);})?
			{$channel = HIDDEN;}
		)
	|	
		('a'..'z'|'A'..'Z'|'_')
		('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
	;






More information about the antlr-interest mailing list