English 中文(简体)
Antlr 遗失
原标题:Antlr Missing token error

我正利用ant子来制作我的教官,但我想推翻一些错误的报告。 此时,如果我给出一些不正确的辛迪克斯,例如,一名失踪的表象,那么ant子就错了“线1:11 失踪的人”。

然而,我无法找到这一错误产生的方法。 我原先认为,这并不是报告方法。 是否有任何人知道信息产生在哪里?

感谢!

最佳回答

www.un.org/spanish/ga/president 请允许我说,你希望用以下图表来划分任务:

grammar T;

parse      : assignment EOF;
assignment : Id  =  Number  ; ;
Number     :  0 .. 9 + ( .   0 .. 9 +)?;
Id         : ( a .. z  |  A .. Z )+;
Space      :     {skip();};

现在简单地凌驾于<代码>reportError(......)方法之上,例如:

grammar T;

@parser::members {
  @Override
  public void reportError(RecognitionException e) {
    System.out.println("CUSTOM ERROR...
" + e);
  }
}

parse      : assignment EOF;
assignment : Id  =  Number  ; ;
Number     :  0 .. 9 + ( .   0 .. 9 +)?;
Id         : ( a .. z  |  A .. Z )+;
Space      :     {skip();};

接着试图 par,例如=123;>(缺失<代码>Id):

java -cp antlr-3.3.jar org.antlr.Tool T.g
javac -cp antlr-3.3.jar *.java
java -cp .:antlr-3.3.jar Main "= 123;"

CUSTOM ERROR...
MissingTokenException(inserted [@-1,0:0= <missing Id> ,<4>,1:0] at =)

As you can see, the custom error message is being printed to the console.

EDIT

象“别无选择......”这样的警告,在法尔,而不是教区,是一个问题。 当弹性体会到你没有在克法中说明的特性时(或至少是作为适当标语)。

请指出输入<代码>a = 123: (注: at the end und a ;。 由于我没有为“<代码>下的任何标注作出定义,因此现在法尔将产生“无法替代......”的警告。

对这种错误作出说明的一个容易的解决办法是,在你的法尔法末尾添加“全副渔获”规则,使之与任何与其相匹配的法理规则相一致。 无论这种“副渔获物-all”规则是否一致,你在<条码>后...}中仅举一个例外(或做其他事情,当然!) 。

页: 1

grammar T;

@parser::members {
  @Override
  public void reportError(RecognitionException e) {
    System.out.println("CUSTOM ERROR...
" + e);
  }
}

parse      : assignment EOF;
assignment : Id  =  Number  ; ;
Number     :  0 .. 9 + ( .   0 .. 9 +)?;
Id         : ( a .. z  |  A .. Z )+;
Space      :     {skip();};

FallThrough
@after{
  throw new RuntimeException(String.format(
      "Encountered an illegal char on line \%d, column \%d:  \%s ", 
      getLine(), getCharPositionInLine(), getText()
    )
  );
}
  :  . // match any char not matched by Number, Id or Space
  ;

如果您现在宣布<代码>a = 123:,你将看到以下内容:

Exception in thread "main" java.lang.RuntimeException: 
    Encountered an illegal char on line 1, column 8:  : 
    ...
问题回答

暂无回答




相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

How to get instance from string in C#?

Is it possible to get the property of a class from string and then set a value? Example: string s = "label1.text"; string value = "new value"; label1.text = value; <--and some code that makes ...

XML DOM parsing br tag

I need to parse a xml string to obtain the xml DOM, the problem I m facing is with the self closing html tag like <br /> giving me the error of Tag mismatch expected </br>. I m aware this ...

Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

Locating specific string and capturing data following it

I built a site a long time ago and now I want to place the data into a database without copying and pasting the 400+ pages that it has grown to so that I can make the site database driven. My site ...

热门标签