⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 语法分析ll1b.txt

📁 这是编译原理的源代码
💻 TXT
📖 第 1 页 / 共 3 页
字号:
	currentP->attr.ProcAttr.paramt=valparamType;
    (*t)=currentP;
	PushPA(&(currentP->sibling));


}
void CparseLL1::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 CparseLL1::process52()
{
   Push(1,FidMore);
   Push(2,ID);

   strcpy( currentP->name[currentP->idnum], currentToken.Sem);
   currentP->idnum++;

}
void CparseLL1::process53()
{
}

void CparseLL1::process54()
{
	Push(1,FormList);
    Push(2,COMMA);
}

void CparseLL1::process55()
{  
	Push(1,DeclarePart);
}
void CparseLL1::process56()
{  
	Push(1,ProgramBody);
}

void CparseLL1::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 CparseLL1::process58()
{  
	Push(1,StmMore);
	Push(1,Stm);
}
void CparseLL1::process59()
{
	PopPA( );
}

void CparseLL1::process60()
{  
	Push(1,StmList);
	Push(2,SEMI);
 
}
void CparseLL1::process61()
{
	Push(1,ConditionalStm);

    currentP=newStmtNode(IfK);
	//currentP->kind.stmt=;

    TreeNode **t=PopPA();
	(*t)=currentP;
	PushPA(&currentP->sibling);


}
void CparseLL1::process62()
{ 
	Push(1,LoopStm);

    currentP=newStmtNode(WhileK);
	//currentP->kind.stmt=;

	TreeNode **t=PopPA();
	(*t)=currentP;
	PushPA(&currentP->sibling);

}

void CparseLL1::process63()
{
	Push(1,InputStm); 

	TreeNode **t=PopPA();
    currentP=newStmtNode(ReadK);
	//currentP->kind.stmt=;
	(*t)=currentP;
	PushPA(&currentP->sibling);

}
void CparseLL1::process64()
{
	Push(1,OutputStm);
	
	TreeNode **t=PopPA();
    currentP=newStmtNode(WriteK);
	//currentP->kind.stmt=;
	(*t)=currentP;
	PushPA(&currentP->sibling);

}
void CparseLL1::process65()
{
	Push(1,ReturnStm);
	
	TreeNode **t=PopPA();
    currentP=newStmtNode(ReturnK);
	(*t)=currentP;
	PushPA(&currentP->sibling);
 	
}

void CparseLL1::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(&currentP->sibling);

}
void CparseLL1::process67()
{
	Push(1,AssignmentRest);

	currentP->kind.stmt=AssignK;
}
void CparseLL1::process68()
{
	Push(1,CallStmRest);
	/*过程调用语句左部是标识符变量,表示过程名*/
	currentP->child[0]->attr.ExpAttr.varkind=IdV;
	
	currentP->kind.stmt=CallK;
}
void CparseLL1::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 CparseLL1::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 CparseLL1::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 CparseLL1::process72()
{
   Push(2,RPAREN);
   Push(1,InVar);
   Push(2,LPAREN);
   Push(2,READ);
}
void CparseLL1::process73()
{
   Push(2,ID);

   strcpy( currentP->name[0], currentToken.Sem);	
   currentP->idnum++;
}
void CparseLL1::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 CparseLL1::process75()
{
   Push(2,RETURN);
}

void CparseLL1::process76()
{ 
   Push(2,RPAREN);
   Push(1,ActParamList);
   Push(2,LPAREN);	

   PushPA(&(currentP->child[1]));
 
}
void CparseLL1::process77()
{
   PopPA();
}
void CparseLL1::process78()
{
   Push(1,ActParamMore);
   Push(1,Exp);

   TreeNode *t=newExpNode(OpK);
   t->attr.ExpAttr.op = END ;
   PushOp(t);  //操作符栈的栈底存入一个特殊的操作符作为标志
}

void CparseLL1::process79()
{
}
void CparseLL1::process80()
{ 
   Push(1,ActParamList);
   Push(2,COMMA);
   
   PushPA(&(currentP->sibling));
}


/*设定操作符的优先级,值越大优先级越高*/
int  CparseLL1::Priosity( LexType  op)
{ int  pri=0;
  switch(op)
  { case END:
			pri = -1; break;//栈底标识,优先级最低
    case LPAREN: 
		    pri = 0;
    case LT:
    case EQ:
		    pri = 1; break;
	case PLUS:
	case MINUS:
		pri = 2; break;
	case TIMES:
	case OVER:
			pri = 3; break;
    default:  {fprintf(listing ,"no such  operator !");
		       fprintf(listing,"%d\n",op);
			   pri= -1;
			  }  
  }
  return  pri;
}  

/*********************表达式部分************************/

void CparseLL1::process81()
{
   Push(1,OtherRelE);
   Push(1,Exp);
   
   TreeNode *t=newExpNode(OpK);
   t->attr.ExpAttr.op = END ;
   PushOp(t);  //操作符栈的栈底存入一个特殊的操作符作为标志	

   getExpResult=FALSE;
}

void CparseLL1::process82()
{   
   Push(1,Exp);
   Push(1,CmpOp);

   TreeNode  *currentP=newExpNode(OpK);
   currentP->attr.ExpAttr.op = currentToken.Lex; 
 
   LexType  sTop=ReadOpStack();
   while ( Priosity(sTop) >= Priosity(currentToken.Lex) )
   /*如果操作符栈顶运算符的优先级高于或等于当前读到的操作符*/
   {   TreeNode *t= PopOp();
	   TreeNode *Rnum= PopNum();
	   TreeNode *Lnum= PopNum();
       t->child[1]=Rnum;
	   t->child[0]=Lnum;
       PushNum(t);

       sTop=ReadOpStack();
   }  
   
   PushOp(currentP);
   /*处理完关系操作符右部的表达式时,要弹语法树栈,故
     设置getExpResult为真*/
   getExpResult	= TRUE;
}

void CparseLL1::process83()
{ 
   Push(1,OtherTerm);
   Push(1,Term);
}

void CparseLL1::process84()
{
  if ((currentToken.Lex==RPAREN)&&(expflag!=0))
     //说明当前右括号是表达式中的一部分
    { while (ReadOpStack()!=LPAREN)
          {TreeNode   *t=PopOp();
	        TreeNode  *Rnum=PopNum();
	        TreeNode  *Lnum=PopNum();

            t->child[1] = Rnum;
			t->child[0] = Lnum;
			PushNum(t);
         }
		PopOp(); //弹出左括号
        expflag--; 
     }
  else
  { if ((getExpResult)||(getExpResult2))
    {  while  (ReadOpStack()!=END)
	  {TreeNode  *t=PopOp();
	   TreeNode  *Rnum=PopNum();
	   TreeNode  *Lnum=PopNum();

       t->child[1] = Rnum;
	   t->child[0] = Lnum;
	   PushNum(t);  
	  }
      PopOp();//弹出栈底标志
	  currentP=PopNum();
    
	  TreeNode  **t=PopPA();
	  (*t)=currentP;
      
	  /*处理完数组变量,标志恢复初始值假,
	    遇到下一个数组下标表达式时,再将其设置为真值*/
	  if (getExpResult2==TRUE)
	      getExpResult2 = FALSE;
	}
 }
}

void CparseLL1::process85()
{ 
   Push(1,Exp);
   Push(1,AddOp);
   
   TreeNode  *currentP=newExpNode(OpK);
   currentP->attr.ExpAttr.op = currentToken.Lex; 
   LexType  sTop=ReadOpStack();
   while ( Priosity(sTop) >= Priosity(currentToken.Lex) )
   /*如果操作符栈顶运算符的优先级高于或等于当前读到的操作符*/
   {   TreeNode *t=PopOp();
	   TreeNode *Rnum=PopNum();
	   TreeNode *Lnum=PopNum();
       t->child[1]=Rnum;
	   t->child[0]=Lnum;
       PushNum(t);
       sTop=ReadOpStack();
   }  
   PushOp(currentP);
}

void CparseLL1::process86()
{ 
   Push(1,OtherFactor);
   Push(1,Factor);
}
void CparseLL1::process87()
{
}
void CparseLL1::process88()
{
   Push(1,Term);
   Push(1,MultOp);

   TreeNode  *currentP=newExpNode(OpK);
   currentP->attr.ExpAttr.op = currentToken.Lex; 
   
   LexType  sTop=ReadOpStack();
   while ( Priosity(sTop) >= Priosity(currentToken.Lex) )
   /*如果操作符栈顶运算符的优先级高于或等于当前读到的操作符*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -