[antlr-interest] Space in values (need more info)

DELZANT Bruno (BMB) Bruno.Delzant at proximus.net
Wed Nov 24 00:28:18 PST 2004


Thanks for the help, but ... I don't see what you mean :-/ I have read
the part on string in the user guide, but I don't see what's the help of
this.
I'll try perhaps with a simpler example of what I want to achieve:
Need to parse the following input:

PRIORITY = "3"
REQ_USER_ID = "PTS JDA"
REQ_PROC_ID = "process"

As you can see, there is a space in second quoted string.
With the following grammar, I am getting stuck on that space.
How can I improve the grammar to detect space in this quoted string and
get back the value ?


  _____  

header {package test;}
class MyParser extends Parser;

 
entries: (entry)+ ;
  
entry:  a:ALPHA_NUM_STRING EQUAL QUOTE b:ALPHA_NUM_STRING QUOTE
     { System.out.println(a.getText() + " - " + b.getText()); };
 
class MyLexer extends Lexer;
 
ALPHA_NUM_STRING
  :  ( 'a'..'z' | 'A'..'Z' | '0'..'9' | '_' | '.' )+ ;
 
QUOTE: '\"' ;
 
EQUAL: '=';  
  
WS:   ( ' ' | '\t'
    | '\r' '\n' { newline(); }
        |   '\n'      { newline(); }
        ) {$setType(Token.SKIP);} ;
  _____  


Output of the program I ran with this grammar and input:
PRIORITY - 3
line 2:20: expecting QUOTE, found 'JDA'
REQ_PROC_ID - process



>-----Original Message-----
>From: Terence Parr [mailto:parrt at cs.usfca.edu]
>Sent: Tuesday, November 23, 2004 6:53 PM
>To: antlr-interest at yahoogroups.com
>Subject: Re: [antlr-interest] Space in values
>
>
>
>Hi.  The answer is to put STRING as a token in the lexer :)  See the
>java grammar or a perhaps a simpler grammar.
>
>Ter
>On Nov 23, 2004, at 8:40 AM, DELZANT Bruno (BMB) wrote:
>> With this grammar file, I get an error on spaces in bolded value. the
>> parser is expecting a double quote and not a space.
>> But I do not see how to solve this (I am new with antlr).
>--
>CS Professor & Grad Director, University of San Francisco
>Creator, ANTLR Parser Generator, http://www.antlr.org
>Cofounder, http://www.jguru.com Cofounder,
>http://www.knowspam.net enjoy email again!
>
>
>
>
>
>
>Yahoo! Groups Links
>
>
>
>
>
>
>
> 



**** DISCLAIMER ****

"This e-mail and any attachment thereto may contain information which is confidential and/or protected by intellectual property rights and are intended for the sole use of the recipient(s) named above. This email is not intended to create or affect any contractual arrangements between the parties.
Any use of the information contained herein (including, but not limited to, total or partial reproduction, communication or distribution in any form) by other persons than the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by telephone or by e-mail and delete the material from any computer".

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at http://www.proximus.be or refer to any Proximus agent.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20041124/d6c95c4b/attachment.html


More information about the antlr-interest mailing list