func (ps *parseStack) AssembleAliasedStreamWindow() {
	_name, _rel := ps.pop2()
	name := _name.comp.(Identifier)
	rel := _rel.comp.(StreamWindowAST)
	ps.PushComponent(_rel.begin, _name.end, AliasedStreamWindowAST{rel, string(name)})
}
AssembleAliasedStreamWindow takes the topmost elements from the stack, assuming
they are components of an AS clause, and replaces them by
a single AliasedStreamWindowAST element.

Identifier
StreamWindowAST
=>
AliasedStreamWindowAST{StreamWindowAST, Identifier}
package parser
import (
	"fmt"
	"gopkg.in/sensorbee/sensorbee.v0/data"
)
type parseStack struct {
	top  *stackElement
	size int
}
type stackElement struct {
	value *ParsedComponent
	next  *stackElement
}
type ParsedComponent struct {
	begin int
	end int
	comp interface{}
}
func (ps *parseStack) Len() int {
	return ps.size
}
func (ps *parseStack) Push(value *ParsedComponent) {
	ps.top = &stackElement{value, ps.top}
	ps.size++
}
func (ps *parseStack) Pop() (value *ParsedComponent) {
	if ps.size > 0 {
		value, ps.top = ps.top.value, ps.top.next
		ps.size--
		return
	}
	return nil
}
func (ps *parseStack) Peek() (value *ParsedComponent) {
	if ps.size > 0 {
		return ps.top.value
	}
	return nil
}
func (ps *parseStack) AssembleSelect() {
	_having, _grouping, _filter, _from, _projections, _emitter := ps.pop6()
	having := _having.comp.(HavingAST)
	grouping := _grouping.comp.(GroupingAST)
	filter := _filter.comp.(FilterAST)
	from := _from.comp.(WindowedFromAST)
	projections := _projections.comp.(ProjectionsAST)
	emitter := _emitter.comp.(EmitterAST)
	s := SelectStmt{emitter, projections, from, filter, grouping, having}
	se := ParsedComponent{_emitter.begin, _having.end, s}
	ps.Push(&se)
}
func (ps *parseStack) AssembleSelectUnion(begin int, end int) {
	elems := ps.collectElements(begin, end)
	selects := make([]SelectStmt, len(elems))
	for i := range elems {
		selects[i] = elems[i].(SelectStmt)
	}
	ps.PushComponent(begin, end, SelectUnionStmt{selects})
}
func (ps *parseStack) AssembleCreateStreamAsSelect() {
	_select, _name := ps.pop2()
	s := _select.comp.(SelectStmt)
	name := _name.comp.(StreamIdentifier)
	css := CreateStreamAsSelectStmt{name, s}
	se := ParsedComponent{_name.begin, _select.end, css}
	ps.Push(&se)
}
func (ps *parseStack) AssembleCreateStreamAsSelectUnion() {
	_selectUnion, _name := ps.pop2()
	selectUnion := _selectUnion.comp.(SelectUnionStmt)
	name := _name.comp.(StreamIdentifier)
	css := CreateStreamAsSelectUnionStmt{name, selectUnion}
	se := ParsedComponent{_name.begin, _selectUnion.end, css}
	ps.Push(&se)
}
func (ps *parseStack) AssembleCreateSource() {
	_specs, _sourceType, _name, _paused := ps.pop4()
	specs := _specs.comp.(SourceSinkSpecsAST)
	sourceType := _sourceType.comp.(SourceSinkType)
	name := _name.comp.(StreamIdentifier)
	paused := _paused.comp.(BinaryKeyword)
	s := CreateSourceStmt{paused, name, sourceType, specs}
	se := ParsedComponent{_paused.begin, _specs.end, s}
	ps.Push(&se)
}
func (ps *parseStack) AssembleCreateSink() {
	_specs, _sinkType, _name := ps.pop3()
	specs := _specs.comp.(SourceSinkSpecsAST)
	sinkType := _sinkType.comp.(SourceSinkType)
	name := _name.comp.(StreamIdentifier)
	s := CreateSinkStmt{name, sinkType, specs}
	se := ParsedComponent{_name.begin, _specs.end, s}
	ps.Push(&se)
}
func (ps *parseStack) AssembleCreateState() {
	_specs, _sinkType, _name := ps.pop3()
	specs := _specs.comp.(SourceSinkSpecsAST)
	sinkType := _sinkType.comp.(SourceSinkType)
	name := _name.comp.(StreamIdentifier)
	s := CreateStateStmt{name, sinkType, specs}
	se := ParsedComponent{_name.begin, _specs.end, s}
	ps.Push(&se)
}
func (ps *parseStack) AssembleUpdateState() {
	_specs, _name := ps.pop2()
	specs := _specs.comp.(SourceSinkSpecsAST)
	name := _name.comp.(StreamIdentifier)
	s := UpdateStateStmt{name, specs}
	se := ParsedComponent{_name.begin, _specs.end, s}
	ps.Push(&se)
}
func (ps *parseStack) AssembleUpdateSource() {
	_specs, _name := ps.pop2()
	specs := _specs.comp.(SourceSinkSpecsAST)
	name := _name.comp.(StreamIdentifier)
	s := UpdateSourceStmt{name, specs}
	se := ParsedComponent{_name.begin, _specs.end, s}
	ps.Push(&se)
}
func (ps *parseStack) AssembleUpdateSink() {
	_specs, _name := ps.pop2()
	specs := _specs.comp.(SourceSinkSpecsAST)
	name := _name.comp.(StreamIdentifier)
	s := UpdateSinkStmt{name, specs}
	se := ParsedComponent{_name.begin, _specs.end, s}
	ps.Push(&se)
}
func (ps *parseStack) AssembleInsertIntoFrom() {
	_input, _sink := ps.pop2()
	input := _input.comp.(StreamIdentifier)
	sink := _sink.comp.(StreamIdentifier)
	s := InsertIntoFromStmt{sink, input}
	se := ParsedComponent{_sink.begin, _input.end, s}
	ps.Push(&se)
}
func (ps *parseStack) AssemblePauseSource() {
	_name := ps.Pop()
	name := _name.comp.(StreamIdentifier)
	se := ParsedComponent{_name.begin, _name.end, PauseSourceStmt{name}}
	ps.Push(&se)
}
func (ps *parseStack) AssembleResumeSource() {
	_name := ps.Pop()
	name := _name.comp.(StreamIdentifier)
	se := ParsedComponent{_name.begin, _name.end, ResumeSourceStmt{name}}
	ps.Push(&se)
}
func (ps *parseStack) AssembleRewindSource() {
	_name := ps.Pop()
	name := _name.comp.(StreamIdentifier)
	se := ParsedComponent{_name.begin, _name.end, RewindSourceStmt{name}}
	ps.Push(&se)
}
func (ps *parseStack) AssembleDropSource() {
	_name := ps.Pop()
	name := _name.comp.(StreamIdentifier)
	se := ParsedComponent{_name.begin, _name.end, DropSourceStmt{name}}
	ps.Push(&se)
}
func (ps *parseStack) AssembleDropStream() {
	_name := ps.Pop()
	name := _name.comp.(StreamIdentifier)
	se := ParsedComponent{_name.begin, _name.end, DropStreamStmt{name}}
	ps.Push(&se)
}
func (ps *parseStack) AssembleDropSink() {
	_name := ps.Pop()
	name := _name.comp.(StreamIdentifier)
	se := ParsedComponent{_name.begin, _name.end, DropSinkStmt{name}}
	ps.Push(&se)
}
func (ps *parseStack) AssembleDropState() {
	_name := ps.Pop()
	name := _name.comp.(StreamIdentifier)
	se := ParsedComponent{_name.begin, _name.end, DropStateStmt{name}}
	ps.Push(&se)
}
func (ps *parseStack) AssembleLoadState() {
	_specs, _tag, _sinkType, _name := ps.pop4()
	specs := _specs.comp.(SourceSinkSpecsAST)
	tag := _tag.comp.(Identifier)
	sinkType := _sinkType.comp.(SourceSinkType)
	name := _name.comp.(StreamIdentifier)
	s := LoadStateStmt{name, sinkType, string(tag), specs}
	se := ParsedComponent{_name.begin, _specs.end, s}
	ps.Push(&se)
}
func (ps *parseStack) AssembleLoadStateOrCreate() {
	_createSpecs, _loadStateStmt := ps.pop2()
	loadStateStmt := _loadStateStmt.comp.(LoadStateStmt)
	createSpecs := _createSpecs.comp.(SourceSinkSpecsAST)
	specs := loadStateStmt.SourceSinkSpecsAST
	tag := loadStateStmt.Tag
	sinkType := loadStateStmt.Type
	name := loadStateStmt.Name
	s := LoadStateOrCreateStmt{name, sinkType, tag, specs, createSpecs}
	se := ParsedComponent{_loadStateStmt.begin, _createSpecs.end, s}
	ps.Push(&se)
}
func (ps *parseStack) AssembleSaveState() {
	_tag, _name := ps.pop2()
	tag := _tag.comp.(Identifier)
	name := _name.comp.(StreamIdentifier)
	se := ParsedComponent{_name.begin, _tag.end, SaveStateStmt{name, string(tag)}}
	ps.Push(&se)
}
func (ps *parseStack) AssembleEval(begin, end int) {
	var exprBegin int
	var expr Expression
	var inputRow *MapAST
	if begin == end {
		_expr := ps.Pop()
		exprBegin = _expr.begin
		expr = _expr.comp.(Expression)
	} else {
		_input, _expr := ps.pop2()
		exprBegin = _expr.begin
		expr = _expr.comp.(Expression)
		input := _input.comp.(MapAST)
		inputRow = &input
	}
	se := ParsedComponent{exprBegin, end, EvalStmt{expr, inputRow}}
	ps.Push(&se)
}
func (ps *parseStack) AssembleEmitter() {
	_options, _emitter := ps.pop2()
	emitter := _emitter.comp.(Emitter)
	options := _options.comp.([]interface{})
	ps.PushComponent(_emitter.begin, _options.end, EmitterAST{emitter, options})
}
func (ps *parseStack) AssembleEmitterOptions(begin int, end int) {
	elems := ps.collectElements(begin, end)
	if len(elems) == 0 {
		elems = nil
	}
	ps.PushComponent(begin, end, elems)
}
func (ps *parseStack) AssembleEmitterLimit() {
	_limit := ps.Pop()
	limit := _limit.comp.(NumericLiteral)
	ps.PushComponent(_limit.begin, _limit.end, EmitterLimit{limit.Value})
}
func (ps *parseStack) AssembleEmitterSampling(samplingType EmitterSamplingType, factor float64) {
	_value := ps.Pop()
	var value float64
	if num, ok := _value.comp.(NumericLiteral); ok {
		value = float64(num.Value)
	} else {
		num := _value.comp.(FloatLiteral)
		value = num.Value
	}
	ps.PushComponent(_value.begin, _value.end, EmitterSampling{value * factor, samplingType})
}
func (ps *parseStack) AssembleProjections(begin int, end int) {
	elems := ps.collectElements(begin, end)
	exprs := make([]Expression, len(elems))
	for i := range elems {
		exprs[i] = elems[i].(Expression)
	}
	ps.PushComponent(begin, end, ProjectionsAST{exprs})
}
func (ps *parseStack) AssembleAlias() {
	_name, _expr := ps.pop2()
	name := _name.comp.(Identifier)
	expr := _expr.comp.(Expression)
	ps.PushComponent(_expr.begin, _name.end, AliasAST{expr, string(name)})
}
func (ps *parseStack) AssembleWindowedFrom(begin int, end int) {
	if begin == end {
		ps.PushComponent(begin, end, WindowedFromAST{})
	} else {
		elems := ps.collectElements(begin, end)
		rels := make([]AliasedStreamWindowAST, len(elems), len(elems))
		for i, elem := range elems {
			e := elem.(AliasedStreamWindowAST)
			rels[i] = e
		}
		ps.PushComponent(begin, end, WindowedFromAST{rels})
	}
}
func (ps *parseStack) AssembleInterval() {
	_unit, _num := ps.pop2()
	unit := _unit.comp.(IntervalUnit)
	var val float64
	if num, ok := _num.comp.(NumericLiteral); ok {
		val = float64(num.Value)
	} else {
		num := _num.comp.(FloatLiteral)
		val = num.Value
	}
	ps.PushComponent(_num.begin, _unit.end, IntervalAST{FloatLiteral{val}, unit})
}
func (ps *parseStack) AssembleFilter(begin int, end int) {
	if begin == end {
		ps.PushComponent(begin, end, FilterAST{})
	} else {
		f := ps.Pop()
		if begin > f.begin || end < f.end {
			panic("the item on top of the stack is not within given range")
		}
		ps.PushComponent(begin, end, FilterAST{f.comp.(Expression)})
	}
}
func (ps *parseStack) AssembleGrouping(begin int, end int) {
	elems := ps.collectElements(begin, end)
	var exprs []Expression
	if len(elems) > 0 {
		exprs = make([]Expression, len(elems))
	}
	for i := range elems {
		exprs[i] = elems[i].(Expression)
	}
	ps.PushComponent(begin, end, GroupingAST{exprs})
}
func (ps *parseStack) AssembleHaving(begin int, end int) {
	if begin == end {
		ps.PushComponent(begin, end, HavingAST{})
	} else {
		h := ps.Pop()
		if begin > h.begin || end < h.end {
			panic("the item on top of the stack is not within given range")
		}
		ps.PushComponent(begin, end, HavingAST{h.comp.(Expression)})
	}
}