private void formList( TreeNode ptr , int layer , integer Count , ParamTable param , typeIR tIR , bool ntype ) { TreeNode p ; TreeNode tar = new TreeNode() ; SymTableNode sym = new SymTableNode() ; sym.name = ptr.childs[0].Data ; sym.next = new SymTableNode() ; sym.attrIR.idtype.copy( tIR ) ; sym.attrIR.kind = IdKind.varkind ; if( ntype == true ) sym.attrIR.More.VarAttr.access = AccessKind.indir ; else sym.attrIR.More.VarAttr.access = AccessKind.dir ; sym.attrIR.level = layer ; sym.attrIR.More.VarAttr.offset.value = Count.value ; if( myScope.FindID( sym.name , false ) != null ) { String str = "语义错误: 参数标识符" + sym.name + "重复定义!" ; error( str , ptr.Line , ptr.Row ) ; sym = null ; tar.IsTerminal=true ; tar.NonTerminal = nonTerminals.FormList ; p = Search( ptr.childs[1] , tar , 2 ) ; if( p != null ) formList( p , layer , Count , param , tIR , ntype ) ; } else { Count.value += tIR.Count.value ; symTable.insertNode( sym ) ; param.type.copy( tIR ) ; param.symPtr = sym ; if( myScope.scope.Peek().front == null ) myScope.scope.Peek().front = sym ; tar.IsTerminal=true ; tar.NonTerminal = nonTerminals.FormList ; p = Search( ptr.childs[1] , tar , 2 ) ; if( p != null ) { param.next = new ParamTable() ; formList( p , layer , Count , param.next , tIR , ntype ) ; } } }
private void paramList( TreeNode ptr , int layer , integer Count , ParamTable param ) { TreeNode p ; TreeNode tar = new TreeNode() ; tar.IsTerminal=true ; tar.NonTerminal = nonTerminals.ParamDecList ; p = Search( ptr , tar , 1 ) ; if( p != null ) { paramDecList( p , layer , Count , param ) ; } }
private void paramDecList( TreeNode ptr , int layer , integer Count , ParamTable param ) { TreeNode p ; TreeNode tar = new TreeNode() ; tar.IsTerminal=true ; if( ptr.ChildNum != 0 && ptr.childs[0].NonTerminal.Equals(nonTerminals.Param ) ) { typeIR tIR = new typeIR() ; tar.NonTerminal = nonTerminals.TypeDef ; p = Search( ptr , tar , 1 ) ; if( p != null ) { typeDef( p , tIR , layer ) ; if( tIR != null ) { p = p.father.childs[1] ; formList( p , layer , Count , param , tIR , false ) ; } } else { tar.IsTerminal = false; tar.Terminal = LexType.VAR; p = Search( ptr , tar , 1 ) ; if( p != null ) { if( p.father.childs[1].NonTerminal.Equals(nonTerminals.TypeDef ) ) { typeDef( p.father.childs[1] , tIR , layer ) ; tar.IsTerminal = true; tar.NonTerminal = nonTerminals.FormList; p = Search( p.father.childs[1] , tar , 1 ) ; if( tIR != null && p != null ) formList( p , layer , Count , param , tIR , true ) ; } } } } tar.NonTerminal = nonTerminals.ParamMore ; p = Search( ptr , tar , 0 ) ; if( p != null ) { tar.NonTerminal = nonTerminals.ParamDecList ; p = Search( p , tar , 0 ) ; if( p != null ) { if( param != null ) { ParamTable pm = param ; while( pm.next != null ) pm = pm.next ; paramDecList( p , layer , Count , pm.next ) ; } else paramDecList( p , layer , Count , param ) ; } } }
private void actParamList( TreeNode ptr , ParamTable param ) { TreeNode p ; TreeNode tar = new TreeNode() ; integer ntype = new integer( 1 ) ; typeIR tIR = new typeIR() ; tar.IsTerminal=true ; tar.NonTerminal = nonTerminals.Exp ; p = Search( ptr , tar , 1 ) ; if( p != null ) { if( param == null ) { error( "语义错误: 过程调用实参数目过多" , ptr.Line , ptr.Row ) ; return ; } if( param.type.Equals( CharTy ) ) { ntype.value = 0 ; Exp( p , tIR = IntTy , ntype ) ; } else Exp( p , tIR = param.type , ntype ) ; tar.NonTerminal = nonTerminals.ActParamMore ; p = Search( ptr , tar , 0 ) ; if( p != null ) { tar.NonTerminal = nonTerminals.ActParamList ; p = Search( p , tar , 0 ) ; if( p != null ) actParamList( p , param.next ) ; else if( param.next != null ) { error( "语义错误: 过程调用实参数目不完整" , ptr.Line , ptr.Row ) ; return ; } } } else if( param != null ) { error( "语义错误: 过程调用实参数目不完整" , ptr.Line , ptr.Row ) ; return ; } }