[antlr-interest] ANTLR

karl wettin kalle at snigel.net
Mon Apr 3 07:25:58 PDT 2006


3 apr 2006 kl. 14.43 skrev Yassin.Chkouri at imag.fr:


> Can you could help me in this point???
>

I'm still at RTFM-level my self, so I might just make it worse. But  
here we go:


> parser exception: line 2:10: expecting ':', found ' '
>  line 2:10: expecting ':', found ' '
>

"component worker" seems to be row two.

COLON does not seem to be used at all? What happens if you make it  
protected?

Can you try to make a small test grammar that parses nothing but  
COMPONENT IDENTIFIER and see if that isolate the problem?


> here the mmessage of error posted in the console:
>
> parser exception: line 2:10: expecting ':', found ' '
>  line 2:10: expecting ':', found ' '
>          at BipLexer.nextToken(BipLexer.java:286)
>          at antlr.TokenBuffer.fill(TokenBuffer.java:69)
>          at antlr.TokenBuffer.LA(TokenBuffer.java:80)
>          at antlr.LLkParser.LA(LLkParser.java:52)
>          at BipParser.top(BipParser.java:51)
>          at Main.parseFile(Main.java:68)
>          at Main.doFile(Main.java:53)
>          at Main.main(Main.java:20)
> **********************************************************************
> The Grammar:
>
> class BipParser extends Parser;
>
> options {
>    k=4; // needed for newline junk
> //   buildAST=false;
> //   defaultErrorHandler=false;
>  }
>
>
> top :  (compDef)+
>
> ;
>
>
> compDef
>   : COMPONENT IDENTIFIER opt_arg CODE END
> ;
>
> opt_arg   : ( LPAREN (arg_decl_list) RPAREN )?
> 		
> ;
>
> arg_decl_list : arg_decl (COMMA arg_decl)*
> 			
> ;
>
> arg_decl : type_id IDENTIFIER
> ;
>
> type_id : IDENTIFIER
> 		| CPPIDENTIFIER
> ;
>
> c_code : CODE
> ;
> ////////////////////////////////////////////////////////////////////// 
> //
> ////////////////////////////////////////////////////////////////////// 
> /
>
>
> class BipLexer extends Lexer;
>
> options {
>    k=3; // needed for newline junk
>    charVocabulary='\u0000'..'\uFFFF'; // allow UNICODE
> //    caseSensitive = false;
> //    caseSensitiveLiterals = false;
> //	defaultErrorHandler=true;
>  }
>
>
> tokens {
> 	
> 	COMPONENT="component";
> 	END="end";
> 	BEHAVIOR="behavior";
> 	STATE="state";
> 	WITH="with";
> 	ON="on";
> 	PROVIDED="provided";
> 	WHEN="when";
> 	DO="do";
> 	TO="to";
> 	PORT="port";
> 	DATA="data";
> 	CONNECTOR="connector";
> 	EAGER="eager";
> 	DELAYABLE="delayable";
> 	LAZY="lazy";
> 	CONTAINS="contains";
> 	CLASS="class";
> 	PRIORITY="priority";
> 	IF="if";
> 	ELSE="else";
> 	INIT="init";
> 	RENAME="rename";
> 	COMPLETE="complete";
> 	INCOMPLETE="incomplete";
> 	
> 	
> }
>
>
> LPAREN: '(' ;
> RPAREN: ')' ;
> CO  : "{#";
> CC  : "#}";
> LCURLY: '{' ;
> RCURLY: '}' ;
> COLON:  ':' ;
> PLUS  : '+' ;
> MINUS : '-' ;
> STAR  : '*' ;
> SEMI  : ';' ;
> COMMA : ',' ;
> DOT	  : '.' ;
> EQUALS: '=' ;
> LT: '<' ;
> GT: '>' ;
> DIV: '/' ;
> POURCENT: '%' ;
> CHAPEAU : '^' ;
> INTERO  : '!' ;
> LBRACKET : '[' ;
> RBRACKET : ']' ;
> XX : '#' ;
>
> EQ : "==" ;
> NE : "!=";
> GE : ">=";
> LE : "<=";
> AND : "&&";
> OR : "||";
> DPT : "::";
>
> IDENTIFIER :	('a'..'z'|'A'..'Z') ( ('_')?  
> ('a'..'z'|'A'..'Z'|'0'..'9'))*
> 			exception
>           catch [RecognitionException ex] {
>             reportError(ex);
> 			consume();
>           }
> 	;
>
>
> CODE
> 	:		
> 	"{#" (	
> 			options {
> 				generateAmbigWarnings=false;
> 			}
> 		:
> 			{ LA(2)!='#' || LA(3) != '}' }? '#'
> 		|	'\r' '\n'		{newline();}
> 		|	'\r'			{newline();}
> 		|	'\n'			{newline();}
> 		|	~('#'|'\n'|'\r')
> 		)*
> 	"#}"
>
> ;
>
>
>
> CPPIDENTIFIER
>   :  IDENTIFIER DPT IDENTIFIER
> ;
>
> LETTER  : ('a'..'z')|('A'..'Z') ;
>
> DIGIT   :  ( '0'..'9' ) ;
>
> ALPHA
>   : LETTER IDENTIFIER
> ;
>
> INTEGER
>   :  (DIGIT)+
> ;
>
> REAL
>   : INTEGER DOT INTEGER
> ;
>
>
>
> WS
>   : ( ' '
>     | '\t'
>     | '\f'
>
>     // handle newlines
>     | ( "\r\n"  // DOS/Windows
>       | '\r'    // Macintosh
>       | '\n'    // Unix
>       )
>       // increment the line count in the scanner
>       { newline(); }
>     )
>     { $setType(Token.SKIP); }
>   ;
>
>
>
>
> SL_COMMENT
> 	:	"//"
> 		(~('\n'|'\r'))* ('\n'|'\r'('\n')?)
> 		{$setType(Token.SKIP); newline();}
> ;
>
>   
> ********************************************************************** 
> ***
> The text are parsing :
>
> component worker
> 	
> {# printf("xxxxx"); #}
>
> end
>
>
> component Team
> 	
> end
> ********************************************************************** 
> *****
>
> Cordially
> M.Y.CHKOURI
>
>
> -------------------------------------------------
> envoyé via Webmail/IMAG !
>
>
>




More information about the antlr-interest mailing list