[antlr-interest] UnwantedTokenException(found=null)

Andrey Pohilko apc at fininfor.ru
Thu Dec 17 01:03:14 PST 2009


Hello!

I'm studying capabilities of ANTLR, building very simple grammar. In my
tests, ANTLRWorks says in debug about UnwantedTokenException(found=null) at
rule:
	interface_decl
		: 	INTERFACE ID '{' interface_parts '}'
		;


It recognizes INTERFACE token and ID, consumes whitespace before curly
bracket, but fails to recongnize bracket. I'm completely confused with this.
Grammar and debug input follows.

Can anyone tell me what is mistake?

Andrey

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

grammar BppIDL;

tokens {
	INTERFACE='interface';
}

specification:
	interface_decl
;

header_decl	:
		'[' 'uuid' '(' UUID ')' ','
  		'version' '(' '1.0' ')' ','
  		'pointer_default' '(' 'unique' ')'
		']'
	;

interface_decl
	: 	INTERFACE ID '{' interface_parts '}'
	;

interface_parts
	: 	interface_part*
	;

interface_part
	: 	typedef_decl
	|	include_decl
	|	operation_decl
	;

include_decl	:
	'#' 'include' STRING_LITERAL '\n'
	;

typedef_decl	:
	'typedef' type_decl call_modifier? ID ';'
	;

type_decl	:
	ID '*'*
	;

call_modifier
	: '_stdcall'
	;

operation_decl
	:
		type_decl ID operation_parameters ';'
	;

operation_parameters
	:	'(' operation_parameter ( ',' operation_parameter )* ')'
	|	'(' ')'
	;

operation_parameter
	: type_decl ID
	;

ID  :	('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
    ;

INT :	'0'..'9'+
    ;

WS
	:	(' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;}
	;

COMMENT
	:	'/*' ( options {greedy=false;} : . )* '*/'
{$channel=HIDDEN;}
	;
	
LINE_COMMENT
	:	'//' ~('\n'|'\r')* '\r'? ('\n'|EOF) {$channel=HIDDEN;}
	;

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

UUID 	
	:	HEX_DIGIT+ '-' HEX_DIGIT+  '-' HEX_DIGIT+ '-' HEX_DIGIT+ '-'
HEX_DIGIT+ ;

STRING_LITERAL
	:	'"' ( ~('"') )* '"'
	;

--------------------------
Test file is:
interface Server32rpc
	{
		typedef error_status_t _stdcall  RPCALL;
		typedef const char * BPP_USERID;
		typedef unsigned int * BPP_RCODE;

		#include "..\Bank32flds.h"
		#include "..\Bank32stru.h"
	

    RPCALL IsServerListening ();
}



More information about the antlr-interest mailing list