?? parsell1.cpp
字號(hào):
currentP->idnum++;
}
void process12()
{
Push(1,BaseType);
/*由于數(shù)組基類(lèi)型的問(wèn)題,這里不能直接用currentP->kind.dec=IntegerK;
而應(yīng)該這么做,以適應(yīng)所有情形*/
temp=&(currentP->kind.dec);
}
void process13()
{
Push(1,StructureType);
}
void process14()
{
Push(2,ID);
/*聲明的類(lèi)型部分為類(lèi)型標(biāo)識(shí)符*/
(*currentP).kind.dec=IdK;
strcpy(currentP->attr.type_name ,currentToken.Sem);
}
void process15()
{
Push(2,INTEGER);
/*聲明的類(lèi)型部分為整數(shù)類(lèi)型*/
(*temp)=IntegerK;
}
void process16()
{
Push(2,CHAR);
/*聲明的類(lèi)型部分為子符類(lèi)型*/
(*temp) =CharK;
}
void process17()
{
Push(1,ArrayType);
}
void process18()
{
Push(1,RecType);
}
void process19()
{
Push(1,BaseType);
Push(2,OF);
Push(2,RMIDPAREN);
Push(1,Top);
Push(2,UNDERANGE);
Push(1,Low);
Push(2,LMIDPAREN);
Push(2,ARRAY);
/*聲明的類(lèi)型為數(shù)組類(lèi)型*/
(*currentP).kind.dec=ArrayK;
temp = &(currentP->attr.ArrayAttr.childtype);
}
void process20()
{
Push(2,INTC);
/*存儲(chǔ)數(shù)組的下屆*/
(*currentP).attr.ArrayAttr.low=atoi(currentToken.Sem);
}
void process21()
{
Push(2,INTC);
/*存儲(chǔ)數(shù)組的上屆*/
(*currentP).attr.ArrayAttr.up=atoi(currentToken.Sem);
}
void process22()
{
Push(2,END);
Push(1,FieldDecList);
Push(2,RECORD);
/*聲明的類(lèi)型部分為記錄類(lèi)型*/
(*currentP).kind.dec=RecordK;
saveP = currentP; /*壓入當(dāng)前節(jié)點(diǎn),是為了處理完后回到當(dāng)前節(jié)點(diǎn),
主要是為了變量聲明部分標(biāo)識(shí)符部分在后面,考慮*/
PushPA(&((*currentP).child[0]));
}
void process23()
{
Push(1,FieldDecMore);
Push(2,SEMI);
Push(1,IdList);
Push(1,BaseType);
TreeNode **t=PopPA();
currentP = newDecNode(); /*生成記錄類(lèi)型的下一個(gè)域,不添任何信息*/
temp=(&(currentP->kind.dec));
(*t) = currentP; /*若是第一個(gè),則是record類(lèi)型的子結(jié)點(diǎn)指向當(dāng)前結(jié)點(diǎn),
否則,是上一個(gè)紀(jì)錄域聲明的兄弟結(jié)點(diǎn)*/
PushPA(&((*currentP).sibling));
}
void process24()
{
Push(1,FieldDecMore);
Push(2,SEMI);
Push(1,IdList);
Push(1,ArrayType);
TreeNode **t=PopPA();
currentP = newDecNode(); /*生成記錄類(lèi)型的下一個(gè)域,不添任何信息*/
(*t) = currentP; /*若是第一個(gè),則是record類(lèi)型的子結(jié)點(diǎn)指向當(dāng)前結(jié)點(diǎn),
否則,是上一個(gè)紀(jì)錄域聲明的兄弟結(jié)點(diǎn)*/
PushPA(&((*currentP).sibling));
}
void process25()
{
/*后面沒(méi)有記錄類(lèi)型的下一個(gè)域了,恢復(fù)當(dāng)前紀(jì)錄類(lèi)型節(jié)點(diǎn)的指針*/
PopPA( );
currentP = saveP;
}
void process26()
{
Push(1,FieldDecList);
}
void process27()
{
Push(1,IdMore);
Push(2,ID);
/*紀(jì)錄一個(gè)域中各個(gè)變量的語(yǔ)義信息*/
strcpy(currentP->name[currentP->idnum], currentToken.Sem);
currentP->idnum++;
}
void process28()
{
}
void process29()
{
Push(1,IdList);
Push(2,COMMA);
}
void process30()
{
}
void process31()
{
Push(1,VarDeclaration);
}
void process32()
{
Push(1,VarDecList);
Push(2,VAR);
currentP=newVarNode(); /*生成一個(gè)標(biāo)志變量聲明的節(jié)點(diǎn)*/
TreeNode **t=PopPA();
(*t)=currentP;
PushPA(&((*currentP).sibling)); /*壓入指向函數(shù)聲明的指針*/
PushPA(&((*currentP).child[0])); /*壓入指向第一個(gè)變量聲明節(jié)點(diǎn)的指針*/
}
void process33()
{
Push(1,VarDecMore);
Push(2,SEMI);
Push(1,VarIdList);
Push(1,TypeName);
TreeNode **t=PopPA();
currentP = newDecNode();/*建立一個(gè)新的聲明節(jié)點(diǎn),這里表示變量聲明*/
(*t) = currentP; /*若是第一個(gè)節(jié)點(diǎn),則變量聲明的頭指針指向它,
否則它是前一個(gè)變量聲明的后繼*/
PushPA(&((*currentP).sibling));
}
void process34()
{
PopPA( );
}
void process35()
{
Push(1,VarDecList);
}
void process36()
{
Push(1,VarIdMore);
Push(2,ID);
strcpy(currentP->name[currentP->idnum], currentToken.Sem);
currentP->idnum++;
}
void process37()
{
}
void process38()
{
Push(1,VarIdList);
Push(2,COMMA);
}
void process39()
{
}
void process40()
{
Push(1,ProcDeclaration);
}
void process41()
{
Push(1,ProcDecMore);
Push(1,ProcBody);
Push(1,ProcDecPart);
Push(2,SEMI);
Push(2,RPAREN);
Push(1,ParamList);
Push(2,LPAREN);
Push(1,ProcName);
Push(2,PROCEDURE);
currentP=newProcNode();
TreeNode **t=PopPA();
(*t)=currentP;
PushPA(&(currentP->sibling));
PushPA(&(currentP->child[2])); /*指向語(yǔ)句序列*/
PushPA(&(currentP->child[1])); /*指向函數(shù)的聲明部分*/
PushPA(&(currentP->child[0])); /*指向參數(shù)聲明部分*/
}
void process42()
{ /*彈出過(guò)程節(jié)點(diǎn)的兄弟節(jié)點(diǎn)指針*/
//PopPA( ); /*為了統(tǒng)一處理,不能現(xiàn)在彈出*/
}
void process43()
{
Push(1,ProcDeclaration);
}
void process44()
{
Push(2,ID);
strcpy( currentP->name[0] , currentToken.Sem );
currentP->idnum++;
}
void process45()
{
/*形參部分為空,彈出指向形參的指針*/
PopPA();
}
void process46()
{
Push(1,ParamDecList);
}
void process47()
{
Push(1,ParamMore);
Push(1,Param);
}
void process48()
{
PopPA( );
}
void process49()
{
Push(1,ParamDecList);
Push(2,SEMI);
}
void process50()
{
Push(1,FormList);
Push(1,TypeName);
TreeNode **t=PopPA();
currentP=newDecNode();
/*函數(shù)的參數(shù)類(lèi)型是值類(lèi)型*/
currentP->attr.ProcAttr.paramt=valparamType;
(*t)=currentP;
PushPA(&(currentP->sibling));
}
void process51()
{
Push(1,FormList);
Push(1,TypeName);
Push(2,VAR);
TreeNode **t=PopPA();
currentP=newDecNode();
/*函數(shù)的參數(shù)類(lèi)型是變量類(lèi)型*/
currentP->attr.ProcAttr.paramt=varparamType;
(*t)=currentP;
PushPA(&(currentP->sibling));
}
void process52()
{
Push(1,FidMore);
Push(2,ID);
strcpy( currentP->name[currentP->idnum], currentToken.Sem);
currentP->idnum++;
}
void process53()
{
}
void process54()
{
Push(1,FormList);
Push(2,COMMA);
}
void process55()
{
Push(1,DeclarePart);
}
void process56()
{
Push(1,ProgramBody);
}
void process57()
{
Push(2,END);
Push(1,StmList);
Push(2,BEGIN);
/*注意,若沒(méi)有聲明部分,則彈出的是程序或過(guò)程根節(jié)點(diǎn)中指向
聲明部分的指針child[1];若有聲明部分,則彈出的是語(yǔ)句序列前
的最后一個(gè)聲明標(biāo)識(shí)節(jié)點(diǎn)的兄弟指針;不管是哪種情況,都正好
需要彈出語(yǔ)法樹(shù)棧中的一個(gè)指針*/
PopPA();
/*建立語(yǔ)句序列標(biāo)識(shí)節(jié)點(diǎn)*/
TreeNode **t=PopPA();
currentP=newStmlNode();
(*t)=currentP;
PushPA(&(currentP->child[0]));
}
void process58()
{
Push(1,StmMore);
Push(1,Stm);
}
void process59()
{
PopPA( );
}
void process60()
{
Push(1,StmList);
Push(2,SEMI);
}
void process61()
{
Push(1,ConditionalStm);
currentP=newStmtNode(IfK);
//currentP->kind.stmt=;
TreeNode **t=PopPA();
(*t)=currentP;
PushPA(¤tP->sibling);
}
void process62()
{
Push(1,LoopStm);
currentP=newStmtNode(WhileK);
//currentP->kind.stmt=;
TreeNode **t=PopPA();
(*t)=currentP;
PushPA(¤tP->sibling);
}
void process63()
{
Push(1,InputStm);
TreeNode **t=PopPA();
currentP=newStmtNode(ReadK);
//currentP->kind.stmt=;
(*t)=currentP;
PushPA(¤tP->sibling);
}
void process64()
{
Push(1,OutputStm);
TreeNode **t=PopPA();
currentP=newStmtNode(WriteK);
//currentP->kind.stmt=;
(*t)=currentP;
PushPA(¤tP->sibling);
}
void process65()
{
Push(1,ReturnStm);
TreeNode **t=PopPA();
currentP=newStmtNode(ReturnK);
//currentP->kind.stmt=;
(*t)=currentP;
PushPA(¤tP->sibling);
}
void process66()
{
Push(1,AssCall);
Push(2,ID);
currentP=newStmtNode(AssignK);
/*賦值語(yǔ)句左部變量節(jié)點(diǎn)*/
TreeNode *t = newExpNode(VariK);
strcpy( t->name[0], currentToken.Sem );
t->idnum++;
/*賦值語(yǔ)句的child[0]指向左部的變量節(jié)點(diǎn)*/
currentP->child[0]=t;
TreeNode **t1=PopPA();
(*t1)=currentP;
PushPA(¤tP->sibling);
}
void process67()
{
Push(1,AssignmentRest);
currentP->kind.stmt=AssignK;
}
void process68()
{
Push(1,CallStmRest);
/*過(guò)程調(diào)用語(yǔ)句左部是標(biāo)識(shí)符變量,表示過(guò)程名*/
currentP->child[0]->attr.ExpAttr.varkind=IdV;
currentP->kind.stmt=CallK;
}
void process69()
{
Push(1,Exp);
Push(2,ASSIGN);
Push(1,VariMore);
/*壓入指向賦值右部的指針*/
PushPA(&(currentP->child[1]));
/*當(dāng)前指針指向賦值左部*/
currentP=currentP->child[0];
TreeNode *t=newExpNode(OpK);
t->attr.ExpAttr.op = END ;
PushOp(t); //操作符棧的棧底存入一個(gè)特殊的操作符作為標(biāo)志
}
void process70()
{
Push(2,FI);
Push(1,StmList);
Push(2,ELSE);
Push(1,StmList);
Push(2,THEN);
Push(1,RelExp);
Push(2,IF);
PushPA(&(currentP->child[2]));
PushPA(&(currentP->child[1]));
PushPA(&(currentP->child[0]));
}
void process71()
{
Push(2,ENDWH);
Push(1,StmList);
Push(2,DO);
Push(1,RelExp);
Push(2,WHILE);
PushPA(&(currentP->child[1]));
PushPA(&(currentP->child[0]));
}
void process72()
{
Push(2,RPAREN);
Push(1,InVar);
Push(2,LPAREN);
Push(2,READ);
}
void process73()
{
Push(2,ID);
strcpy( currentP->name[0], currentToken.Sem);
currentP->idnum++;
}
void process74()
{
Push(2,RPAREN);
Push(1,Exp);
Push(2,LPAREN);
Push(2,WRITE);
PushPA(&(currentP->child[0]));
TreeNode *t=newExpNode(OpK);
t->attr.ExpAttr.op = END ;
PushOp(t); //操作符棧的棧底存入一個(gè)特殊的操作符作為標(biāo)志
}
void process75()
{
Push(2,RETURN);
}
void process76()
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -