コード例 #1
0
ファイル: report.go プロジェクト: zerobias/gosyn
func MakeReport(tree *models.TreeNode) {
	newTree := models.NewTreeNode()
	treeRebuilding(tree, newTree)
	fmt.Println("-----Rebuilded:")
	fmt.Println(*tree)
	storeResult(htmlHead + makeList(newTree, true) + htmlEnd)
	fmt.Println(*newTree)
}
コード例 #2
0
ファイル: report.go プロジェクト: zerobias/gosyn
func treeRebuilding(tree models.PTreeNode, newTree models.PTreeNode) {
	rebuildChilds := func(parent models.PTreeNode) {
		for _, child := range tree.ChildList {
			rebuildTree(*child, parent)
		}
	}

	switch (*tree).Type() {
	case models.ST_SEQ:
		rebuildChilds(newTree)
	default:
		result := models.NewTreeNode()
		(*result).StringElement = tree.StringElement
		rebuildChilds(result)
		(*newTree).AddTreeNode(result)
	}
	return
}
コード例 #3
0
ファイル: iterator.go プロジェクト: zerobias/gosyn
func NewIterator(value int) *SeqIterator {
	return &SeqIterator{value, nil, models.NewTreeNode()}
}
コード例 #4
0
ファイル: syntaxmachine.go プロジェクト: zerobias/gosyn
//Main syntax parsing function
func Translate(word *models.StringElement, parentCursor *SeqIterator) (result bool) {
	deepInc()
	defer deepDec()

	cursor, element, error := GetCurrent(parentCursor)
	if isError(error) {
		return false
	}
	cursor.buffer.StringElement = *word
	switch word.Type() {
	case models.ST_CLASS:
		output.Par.SendPair(deep-1, COL_BLUE_B, "CLASS", word.Value,
			"curs.i", strconv.Itoa(cursor.int), (*element.Value).String())
		result = lexer.GetClassByName(word.Value) == element.Cat
	case models.ST_TERM:
		output.Par.SendPair(deep-1, COL_BLUE_B, "TERM", word.Value, (*element.Value).String())
		result = element.Name == word.Value
	case models.ST_RULE:
		output.Par.Send(deep-1, COL_BLUE_B, "RULE", word.Value)
		result = Translate(&GetRule(word.Value).TopWord, cursor)
	case models.ST_SEQ:
		output.Par.SendPair(deep, COL_BLUE_U, "SEQ", deep,
			"O", word.Optional,
			"C", word.Choises, "I", word.Iterative)
		checkChilds := func(curs *SeqIterator) bool {
			isLast := func(n int) bool {
				if n == len(word.Words)-1 {
					return true
				} else {
					return false
				}
			}
			for i, child := range word.Words {
				childResult := Translate(&child, curs)
				if word.Choises {
					if childResult {
						return true
					} else if isLast(i) {
						return false
					}
				} else {
					if childResult {
						if isLast(i) {
							return true
						}
					} else {
						return false
					}
				}
			}
			return false
		}

		if word.Iterative {
			Nrep := 0
			cycleCursor, error := InitIter(cursor)
			cycleCursor.buffer.XMLName.Local = string(models.ST_SEQ)
			if !isError(error) {
				for iterSucc := true; iterSucc; {
					iterSucc = checkChilds(cycleCursor)
					output.Par.SendPair(deep, COL_RED, iterSucc,
						Nrep, cursor.int, cycleCursor.int)
					if iterSucc {
						Nrep++
					}
				}
			}
			if Nrep > 0 {
				cycleCursor.ApplyToParent()
				result = true
			} else {
				result = false
			}
		} else {
			result = checkChilds(cursor)
		}
		if word.Optional && !result {
			result = true
			cursor.buffer = models.NewTreeNode()
			cursor.buffer.XMLName.Local = string(models.ST_SEQ)
			output.Par.Send(0, COL_DEEP_LIM, "OPTIONAL")
		}
	}
	if result {
		if word.Type() == models.ST_RULE ||
			word.Type() == models.ST_SEQ {
			cursor.ApplyToParent()
		} else {
			fmt.Println("Add to parent", *word, "|", *element)
			cursor.AddToParent(word, element)
		}
		output.Par.SendPair(deep, COL_GREEN, "RES", result, word.Type()) //TODO print output for failures too
	}
	return
}