[antlr-interest] Error in 2.7.1 translator

Anthony W Youngman Anthony.Youngman at ECA-International.com
Fri May 30 06:49:20 PDT 2003


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/ 

-------------- next part --------------
This transmission is intended for the named recipient only. It may contain private and confidential information. If this has come to you in error you must not act on anything disclosed in it, nor must you copy it, modify it, disseminate it in any way, or show it to anyone. Please e-mail the sender to inform us of the transmission error or telephone ECA International immediately and delete the e-mail from your information system.

Telephone numbers for ECA International offices are: Sydney +61 (0)2 9911 7799, Hong Kong + 852 2121 2388, London +44 (0)20 7351 5000 and New York +1 212 582 2333.


More information about the antlr-interest mailing list