2013-10-14 49 views
0

這裏是代碼,我使用gccgo進行彙編。這是一個基於圖形的組織者。我不需要對圖算法提出建議。彙編程序錯誤

package element 

import (
     "fmt" 
     "strings" 
     "io" 
     "strconv" 
) 

type Node struct { 
    id int 
    name string 
    props map[string]string 
    links map[string][]*Node 
} 

var names = make(map[string]int , 8) 
var nodes = make(map[string][]*Node , 8) 


//========functions================ 
func new_node(Id int) *Node { 
    return &Node(Id, " ", nil, nil) 
} 

func getNode_byId(nodes []*Node, id int) *Node {  
    for _, node := range nodes{ 
     if node.id == id { 
      return node 
     } 
    } 
    return nil 
} 

func addNode(store string, node *Node) { 
    nodes[store] = append(nodes[store], node) 
} 

func addLinkToNode(node, link *Node, property string) { 
    node.links[property] = append(node.links[property], link) 
} 

func nodeFromString(str string, typ string) { 

    lines := strings.Split(str, "\n") 
    lcount := len(lines) 

    if lines[0] == "[begin]" && lines[lcount] == "[end]" { 
     fmt.Println("common dude! something wrong with ur string") 
     return 
    } 

    fields := strings.Fields(lines[1]) 
    id , _ := strconv.Atoi(fields[1]) 
    nod  := getNode_byId(nodes[typ], id) 

    if nod == nil { nod = new_node(id) } 
    addNode(typ, nod) 

    nod.name = typ 

    lines = lines[2:] 
    ind :=0 
    for index, line := range lines { 
     fields := strings.Fields(line) 
     if field := fields[0]; field[0] != '-' { 
      ind = index 
      break 
     } 

     nod.props[fields[0]] = fields[1] 
    } 

    lines = lines[ind:] 
    for index, line := range lines { 
     if line[0]!= '+' { 
      ind = index 
      break 
     } 

     pivot := strings.Index(line, " ") 
     field := line[0:pivot] 
     fields := strings.Split(line[pivot:], ",")  

    for _, value := range fields { 
     id, _ := strconv.Atoi(strings.TrimSpace(value)) 
     var link *Node = getNode_byId(nodes[typ], id) 
     if link == nil { link = new_node(id) } 
     addNode(typ, link) 

     append(nod.links[field], link) 
    } 
} 
} 


func equal_byId(nodeA, nodeB Node) bool { 
    return (nodeA.id == nodeB.id) 
} 

func equal_byProp(nodeA, nodeB Node, property string) bool { 
    return (nodeA.props[property] == nodeB.props[property]) 
} 

//========methods on node========== 
func (node Node) IsEqual_byId(comparand Node) bool { 
    return equal_byId(node, comparand) 
} 

func (node Node) IsEqual_byProp(comparand Node, property string) bool { 
    return equal_byProp(node, comparand, property) 
} 

func (node *Node) addLink (property string, link *Node){ 
    addLinkToNode(node, link, property) 
} 

//=================== 
func main() { 
     fmt.Println("hello world") 
} 

這是我得到的錯誤,我盡我所能,但我無法解決。

$ gccgo elements.go 
elements.go:23:19: error: expected ‘)’ 
elements.go:23:34: error: expected ‘;’ or ‘}’ or newline 
elements.go:23:2: error: too many values in return statement 
elements.go:91:4: error: value computed is not used 

我不明白的地方,我需要使用分號和原因。

回答

3

的問題,我想,可能是func new_node

return &Node(Id, " ", nil, nil) 

應該

return &Node{Id, " ", nil, nil} 

http://golang.org/ref/spec#Composite_literals

另外,我有一種感覺,在func nodeFromString(第93行-ish):

append(nod.links[field], link) 

應該是:

nod.links[field] = append(nod.links[field], link) 

否則,你會得到一個錯誤。