Пример #1
0
func (buffer *lexBuffer) lexSequence() *types.TreeNode {
	var node, p, q *types.TreeNode = nil, nil, nil

	for buffer.token.TokenType != types.ENDFILE {
		if buffer.token.TokenType == types.END ||
			buffer.token.TokenType == types.ELSE ||
			buffer.token.TokenType == types.UNTIL {
			buffer.nextToken()
		}
		if buffer.token.TokenType == types.ENDFILE {
			break
		}
		p = buffer.stmtSequence()

		if node == nil {
			node = p
		} else {
			q = node

			for q.Sibling != nil {
				q = q.Sibling
			}
			q.Sibling = p
		}
	}

	return node
}
Пример #2
0
func newExpNode(kind types.ExpKind, lineno int) *types.TreeNode {
	node := new(types.TreeNode)

	node.Children = make([]*types.TreeNode, 0, 0)
	node.Sibling = nil
	node.Node = types.ExpK
	node.Exp = kind
	node.Lineno = lineno

	return node
}