[antlr-interest] Re: RE : Problem with new lines

Sharon Li hushlee83 at yahoo.com.sg
Wed Feb 5 16:12:00 PST 2003


Thanks i will go have a look at that..
replacing "angle factor" with "initial color" still doesn't work. My parser looks something like that:
/************** parser ********************************/
keyword returns [String keyword] {keyword = null;} 
    : "angle" "factor"(COLON) (num : NUMERIC)
     { 
      keyword = "angle factor"; 
      System.out.println("^^angle factor : "+num.getText());
      try{
       double angle = Double.parseDouble(num.getText());
       file.ANGLE_FACTOR = angle;
      }catch(Exception e){
       System.out.println("Invalid value of angle factor entered!");
      }      
     }     
    | "initial" "color" (COLON) (n: NUMERIC) (initialColor:NUMERIC)* {....};
/************* lexer ******************************/
.................
NEWLINE : ('\r''\n')=> '\r''\n' {System.out.println("slash r slash n");}
        | '\r'                  {System.out.println("slash r");}
        | '\n'                  {System.out.println("slash n");}
        { newline(); }
    ;
WS      : (' '|'\t') 
    { $setType(Token.SKIP); } 
    ;
.................................
the input file:
angle factor: 10
initial color: 1 5
color increment: 1 10
initial line width: 5 pixels
line width increment: 0
viewpoint: 0.0,0.0,1.0
view reference point: 0.0,0.0,0.0
twist: 0

/*************************************************************/

And the output I get:

^^angle factor : 10
slash r slash n
slash r slash n
^^initial color : 1 5
slash r slash n
^^color increment : 1 10
slash r slash n
^^initial line width : 5 pixels
^^line width increment : 0
slash r slash n
^^viewpoint : 0.0, 0.0, 1.0
slash r slash n
^^view reference point : 0.0, 0.0, 0.0
slash r slash n
^^twist : 0
slash r slash n
^^projection : parallel

......................
when i insert a newline after angle factor :
^^angle factor : 10
slash r slash n
slash r slash n
Exception occured!
 "micheal_jor <open.zone at virgin.net>" <open.zone at virgin.net> wrote:
> hmm..seems like it still doesn't work, but thanks anyway.
> angle factor: 10 //--> exception after first line
> initial color: 1 5
> color increment: 1 10
> initial line width: 5 pixels
> // another comment
> line width increment: 0
> ..............
> An exception occurs straight after the first line.

Is it dependent on the contents of the line?. If you replace 
the "angle factor: 10" line with "initial color: 10" would it work?

> I can't figure where the problem lies. The previous codes works 
well with this but it doesn't work once I insert a newline 
after "angle factor:10":

Look in the example 'java' grammar for a good NEWLINE definition. It 
might be a protected rule but you can change that since you will be 
Token.SKIP-ping it in any case.

Micheal





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


 Yahoo! Travel
- Valentine surprise deals. Book now!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20030206/ae3b5773/attachment.html


More information about the antlr-interest mailing list