[antlr-interest] Matching the * character

Loring Craymer lgcraymer at yahoo.com
Thu Mar 27 16:59:05 PDT 2008


This looks ok, except for the (STAR | QUESTION*)? idiom (equivalent to (STAR | QUESTION+ | | ).  Try either changing QUESTION* to QUESTION+ or remove the terminal ?.  I would have thought that ANTLR would issue a warning about the two empty alts; maybe it did and you missed it.

--Loring

----- Original Message ----
From: Steve O'Hara <sohara at pivotal-solutions.co.uk>
To: antlr-interest at antlr.org
Sent: Thursday, March 27, 2008 4:27:33 PM
Subject: [antlr-interest] Matching the * character

  
<!--
 _filtered {font-family:Wingdings;panose-1:5 0 0 0 0 0 0 0 0 0;}
 _filtered {font-family:"Cambria Math";panose-1:2 4 5 3 5 4 6 3 2 4;}
 _filtered {font-family:Calibri;panose-1:2 15 5 2 2 2 4 3 2 4;}
 _filtered {font-family:Tahoma;panose-1:2 11 6 4 3 5 4 4 2 4;}
 _filtered {font-family:Verdana;panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;margin-bottom:.0001pt;font-size:11.0pt;font-family:"Calibri", "sans-serif";}
a:link, span.MsoHyperlink
	{color:blue;text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;text-decoration:underline;}
pre
	{margin:0cm;margin-bottom:.0001pt;font-size:10.0pt;font-family:"Courier New";}
span.EmailStyle17
	{font-family:"Calibri", "sans-serif";color:windowtext;}
span.HTMLPreformattedChar
	{font-family:"Courier New";}
.MsoChpDefault
	{}
 _filtered {margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.Section1
	{}
-->
I'mnew to Antlr so forgive me if this is a stupid question...
I'm trying to match a database search criteria that looks like the following;
   
 'some
text'*, *'more criteria' & 'more criteria'*
 
My grammar is;
   
 expression
    
: subExpression (WS? (COMMA | AMPERSAND) WS? subExpression)*
    
;
   
 subExpression
    
: WS? (Identifier | subExpressionText) WS?
    
;
   
 subExpressionText
    
:  (STAR | QUESTION*)? QuotedString  (STAR | QUESTION*)? WS?
    
;
   
 Letter
: 'a'..'z' | 'A'..'Z' | '_' | '\u0080'..'\ufffe' ;
 Digit
: '0'..'9' ;
 Identifier
: Letter (Letter | Digit)* ;
 QuotedString
:'\'' (~'\'')* '\'' ;
 WS
: (' ' | '\t' | '\n' | '\r')+ ;
   
 COMMA
: ',' ;
 AMPERSAND
: '&' ;
 QUESTION
: '?' ;
 STAR
: '*' ;
 
The parser finds the first quoted string (some text) but fails after that witha NoViableAltException. If I change the * to ? it works fine. I'm waiting fordelivery of the reference manual so maybe I'm breaking some sort of golden rulehere, but any help would be greatly appreciated.

Steve
   
 SteveO'Hara
Pivotal Solutions 

 ( +44 (0)7802 484227
    +44 (0)208 660 7288 (Fax)
*  sohara at pivotal-solutions.co.uk
 



 
 






      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080327/c572f028/attachment.html 


More information about the antlr-interest mailing list