%{ package patch.src; import java.util.*; import java.io.*; import patch.src.util.*; import pp.src.jbf.*; %} %token ERROR /* used by the lexer. */ %token SYMBOL %token FINAL SYNCHRONIZED PUBLIC ABSTRACT %token INTERFACE IMPLEMENTS EXTENDS CLASS %token PRIVATE PROTECTED STATIC TRANSIENT VOLATILE NATIVE %token BOOLEAN BYTE CHAR DOUBLE FLOAT VOID LONG STRING INT SHORT %% compilationUnit : typeDeclaration ; typeDeclaration : ';' | classDeclaration | interfaceDeclaration ; classDeclaration : classDecl1 classDecl2 ; interfaceDeclaration : interfaceDecl1 interfaceDecl2 ; classDecl1 : classModifierList CLASS qualifiedSymbol { // pat.startClass($3); nothing needed at this point } | classModifierList CLASS qualifiedSymbol EXTENDS qualifiedSymbol interfaces { // pat.startClass(new ClassNode($3, $4, $5));} // pat.startClass($3, $5); boolean addVar = true; // Add Var of Parent Class to current scope pat.parseClass($5.text, addVar); } ; classDecl2 : classBlock { // pat.endClass(); } ; interfaceDecl1 : classModifierList INTERFACE simpleSymbol EXTENDS qualifiedSymbol { // pat.startClass($3, $5); boolean addVar = true; // Add Var of Parent Class to current scope pat.parseClass($5.text, addVar); } ; interfaceDecl2: classBlock { // pat.endClass(); } ; classModifierList : | classModifierList FINAL | classModifierList SYNCHRONIZED | classModifierList PUBLIC | classModifierList ABSTRACT ; interfaces : | IMPLEMENTS qualifiedSymbol | interfaces ',' qualifiedSymbol ; qualifiedSymbol : simpleSymbol { $$ = $1; } | qualifiedSymbol '.' simpleSymbol { ($1).text += ("."+($3).text); $$ = $1;} ; simpleSymbol : SYMBOL { // System.out.println($1.text); $$ = $1 ; } classBlock : '{' '}' | '{' fieldList '}' | '{' '}' ';' | '{' fieldList '}' ';' ; fieldList : field | fieldList field ; field : ignore ';' | modifierList methodDeclaration | modifierList variableDeclaration ; modifierList : | modifierList PRIVATE { $$ = $2; } | modifierList PUBLIC { $$ = $2; } | modifierList PROTECTED { $$ = $2; } | modifierList STATIC { $$ = $2; } | modifierList TRANSIENT { $$ = $2; } | modifierList VOLATILE { $$ = $2; } | modifierList FINAL { $$ = $2; } | modifierList NATIVE { $$ = $2; } | modifierList SYNCHRONIZED { $$ = $2; } | modifierList ABSTRACT { $$ = $2; } ; methodDeclaration : method ';' ; method : simpleType qualifiedSymbol '(' optArgList ')' | simpleSymbol '(' optArgList ')' | method '[' ']' ; variableDeclaration : variable ';' { pat.addLocalVar((FormalNode)($1)); } ; variable : qualifiedSymbol '.' SYMBOL simpleSymbol { $$ = (YYtoken) (new FormalNode(new TypeNode($3), $4)); boolean addVar = false; pat.parseClass($3.text, addVar); } | simpleSymbol simpleSymbol { $$ = (YYtoken) (new FormalNode(new TypeNode($1), $2)); boolean addVar = false; pat.parseClass($1.text, addVar); } | simpleType simpleSymbol { $$ = (YYtoken) (new FormalNode($1, $2)); } | variable '[' ']' { ((FormalNode)$1).type.addDim(1); } ; simpleType : BOOLEAN { $$ = (YYtoken) (new TypeNode(TypeNode.BOOL, $1)); } | BYTE { $$ = (YYtoken) (new TypeNode(TypeNode.BYTE, $1)); } | CHAR { $$ = (YYtoken) (new TypeNode(TypeNode.CHAR, $1)); } | SHORT { $$ = (YYtoken) (new TypeNode(TypeNode.SHORT, $1)); } | INT { $$ = (YYtoken) (new TypeNode(TypeNode.INT, $1)); } | FLOAT { $$ = (YYtoken) (new TypeNode(TypeNode.FLOAT, $1)); } | LONG { $$ = (YYtoken) (new TypeNode(TypeNode.LONG, $1)); } | DOUBLE { $$ = (YYtoken) (new TypeNode(TypeNode.DOUBLE, $1)); } | STRING { $$ = (YYtoken) (new TypeNode(TypeNode.STRING, $1)); } | VOID { $$ = (YYtoken) (new TypeNode(TypeNode.VOID, $1)); } ; optArgList : | argList ; argList : arg | argList ',' arg ; arg : simpleType optArrayBounds | qualifiedSymbol ; optArrayBounds : | optArrayBounds '[' ']' ; ignore : | modifierList STATIC '{' '}' { if (!($1.text).equals("static")) { System.err.println("UnHandled Profiler Output in "+pat.modName+".tmp"); } } %% /* put suffix code here */ /* Override yyerror */ public void yyverror(String s) throws ParseException { yyerror(s, true); //throw new ParseException(s); } // protected Patch pat; protected npp.src.util.NslPreProcessor pat; public void init(npp.src.util.NslPreProcessor p) { pat = p; } /* init(npp.src.NPP p) { pat = p; } */