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

📄 parseb.java

📁 编译原理实验
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	void process22()
	{
	   Push(2,LexType.END.ordinal());
	   Push(1,NontmlType.FieldDecList.ordinal());
	   Push(2,LexType.RECORD.ordinal());
	   
	   /*声明的类型部分为记录类型*/
	   (currentP).kind.dec=DecKind.RecordK;  

	   saveP = currentP; /*压入当前节点,是为了处理完后回到当前节点,
					     主要是为了变量声明部分标识符部分在后面,考虑*/
	   PushPA(((currentP).child[0]));
	}
	void process23()
	{
	 	Push(1,NontmlType.FieldDecMore.ordinal());
	    Push(2,LexType.SEMI.ordinal());
	    Push(1,NontmlType.IdList.ordinal());
	    Push(1,NontmlType.BaseType.ordinal());
		
		TreeNode  t=PopPA();
	    currentP = newDecNode(); /*生成记录类型的下一个域,不添任何信息*/
		temp=((currentP.kind.dec));
		(t) = currentP; /*若是第一个,则是record类型的子结点指向当前结点,
	                    	否则,是上一个纪录域声明的兄弟结点*/
		PushPA(((currentP).sibling)); 

	}

	void process24()
	{
	    Push(1,NontmlType.FieldDecMore.ordinal());
	    Push(2,LexType.SEMI.ordinal());
	    Push(1,NontmlType.IdList.ordinal());
	    Push(1,NontmlType.ArrayType.ordinal());
	   
		TreeNode  t=PopPA();
	    currentP = newDecNode(); /*生成记录类型的下一个域,不添任何信息*/
		(t) = currentP; /*若是第一个,则是record类型的子结点指向当前结点,
						   否则,是上一个纪录域声明的兄弟结点*/
		PushPA(((currentP).sibling)); 

	}

	void process25()
	{
	    /*后面没有记录类型的下一个域了,恢复当前纪录类型节点的指针*/ 
		PopPA( );
		currentP = saveP; 
	}

	void process26()
	{ 
	  	Push(1,NontmlType.FieldDecList.ordinal());

	}
	void process27()
	{
		Push(1,NontmlType.IdMore.ordinal());
	    Push(2,LexType.ID.ordinal());
		
		/*纪录一个域中各个变量的语义信息*/ 
		currentP.name[currentP.idnum]=currentToken.sem;
	    currentP.idnum++;
	}
	void process28()
	{
	}

	void process29()
	{
	    Push(1,NontmlType.IdList.ordinal());
	    Push(2,LexType.COMMA.ordinal());	
		
	}
	void process30()
	{ 
	}

	void process31()
	{  
	  	Push(1,NontmlType.VarDeclaration.ordinal());
	    
	}
	void process32()
	{
	   Push(1,NontmlType.VarDecList.ordinal());
	   Push(2,LexType.VAR.ordinal());

	   currentP=newVarNode();   /*生成一个标志变量声明的节点*/
	   TreeNode t=PopPA();
	   (t)=currentP;
	   PushPA(((currentP).sibling));  /*压入指向函数声明的指针*/
	   PushPA(((currentP).child[0])); /*压入指向第一个变量声明节点的指针*/ 
	}
	void process33()
	{
	    Push(1,NontmlType.VarDecMore.ordinal());
	    Push(2,LexType.SEMI.ordinal());
	    Push(1,NontmlType.VarIdList.ordinal());
	    Push(1,NontmlType.TypeName.ordinal());
		
		TreeNode  t=PopPA();
		currentP = newDecNode();/*建立一个新的声明节点,这里表示变量声明*/
		(t) = currentP;       /*若是第一个节点,则变量声明的头指针指向它,
						         否则它是前一个变量声明的后继*/
		PushPA(((currentP).sibling));

	}
	void process34()
	{
		PopPA( );
	}

	void process35()
	{ 
		Push(1,NontmlType.VarDecList.ordinal());

	}
	void process36()
	{
	   Push(1,NontmlType.VarIdMore.ordinal());
	   Push(2,LexType.ID.ordinal());
	   
	   currentP.name[currentP.idnum]=currentToken.sem;
	   currentP.idnum++;

	}
	void process37()
	{ 
	}

	void process38()
	{
		Push(1,NontmlType.VarIdList.ordinal());
	    Push(2,LexType.COMMA.ordinal());
		
	}
	void process39()
	{
	}

	void process40()
	{
		Push(1,NontmlType.ProcDeclaration.ordinal());
	  
	}
	void process41()
	{  
	   Push(1,NontmlType.ProcDecMore.ordinal());
	   Push(1,NontmlType.ProcBody.ordinal());
	   Push(1,NontmlType.ProcDecPart.ordinal());
	   Push(2,LexType.SEMI.ordinal());
	   Push(2,LexType.RPAREN.ordinal());
	   Push(1,NontmlType.ParamList.ordinal());
	   Push(2,LexType.LPAREN.ordinal());
	   Push(1,NontmlType.ProcName.ordinal());
	   Push(2,LexType.PROCEDURE.ordinal());

	   
	   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,NontmlType.ProcDeclaration.ordinal());
	}

	void process44()
	{
	    Push(2,LexType.ID.ordinal());
		
		 currentP.name[0]=currentToken.sem ;
		currentP.idnum++;
	}

	void process45()
	{   
		/*形参部分为空,弹出指向形参的指针*/
	    PopPA();
	}

	void process46()
	{  
		Push(1,NontmlType.ParamDecList.ordinal());
	}
	void process47()
	{  
		Push(1,NontmlType.ParamMore.ordinal());
	    Push(1,NontmlType.Param.ordinal());
	}
	void process48()
	{  
		PopPA( );
	}

	void process49()
	{  
		Push(1,NontmlType.ParamDecList.ordinal());
	    Push(2,LexType.SEMI.ordinal());

	}
	void process50()
	{
		Push(1,NontmlType.FormList.ordinal());
	    Push(1,NontmlType.TypeName.ordinal());

		TreeNode t=PopPA();
	    currentP=newDecNode();
		/*函数的参数类型是值类型*/
		currentP.attr.procAttr.paramt=ParamType.valparamType;
	    (t)=currentP;
		PushPA((currentP.sibling));


	}
	void process51()
	{ 
	    Push(1,NontmlType.FormList.ordinal());
	    Push(1,NontmlType.TypeName.ordinal());
	    Push(2,LexType.VAR.ordinal());

		TreeNode t=PopPA();
	    currentP=newDecNode();
		/*函数的参数类型是变量类型*/
		currentP.attr.procAttr.paramt=ParamType.varparamType;
	    (t)=currentP;
		PushPA((currentP.sibling));
		
	}
	void process52()
	{
	   Push(1,NontmlType.FidMore.ordinal());
	   Push(2,LexType.ID.ordinal());

	   currentP.name[currentP.idnum]=currentToken.sem;
	   currentP.idnum++;

	}
	void process53()
	{
	}

	void process54()
	{
		Push(1,NontmlType.FormList.ordinal());
	    Push(2,LexType.COMMA.ordinal());
	}

	void process55()
	{  
		Push(1,NontmlType.DeclarePart.ordinal());
	}
	void process56()
	{  
		Push(1,NontmlType.ProgramBody.ordinal());
	}

	void process57()
	{
	    Push(2,LexType.END.ordinal());
	    Push(1,NontmlType.StmList.ordinal());
	    Push(2,LexType.BEGIN.ordinal());
	   
		/*注意,若没有声明部分,则弹出的是程序或过程根节点中指向
		  声明部分的指针child[1];若有声明部分,则弹出的是语句序列前
		  的最后一个声明标识节点的兄弟指针;不管是哪种情况,都正好
		  需要弹出语法树栈中的一个指针*/
	    PopPA();

		/*建立语句序列标识节点*/
		TreeNode t=PopPA();
	    currentP=newStmlNode();
	    (t)=currentP;
	    PushPA((currentP.child[0]));

	}
	void process58()
	{  
		Push(1,NontmlType.StmMore.ordinal());
		Push(1,NontmlType.Stm.ordinal());
	}
	void process59()
	{
		PopPA( );
	}

	void process60()
	{  
		Push(1,NontmlType.StmList.ordinal());
		Push(2,LexType.SEMI.ordinal());
	 
	}
	void process61()
	{
		Push(1,NontmlType.ConditionalStm.ordinal());

	    currentP=newStmtNode(StmtKind.IfK);
		//currentP.kind.stmt=;

	    TreeNode t=PopPA();
		(t)=currentP;
		PushPA(currentP.sibling);


	}
	void process62()
	{ 
		Push(1,NontmlType.LoopStm.ordinal());

	    currentP=newStmtNode(StmtKind.WhileK);
		//currentP.kind.stmt=;

		TreeNode t=PopPA();
		(t)=currentP;
		PushPA(currentP.sibling);

	}

	void process63()
	{
		Push(1,NontmlType.InputStm.ordinal()); 

		TreeNode t=PopPA();
	    currentP=newStmtNode(StmtKind.ReadK);
		//currentP.kind.stmt=;
		( t)=currentP;
		PushPA(currentP.sibling);

	}
	void process64()
	{
		Push(1,NontmlType.OutputStm.ordinal());
		
		TreeNode t=PopPA();
	    currentP=newStmtNode(StmtKind.WriteK);
		//currentP.kind.stmt=;
		( t)=currentP;
		PushPA(currentP.sibling);

	}
	void process65()
	{
		Push(1,NontmlType.ReturnStm.ordinal());
		
		TreeNode t=PopPA();
	    currentP=newStmtNode(StmtKind.ReturnK);
		( t)=currentP;
		PushPA(currentP.sibling);
	 	
	}

	void process66()
	{
		Push(1,NontmlType.AssCall.ordinal());
	    Push(2,LexType.ID.ordinal());

	    currentP=newStmtNode(StmtKind.AssignK);

		/*赋值语句左部变量节点*/
		TreeNode   t = newExpNode(ExpKind.VariK);
		t.name[0]=currentToken.sem;
	    t.idnum++;

		/*赋值语句的child[0]指向左部的变量节点*/
		currentP.child[0]=t;

		TreeNode t1=PopPA();
		( t1)=currentP;
		PushPA(currentP.sibling);

	}
	void process67()
	{
		Push(1,NontmlType.AssignmentRest.ordinal());

		currentP.kind.stmt=StmtKind.AssignK;
	}
	void process68()
	{
		Push(1,NontmlType.CallStmRest.ordinal());
		/*过程调用语句左部是标识符变量,表示过程名*/
		currentP.child[0].attr.expAttr.varkind=VarKind.IdV;
		
		currentP.kind.stmt=StmtKind.CallK;
	}
	void process69()
	{ 
	   Push(1,NontmlType.Exp.ordinal());
	   Push(2,LexType.ASSIGN.ordinal());
	   Push(1,NontmlType.VariMore.ordinal());
	   /*压入指向赋值右部的指针*/
	   PushPA((currentP.child[1]));
	   /*当前指针指向赋值左部*/
	   currentP=currentP.child[0];

	   TreeNode t=newExpNode(ExpKind.OpK);
	   t.attr.expAttr.op=LexType.END ;
	   PushOp(t);  //操作符栈的栈底

⌨️ 快捷键说明

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