Files

431 lines
12 KiB
Plaintext

%parser minijava.lexer // INCOMPLETE YOU MUST WRITE THE PRODUCTIONS
%{
using visitor;
%}
%namespace syntaxtree
%symbol Program {
public MainClass m;
public ClassDeclList cl;
public Program(MainClass am, ClassDeclList acl)
{
m=am; cl=acl;
}
public void accept(Visitor v) { v.visit(this); }
public Type accept(TypeVisitor v) { return v.visit(this); }
}
%symbol MainClass {
public Identifier i1,i2;
public Statement s;
public MainClass(Identifier ai1, Identifier ai2, Statement a)
{
i1=ai1; i2=ai2; s=a;
}
public void accept(Visitor v) { v.visit(this); }
public Type accept(TypeVisitor v) { return v.visit(this); }
}
%symbol ClassDeclList {
public ClassDecl head = null;
public ClassDeclList tail = null;
public ClassDeclList(ClassDecl c,ClassDeclList t) { head=c; tail=t; }
public ClassDecl this[int i]
{
get { if (i<=0) return head;
return tail[i-1]; }
}
public int size
{
get { if (head==null) return 0;
if (tail==null) return 1;
return 1+tail.size; }
}
}
%symbol ClassDecl {
public virtual void accept(Visitor v) { }
public virtual Type accept(TypeVisitor v) { return null; }
}
%node ClassDeclSimple : ClassDecl {
public Identifier i;
public VarDeclList vl;
public MethodDeclList ml;
public ClassDeclSimple(Identifier ai, VarDeclList avl, MethodDeclList aml)
{
i=ai; vl=avl; ml=aml;
}
public override void accept(Visitor v)
{
v.visit(this);
}
public override Type accept(TypeVisitor v)
{
return v.visit(this);
}
}
%node ClassDeclExtends : ClassDecl {
public Identifier i;
public Identifier j;
public VarDeclList vl;
public MethodDeclList ml;
public ClassDeclExtends(Identifier ai, Identifier aj,
VarDeclList avl, MethodDeclList aml)
{
i=ai; j=aj; vl=avl; ml=aml;
}
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this);}
}
%symbol VarDeclList {
public VarDecl head = null;
public VarDeclList tail = null;
public VarDeclList(VarDecl c,VarDeclList t) { head=c; tail=t; }
public VarDecl this[int i]
{
get { if (i<=0) return head;
return tail[i-1]; }
}
public int size
{
get { if (head==null) return 0;
if (tail==null) return 1;
return 1+tail.size; }
}
}
%symbol MethodDeclList {
public MethodDecl head = null;
public MethodDeclList tail = null;
public MethodDeclList(MethodDecl c,MethodDeclList t) { head=c; tail=t; }
public MethodDecl this[int i]
{
get { if (i<=0) return head;
return tail[i-1]; }
}
public int size
{
get { if (head==null) return 0;
if (tail==null) return 1;
return 1+tail.size; }
}
}
%symbol Exp {
public virtual void accept(Visitor v) {}
public virtual Type accept(TypeVisitor v) { return null; }
}
%node And : Exp {
public Exp e1, e2;
public And(Exp ae1,Exp ae2) { e1=ae1; e2=ae2; }
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%node ArrayLength : Exp {
public Exp e;
public ArrayLength(Exp ae) { e = ae; }
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%node ArrayLookup : Exp {
public Exp e1, e2;
public ArrayLookup(Exp ae1,Exp ae2) { e1=ae1; e2=ae2; }
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%node Call : Exp {
public Exp e;
public Identifier i;
public ExpList el;
public Call(Exp ae, Identifier ai, ExpList ael)
{
e=ae; i=ai; el=ael;
}
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%node False : Exp {
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%node IdentifierExp : Exp {
public string s;
public IdentifierExp(string a) { s=a; }
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%node IntegerLiteral : Exp {
public int i;
public IntegerLiteral(int ai) { i=ai; }
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%node LessThan : Exp {
public Exp e1, e2;
public LessThan(Exp ae1,Exp ae2) { e1=ae1; e2=ae2; }
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%node Minus : Exp {
public Exp e1, e2;
public Minus(Exp ae1,Exp ae2) { e1=ae1; e2=ae2; }
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%node NewArray : Exp {
public Exp e;
public NewArray(Exp ae) { e = ae; }
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%node NewObject : Exp {
public Identifier i;
public NewObject(Identifier ai) { i = ai; }
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%node Not : Exp {
public Exp e;
public Not(Exp ae) { e = ae; }
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%node Plus : Exp {
public Exp e1, e2;
public Plus(Exp ae1,Exp ae2) { e1=ae1; e2=ae2; }
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%node This : Exp {
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%node Times : Exp {
public Exp e1, e2;
public Times(Exp ae1,Exp ae2) { e1=ae1; e2=ae2; }
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%node True : Exp {
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%symbol ExpList {
public Exp head = null;
public ExpRest tail = null;
public ExpList(Exp c,ExpRest t) { head=c; tail=t; }
public Exp this[int i]
{
get { if (i<=0) return head;
return tail[i-1]; }
}
public int size
{
get { if (head==null) return 0;
if (tail==null) return 1;
return 1+tail.size; }
}
}
%symbol ExpRest {
public Exp head;
public ExpRest tail;
public ExpRest(Exp c,ExpRest t) { head=c; tail=t; }
public Exp this[int i]
{
get { if (i<=0) return head;
return tail[i-1]; }
}
public int size
{
get { if (tail==null) return 1;
return 1+tail.size; }
}
}
%symbol Formal {
public Type t;
public Identifier i;
public Formal(Type at, Identifier ai)
{
t=at; i=ai;
}
public void accept(Visitor v) { v.visit(this); }
public Type accept(TypeVisitor v) { return v.visit(this); }
}
%symbol FormalList {
public Formal head = null;
public FormalRest tail = null;
public FormalList(Formal c,FormalRest t) { head=c; tail=t; }
public Formal this[int i]
{
get { if (i<=0) return head;
return tail[i-1]; }
}
public int size
{
get { if (head==null) return 0;
if (tail==null) return 1;
return 1+tail.size; }
}
}
%symbol FormalRest {
public Formal head = null;
public FormalRest tail = null;
public FormalRest(Formal c,FormalRest t) { head=c; tail=t; }
public Formal this[int i]
{
get { if (i<=0) return head;
return tail[i-1]; }
}
public int size
{
get { if (head==null) return 0;
if (tail==null) return 1;
return 1+tail.size; }
}
}
%symbol Identifier {
public string s;
public Identifier(string a) { s=a; }
public void accept(Visitor v) { v.visit(this); }
public Type accept(TypeVisitor v) { return v.visit(this);}
public override string ToString() { return s; }
}
%symbol MethodDecl {
public Type t;
public Identifier i;
public FormalList fl;
public VarDeclList vl;
public StatementList sl;
public Exp e;
public MethodDecl(Type at, Identifier ai, FormalList afl, VarDeclList avl,
StatementList asl, Exp ae)
{
t=at; i=ai; fl=afl; vl=avl; sl=asl; e=ae;
}
public void accept(Visitor v)
{
v.visit(this);
}
public Type accept(TypeVisitor v)
{
return v.visit(this);
}
}
%symbol Statement {
public virtual void accept(Visitor v) {}
public virtual Type accept(TypeVisitor v) { return null; }
}
%node ArrayAssign : Statement {
public Identifier i;
public Exp e1,e2;
public ArrayAssign(Identifier ai,Exp ae1,Exp ae2)
{
i = ai; e1 = ae1; e2 = ae2;
}
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%node Assign : Statement {
public Identifier i;
public Exp e;
public Assign(Identifier ai,Exp ae)
{
i = ai; e = ae;
}
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%node Block : Statement {
public StatementList sl;
public Block(StatementList asl)
{
sl = asl;
}
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%node If : Statement {
public Exp e;
public Statement s1,s2;
public If(Exp ae, Statement as1, Statement as2)
{
e=ae; s1=as1; s2=as2;
}
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%node Print : Statement {
public Exp e;
public Print(Exp ae) { e=ae; }
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%node While : Statement {
public Exp e;
public Statement s;
public While(Exp ae, Statement a)
{
e=ae; s=a;
}
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%symbol StatementList {
public Statement head = null;
public StatementList tail = null;
public StatementList(Statement c,StatementList t) { head=c; tail=t; }
public Statement this[int i]
{
get { if (i<=0) return head;
return tail[i-1]; }
}
public int size
{
get { if (head==null) return 0;
if (tail==null) return 1;
return 1+tail.size; }
}
}
%symbol Type {
public virtual void accept(Visitor v) {}
public virtual Type accept(TypeVisitor v) { return null; }
}
%node BooleanType : Type {
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%node IdentifierType : Type {
public string s;
public IdentifierType(string a) { s=a; }
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%node IntArrayType : Type {
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%node IntegerType : Type {
public override void accept(Visitor v) { v.visit(this); }
public override Type accept(TypeVisitor v) { return v.visit(this); }
}
%symbol VarDecl {
public Type t;
public Identifier i;
public VarDecl(Type at, Identifier ai) { t=at; i=ai; }
public void accept(Visitor v) { v.visit(this); }
public Type accept(TypeVisitor v) { return v.visit(this); }
}
Program : ;