English 中文(简体)
• 如何与Antlr4合并,以平整一个民族阵线
原标题:How to parse a PGN move with Antlr4
  • 时间:2024-02-06 22:14:29
  •  标签:
  • java
  • antlr4

I am trying to create a parser for a PGN file and am getting errors on the moves. If my input is Ng4, the output should be (standard_move (moving_Piece N) (moving_File g) (moving_Rank 4) ). This works well with the below .g4 file:

grammar MOVE;

standard_move: moving_Piece moving_File moving_Rank Newline;
moving_Piece: Moving_Piece ;
moving_File: Moving_File;
moving_Rank: Moving_Rank;


Moving_Piece: ( K | Q | R | B | N ) ;
Moving_File: [a-h];
Moving_Rank: [1-8];
Newline: [
]; 
WHITESPACE :     -> skip ;

然而,如果我把同样的逻辑列入我较大型的.g4文档中,有其他的国产总值要素,那么我就获得了<代码>1:0不匹配的投入。 Ng Requesting Moving_Piece

grammar PGN;

annotations: annotation+;
annotation  : Open_Bracket tag value Close_Bracket Newline ; 
value: String;
tag: Chars;
move_time: Move_time Newline;
move_number: Move_Number Newline;
standard_move: moving_Piece moving_File moving_Rank Newline;
moving_Piece: Moving_Piece ;
moving_File: Moving_File;
moving_Rank: Moving_Rank;


Moving_Piece: ( K | Q | R | B | N ) ;
Moving_File: [a-h];
Moving_Rank: [1-8];
Move_Number: [0-9]+  . ;
Move_time:  {[%emt  .*?  ]} ;
Chars: [a-zA-Z]*;
String :  "  ~["]*  " ;
Quote :  " ;
Open_Bracket :  [  ;
Close_Bracket :  ]  ;
Newline: [
]; 
WHITESPACE :     -> skip ;

任何帮助为什么发生这种情况都会受到高度赞赏!

问题回答

问题的根源是较法规则中的冲突重叠。

Moving_Piece: ( K | Q | R | B | N ) ;
Moving_File: [a-h];
Moving_Rank: [1-8];
Move_Number: [0-9]+  . ;
Chars: [a-zA-Z]*;

。 Bart s response to a similar question for a details interpret.

实际固定装置见以下有详细记录的例子:PGNgrammar。

BTW, the Antlr Grammars 储藏处是一个巨大的学习资源。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签