开发者

Missing fields in JavaCC/JJTree node classes?

I "inherited" a project that uses JJTree from JavaCC to implement a simple language parser. Since the code was over 5 years old, I decided to update all dependencies, including JavaCC, to the latest release before I do any actual development.

Therefore, I deleted all the files generated by JJTree/JavaCC and used the latest version (5.0) to rebuild them. The resulting files, however, seem to miss fields and methods that were previously present and the code does not compile any more.

I assumed that something changed in JavaCC that requires me to update the grammar file, so I tried out the Interpretter example from the current JavaCC distribution, with the same results: missing class fields that do not allow the code to compile.

For example, here is a definition from SPL.jjt of the Interpretter example:

void Id() :
{
   Token t;
}
{
   t = <IDENTIFIER>  { jjtThis.name = t.image; }
}

The folder for this example contains an ASTId.java file which originally had this content:

public class ASTId extends SimpleNode {
  String name;

  public ASTId(int id) {
    super(id);
  }

  public ASTId(SPLParser p, int id) {
    super(p, id);
  }

  public void interpret()
  {
     stack[++top] = symtab.get(name);
  }
}

After I regenerated the AST*.java files, the content changed:

public class ASTId extends SimpleNode {
  public ASTId(int id) {
    super(id);
  }

  public ASTId(SPLParser p, int id) {
    super(p, id);
  }
}

There is a lot missing here and as a result the SPLParser.java generated file does not compile because it uses fields that are not defined in the corresponding classes.

What am I missing? Is there a JJTree or JavaCC option that I have to use? Perhaps a modification to make in the grammar file? Or, as I don't really know if the original files have been edited, am I supposed to direc开发者_运维百科tly modify the generated files and add the missing bits manually?

I have no experience with JavaCC, so I would appreciate any hints to resolve this issue.


It's a pretty standard practice to edit the generated nodes files... the parser file and the token manager shouldn't be changed though; that's what TOKEN_MGR_DECLS and the code inside the grammar file is for.

The reason folks edit these files is that they don't change very often... although of course when they do, it's a bit of a pain.


The stuff that's missing was probably edited in by the original developers. It's not necessarily a sign that something has changed in JavaCC or JJTree. Those are relatively mature projects.

Here's hoping that the original was checked into a version control system or backed up so you can get the code back. Perhaps the decision to delete and recompile wasn't the best.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜