private void idList( TreeNode ptr , TreeNode parent , fieldChain body , int layer , integer Count , typeIR tIR ) { body = new fieldChain() ; TreeNode p ; body.idname = ptr.childs[0].Data ; body.offset.value = Count.value ; body.unitType = tIR ; body.next = new fieldChain() ; Count.value += tIR.Count.value ; TreeNode tar = new TreeNode() ; tar.IsTerminal=true ; tar.NonTerminal = nonTerminals.IdMore ; p = Search( ptr , tar , 0 ) ; if( p != null ) { idList( ptr.childs[1].childs[1] , parent , body.next , layer , Count , tIR ) ; return ; } tar.NonTerminal = nonTerminals.FieldDecList ; p = Search( parent.father.childs[4] , tar , 0 ) ; if( p != null ) { fieldDecList( p , body.next , Count , layer ) ; } }
private void variMore( TreeNode ptr , SymTableNode sym , typeIR tIR ) { TreeNode p ; TreeNode tar = new TreeNode() ; integer ntype = new integer( 2 ) ; tar.IsTerminal=true ; tar.NonTerminal = nonTerminals.Exp ; p = Search( ptr , tar , 0 ) ; if( p != null ) { tIR.copy( sym.attrIR.idtype.More.ArrayAttr.indexTy ) ; Exp( p , tIR , ntype ) ; } else { tar.NonTerminal = nonTerminals.FieldVar ; p = Search( ptr , tar , 0 ) ; if( p != null ) { if( p.ChildNum != 0 && p.childs[0].Terminal.Equals( LexType.ID ) ) { fieldChain body = new fieldChain() ; body = sym.attrIR.idtype.More.body ; while( body != null ) { if( body.idname.Equals( p.childs[0].Data) ) break ; body = body.next ; } if( body != null ) { tIR.copy( IntTy ) ; tar.NonTerminal = nonTerminals.FieldVarMore ; p = Search( p , tar , 0 ) ; if( p != null ) { tar.NonTerminal = nonTerminals.Exp ; p = Search( p , tar , 0 ) ; ntype.value = 2 ; Exp( p , tIR , ntype ) ; } } else { error( "语义错误: " + p.childs[0].Data+"并非过程标识符,而是"+sym.name+"类型" , p.childs[0].Line , p.childs[0].Row ) ; } } } } }
private void fieldDecList( TreeNode ptr , fieldChain body , integer Count , int layer ) { TreeNode p ; TreeNode tar = new TreeNode() ; tar.IsTerminal=true ; tar.NonTerminal = nonTerminals.BaseType ; p = Search( ptr , tar , 1 ) ; if( p != null ) { if( p.childs[0].Terminal.Equals( LexType.INTEGER ) ) idList( p.father.childs[1] , p.father.childs[1] , body , layer , Count , IntTy ) ; else if( p.childs[0].Terminal.Equals( LexType.CHAR ) ) idList( p.father.childs[1] , p.father.childs[1] , body , layer , Count , CharTy ) ; return ; } tar.NonTerminal = nonTerminals.ArrayType ; p = Search( ptr , tar , 1 ) ; if( p != null ) { typeIR tIR = new typeIR() ; arrayType( p , tIR , layer ) ; idList( p.father.childs[1] , p.father.childs[1] , body , layer , Count , tIR ) ; } }