[antlr-interest] parse "search criterion"

Stefan Chrobot jan_ek at op.pl
Fri May 11 09:49:44 PDT 2007


Otto, Frank napisał(a):
> Hi,
> 
> I want to parse a search criterion (with +, -, "", AND, OR) like "google" with antlr. For example:
> 
> Hello World
> "Hello World"
> Hello +World
> Hello OR WORLD
> Hello -World
> 
> But I have no idea, how I start. Has someone do this? Is there a simple tutorial for parsing search words? I haven't found one.

Well, you need to start with the grammar. Maybe something like this:

grammar Query;

WS	:	(' ' | '\t')+ { $channel = HIDDEN; };
OPERATOR:	'+' | '-' | 'AND' | 'OR';
SIMPLE_QUERY
	:	('a'..'z' | 'A'..'Z' | '0'..'9')+
	|	'"' (~'"')+ '"';
query	:	
	|	SIMPLE_QUERY ((OPERATOR)? SIMPLE_QUERY)*;


Stefan


More information about the antlr-interest mailing list