Hey there good people. well i have implemented the whole code of compiler phase 1. Have implemented al the DFAs and most are working fine. But this comments DFA is giving me grief. What it should do is, it should ignore anything written between { } . but it's not doing it. What it does is remove the first character after { and that's it. I am posting the code snippet here. Any kind of help will be greatly appreciated!
e.g.. it should ignore:
{integer program var INTEGER PROGRAM
dfjdfj dhvdfhvk dufhvkhdfv
dkvhnfdk
fkhvkdf
}
but what it does is this:
nteger, Identifier //Notice the missing I
program Reserved words
var Reserved words
INTEGER, Identifier
program Reserved words
dfjdfj, Identifier
dhvdfhvk, Identifier
dufhvkhdfv, Identifier
dkvhnfdk, Identifier
fkhvkdf, Identifier
This is the DFA.
dfa1[0][0]=0;
dfa1[1][1]=2;
dfa1[1][2]=-1;
dfa1[2][1]=-1;
dfa1[2][2]=3;
dfa1[3][1]=-1;
dfa1[3][2]=-1;
This is the code i have implemented:
all the initializations etc have been done. This is just the part of whole phase 1.
dfavalue=1;
accept1=0;
while(dfavalue!=-1){
if(tokenclass.chartoken(t)=='{'){
dfavalue=dfa1[dfavalue][1];
if(dfavalue!=-1){
acceptedtoken1[accept1]=tokenclass.chartoken(t);
accept1++;
t++;
}
}
if(tokenclass.chartoken(t)!='}'){
dfavalue=dfa1[dfavalue][2];
if(dfavalue!=-1){
t++;
}
}
if(tokenclass.chartoken(t)=='}'){
dfavalue=dfa1[dfavalue][2];
if(dfavalue==3 ){
acceptedtoken1[accept1]='}';
accept1++;
acceptedtoken1[accept1]=',';
accept1++;
for(int j=0;j<accept1;j++){
out.print(acceptedtoken1[j]);
if(acceptedtoken1[j]==','){
out.println(" Comments");
}
}
}
else{
errortoken[error]=tokenclass.chartoken(t);
error++;
}
dfavalue=-1;
accept1=0;
}
}
//End implementation Question 1
Any kind of help is greatly appreciated.
Thanks!