. .


7.9. -

. java, Parser. , , . , 7.5.

main, while, . . switch , .

executeAction, Parser,

 

package converter;

 

public class Parser implements MagazineSymbolsName

{

public static Token tkn;

public static int vtype = 0;

 

public static void executeAction(Magazine mg1, LexTab lext, FunTab fft, ValueTable tl, VariableTable tr, AtomTable ta, MagazineSymbol ms, Token tk) throws ParsExcetption{

 

switch(ms.getIndex()){

case MAS:{ta.makeASS(mg1, tr, lext, tl); break;}

case MAD:{ ta.makeAND(mg1, tr, lext, tl); break;}

case MOR:{ ta.makeOR(mg1, tr, lext, tl); break;}

case MNT:{ ta.makeNOT(mg1, tr, lext, tl); break;}

case MVR:{ tr.makeVariable(lext, tk.getIndex(), tl, mg1); break; }

case STP:{ vtype = ta.setType(mg1, lext); break;}

case CVR:{ tr.checkVariable( mg1, tk.getIndex()); break;}

case PAT:{ ta.passAtribute(mg1); break;}

case CKW:{tr.makeValue(mg1, lext, tk.getIndex() ,tl); break;}

case RAT:{ mg1.pop(); break;}

default: throw new ParsExcetption("executeAction: Impossble symbol !");

}

}

 

public static void printResults(LexTab ltlt, VariableTable trtr, AtomTable tata){

String ss;

int k, m;

System.out.println("----------Lex Table-------- ----------------TVR---------------");

System.out.println();

for (int i = 0; i <= LexTab.markLT; i++) {

ss = ltlt.getElementLT(i);

System.out.print(" i=" + i + " " + ss);

m = 20 - ss.length();

k = (i < 10) ? m : m - 1;

for (int j = 0; j < k; j++) System.out.print(" ");

if (i < VariableTable.finger)

System.out.print(" pLexTab= " + trtr.getpointerLexTab(i) + " " +

"pTVL= " + trtr.getIndexTVL(i)

+ " " + "type= " + trtr.getType(i) + " " +

"hasvalue= " + trtr.getHasvalue(i) + " " + "useing = " +

trtr.getUseing(i));

System.out.println();

} //end for

System.out.println();

tata.printTAtom();

System.out.println();

for (int n = 2; n < VariableTable.finger; n++) {

if (trtr.getHasvalue(n) == 0)

System.out.println(" " +

ltlt.getElementLT(trtr.getpointerLexTab(n))+ " ");

if (trtr.getUseing(n) == 0)

System.out.println(" " +

ltlt.getElementLT(trtr.getpointerLexTab(n))+ " ");

}

}

public static void main(String[] args) {

Lexer lxr = new Lexer(args[0]);

FunTab ft = new FunTab();

TsrminalTable ts = new TsrminalTable();

ValueTable tval = new ValueTable();

VariableTable tvar = new VariableTable();

AtomTable tat = new AtomTable();

Parser pr = new Parser();

Magazine mg = new Magazine();

mg.push(new MagazineSymbol(5,1));

MagazineSymbol ms;

LexTab lxt = lxr.getLexTab();

tkn = lxr.getnextToken();

ms = mg.pop();

while(ms != MagazineSymbol.MGnull){

try{

int q = ms.getType();

switch(q){

case Identifier:if ((tkn.getType() == 'I')& (ms.getType() == 1)){

break; }

else throw new ParsExcetption("Parser.case1: ");

 

 

case Keyword: if(((tkn.getType() == 'K')& (ms.getType() == 3)&

(tkn.getIndex() == ms.getIndex()))) break;

else throw new ParsExcetption("Parser.case3: ");

 

case Symbol: if (tkn.getIndex() == ms.getIndex()) {

tkn = lxr.getnextToken();

break; }

else throw new ParsExcetption("Parser.case4: !");

 

case Nonterminal: {

ft.moveInstruction(mg, ms.getIndex());

break; }

 

case ActionSymbol:{

executeAction(mg, lxt, ft, tval, tvar,tat, ms, tkn);

break; }

 

case Atribute:{ break;}

 

case Link:{ throw new ParsExcetption("Parser case 8; Reference at the top !"); }

 

case Read :{ tkn = lxr.getnextToken(); break; }

 

default: {throw new ParsExcetption("ParsA, default: Impossible MGsym !");}

}//end switch

}//end try

catch(ParsExcetption e){ System.out.println("ParsException : "+e.getMessage());System.exit(0);}

if(mg.empty())break; else ms = mg.pop();

}//end while

if(tkn != Token.Toknull) System.out.println(" , !");

else System.out.println(" FIN !");

printResults(lxt, tvar, tat);

}//end main

 

}//end class

 

 

, java converter, java_converter. , javac , Parser java, , .

 


. .