📄 parsell1.cpp
字号:
currentP->idnum++;
}
void process12()
{
Push(1,BaseType);
/*由于数组基类型的问题,这里不能直接用currentP->kind.dec=IntegerK;
而应该这么做,以适应所有情形*/
temp=&(currentP->kind.dec);
}
void process13()
{
Push(1,StructureType);
}
void process14()
{
Push(2,ID);
/*声明的类型部分为类型标识符*/
(*currentP).kind.dec=IdK;
strcpy(currentP->attr.type_name ,currentToken.Sem);
}
void process15()
{
Push(2,INTEGER);
/*声明的类型部分为整数类型*/
(*temp)=IntegerK;
}
void process16()
{
Push(2,CHAR);
/*声明的类型部分为子符类型*/
(*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);
/*声明的类型为数组类型*/
(*currentP).kind.dec=ArrayK;
temp = &(currentP->attr.ArrayAttr.childtype);
}
void process20()
{
Push(2,INTC);
/*存储数组的下届*/
(*currentP).attr.ArrayAttr.low=atoi(currentToken.Sem);
}
void process21()
{
Push(2,INTC);
/*存储数组的上届*/
(*currentP).attr.ArrayAttr.up=atoi(currentToken.Sem);
}
void process22()
{
Push(2,END);
Push(1,FieldDecList);
Push(2,RECORD);
/*声明的类型部分为记录类型*/
(*currentP).kind.dec=RecordK;
saveP = currentP; /*压入当前节点,是为了处理完后回到当前节点,
主要是为了变量声明部分标识符部分在后面,考虑*/
PushPA(&((*currentP).child[0]));
}
void process23()
{
Push(1,FieldDecMore);
Push(2,SEMI);
Push(1,IdList);
Push(1,BaseType);
TreeNode **t=PopPA();
currentP = newDecNode(); /*生成记录类型的下一个域,不添任何信息*/
temp=(&(currentP->kind.dec));
(*t) = currentP; /*若是第一个,则是record类型的子结点指向当前结点,
否则,是上一个纪录域声明的兄弟结点*/
PushPA(&((*currentP).sibling));
}
void process24()
{
Push(1,FieldDecMore);
Push(2,SEMI);
Push(1,IdList);
Push(1,ArrayType);
TreeNode **t=PopPA();
currentP = newDecNode(); /*生成记录类型的下一个域,不添任何信息*/
(*t) = currentP; /*若是第一个,则是record类型的子结点指向当前结点,
否则,是上一个纪录域声明的兄弟结点*/
PushPA(&((*currentP).sibling));
}
void process25()
{
/*后面没有记录类型的下一个域了,恢复当前纪录类型节点的指针*/
PopPA( );
currentP = saveP;
}
void process26()
{
Push(1,FieldDecList);
}
void process27()
{
Push(1,IdMore);
Push(2,ID);
/*纪录一个域中各个变量的语义信息*/
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(); /*生成一个标志变量声明的节点*/
TreeNode **t=PopPA();
(*t)=currentP;
PushPA(&((*currentP).sibling)); /*压入指向函数声明的指针*/
PushPA(&((*currentP).child[0])); /*压入指向第一个变量声明节点的指针*/
}
void process33()
{
Push(1,VarDecMore);
Push(2,SEMI);
Push(1,VarIdList);
Push(1,TypeName);
TreeNode **t=PopPA();
currentP = newDecNode();/*建立一个新的声明节点,这里表示变量声明*/
(*t) = currentP; /*若是第一个节点,则变量声明的头指针指向它,
否则它是前一个变量声明的后继*/
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])); /*指向语句序列*/
PushPA(&(currentP->child[1])); /*指向函数的声明部分*/
PushPA(&(currentP->child[0])); /*指向参数声明部分*/
}
void process42()
{ /*弹出过程节点的兄弟节点指针*/
//PopPA( ); /*为了统一处理,不能现在弹出*/
}
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();
/*函数的参数类型是值类型*/
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();
/*函数的参数类型是变量类型*/
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);
/*注意,若没有声明部分,则弹出的是程序或过程根节点中指向
声明部分的指针child[1];若有声明部分,则弹出的是语句序列前
的最后一个声明标识节点的兄弟指针;不管是哪种情况,都正好
需要弹出语法树栈中的一个指针*/
PopPA();
/*建立语句序列标识节点*/
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);
/*赋值语句左部变量节点*/
TreeNode *t = newExpNode(VariK);
strcpy( t->name[0], currentToken.Sem );
t->idnum++;
/*赋值语句的child[0]指向左部的变量节点*/
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);
/*过程调用语句左部是标识符变量,表示过程名*/
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]));
/*当前指针指向赋值左部*/
currentP=currentP->child[0];
TreeNode *t=newExpNode(OpK);
t->attr.ExpAttr.op = END ;
PushOp(t); //操作符栈的栈底存入一个特殊的操作符作为标志
}
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); //操作符栈的栈底存入一个特殊的操作符作为标志
}
void process75()
{
Push(2,RETURN);
}
void process76()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -