[antlr-interest] How to make this work ?? Again

v_vivekg <v_vivekg at yahoo.com> v_vivekg at yahoo.com
Fri Dec 20 21:50:20 PST 2002


Thanks Monty,

That really worked. And I still wonder how. In my parser rules I call 
B_STRING or H_STRING and not BIN_OR_HEX_STRING as defined in lexer 
and it still works. Ok this solves one problem. I have two more 
problems to resolve related to ASN.1 grammar posted on antlr site.. 
Kindly help me out with them. 


Problem1 :

I want to use syntatic predicates in the parser. Like for a rule
with embedded code as 

type returns [Object obj]		
{obj = null;}
	:	(obj = built_in_type)
	|	(obj = defined_type)		
	|	(obj = useful_type)		
	|	(obj = selection_type ) 		
	|	(obj = type_from_Object )		
	|	(obj = value_set_from_objects)	
	|       (obj = type_and_constraint )		
	|	(obj = type_with_constraint)	
	|	(obj = macros_type)
        ;

How can I check for the correct type using predicates. ??
In the parser only type will be called .


Problem 2 :
In lexer I had declared tokens as

tokens { 
TOK1_ID = "TOK1" ;
TOK1_ID = "TOK1" ;
}

and UpperCase and Lower Case identifiers as

----------
UPPER	
options {testLiterals = false;}
	:   ('A'..'Z') 
		(options {warnWhenFollowAmbig = false;}
	:	( 'a'..'z' | 'A'..'Z' |'-' | '0'..'9' ))* 	;

LOWER
options {testLiterals = false;}
	:	('a'..'z') 
		(options {warnWhenFollowAmbig = false;}
	:	( 'a'..'z' | 'A'..'Z' |'-' | '0'..'9' ))* 	;

---------

testLiteral Option is set to true in the lexer. 
The problem is that while parsing if antlr finds a Keyword
in place of an ID there is an error.
I would like that in the parser when I specify LOWER or UPPER I should
get whatsoever is there , even if it is a token defined in the lexer.
How can this be done. I tried reversing the testLiterals option as 
well but it does not work.

I am sure these are very trival problem, I searched for an example
in this group and on google as well, but am still not able to solve
them.

Thanks for help

Regards
Vivek









--- In antlr-interest at yahoogroups.com, mzukowski at y... wrote:
> Like this:
> 
> protected
> BDIG		: ('0'|'1') ;
> protected
> HDIG		:	(options {warnWhenFollowAmbig = false;} :
('0'..'9')
> )
> 			|	('A'..'F')
> 			|	('a'..'f')
> 			;
> 
> protected B_STRING : "'"   (BDIG)+  "'B"  ;
> protected H_STRING : "'"   (HDIG)+  "'H"  ;
> 
> BIN_OR_HEX_STRING: (B_STRING)=>B_STRING {$setType(B_STRING);}
> 			 | H_STRING {$setType(H_STRING);}
> 			 ;
> 
> Monty
> 
> -----Original Message-----
> From: v_vivekg <v_vivekg at y...> [mailto:v_vivekg at y...]
> Sent: Wednesday, December 18, 2002 12:50 AM
> To: antlr-interest at yahoogroups.com
> Subject: [antlr-interest] How to make this work ??
> 
> 
> Hi all,
> 
> I have binary and hex digits defined as follows :
> 
> protected
> BDIG		: ('0'|'1') ;
> protected
> HDIG		:	(options {warnWhenFollowAmbig = false;} :
('0'..'9')
> )
> 			|	('A'..'F')
> 			|	('a'..'f')
> 			;
> 
> and Binary String and Hex String defined as follows in the lexer
> 
> B_STRING : "'"   (BDIG)+  "'B"  ;
> H_STRING : "'"   (HDIG)+  "'H"  ;
> 
> Now the problem is that this definition is not able to
> parse the string of type '01010111'H . The code goes into
> binary string parsing and gives error that 'B was expected
> but 'H was found instead.
> I tried with semantic and syntatic predicates with lot of
> options but unable to make this work.
> 
> Kindly help on how this simple thing can be made to work.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>  
> 
> Your use of Yahoo! Groups is subject to 
http://docs.yahoo.com/info/terms/


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list