Parser geändert

This commit is contained in:
JanUlrich 2014-07-09 15:07:40 +02:00
parent 053edc0f73
commit bbb3cf76d9
10 changed files with 1219 additions and 1221 deletions

7
bin/.gitignore vendored
View File

@ -1,9 +1,6 @@
/bytecode
/log4jTesting.xml
/mycompiler
/typinferenz
/userinterface
/myJvmDisassembler
/parser
/plugindevelopment
/syntaxTree
/typinferenz
/parser

View File

@ -169,6 +169,5 @@ null {
{ws}|\n { /* System.out.print(yytext()); */ }
\\.\n {org.apache.log4j.Logger.getLogger("parser").debug("Kommentar: "+yytext());}
"->" {this.token = new Token(JavaParser.LAMBDAASSIGNMENT, yytext(), yyline, yychar);return true;}
">" {this.token = new Token(JavaParser.ENDOFGENERICVARDECLARATION, yytext(), yyline, yychar);return true;}

View File

@ -300,7 +300,7 @@ public Vector<Pair> testPair = new Vector<Pair>();
%type <GenericTypeVar> boundedMethodParameter;
%type <GenericTypeVar> boundedClassParameter;
%type <Vector> boundedclassidentifierlist //Vector<Type>
%type <Vector> boundedMethodParameters; // Vector<GenericTypeVar>
%type <GenericVarDeclarationList> boundedMethodParameters; // Vector
%type <ParaList> boundedClassParameters; // ParaList
%type <UsedId> packagedeclaration
%type <Assign> assignment
@ -903,11 +903,16 @@ fielddeclarator :
ret.setWert($3);
$$=ret;
}
| variabledeclarator
{
FieldDeclaration ret = new FieldDeclaration($1.getOffset());
ret.set_DeclId($1);
$$=ret;
}
genericdeclarationlist : '<' boundedMethodParameters ENDOFGENERICVARDECLARATION
genericdeclarationlist : '<' boundedMethodParameters '>'
{
GenericDeclarationList ret = new GenericDeclarationList($2,$3.getOffset());
GenericDeclarationList ret = new GenericDeclarationList($2.getElements(),$2.getEndOffset());
$$ = ret;
}
@ -1064,7 +1069,7 @@ boundedclassidentifierlist : referencetype
// returns Vector<Type>
boundedMethodParameters : boundedMethodParameter
{
Vector<Type> vec=new Vector<Type>();
GenericVarDeclarationList vec=new GenericVarDeclarationList();
vec.addElement($1);
$$=vec;
}

View File

@ -2,6 +2,7 @@ package mycompiler.myclass;
import java.util.Vector;
import mycompiler.myparser.GenericVarDeclarationList;
import mycompiler.mytype.GenericTypeVar;
@ -13,8 +14,14 @@ import mycompiler.mytype.GenericTypeVar;
*/
public class GenericDeclarationList extends Vector<GenericTypeVar>{
public GenericDeclarationList(Vector<GenericTypeVar> vector, int offset) {
// TODO Auto-generated constructor stub
private int offsetOfLastElement;
public GenericDeclarationList(Vector<GenericTypeVar> values, int offset) {
this.addAll(values);
this.offsetOfLastElement = offset;
}
public int getOffsetOfLastElement(){
return offsetOfLastElement;
}
}

View File

@ -0,0 +1,26 @@
package mycompiler.myparser;
import java.util.Vector;
import typinferenz.exceptions.DebugException;
import mycompiler.mytype.GenericTypeVar;
public class GenericVarDeclarationList {
private Vector<GenericTypeVar> elements = new Vector<>();
public void addElement(GenericTypeVar e){
elements.addElement(e);
}
public int getEndOffset() {
int ret;
if(elements.isEmpty())throw new DebugException("Es wurde eine GenericVarDeclarationList ohne Elemente geparst");
ret = elements.lastElement().getOffset() + elements.lastElement().getName().length();
return ret;
}
public Vector<GenericTypeVar> getElements(){
return elements;
}
}

View File

@ -169,6 +169,5 @@ null {
{ws}|\n { /* System.out.print(yytext()); */ }
\\.\n {org.apache.log4j.Logger.getLogger("parser").debug("Kommentar: "+yytext());}
"->" {this.token = new Token(JavaParser.LAMBDAASSIGNMENT, yytext(), yyline, yychar);return true;}
">" {this.token = new Token(JavaParser.ENDOFGENERICVARDECLARATION, yytext(), yyline, yychar);return true;}

File diff suppressed because it is too large Load Diff

View File

@ -300,7 +300,7 @@ public Vector<Pair> testPair = new Vector<Pair>();
%type <GenericTypeVar> boundedMethodParameter;
%type <GenericTypeVar> boundedClassParameter;
%type <Vector> boundedclassidentifierlist //Vector<Type>
%type <Vector> boundedMethodParameters; // Vector<GenericTypeVar>
%type <GenericVarDeclarationList> boundedMethodParameters; // Vector
%type <ParaList> boundedClassParameters; // ParaList
%type <UsedId> packagedeclaration
%type <Assign> assignment
@ -903,11 +903,16 @@ fielddeclarator :
ret.setWert($3);
$$=ret;
}
| variabledeclarator
{
FieldDeclaration ret = new FieldDeclaration($1.getOffset());
ret.set_DeclId($1);
$$=ret;
}
genericdeclarationlist : '<' boundedMethodParameters ENDOFGENERICVARDECLARATION
genericdeclarationlist : '<' boundedMethodParameters '>'
{
GenericDeclarationList ret = new GenericDeclarationList($2,$3.getOffset());
GenericDeclarationList ret = new GenericDeclarationList($2.getElements(),$2.getEndOffset());
$$ = ret;
}
@ -1064,7 +1069,7 @@ boundedclassidentifierlist : referencetype
// returns Vector<Type>
boundedMethodParameters : boundedMethodParameter
{
Vector<Type> vec=new Vector<Type>();
GenericVarDeclarationList vec=new GenericVarDeclarationList();
vec.addElement($1);
$$=vec;
}

View File

@ -774,6 +774,7 @@ public class RefType extends Type implements IMatchable
@Override
public Vector<TypePlaceholder> getInvolvedTypePlaceholder() {
Vector<TypePlaceholder> ret = super.getInvolvedTypePlaceholder();
if(this.parameter == null)return ret;
for(Type param : this.parameter){
ret.addAll(param.getInvolvedTypePlaceholder());
}

View File

@ -29,8 +29,8 @@ public class GeneralParserTest{
public void run(){
Vector<String> filenames = new Vector<String>();
filenames.add("FieldInitializationTest.jav");
//filenames.add("ImportTest.jav");
//filenames.add("BoundedParameter.jav");
filenames.add("ImportTest.jav");
filenames.add("BoundedParameter.jav");
filenames.add("GenericFieldVarTest.jav");
MyCompilerAPI compiler = MyCompiler.getAPI();
try{