[antlr-interest] Error in 2.7.1 translator

Matthew Ford Matthew.Ford at forward.com.au
Fri May 30 14:45:57 PDT 2003


No I don't think I have
The first example is
>  | .  ;  // no action here and no errors
ie
| .
;  // end of rule

The second example is
>  | . {output.print("");}  // added this action to get errors
>  ;
ie
| .   {   ; }
;  // end of rule

thanks anyway
matthew
----- Original Message -----
From: "Anthony W Youngman" <Anthony.Youngman at ECA-International.com>
To: <antlr-interest at yahoogroups.com>
Sent: Friday, May 30, 2003 11:49 PM
Subject: RE: [antlr-interest] Error in 2.7.1 translator


> Have you got your curly braces muddled?
>
> The first example (simplified) is:
> . ;
>
> The second is:
> . { ; }
>
> It should probably be
> . { ; } ;
>
> Cheers,
> Wol
>
> -----Original Message-----
> From: Matthew Ford [mailto:Matthew.Ford at forward.com.au]
> Sent: 30 May 2003 13:33
> To: antlr-interest at yahoogroups.com
> Subject: [antlr-interest] Error in 2.7.1 translator
>
>
> Hi
> When I add one action I get the error message.  I think this is an error
> as
> the grammar has not changed.
>
>    [antlr] ANTLR Parser Generator   Version 2.7.1   1989-2000 jGuru.com
>     [antlr] C:\temp\antlrTest\links.g:107: warning: lexical
> nondeterminism
> upon
>     [antlr] C:\temp\antlrTest\links.g:107:
> k==1:'\t','\n','\u000c','\r',' '
>     [antlr] C:\temp\antlrTest\links.g:107:  k==2:<end-of-token>
>     [antlr] C:\temp\antlrTest\links.g:107:  between alts 1 and 2 of
> block
>
> The .g file is shown below
> The only difference needed to generate the above error is to change
>
> protected
> SCARF
>  : WS // track line numbers while you scarf
>  | .  ;  // no action here and no errors
>
> TO
>
> protected
> SCARF
>  : WS // track line numbers while you scarf
>  | . {output.print("");}  // added this action to get errors
>  ;
>
>
> regards
> Matthew
> P.S. I will try this on 2.7.2 tomorrow.
>
>
> //link.g file
> {
> import java.util.Vector;
> import java.io.PrintStream;
> }
>
>
> /** Parse an entire html file, firing events to a single listener
>  *  for each image and href link encountered.  All tokens are
>  *  defined to skip so the lexer will continue scarfing until EOF.
>  */
> class ImageLinkExtractor extends Lexer;
> options {
>  caseSensitive=false;
>  k=2;
>  filter=SCARF;
>  charVocabulary='\3'..'\u0FFE';
> }
>
> {
>  PrintStream output = null;
>
>   String tableWidth="65";
>
>  public void setOutput(PrintStream out) {
>    output = out;
>  }
>
>  /** strip quotes from "..." or '...' strings */
>  public static String stripQuotes(String src) {
>   int h = src.indexOf('"');
>   if ( h==-1 ) h = src.indexOf('\'');
>   int t = src.lastIndexOf('"');
>   if ( t==-1 ) t = src.lastIndexOf('\'');
>   if ( h==-1 || t==-1 ) return src;
>   return src.substring(h+1,t);
>  }
> }
>
>
> IMG : ("<img" {output.print("<img");}
>        WS (ATTR)+
>     '>' {output.print(">");})
>     {$setType(Token.SKIP);}
>  ;
>
> protected
> ATTR
> options {
>  ignore=WS;
> }
>  : w:WORD '='
>   ( s:STRING // output handled below
>   | v:WORD {output.print(v.getText());}
>   )
>   { output.print(" "+w.getText()+"=");
>     if (v!=null) {
>      output.print(v.getText());
>    } else if (s!=null) {
>     String heightOrWidth = stripQuotes(s.getText());
>     if (( w.getText().equalsIgnoreCase("height") )
>       || ( w.getText().equalsIgnoreCase("width") ) ) {
>       int size = Integer.parseInt(heightOrWidth);
>       size++;
>       output.print("\""+size+"\"");
>     } else {
>       // some other attribute like src just output
>      output.print(s.getText()+"");
>     }
>    } else {
>      // s==null have output v above
>    }
>   }
>   ;
>
> /** Match until next whitespace; can be file, int, etc... */
> protected
> WORD: (
>    options {
>     generateAmbigWarnings=false;
>    }
>   : 'a'..'z' | '0'..'9' | '/' | '.' | '#' | '_'
>   )+
>  ;
>
> protected
> STRING
>  : '"' (~'"')* '"'
>  | '\'' (~'\'')* '\''
>  ;
>
>
> protected
> WS : ( ' ' {output.print(" ");}
>   | '\t' {output.print("\t");}
>   | '\f'  {output.print("\f");}
>   | ( "\r\n"  {output.print("\r\n");} // DOS
>    | '\r'   {output.print("\r");} // Macintosh
>    | '\n'   {output.print("\r");} // Unix (the right way)
>    )
>    { newline(); }
>   )
>   { //$setType(Token.SKIP);
>   }
>  ;
>
> protected
> SCARF
>  : WS // track line numbers while you scarf
>  | . {output.print("");}
>  ;
> ----------------------------------------------------
> Dr. Matthew.Ford
> Forward Computing & Control Pty. Ltd.
> www.forward.com.au
>
>
>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>


 

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




More information about the antlr-interest mailing list