Java 使用byaccj生成ast时出错

Java 使用byaccj生成ast时出错,java,yacc,parser-generator,jflex,Java,Yacc,Parser Generator,Jflex,我正在使用jflex和byaccj构建一个AST。 我无法解决该错误,我已使用类型转换,但错误仍然存在 对于语法中的以下规则: program : CLASS Program '{' field_decl '}' { program1 $$ = new program1($1.sval, $2.sval, $4.obj); } ; 我已经在我的.java文件中声明了这一点 abstract class program e

我正在使用jflex和byaccj构建一个AST。 我无法解决该错误,我已使用类型转换,但错误仍然存在

对于语法中的以下规则:

program : CLASS Program '{' field_decl '}'      {
                program1 $$ = new program1($1.sval, $2.sval, $4.obj);
        }
        ;
我已经在我的
.java
文件中声明了这一点

abstract class program extends ASTnode{
}

class program1 extends program {
  private classexp ce = null;
  private String id="Program";
  private ArrayList<field_decl> fdecl = null;
  public program1(classexp ce,String id, ArrayList<field_decl> fdecl) {
    super();
    this.ce = ce;           
    this.id = id;
    this.fdecl = fdecl;
  }
}
抽象类程序扩展ASTnode{
}
类program1扩展程序{
私有classexp ce=null;
私有字符串id=“程序”;
private ArrayList fdecl=null;
公共程序1(classexp ce、字符串id、ArrayList fdecl){
超级();
this.ce=ce;
this.id=id;
this.fdecl=fdecl;
}
}
错误是:

{program1 yyval= new program1(val_peek(4).sval,val_peek(3).sval,val_peek(1).obj);}
               ^
required: classexp,String,ArrayList<field_decl>
found: String,String,Object
reason: actual argument String cannot be converted to classexp by method invocation conversion
1 error
{program1yyval=newprogram1(val_peek(4).sval,val_peek(3).sval,val_peek(1.obj);}
^
必需:classexp、String、ArrayList
找到:字符串、字符串、对象
原因:无法通过方法调用转换将实际参数字符串转换为classexp
1错误

您的
程序声明1
说明构造函数是:

public program1(classexp ce,String id, ArrayList<field_decl> fdecl)

也就是说,一个
字符串
,另一个
字符串
,以及一个
对象
(如错误消息中的
找到:
行所示)。为了使提供的参数适合所需参数,需要将第一个
字符串
转换为
classexp
,这是不可能的(如错误消息中的
原因:
行所示)。还需要将第三个参数
对象
转换为
数组列表
,这可能也是不可能的,但构造函数中的一个错误足以拒绝调用。

请使用标记功能格式化代码。要查看我做了什么,请编辑问题并查看。(最重要的是:将代码段缩进4个空格。)我不确定是否将错误消息中的
^
放在正确的位置,尽管没有插入符号错误就足够清楚了。
new program1(val_peek(4).sval,val_peek(3).sval,val_peek(1).obj)