[antlr-interest] (unknown)

Terence Parr parrt at cs.usfca.edu
Sat May 1 11:41:47 PDT 2004


Hi.  Check out charVocabulary.
Terence
On Apr 30, 2004, at 10:50 PM, javadesigner wrote:

> I am trying to extend the introduction to antlr example
> by lexing 'hello world' (note the space)
>
> -------- from the antlr docs-----------
> class P extends Parser;
> startRule
>     :   n:NAME
>         {System.out.println("Hi there, "+n.getText());}
>     ;
>
> class L extends Lexer;
> // one-or-more letters followed by a newline
> NAME:   ('a'..'z' | 'A'..'Z' | ' ')+ NEWLINE
>     ;
> NEWLINE
>     :   '\r' '\n'   // DOS
>     |   '\n'        // UNIX
>     ;
> -----------------------------------------
>
> The only change I made was added the ' ' after 'A' ..'Z'
> After compiling the above and running the test
> program (the test program is also from the antlr docs and
> is shown at the end for completeness), I get:
>
> ---------------------------------------------
> root at turing:~/parsing/test# java test
> foo
> Hi there, foo
>
> NOTE THE ERROR BELOW>>>>>
>
> root at turing:~/parsing/test# java test
> foo bar
> exception: line 1:4: unexpected char: ' '
> -------------------------------------------
>
> Can anyone explain what is going on and why
> I get an unexpected char message ? I even tried:
>
> NAME:   ('a'..'z' | 'A'..'Z' | '9')+ NEWLINE
>
> and after recompiling:
> root at turing:~/parsing/test# java test
> foo9bar
> exception: line 1:4: unexpected char: '9'
>
> Help ! This shouldn't be that hard should it ?
>
> Best regards,
>
> --j
>
> ------------ test program -------------------
> import java.io.*;
> class test {
>     public static void main(String[] args) {
>         try {
>             L lexer = new L(new DataInputStream(System.in));
>             P parser = new P(lexer);
>             parser.startRule();
>         } catch(Exception e) {
>             System.err.println("exception: "+e);
>         }
>     }
> }
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
--
Professor Comp. Sci., 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!
Cofounder, http://www.peerscope.com pure link sharing





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

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



More information about the antlr-interest mailing list