/* SCCS - %W% - %G% - %U% */ %{ /********************* header ********************************/ package npp.src; import java.util.*; import java.io.*; import npp.src.util.*; import pp.src.jbf.*; /*****************************************************/ %} /* * SCCS @(#)alpha.y 1.26 - 08/04/99 - 16:51:41 * $Log: alpha.y,v $ * */ // The original java parser.y file was written by David Engberg // for Effective Edge Technologies (info@eecs.com) and was part of a compiler // called guavac. Guavac 0.2.5 (96.8) carries a GNU License which // is also included in this directory for your convenience. // parser.y: Copyright (c) 1995 David Engberg All rights reserved // $Id: alpha.y,v 1.8 1998/01/30 20:03:02 erhan Exp $ // // We (Isaac Siu) modified parser.y to handle the nslj syntax. // We will probably modify this file many more times before its // release so no date is given here. // alpha.y: Copyright (c) 1996 USC Brain Project All rights reserved // $Id: alpha.y 1.1.1.1 1997/03/12 23:09:23 nsl %token ERROR /* used by the lexer. */ %token ABSTRACT BOOLEAN BREAK BYTE CASE CATCH CHAR CLASS CONTINUE DEFAULT %token DO DOUBLE EXTENDS FALSE_TOKEN FINAL FINALLY FLOAT FOR IF IMPLEMENTS // %token IMPORT NSLIMPORT INSTANCEOF INT INTERFACE LONG NATIVE NULL_TOKEN PACKAGE %token NSLIMPORT INSTANCEOF INT INTERFACE LONG NATIVE NULL_TOKEN PACKAGE %token PRIVATE PROTECTED PUBLIC RETURN SHORT STATIC SUPER SWITCH SYNCHRONIZED %token THIS THROW THROWS TRANSIENT VOLATILE TRUE_TOKEN TRY VOID WHILE // %token VERBATIM OFF NSLJ NSLC %token VERBATIM_OFF VERBATIM_NSLJ VERBATIM_NSLC NSLJ //%token NSLENV %token NSLMULTI //%token CONNECT EXTERNAL INTERNAL SPECIAL NSLMODULE NSLMODEL ARRAY %token CONNECT SPECIAL NSLMODULE NSLMODEL NSLCLASS ARRAY %token INT_LITERAL CHARACTER_LITERAL %token LONG_LITERAL %token FLOAT_LITERAL %token DOUBLE_LITERAL %token SYMBOL STRING_LITERAL %token BIT_MUL %token STRING %nonassoc NOT_AN_OPERATOR %right SHIFT_RIGHT_EQUALS FILL_SHIFT_RIGHT_EQUALS SHIFT_LEFT_EQUALS ADD_EQUALS SUB_EQUALS MUL_EQUALS DIV_EQUALS MOD_EQUALS AND_EQUALS XOR_EQUALS OR_EQUALS '=' %right '?' ':' %left OR %left AND %left '|' %left '&' %left '^' %left EQUAL_COMPARE NOT_EQUAL %left LTEQ GTEQ INSTANCEOF '<' '>' %left BITSHIFT_RIGHT FILL_SHIFT_RIGHT SHIFT_LEFT %left '+' '-' %left BIT_MUL '*' '/' '%' %left '@' %nonassoc CAST %nonassoc INCR DECR '!' '~' UMINUS UPLUS %nonassoc POST_INCR POST_DECR %nonassoc NEW %nonassoc '(' ')' '[' ']' %left '.' /* thse two are used to fix the standard dangling 'else' problem: */ %nonassoc LOWER_THAN_ELSE %nonassoc ELSE /* * There should be three shift-reduce conflicts in the following code. They * are essentially the same problem, and 'fixing' them would be extremely * painful, particularly given that bison's default behavior (shift) does the * right thing. In all three cases, expressions can end with a * 'qualifiedSymbol' which is defined to be SYMBOL ('.' SYMBOL)* * and this conflicts with a situation where expression can itself be followed * by '.' SYMBOL * By always shifting, we are sticking all of those extra .SYMBOL markers * onto the qualifiedSymbol, which is what we want to do anyway. * Fixing this would entail modifying every single expression to always * terminate the right way, which would be really difficult given that I * already had to do this for the beginning of expressions to disambiguate * statements from casts that start with a type. */ %expect 3 %% compilationUnit : optPackage importList typeDeclarationList ; optPackage : | PACKAGE qualifiedSymbol ';' { npp.setPackage($2); } | verbatim_line ; importList : // | importList import | importList nslImport ; nslImport : NSLIMPORT qualifiedSymbol BIT_MUL ';' { //System.err.println("Adding 1: "+$1.text+" "+$2.text+" "+$3.text+" "); // Have to solve globing npp.addGenCode("import",$1); npp.addModList($2.text+$3.text); } /* | NSLIMPORT qualifiedSymbol '.' '*' ';' { //System.err.println("Adding 2: "+$1.text+" "+$2.text+" "+$3.text+" "); npp.addGenCode("import",$1); npp.addModList($2.text+$3.text+$4.text); }*/ | NSLIMPORT qualifiedSymbol ';' {// System.err.println("Adding 3: "+$1.text+" "+$2.text+" "+$3.text+" "); npp.addGenCode("import",$1); npp.addModList($2.text); } | SPECIAL NSLIMPORT qualifiedSymbol ';' { //System.err.println("Adding 4: "+$1.text+" "+$2.text+" "+$3.text+" "); if ($3.text.equals("nslAllImports")) { npp.addGenCode("",$1); npp.addGenCode("import nslj.src.system.*; \n import nslj.src.cmd.*; \n import nslj.src.lang.*; \n import nslj.src.math.*; \n import nslj.src.display.*;", $2); npp.addGenCode("",$3); npp.addGenCode("",$4); // System.err.println("nslAllImports added!"); } else { //System.err.println("could not find nslAllImports"); npp.addGenCode("",$1); npp.addGenCode("import",$2); npp.addModList($3.text); npp.parseClass($3.text, true); } } | verbatim_line ; typeDeclarationList : | typeDeclarationList typeDeclaration ; typeDeclaration : ';' | classDeclaration | interfaceDeclaration | verbatim_line ; classDeclaration : classDecl1 classDecl2 | nslclassDecl1 nslclassDecl2 ; nslclassDecl1: NSLJ classModifierList NSLMODULE simpleSymbol '(' optParameterList ')' { //System.err.println("I'm here!"); //System.err.println("open NSLMODULE:"+$4.text+" pars:"+$6.text); npp.startClass(new ClassNode($4,(ParamsNode)$6,"NslModule", null)); // thr if ($6 != null) npp.addLocalVar((ParamsNode)($6)); npp.addGenCode("",$1); npp.addGenCode("public class",$3); if (($3.text).equals("nslOutModule")) npp.addGenCode($4.text+" extends NslOutModule",$4); else if (($3.text).equals("nslInModule")) npp.addGenCode($4.text+" extends NslInModule",$4); else if (($3.text).equals("nslModule")) npp.addGenCode($4.text+" extends NslModule",$4); npp.addGenCode("/*"+$5.text,$5); npp.addGenCode($7.text+"*/",$7); // if ($5==null) npp.getCurClass().set_constructor_pars(""); // else npp.getCurClass().set_constructor_pars(((ParamsNode)$5).code0); } | NSLJ classModifierList NSLMODEL simpleSymbol '(' optParameterList')' {npp.startClass(new ClassNode($4,(ParamsNode)$6,"NslModel", null)); // thr if ($6 != null) npp.addLocalVar((ParamsNode)($6)); npp.addGenCode("",$1); npp.addGenCode("public class",$3); //just puts public class npp.addGenCode($4.text+" extends NslModel",$4); npp.addGenCode("/*"+$5.text,$5); npp.addGenCode($7.text+"*/",$7); } | NSLJ classModifierList NSLCLASS simpleSymbol '(' optParameterList')' {npp.startClass(new ClassNode($4,(ParamsNode)$6,"NslClass", null)); // thr if ($6 != null) npp.addLocalVar((ParamsNode)($6)); npp.addGenCode("",$1); npp.addGenCode("public class",$3); //just puts public class npp.addGenCode($4.text+" extends NslClass",$4); npp.addGenCode("/*"+$5.text,$5); npp.addGenCode($7.text+"*/",$7); } | classModifierList NSLMODULE simpleSymbol '(' optParameterList ')' nslextends simpleSymbol '(' optArgumentList ')' {//System.err.println("GOT EXTEND.."); // thr // add_var_to_relvant_scope(npp, $8.text); // System.err.println("parse BASECLASS:"+$8.text+" for "+$3.text); boolean addVar = true; // Add public variables of parent class to its scope //npp.parseClass($8.text, addVar); // thr npp.startClass(new ClassNode($3,(ParamsNode)$5,"NslModule", null)); // thr if ($5 != null) npp.addLocalVar((ParamsNode)($5)); npp.addGenCode("public class",$2); npp.addGenCode("/*"+$4.text,$4); npp.addGenCode($6.text+"*/",$6); npp.addGenCode("/*"+$9.text,$9); npp.addGenCode($11.text+"*/",$11); if ($10==null) npp.getCurClass().set_superargs(""); else npp.getCurClass().set_superargs(((ExprsNode)$10).code0); } | classModifierList NSLMODEL simpleSymbol '(' optParameterList ')' nslextends simpleSymbol '(' optArgumentList ')' {//System.err.println("GOT EXTEND.."); // System.err.println("model line: "+$1.text+":"+ $2.text+":"+ $3.text+":"+ $4.text+":"+ $5.text+":"+ $6.text+":"+ $7.text+":"+ $8.text+":"+ $9.text); // thr // add_var_to_relvant_scope(npp, $8.text); // System.err.println("parse BASECLASS:"+$8.text+" for "+$3.text); boolean addVar = true; // Add public variables of parent class to its scope //npp.parseClass($8.text, addVar); // thr npp.startClass(new ClassNode($3,(ParamsNode)$5, "NslModel", null)); // thr if ($5 != null) npp.addLocalVar((ParamsNode)($5)); npp.addGenCode("public class",$2); //just puts public class //npp.addGenCode($3.text+" extends NslModel",$3); npp.addGenCode("/*"+$4.text,$4); npp.addGenCode($6.text+"*/",$6); npp.addGenCode("/*"+$9.text,$9); npp.addGenCode($11.text+"*/",$11); if ($10==null) npp.getCurClass().set_superargs(""); else npp.getCurClass().set_superargs(((ExprsNode)$10).code0); } | classModifierList NSLCLASS simpleSymbol '(' optParameterList')' nslextends simpleSymbol '(' optArgumentList ')' { // thr // add_var_to_relvant_scope(npp, $8.text); // System.err.println("parse BASECLASS:"+$8.text+" for "+$3.text); boolean addVar = true; // Add public variables of parent class to its scope //npp.parseClass($8.text, addVar); // thr npp.startClass(new ClassNode($3,(ParamsNode)$5,"NslClass", null)); // thr if ($5 != null) npp.addLocalVar((ParamsNode)($5)); npp.addGenCode("public class",$2); //just puts public class npp.addGenCode("/*"+$4.text,$4); npp.addGenCode($6.text+"*/",$6); npp.addGenCode("/*"+$9.text,$9); npp.addGenCode($11.text+"*/",$11); if ($10==null) npp.getCurClass().set_superargs(""); else npp.getCurClass().set_superargs(((ExprsNode)$10).code0); } ; nslclassDecl2: nslclassBlock { npp.endClass($1); //System.err.println("nslModule closed"); } ; nslextends: EXTENDS | NSLJ EXTENDS {npp.addGenCode("",$1);} ; nslreturn: RETURN | SPECIAL RETURN {npp.addGenCode("",$1);} ; nslclassBlock : classBlock ; classDecl1: classModifierList CLASS simpleSymbol extends interfaces {npp.startClass(new ClassNode($3, $4, $5));} ; classDecl2: classBlock {npp.endClass($1);}; interfaceDeclaration : interfaceDecl1 interfaceDecl2 ; interfaceDecl1 : classModifierList INTERFACE simpleSymbol interfaceExtends {npp.startClass(new ClassNode($3,null,$4));} ; interfaceDecl2: classBlock { npp.endClass($1);} ; classModifierList : // | classModifierList INTERNAL // {npp.addGenCode("",$2); /* no word for internal for classes in java*/ } // | classModifierList EXTERNAL // {npp.addGenCode("public",$2); /* external=public in java*/ } | classModifierList FINAL | classModifierList SYNCHRONIZED | classModifierList PUBLIC { npp.addGenCode("external",$2);} | classModifierList ABSTRACT ; extends : | EXTENDS qualifiedSymbol | NSLJ EXTENDS qualifiedSymbol {npp.addGenCode("",$1);} ; interfaceExtends : | EXTENDS qualifiedSymbolList | NSLJ EXTENDS qualifiedSymbolList {npp.addGenCode("",$1);} ; interfaces : | IMPLEMENTS qualifiedSymbolList ; classBlock : '{' '}' { $$ = $2; } | '{' fieldList '}' { $$ = $3; } | '{' '}' ';' { npp.addGenCode("",$3); $$ = $2; } | '{' fieldList '}' ';' { npp.addGenCode("",$4); $$ = $3; } | verbatim_line ; fieldList : field | fieldList field ; field : ';' | NSLMULTI { npp.getCurClass().add_nsldecl(($1.text).substring(2)); npp.addGenCode("",$1); } | modifierList nslInstantiation ';' { /*if ($1!=null) System.err.println("----------------"+$1.text+"-------------"); */ //npp.addGenCode(((NslInstNode)$2).typestring+" "+ npp.addGenCode( /* no need for type string*/ ((NslInstNode)$2).variablename+" ; /*",$2); npp.getCurClass().add_nsldecl(((NslInstNode)$2).variablename+"=new "+ ((NslInstNode)$2).typestring+" "+ Expand(((NslInstNode)$2).variablename, ((NslInstNode)$2).arguments) ); npp.addGenCode("*/",$3); } | ABSTRACT XmodifierList nslInstantiation ';' { npp.addGenCode("; /*NO WORK*/ ",$4); } | methodDeclaration | constructorDeclaration | modifierList variableDeclaration {/* creates class level variable if not exists, check compatibility if created */ } | staticInitializer | verbatim_line ; CARRAYDECL : ARRAY simpleSymbol simpleSymbol '[' Carray { String s=remArrDims($5.text); if (s!=null) { npp.addGenCode($2.text+s+" "+$3.text+" = new ",$1); npp.addGenCode("",$3); //System.err.println("debug:C ARRAY ARGS: ["+$2.text+$3.text+$5.text); } else npp.addGenCode("",$1); } | ARRAY simpleType simpleSymbol '[' Carray { String s=remArrDims($5.text); if (s!=null) { npp.addGenCode($2.text+s+" "+$3.text+" = new ", $1); npp.addGenCode("",$3); //System.err.println("debug:C ARRAY ARGS: ["+$2.text+$3.text+$5.text); FormalNode fn = (new FormalNode($2, $3)); fn.type.addDim(s.length()/2); npp.addLocalVar(fn); } else npp.addGenCode("",$1); } ; Carray : expression ']' { /* ERH: if we wished we could have expressions instead */ //System.err.println("debug:Carray1:["+$1.text+"]"); $$.text=$1.text+']'; $$.charno = $2.charno; $$.lineno = $2.lineno; } | expression ']' '[' Carray { //System.err.println("debug:Carray2:["+$1.text+"]"); $$.text=$1.text+']'+'['+$4.text; $$.charno = $4.charno; $$.lineno = $4.lineno; } | ']' | ']' '[' Carray { //System.err.println("debug:Carray3:["+$1.text+"]"); $$.text="]"+"["+$3.text; $$.charno = $3.charno; $$.lineno = $3.lineno; } ; nslInstantiation: nslCouple nslArgs {$$=new NslInstNode((NslCoupleNode)$1,$2.text); $$.text=$1.text; $$.charno = $1.charno; $$.lineno = $1.lineno; npp.addLocalVar(((NslInstNode)$$).formal); } | nslCouple nslPars {$$=new NslInstNode((NslCoupleNode)$1,"(/* VOID */)"); $$.text=$1.text; $$.charno = $1.charno; $$.lineno = $1.lineno; npp.addLocalVar(((NslInstNode)$$).formal); } ; nslCouple : SYMBOL SYMBOL { //System.err.println("COUPLE FORMED:"+$1.text+" - "+$2.text); boolean addVar = false; // Don't add variables to current scope //npp.parseClass($1.text, addVar); $$=new NslCoupleNode($1,$2); //npp.addGenCode(" /*[ ",$2); $$.text=$2.text; $$.charno = $2.charno; //+($2.text).length(); $$.lineno = $2.lineno; } | qualifiedSymbol '.' SYMBOL SYMBOL { // thr // System.err.println("COUPLE FORMED:"+$3.text+" - "+$4.text); $$=new NslCoupleNode($3,$4); //npp.addGenCode(" /*[ ",$2); $$.text=$4.text; $$.charno = $4.charno; //+($4.text).length(); $$.lineno = $4.lineno; } ; nslArgs : '(' optArgumentList ')' { //if ($2!=null) System.err.println("nslInst2: done "+$2.text); //else System.err.println("nslInst2: done: VOID ARGS"); if ($2==null) { $$=$1; $$.text="()"; } else { $$=$1; $$.text="("+((ExprsNode)$2).code0+")";} //npp.addGenCode($3.text+"]*/",$3); //if ($2!=null)System.err.println("I'm in nslArgs: "+$2.text); } ; nslPars : '(' optParameterList ')' { if ($2!=null) System.err.println("Error: Module must be abstract! "+$2.text); else { //System.err.println("debug: nslInst2: done: VOID PARS"); } // thr if ($2 != null) npp.addLocalVar((ParamsNode)($2)); $$=$2; //npp.addGenCode($3.text+"]*/",$3); //if ($2!=null)System.err.println("I'm in nslPars: "+$2.text); } ; staticInitializer : modifierList compoundStatement ; // methodDeclaration : methodDecl1 methodDecl2 methodDecl3 methodDeclaration : methodDecl1 methodDecl3 ; methodDecl1 : modifierList NSLJ type simpleSymbol '(' optParameterList ')' optArrayBounds optThrows { npp.addGenCode("",$2); MethodNode mn = new MethodNode((new FormalNode($3, $4))); npp.startMethod(mn); // thr if ($6 != null) npp.addLocalVar((ParamsNode)($6)); // 98/7/30 aa: changed CALLFROMCONST to CALLFROMCONSTRBOTTOM and // changed flag name to exists_callFromConstructor if (mn.method_type==MethodNode.CALLFROMCONSTR) (npp.getCurClass()).exists_callFromConstructor=true; // System.err.println("^^^^^^^^ GOT callfromConst"); if (mn.method_type==MethodNode.CALLFROMCONSTRBOTTOM) (npp.getCurClass()).exists_callFromConstructorBottom=true; // System.err.println("^^^^^^^^ GOT callfromConst"); if (mn.method_type==MethodNode.CALLFROMCONSTRTOP) (npp.getCurClass()).exists_callFromConstructorTop=true; //System.err.println("^^^^^^^^ GOT callfromConst"); // npp.setCurMethodParams((ParamsNode)$6); npp.getCurMethod().makeInstSpecialProcess(npp); /* ((TypeNode)$2).addDim($7);*/ } ; // methodDecl2 : optParameterList ')' optArrayBounds optThrows // { // npp.setCurMethodParams((ParamsNode)$1); // npp.getCurMethod().makeInstSpecialProcess(npp); // /* ((TypeNode)$2).addDim($7);*/} // ; methodDecl3 : methodBlock { /* check name: makeinst, makeconn, init, execute, finalprint. check access flag check return value check duplicates check parameter: any parameter set in the mentioned method? */ npp.endMethod($1); $$ = $1; } ; constructorDeclaration : constructorDecl1 constructorDecl2 ; constructorDecl1 : NSLJ modifierList simpleSymbol '(' { // 98/8/25 aa took out //System.err.println("debug: ============= CONSTRUCTOR ==========******"); npp.addGenCode("",$1); ConstructorNode cn = new ConstructorNode($3); npp.startConstructor(cn); } ; constructorDecl2 : optParameterList ')' optThrows '{' optConstructorStatements '}' { /* check name-match check parameter */ npp.setCurConstructorParams((ParamsNode)$1); // thr if ($1 != null) npp.addLocalVar((ParamsNode)($1)); npp.endConstructor($1); $$ = $1; } ; optThrows : | THROWS qualifiedSymbolList ; optConstructorStatements : | statement statementList | SUPER '(' optArgumentList ')' ';' statementList { } | THIS '(' optArgumentList ')' ';' statementList { } ; methodBlock : ';' { $$ = $1; } | compoundStatement { $$ = $1; } ; optParameterList : { $$ = null; } | parameterList { $$ = $1; //System.err.println(" >>>>>>>>> PARAMS:"+$$.text); } ; parameterList : parameter { $$ = new ParamsNode((FormalNode)$1); } | parameterList ',' parameter { $$ = $1; ((ParamsNode)$$).addTail((FormalNode)$3); } ; parameter : type simpleSymbol optArrayBounds { ((TypeNode)$1).addDim($3); $$ = (YYtoken) (new FormalNode($1, $2)); // thr- addLocalVar done later // npp.addLocalVar((FormalNode)($$)); /* | JAVAREFDECL | CARRAYDECL ';' */ } ; variableDeclaration : SPECIAL subvariableDeclaration {//System.out.println("GOT SPECIAL on :"+$2.text); npp.addGenCode("",$1);} | CARRAYDECL ';' ; subvariableDeclaration : partialVariable ';' ; /* * This rule is structured a little awkwardly because each rule needs to * know the base type when it is being evaluated, since in a situation like * this: int x=0, y=x; * I can't evaluate "x=0, y=x" as a normal list and then wait to add the 'int' * type to these variables, since 'x' has already been used once. */ partialVariable : type simpleSymbol optArrayBounds optInitializer { /* create local symbols */ $$ = $1; FormalNode fn = (new FormalNode($1, $2)); fn.type.addDim($3); npp.addLocalVar(fn); if (($1.text).equals("NslFloat0") || ($1.text).equals("NslFloat1") || ($1.text).equals("NslFloat2") || ($1.text).equals("NslFloat3") || ($1.text).equals("NslFloat4") || ($1.text).equals("NslInt0") || ($1.text).equals("NslInt1") || ($1.text).equals("NslInt2") || ($1.text).equals("NslInt3") || ($1.text).equals("NslInt4") || ($1.text).equals("NslDouble0") || ($1.text).equals("NslDouble1") || ($1.text).equals("NslDouble2") || ($1.text).equals("NslDouble3") || ($1.text).equals("NslDouble4") || ($1.text).equals("NslString0") ) System.err.println("warning- Expected paranthesis after \""+$1.text+"\" in line "+($$.lineno+1)); } | partialVariable ',' simpleSymbol optArrayBounds optInitializer { $$ = $1; FormalNode fn = (new FormalNode(new TypeNode((TypeNode)$1), $3)); fn.type.addDim($4); npp.addLocalVar(fn); } ; optInitializer : | '=' initializer ; initializer : expression | '{' optVariableInitializerList '}' ; optVariableInitializerList : | variableInitializerList optComma ; variableInitializerList : initializer | variableInitializerList ',' initializer ; optComma : | ',' ; compoundStatement : compoundStatement1 compoundStatement2 { $$ = $2;} ; compoundStatement1 : '{' { $$ = $1; npp.pushScope();} ; compoundStatement2 : statementList '}' { $$ = $2; npp.popScope();} ; statementList : | statementList statement ; nslInst_st: nslInstantiation ';' { /* YmodifierList is non null */ NslInstNode ni=(NslInstNode)$2; npp.addGenCode( ni.typestring+" "+ni.variablename+" = new "+ ni.typestring+ni.arguments ,$2); // System.err.println("debug: nslInstantiation-"+ni.variablename+" = new "+ni.typestring); } ; statement : ';' | error ';' | error '}' | compoundStatement | expressionStatement ';' { $$ = $1; //System.err.println("-- Expression Statement"); if (!($1 instanceof NslInstNode)) { ((ExprNode)$$).genCode(npp); npp.addGenCode((ExprNode)$$, $2); } } | variableDeclaration | IF '(' expression ')' statement %prec LOWER_THAN_ELSE { //System.out.print("if "+$1.charno+" 1st p "+$2.charno+" expr "+$3.charno+" 2nd p "+$4.charno); //System.err.println("-- if Statement"); $$ = $3; ((ExprNode)$$).genCode(npp); //System.out.println(" output "+$$.charno+" end "+$4.charno); npp.addGenCode((ExprNode)$$, $4); } | IF '(' expression ')' statement ELSE statement { //System.err.println("-- if-else Statement"); $$ = $3; ((ExprNode)$$).genCode(npp); npp.addGenCode((ExprNode)$$, $4); } | WHILE '(' expression ')' statement { //System.err.println("-- while Statement"); $$ = $3; ((ExprNode)$$).genCode(npp); npp.addGenCode((ExprNode)$$, $4 ); } | DO statement WHILE '(' expression ')' ';' { //System.err.println("-- do-while Statement"); $$ = $5; ((ExprNode)$$).genCode(npp); npp.addGenCode((ExprNode)$$, $6); } | verbatim_line | CONNECT '(' '{' portrefList '}' ',' '{' portrefList '}' ')' ';' {// MULTIPLEX //System.err.println("-- multpiple to multiple connect Statement"); npp.addGenCode(" /* conn",$1) ; npp.addGenCode("; */",$11) ; String expandedconn=((PortListNode)$4).multiplex((PortListNode)$8); npp.addGenCode(expandedconn,$1.lineno+1,0, 0,-1); } | CONNECT '(' '{' portrefList '}' ',' portrefSymbol ')' ';' {// FAN-IN //System.err.println("-- multiple to one connect Statement"); npp.addGenCode(" /* conn",$1) ; npp.addGenCode("; */",$9) ; String expandedconn=((PortListNode)$4).fanin($7.text); npp.addGenCode(expandedconn,$1.lineno+1,0, 0,-1); } | CONNECT '(' portrefSymbol ',' '{' portrefList '}' ')' ';' {// FAN-OUT //System.err.println("-- one to multiple connect Statement"); npp.addGenCode(" /* conn",$1) ; npp.addGenCode("; */",$9) ; npp.addGenCode(" /* conn",$1) ; npp.addGenCode("; */",$9) ; String expandedconn=((PortListNode)$6).fanout($3.text); npp.addGenCode(expandedconn,$1.lineno+1,0, 0,-1); } | CONNECT '(' portrefSymbol ',' portrefSymbol ')' ';' { //System.err.println("-- one to one connect Statement"); npp.addGenCode("nslConnect",$1); //npp.addGenCode(PortListNode.root(($3).text)+",\""+PortListNode.tail(($3).text)+"\"",$3); //npp.addGenCode(PortListNode.root(($5).text)+",\""+PortListNode.tail(($5).text)+"\"",$5); $$=$7; } /*commented out to disallow old style of connect | CONNECT '(' portNode ',' expression ',' portNode ',' expression ')' ';' { npp.addGenCode("nslConnect",$1); } */ | NSLMULTI '(' ')' ';' { //System.err.println("-- nsl operators Statement"); npp.addGenCode(NslConvert($1.text),$1);} | BREAK ';' | BREAK simpleSymbol ';' | CONTINUE ';' | CONTINUE simpleSymbol ';' | nslreturn ';' | nslreturn expression ';' { //System.err.println("-- nsl return ? Statement"); $$ = $2; ((ExprNode)$$).genCode(npp); npp.addGenCode((ExprNode)$$, $3); } | FOR '(' forInit optExpression forIncr ')' statement | THROW expression ';' { //System.err.println("-- throw Statement"); $$ = $2; ((ExprNode)$$).genCode(npp); npp.addGenCode((ExprNode)$$, $3); } | SYNCHRONIZED '(' expression ')' statement { //System.err.println("-- synchronized Statement"); $$ = $3; ((ExprNode)$$).genCode(npp); npp.addGenCode((ExprNode)$$, $4); } | simpleSymbol ':' statement %prec NOT_AN_OPERATOR | TRY compoundStatement catchList optFinally | TRY compoundStatement finally | SWITCH '(' expression ')' compoundStatement { //System.err.println("-- switch Statement"); $$ = $3; ((ExprNode)$$).genCode(npp); npp.addGenCode((ExprNode)$$, $4); } | CASE expression ':' statement { //System.err.println("-- case Statement"); $$ = $2; ((ExprNode)$$).genCode(npp); npp.addGenCode((ExprNode)$$, $3); } | DEFAULT ':' statement ; /* commented out to disallow old style of connect // added to allow "this" to be passed as an argument for connect portNode : simpleSymbol | THIS { $$ = $1; } ; */ optExpression : ';' | expression ';' { //System.err.println("-- optExpression"); $$ = $1; ((ExprNode)$$).genCode(npp); npp.addGenCode((ExprNode)$$, $2); } ; forInit : ';' | expressionStatements ';' { //System.err.println("-- forInit"); $$ = $1; ((ExprNode)$$).genCode(npp); npp.addGenCode((ExprNode)$$, $2); } | variableDeclaration ; portList: '{' argumentList '}' { $$=$2; } ; verbatim_line: VERBATIM_NSLJ { npp.addGenCode("/* verbatim NSLJ */",$1); vlang='J'; } | VERBATIM_NSLC { npp.addGenCode("/* verbatim NSLC */",$1); vlang='C'; } | VERBATIM_OFF { if (vlang=='J') { npp.addGenCode("/* verbatim off */",$1); } else { npp.addGenCode("off */",$1); } } ; forIncr : | expressionStatements ; expressionStatements : expressionStatement { //System.err.println("-- expressionStatement"); $$ = $1; ((ExprNode)$$).genCode(npp); } | expressionStatements ',' expressionStatement { // System.err.println("-- expressionStatement list"); ((ExprsNode)($1)).addTail($3); ((ExprNode)$3).genCode(npp); $$ = $1; } ; optFinally : | finally ; finally : FINALLY compoundStatement ; catchList : catchItem | catchList catchItem { } ; catchItem : CATCH '(' qualifiedSymbol simpleSymbol ')' compoundStatement ; expression : qualifiedSymbol { $$ = npp.resolveVar($1); TypeNode t= ((ExprNode)($$)).type; if (t==null) ((ExprNode)$$).nslSymbol=false; else if (t.nslNumeric || t.nslBool) ((ExprNode)$$).nslSymbol=true; else ((ExprNode)$$).nslSymbol=false; /* System.err.println("&&&&&& HEY HEY &&&&&& for "+$1.text); if (((ExprNode)($$)).type==null) System.err.println(" && Cannot resolve variable: "+($1).text); else System.err.println(" && Resolved Variable: "+($1).text+" with type:"+((ExprNode)($$)).type); */ } | nonSymbolExpression { $$ = $1; } ; symbolArrayExpression : qualifiedSymbolWithLBracket expression ']' { YYtoken n = npp.resolveVar($1); $$ = new ArrayIndexNode((ExprNode)n, ((ExprNode)($2))); // System.err.println("The begining of an array: "+$1.text+" ["+$2+"]"); if (((ArrayIndexNode)$$).getDim()<0) { yyerror("Invalid Array - addressing Dim="+((ArrayIndexNode)$$).getDim()); } // int errcode = ((ArrayIndexNode)$$).genCode(npp); // System.out.println("code#"+errcode+"\t"+((ArrayIndexNode)$$).code); }; nonSymbolExpression : expressionStatement { $$ = $1;} | expression '?' expression ':' expression { $$ = new TrinaryExprNode((ExprNode)$1, (ExprNode)$3, (ExprNode)$5); } | expression BIT_MUL expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression OR expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression AND expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression '|' expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression '&' expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression '^' expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression EQUAL_COMPARE expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression NOT_EQUAL expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression LTEQ expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression GTEQ expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression '<' expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression '>' expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression BITSHIFT_RIGHT expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression FILL_SHIFT_RIGHT expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression SHIFT_LEFT expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression '+' expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression '-' expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression '*' expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression '@' expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression '/' expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression '%' expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } /* $$ = new BinaryExprNode((ExprNode)$1, OR, (ExprNode)$3); } | expression AND expression { $$ = new BinaryExprNode((ExprNode)$1, AND, (ExprNode)$3); } | expression '|' expression { $$ = new BinaryExprNode((ExprNode)$1, '|', (ExprNode)$3); } | expression '&' expression { $$ = new BinaryExprNode((ExprNode)$1, '&', (ExprNode)$3); } | expression '^' expression { $$ = new BinaryExprNode((ExprNode)$1, '^', (ExprNode)$3); } | expression EQUAL_COMPARE expression { $$ = new BinaryExprNode((ExprNode)$1, EQUAL_COMPARE, (ExprNode)$3); } | expression NOT_EQUAL expression { $$ = new BinaryExprNode((ExprNode)$1, NOT_EQUAL, (ExprNode)$3); } | expression LTEQ expression { $$ = new BinaryExprNode((ExprNode)$1, LTEQ, (ExprNode)$3); } | expression GTEQ expression { $$ = new BinaryExprNode((ExprNode)$1, GTEQ, (ExprNode)$3); } | expression '<' expression { $$ = new BinaryExprNode((ExprNode)$1, '<', (ExprNode)$3); } | expression '>' expression { $$ = new BinaryExprNode((ExprNode)$1, '>', (ExprNode)$3); } | expression BITSHIFT_RIGHT expression { $$ = new BinaryExprNode((ExprNode)$1, BITSHIFT_RIGHT, (ExprNode)$3); } | expression FILL_SHIFT_RIGHT expression { $$ = new BinaryExprNode((ExprNode)$1, FILL_SHIFT_RIGHT, (ExprNode)$3); } | expression SHIFT_LEFT expression { $$ = new BinaryExprNode((ExprNode)$1, SHIFT_LEFT, (ExprNode)$3); } | expression '+' expression { $$ = new BinaryExprNode((ExprNode)$1, '+', (ExprNode)$3); } | expression '-' expression { $$ = new BinaryExprNode((ExprNode)$1, '-', (ExprNode)$3); } | expression '*' expression { $$ = new BinaryExprNode((ExprNode)$1, '*', (ExprNode)$3); } | expression '@' expression { $$ = new BinaryExprNode((ExprNode)$1, '@', (ExprNode)$3); } | expression '/' expression { $$ = new BinaryExprNode((ExprNode)$1, '/', (ExprNode)$3); } | expression '%' expression { $$ = new BinaryExprNode((ExprNode)$1, '%', (ExprNode)$3); } */ | '-' expression %prec UMINUS { $2.charno = $1.charno; $2.lineno = $1.lineno; $$ = new UnaryExprNode((ExprNode)$2, '-'); } | '+' expression %prec UPLUS { $2.charno = $1.charno; $2.lineno = $1.lineno; $$ = new UnaryExprNode((ExprNode)$2, '+'); } | '!' expression { $2.charno = $1.charno; $2.lineno = $1.lineno; $$ = new UnaryExprNode((ExprNode)$2, '!'); } | '~' expression { $2.charno = $1.charno; $2.lineno = $1.lineno; $$ = new UnaryExprNode((ExprNode)$2, '~'); } | expression INSTANCEOF type { $$ = $1; } | cast {$$=$1;} | nonSymbolComplexPrimary {$$ = $1;} | SUPER {$$ = new SpecialExprNode($1, SpecialExprNode.SUPER);} | THIS {$$ =new SpecialExprNode($1, SpecialExprNode.THIS);} | NULL_TOKEN {$$ =new SpecialExprNode($1, SpecialExprNode.NULL);} ; nonSymbolComplexPrimary : literal { $$ = $1;} | '(' nonSymbolExpression ')' { $2.charno = $1.charno; $2.lineno = $1.lineno; $$ = $2;} | '(' qualifiedSymbol ')' { $2.charno = $1.charno; $2.lineno = $1.lineno; $$ = npp.resolveVar($2); /* if (((ExprNode)($$)).type==null) System.out.println("Cannot resolve variable: "+($2).text); else System.out.println("Resolved Variable: "+($2).text); */ } | nonSymbolComplexPrimary '[' expression ']' { $$ = new ArrayIndexNode((ExprNode)$1,(ExprNode)$3); // System.err.println("Array continued: "+$1.text+" ["+$3+"]"); if (((ArrayIndexNode)$$).getDim()<0) { yyerror("Invalid Array -- addressing.Dim="+((ArrayIndexNode)$$).getDim()); } // ((ArrayIndexNode)$$).genCode(npp); } | methodCall '[' expression ']' { $$ = new ArrayIndexNode((ExprNode)$1,(ExprNode)$3); if (((ArrayIndexNode)$$).getDim()<0) { yyerror("Invalid Array --- addressing.Dim="+((ArrayIndexNode)$$).getDim()); } // ((ArrayIndexNode)$$).genCode(npp); } | nonSymbolExpression '.' simpleSymbol { $$ = $1; ((ExprNode)$$).code += ('.'+$3.text); } | symbolArrayExpression { $$ = $1;} ; expressionStatement : expression '=' expression { //System.err.println("Asignment: "+$1.text+" = "+$3.text); $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); // ((BinaryExprNode)$$).genCode(npp); } | expression SHIFT_RIGHT_EQUALS expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression FILL_SHIFT_RIGHT_EQUALS expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression SHIFT_LEFT_EQUALS expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression ADD_EQUALS expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression SUB_EQUALS expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression MUL_EQUALS expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression DIV_EQUALS expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression MOD_EQUALS expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression AND_EQUALS expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression XOR_EQUALS expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | expression OR_EQUALS expression { $$ = new BinaryExprNode((ExprNode)$1, $2, (ExprNode)$3); } | INCR expression { $2.charno = $1.charno; $2.lineno = $1.lineno; $$ = new UnaryExprNode((ExprNode)$2, UnaryExprNode.PRE_INCR); } | DECR expression { $2.charno = $1.charno; $2.lineno = $1.lineno; $$ = new UnaryExprNode((ExprNode)$2, UnaryExprNode.PRE_DECR); } | expression INCR %prec POST_INCR { $$ = new UnaryExprNode((ExprNode)$1, UnaryExprNode.POST_INCR); } | expression DECR %prec POST_DECR { $$ = new UnaryExprNode((ExprNode)$1, UnaryExprNode.POST_DECR); } | methodCall { $$ = $1;} | newExpression { $$ = $1;} | nslInstantiation { NslInstNode ni=(NslInstNode)$1; npp.addGenCode( ni.variablename+" = new "+ ni.typestring,$1); // Catch NslNumerics within methods and add new // System.err.println("debug: nslInstantiation-"+ni.variablename+" = new "+ni.typestring); } ; methodCall : qualifiedSymbol '(' optArgumentList ')' { int separator = $1.text.lastIndexOf('.'); if(separator != -1 && $1.text.indexOf('.')==separator) { // contains dot YYtoken tmptoken = new YYtoken(YYtokentypes.SYMBOL, $1.text.substring(0,separator), $1.lineno, $1.charno, $1.charno0); // token.text =method_sym.text.substring(0,separator); $1.text = $1.text.substring(separator+1); ExprNode expr = (ExprNode)npp.resolveVar(tmptoken); /* if (expr.type == null) { System.out.println("null type error!!!"); } */ $$ = new MethodCallNode((ExprNode)npp.resolveVar(tmptoken), $1, (ExprsNode)$3); } else /* we do nothing to the methodCall at the current stage */ $$ = new MethodCallNode($1, (ExprsNode)$3); } | nonSymbolExpression '.' simpleSymbol '(' optArgumentList ')' { $$ = new MethodCallNode((ExprNode)$1, $3, (ExprsNode)$5); } | NSLMULTI '(' optArgumentList ')' { //System.err.println("HERE!@!@@#!# for "+$1.text); // $1.charno = $2.charno; // $1.lineno = $2.lineno; // npp.addGenCode("[",$2); // npp.addGenCode(NslConvert($1.text),$1); $$ = new MethodCallNode((YYtoken)($1), (ExprsNode)$3); ((MethodCallNode)$$).expandedname=NslConvert($1.text); ((MethodCallNode)$$).processed=true; } | NSLMULTI '(' expression ')' { if (!($3 instanceof ExprsNode)) $$ = new MethodCallNode((YYtoken)($1), (ExprsNode)(new ExprsNode($3))); else $$ = new MethodCallNode((YYtoken)($1), (ExprsNode)$3); ((MethodCallNode)$$).expandedname=NslConvert($1.text); ((MethodCallNode)$$).processed=true; } ; cast : '(' simpleType optArrayBounds ')' expression %prec CAST { $2.charno = $1.charno; $2.lineno = $1.lineno; /* check things like (NslDouble2d) x, where x is a NslInt2d */ ((TypeNode)$2).addDim($3); /* check dimension */ /* do some process in expression creation */ $$ = new CastNode((TypeNode)($2), (ExprNode)($5)); // ((CastNode)$$).genCode(npp); } | '(' qualifiedSymbol ')' expression %prec CAST { $2.charno = $1.charno; $2.lineno = $1.lineno; $$ = new CastNode(new TypeNode(TypeNode.CLASS, ($2)), (ExprNode)($4)); // ((CastNode)$$).genCode(npp); } | '(' qualifiedSymbolWithLBracket ']' optArrayBounds ')' expression %prec CAST { $2.charno = $1.charno; $2.lineno = $1.lineno; TypeNode n = new TypeNode(TypeNode.CLASS, $2); n.addDim(1); n.addDim($4); $$ = new CastNode(n, (ExprNode)($6)); // ((CastNode)$$).genCode(npp); } ; newExpression : NEW simpleType '[' allocationBounds { //(new TypeNode($2)).addDim(((ExprsNode) ($4)).list.size()); TypeNode tn = new TypeNode($2); tn.addDim(((ExprsNode) ($4)).list.size()); $$ = (YYtoken)(new NewNode(tn, (ExprsNode)($4), null)); } | NEW qualifiedSymbol '[' allocationBounds { TypeNode tn = new TypeNode($2); tn.addDim(((ExprsNode) ($4)).list.size()); $$ = (YYtoken)(new NewNode(tn, (ExprsNode)($4), null)); } | NEW qualifiedSymbol { $$ = (YYtoken)(new NewNode(new TypeNode($2), null, null)); } | NSLMODULE qualifiedSymbol '(' optArgumentList ')' { $$ = (YYtoken)(new NewNode(new TypeNode($2), null, (ExprsNode)($4))); //npp.addGenCode("new",$1); } //| NSLMODEL qualifiedSymbol '(' optArgumentList ')' //{ // $$ = (YYtoken)(new NewNode(new TypeNode($2), null, (ExprsNode)($4))); // //npp.addGenCode("new",$1); // } | NEW qualifiedSymbol '(' optArgumentList ')' { $$ = (YYtoken)(new NewNode(new TypeNode($2), null, (ExprsNode)($4))); } | qualifiedSymbol NSLMODULE qualifiedSymbol '(' optArgumentList ')' { npp.addGenCode("",$1); /* remove the first word */ $$ = (YYtoken)(new NewNode(new TypeNode($3),null,(ExprsNode)($5))); ((NewNode)$$).processed=true; //-ERH:not required ExprNode left = new ExprNode($1); left.charno = $1.charno; left.lineno = $1.lineno; YYtoken op = new YYtoken('=',"="); //ERH: check this ExprNode right = (ExprNode)$$; $$ = new BinaryExprNode(left,op,right); ((BinaryExprNode)$$).processed=true; } //| qualifiedSymbol NSLMODEL qualifiedSymbol '(' optArgumentList ')' // { // npp.addGenCode("",$1); /* remove the first word */ // $$ = (YYtoken)(new NewNode(new TypeNode($3),null,(ExprsNode)($5))); // ((NewNode)$$).processed=true; //-ERH:not required // ExprNode left = new ExprNode($1); // left.charno = $1.charno; // left.lineno = $1.lineno; // YYtoken op = new YYtoken('=',"="); //ERH: check this // ExprNode right = (ExprNode)$$; // $$ = new BinaryExprNode(left,op,right); // ((BinaryExprNode)$$).processed=true; // } | qualifiedSymbol '(' optArgumentList ')' qualifiedSymbol { /* This was once used to lexically convert new-less instantiations to reguler new statements //convert newless statement /// System.out.println("// CATCH:"+$1.text+" "+$2.text+" "+$4.text); //#1 npp.addGenCode($2.text+" = new "+$1.text,$1); //#1 npp.addGenCode("",$2); // remove variable name */ npp.addGenCode("",$1); /* remove the first word */ $$ = (YYtoken)(new NewNode(new TypeNode($1),null,(ExprsNode)($3))); ((NewNode)$$).processed=true; //-ERH:not required ExprNode left = new ExprNode($5); left.charno = $1.charno; left.lineno = $1.lineno; YYtoken op = new YYtoken('=',"="); //ERH: check this ExprNode right = (ExprNode)$$; $$ = new BinaryExprNode(left,op,right); ((BinaryExprNode)$$).processed=true; } /* | NSLENV '(' optArgumentList ')' qualifiedSymbol { //System.out.println("//NSLENV returned with "+$2.text+" with args:"+$4.text); //npp.addGenCode( "Nsl"+$1.text.substring(6,$1.text.length())+" " + // $2.text+" = " + // "(Nsl"+$1.text.substring(6,$1.text.length())+")"+ // "env (new Nsl"+$1.text.substring(6,$1.text.length()),$1); // npp.addGenCode("))",$5); //npp.addGenCode("",$2); npp.addGenCode("",$1); npp.addGenCode("",$2); if ($3!=null) npp.addGenCode("",$3); npp.addGenCode("",$4); if ($1.text.equals("NslVisible")) npp.addGenCode("\t"+$5+"=(Nsl"+$1.text.substring(7,$1.text.length())+")"+ "NslVisible("+$5+");\n" ,$1.lineno+1,0, 0,-1); else npp.addGenCode("\t"+$5+"=(Nsl"+$1.text.substring(7,$1.text.length())+")"+ "common("+$5+");\n" ,$1.lineno+1,0, 0,-1); //ERH: I could make this one line if I had used castnode node (for // env method return) TypeNode tt= new TypeNode($1); tt.text="Nsl"+$1.text.substring(7,$1.text.length()); tt.setProperties($1.text); // use the nslnumeric properties $$ = (YYtoken)(new NewNode(tt,null,(ExprsNode)($3))); ExprNode left = new ExprNode($5); YYtoken op = new YYtoken('=',"="); // ERH:check this ExprNode right = (ExprNode)$$; $$ = new BinaryExprNode(left,op,right); $$.lineno=$1.lineno; $$.charno=$1.charno; ((BinaryExprNode)$$).processed=true; } */ ; allocationBounds : expression ']' { $$=new ExprsNode($1); } | expression ']' '[' allocationBounds { $$=$4; ((ExprsNode)($$)).addHead($1); } | expression ']' '[' ']' optArrayBounds { $$=$4; { int count = ((Int_Token)($5)).int_val; while (count-- > 0) ((ExprsNode)($$)).addTail((YYtoken)null); } } ; optArrayBounds : { $$ = null; } | optArrayBounds '[' ']' { if ($1==null) $$ = (YYtoken) (new Int_Token(YYtokentypes.nt_optArrayBounds, $2, 1)); else { ((Int_Token)($1)).int_val ++; $$ = $1; } } ; literal : INT_LITERAL {$$ = new ExprNode(new TypeNode(TypeNode.INT, $1), $1);} | STRING_LITERAL {$$ = new ExprNode(new TypeNode(TypeNode.STRING, $1), $1);} | CHARACTER_LITERAL {$$ = new ExprNode(new TypeNode(TypeNode.CHAR, $1), $1);} | LONG_LITERAL {$$ = new ExprNode(new TypeNode(TypeNode.LONG, $1), $1);} | FLOAT_LITERAL {$$ = new ExprNode(new TypeNode(TypeNode.FLOAT, $1), $1);} | DOUBLE_LITERAL {$$ = new ExprNode(new TypeNode(TypeNode.DOUBLE, $1), $1);} | TRUE_TOKEN {$$ = new ExprNode(new TypeNode(TypeNode.BOOL, $1), $1);} | FALSE_TOKEN {$$ = new ExprNode(new TypeNode(TypeNode.BOOL, $1), $1);} ; optArgumentList : { $$ = null; // System.err.println("optArgumentList: returning NULL"); } | argumentList { $$ = $1; // System.err.println("optArgumentList: returning: "+$1.text); } ; argumentList : expression { $$ = new ExprsNode($1); // System.err.println("argumentList: evluating the last expression "+$1.text); } | argumentList ',' expression { if($3!=null)((ExprsNode)$1).addTail($3); $$ = $1; // System.err.println("argumentList: evluating an expression "+$3.text); } ; type : qualifiedSymbolWithLBracket ']' optArrayBounds { $$ = (YYtoken) (new TypeNode(TypeNode.CLASS, $1)); ((TypeNode)$$).addDim(1); // for the first pair of blanket ((TypeNode)$$).addDim($2); } | qualifiedSymbol { $$ = (YYtoken) (new TypeNode(TypeNode.CLASS, $1)); } | simpleType optArrayBounds { if(($2)!=null) { ((TypeNode)$1).addDim($2); } $$ = $1; } ; qualifiedSymbolWithLBracket : qualifiedSymbol '[' { $$=$1; /* = npp.resolveVar($1); if (((ExprNode)($$)).type==null) System.out.println("Cannot resolve variable: "+($1).text); else System.out.println("Resolved Variable: "+($1).text); */ } ; simpleType : Erh_simpleType | SPECIAL Erh_simpleType {$$=$2;} ; Erh_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)); $$.text = "String"; npp.addGenCode("String", $1); } | VOID { $$ = (YYtoken) (new TypeNode(TypeNode.VOID, $1)); } ; YmodifierList: YmodifierList PRIVATE // | YmodifierList EXTERNAL // {npp.addGenCode("public",$2);} // | YmodifierList INTERNAL // {npp.addGenCode("private",$2);} | YmodifierList PUBLIC | YmodifierList PROTECTED | YmodifierList STATIC | YmodifierList TRANSIENT | YmodifierList VOLATILE | YmodifierList FINAL | YmodifierList NATIVE | YmodifierList SYNCHRONIZED | PRIVATE | PUBLIC | PROTECTED | STATIC | TRANSIENT | VOLATILE | FINAL | NATIVE | SYNCHRONIZED // | INTERNAL // {npp.addGenCode("private",$1);} // | EXTERNAL // {npp.addGenCode("public",$1);} ; XmodifierList : // | XmodifierList INTERNAL // {npp.addGenCode("private",$2);} // | XmodifierList EXTERNAL // {npp.addGenCode("public",$2);} | XmodifierList PRIVATE | XmodifierList PUBLIC | XmodifierList PROTECTED | XmodifierList STATIC | XmodifierList TRANSIENT | XmodifierList VOLATILE | XmodifierList FINAL | XmodifierList NATIVE | XmodifierList SYNCHRONIZED ; modifierList : XmodifierList | modifierList ABSTRACT ; qualifiedSymbol : simpleSymbol { $$ = $1; } | qualifiedSymbol '.' simpleSymbol { ($1).text += ("."+($3).text); ($1).tokentype = YYtokentypes.nt_qualifiedSymbol; $$ = $1;} ; portrefSymbol : simpleSymbol { $$ = $1; } | simpleSymbol '.' simpleSymbol { ($3).text = (($1).text+"."+($3).text); ($3).tokentype = YYtokentypes.nt_qualifiedSymbol; $$ = $3;} | THIS '.' simpleSymbol { ($3).text = (($1).text+"."+($3).text); ($3).tokentype = YYtokentypes.nt_qualifiedSymbol; $$ = $3;} ; portrefList : portrefSymbol { $$ = new PortListNode($1); } | portrefSymbol ',' portrefList { /* if($3!=null)((PortListNode)$1).addHead($3); $$=$1; */ if($1!=null)((PortListNode)$3).addHead($1); $$=$3; $$.text =$1.text+$2.text+$$.text; } ; qualifiedSymbolList : qualifiedSymbol | qualifiedSymbolList ',' qualifiedSymbol ; simpleSymbol : SYMBOL { $$ = $1 ; } ; %% /* put suffix code here */ /* Override yyerror */ public void yyverror(String s) throws ParseException { /* String msg = yyerror_verbose(s); System.out.println("yyverror:" + msg); */ yyerror(s, true); //throw new ParseException(s); } protected NslPreProcessor npp; public void init(NslPreProcessor p) { npp = p; // YYtoken.npp = p; } String remArrDims(String s) { String res; char c,oldc; res="["; oldc='['; // 98/8/25 aa: too many print statements //System.err.println("debug: Entering:"+s); for (int i=0;i CONVERT: ["+s+"]"); if (s.equals("nslPrint")) return("System.out.print"); if (s.equals("nslPrintln")) return("System.out.println"); if (s.equals("nslprint")) return("System.out.print"); if (s.equals("nslprintln")) return("System.out.println"); if (s.equals("NslPrint")) return("System.out.print"); if (s.equals("NslPrintln")) return("System.out.println"); //if (s.equals("nslAdd")) return "system.nsladd.eval"; if (s.equals("nslAdd")) return "NslAdd.eval"; if (s.equals("nslConv")) return "NslConv.eval"; if (s.equals("nslConvzero")) return "NslConvZero.eval"; if (s.equals("nslConvW")) return "NslConvW.eval"; if (s.equals("nslConvC")) return "NslConvC.eval"; // cannot have NslDiff because we would need static // and abstract methods cannot also be static if (s.equals("nslDiff")) return "system.nsldiff.eval"; if (s.equals("nslFillColumns")) return "NslFillColumns.eval"; if (s.equals("nslFillRows")) return "NslFillRows.eval"; if (s.equals("nslMath")) return "system.nslmath.eval"; if (s.equals("nslMaxValue")) return "NslMaxValue.eval"; if (s.equals("nslMinValue")) return "NslMinValue.eval"; if (s.equals("nslProd")) return "NslProd.eval"; if (s.equals("nslProduct")) return "NslProd.eval"; if (s.equals("nslRamp")) return "NslRamp.eval"; if (s.equals("nslSaturation")) return "NslSaturation.eval"; if (s.equals("nslSigmoid")) return "NslSigmoid.eval"; if (s.equals("nslSigmoid2")) return "NslSigmoid2.eval"; if (s.equals("nslStep")) return "NslStep.eval"; if (s.equals("nslSub")) return "NslSub.eval"; if (s.equals("nslTrans")) return "NslTrans.eval"; if (s.equals("nslSum")) return "NslSum.eval"; if (s.equals("nslSumRows")) return "NslSumRows.eval"; if (s.equals("nslSumColumns")) return "NslSumColumns.eval"; if (s.equals("nslMaxElem")) return "NslMaxElem.eval"; if (s.equals("nslMinElem")) return "NslMinElem.eval"; if (s.equals("nslGetSector")) return "NslGetSector.eval"; if (s.equals("nslSetSector")) return "NslSetSector.eval"; if (s.equals("nslElemMult")) return "NslElemMult.eval"; if (s.equals("nslElemDiv")) return "NslElemDiv.eval"; if (s.equals("nslConcatenateRows")) return "NslConcatenateRows.eval"; if (s.equals("nslConcatenateColumns")) return "NslConcatenateColumns.eval"; if (s.equals("nslGetRow")) return "NslGetRow.eval"; if (s.equals("nslGetColumn")) return "NslGetColumn.eval"; if (s.equals("nslRandom")) return "NslRandom.eval"; if (s.equals("nslGuassian")) return "NslGuassian.eval"; if (s.equals("nslAll")) return "NslAll.eval"; if (s.equals("nslSome")) return "NslSome.eval"; if (s.equals("nslNone")) return "NslNone.eval"; if (s.equals("nslBound")) return "NslBound.eval"; if (s.equals("nslDotProd")) return "NslDotProd.eval"; // NslOperations if (s.equals("nslRint")) return "NslOperator.rint.eval"; if (s.equals("nslAbs")) return "NslOperator.abs.eval"; if (s.equals("nslPow")) return "NslOperator.pow.eval"; if (s.equals("nslExp")) return "NslOperator.exp.eval"; if (s.equals("nslLog")) return "NslOperator.log.eval"; if (s.equals("nslMaxMerge")) return "NslOperator.max.eval"; if (s.equals("nslMinMerge")) return "NslOperator.min.eval"; if (s.equals("nslCos")) return "NslOperator.cos.eval"; if (s.equals("nslSin")) return "NslOperator.sin.eval"; if (s.equals("nslTan")) return "NslOperator.tan.eval"; if (s.equals("nslArcCos")) return "NslOperator.acos.eval"; if (s.equals("nslArcSin")) return "NslOperator.asin.eval"; if (s.equals("nslArcTan")) return "NslOperator.atan.eval"; if (s.equals("nslSqrt")) return "NslOperator.sqrt.eval"; if (s.equals("nslDistance")) return "NslOperator.distance.eval"; return "UNRECOGNIZED"; } char vlang; /* used by verbatim stuff */ // thr // This method would recursively call itself // For now its assumed that the java profiler would have generated the // relevant tmp file. /* public Stack addBClassVar(NslPreProcessor p, String bClass){ // invoke new parser to parse bClass // return appropriate stack of variables static varStack = new Stack(); yybl = new YYBlex(bClass.tmp); yybl.init(patch); yybp = new YYBparse(yyl, System.err); yybp.init(patch); yybp.yyparse(); varStack = patch.getVarStack(); String bbClass = yyparse.init(bClass.tmp); varStack.push(addBClassVar(p, bbClass); } public Stack YYBparse::init(String tmpClass) { } */