Grammar EPLStatementParser ANTLR-generated HTML file from grammar/epl.g Terence Parr, MageLang Institute ANTLR Version 2.7.5 (20050128); 1989-2005

    Definition of parser EPLStatementParser, which is a subclass of LLkParser.

    startPatternExpressionRule
    	:	patternExpression EOF
    	;

    patternExpression
    	:	followedByExpression
    	;

    startEPLExpressionRule
    	:	eplExpression EOF
    	;

    eplExpression
    	:	(	INSERT insertIntoExpr
    		|
    		)
    		selectExpression
    	;

    startEventPropertyRule
    	:	eventProperty EOF
    	;

    eventProperty
    	:	eventPropertyAtomic ( DOT eventPropertyAtomic )*
    	;

    number
    	:	NUM_INT
    	|	NUM_LONG
    	|	NUM_FLOAT
    	|	NUM_DOUBLE
    	;

    constant
    	:	(	MINUS
    		|	PLUS
    		|
    		)
    		number
    	|	stringconstant
    	|	"true"
    	|	"false"
    	|	"null"
    	;

    stringconstant
    	:	STRING_LITERAL
    	|	QUOTED_STRING_LITERAL
    	;

    insertIntoExpr
    	:	(	ISTREAM
    		|	RSTREAM
    		|
    		)
    		INTO IDENT
    		(	insertIntoColumnList
    		|
    		)

    	;

    selectExpression
    	:	SELECT selectClause
    		(	( FROM fromClause )
    		|	( MATCHING matchingClause )
    		)
    		(	WHERE whereClause
    		|
    		)
    		(	GROUP BY groupByListExpr
    		|
    		)
    		(	HAVING havingClause
    		|
    		)
    		(	ORDER BY orderByListExpr
    		|
    		)
    		(	OUTPUT outputLimit
    		|
    		)
    	;

    selectClause
    	:	(	RSTREAM
    		|	ISTREAM
    		|
    		)
    		selectionList
    	;

    fromClause
    	:	windowDef
    		(	innerJoinList
    		|	outerJoinList
    		)

    	;

    matchingClause
    	:	matchingExpression
    		(	RETAIN retainClause
    		|
    		)

    	;

    whereClause
    	:	evalOrExpression
    	;

    groupByListExpr
    	:	expression ( COMMA expression )*
    	;

    havingClause
    	:	evalOrExpression
    	;

    orderByListExpr
    	:	orderByListElement ( COMMA orderByListElement )*
    	;

    outputLimit
    	:	(	ALL
    		|	( (	FIRST
    				|	LAST
    				)
    				(	NUM_INT
    				|
    				) )
    			(	EVENT
    			|	EVENTS
    			|
    			)
    		|
    		)
    		(	EVERY_EXPR number
    			(	EVENT
    			|	EVENTS
    			|	SECONDS
    			|	SECOND
    			|	SEC
    			|	MINUTES
    			|	MINUTE
    			|	MIN MILLISECONDS
    			|	MS
    			)
    		|
    		)

    	;

    windowDef
    	:	streamExpression
    		(	RETAIN retainClause
    		|
    		)

    	;

    innerJoinList
    	:	( COMMA windowDef )*
    	;

    outerJoinList
    	:	( outerJoin )+
    	;

    insertIntoColumnList
    	:	LPAREN IDENT ( COMMA IDENT )* RPAREN
    	;

    streamExpression
    	:	( (	streamRef
    			|	databaseJoinExpression
    			|	subqueryExpression
    			)
    			(	AS
    			|
    			)
    			(	IDENT
    			|
    			) )
    	;

    retainClause
    	:	( (	( ALL
    					(	EVENTS
    					|
    					) )
    			|	( (	BATCH OF
    					|
    					)
    					retainExpr )
    			)
    			(	withClause
    			|
    			)
    			(	partionByClause
    			|
    			) )
    	;

    outerJoin
    	:	(	LEFT
    		|	RIGHT
    		|	FULL
    		)
    		OUTER JOIN streamExpression outerJoinCondition
    		(	RETAIN retainClause
    		|
    		)

    	;

    outerJoinCondition
    	:	ON eventProperty EQUALS eventProperty
    	;

    evalOrExpression
    	:	evalAndExpression ( OR_EXPR evalAndExpression )*
    	;

    retainExpr
    	:	event_count
    	|	time_period
    		(	basedOnClause
    		|
    		)
    	;

    withClause
    	:	( WITH withIdentifier )+
    	;

    partionByClause
    	:	( PARTITION BY eventProperty )+
    	;

    event_count
    	:	number
    		(	EVENT
    		|	EVENTS
    		)
    	;

    time_period
    	:	(	dayPart
    			(	hourPart
    			|
    			)
    			minutePart
    			(	secondPart
    			|
    			)
    			(	millisecondPart
    			|
    			)
    		|	dayPart
    			(	hourPart
    			|
    			)
    			(	secondPart
    			|
    			)
    			(	millisecondPart
    			|
    			)
    		|	hourPart minutePart
    			(	secondPart
    			|
    			)
    			(	millisecondPart
    			|
    			)
    		|	hourPart
    			(	secondPart
    			|
    			)
    			(	millisecondPart
    			|
    			)
    		|	minutePart
    			(	secondPart
    			|
    			)
    			(	millisecondPart
    			|
    			)
    		|	secondPart
    			(	millisecondPart
    			|
    			)
    		|	millisecondPart
    		)

    	;

    basedOnClause
    	:	( BASED ON eventProperty )+
    	;

    withIdentifier
    	:	(	( (	NUM_INT
    				|
    				)
    				(	LARGEST
    				|	SMALLEST
    				) )
    		|	UNIQUE
    		)
    		eventProperty
    	;

    matchingExpression
    	:	patternExpression
    	;

    selectionList
    	:	selectionListElement ( COMMA selectionListElement )*
    	;

    selectionListElement
    	:	STAR
    	|	expression
    		(	AS IDENT
    		|
    		)

    	;

    expression
    	:	caseExpression
    	;

    streamRef
    	:	classIdentifier
    	;

    databaseJoinExpression
    	:	IDENT LPAREN
    		(	STRING_LITERAL
    		|	QUOTED_STRING_LITERAL
    		)
    		RPAREN
    	;

    subqueryExpression
    	:	LPAREN eplExpression RPAREN
    	;

    classIdentifier
    	:	IDENT ( DOT IDENT )*
    	;

    orderByListElement
    	:	expression
    		(	ASC
    		|	DESC
    		|
    		)

    	;

    caseExpression
    	:	CASE ( whenClause )+
    		(	elseClause
    		|
    		)
    		END
    	|	CASE expression ( whenClause )+
    		(	elseClause
    		|
    		)
    		END
    	|	evalOrExpression
    	;

    whenClause
    	:	( WHEN expression THEN expression )
    	;

    elseClause
    	:	( ELSE expression )
    	;

    evalAndExpression
    	:	bitWiseExpression ( AND_EXPR bitWiseExpression )*
    	;

    bitWiseExpression
    	:	negatedExpression ( (	BAND
    			|	BOR
    			|	BXOR
    			)
    			negatedExpression )*
    	;

    negatedExpression
    	:	evalEqualsExpression
    	|	NOT_EXPR evalEqualsExpression
    	;

    evalEqualsExpression
    	:	evalRelationalExpression ( (	EQUALS
    			|	IS
    			|	IS NOT_EXPR
    			|	SQL_NE
    			|	NOT_EQUAL
    			)
    			evalRelationalExpression )*
    	;

    evalRelationalExpression
    	:	concatenationExpr
    		(	( ( (	LT
    					|	GT
    					|	LE
    					|	GE
    					)
    					concatenationExpr )* )
    		|	(	NOT_EXPR
    			|
    			)
    			(	( IN_SET ( LPAREN expression ( COMMA expression )* RPAREN ) )
    			|	( BETWEEN betweenList )
    			|	( LIKE concatenationExpr
    					(	ESCAPE stringconstant
    					|
    					) )
    			|	( REGEXP concatenationExpr )
    			)
    		)
    	;

    concatenationExpr
    	:	additiveExpression
    		(	LOR additiveExpression ( LOR additiveExpression )*
    		|
    		)

    	;

    betweenList
    	:	concatenationExpr AND_EXPR concatenationExpr
    	;

    additiveExpression
    	:	multiplyExpression ( (	PLUS
    			|	MINUS
    			)
    			multiplyExpression )*
    	;

    multiplyExpression
    	:	unaryExpression ( (	STAR
    			|	DIV
    			|	MOD
    			)
    			unaryExpression )*
    	;

    unaryExpression
    	:	MINUS eventProperty
    	|	constant
    	|	LPAREN expression RPAREN
    	|	eventPropertyOrLibFunction
    	|	builtinFunc
    	|	arrayExpression
    	;

    eventPropertyOrLibFunction
    	:	eventProperty
    	|	libFunction
    	;

    builtinFunc
    	:	SUM LPAREN
    		(	ALL
    		|	DISTINCT
    		|
    		)
    		expression RPAREN
    	|	AVG LPAREN
    		(	ALL
    		|	DISTINCT
    		|
    		)
    		expression RPAREN
    	|	PERC LPAREN
    		(	ALL
    		|	DISTINCT
    		|
    		)
    		expression RPAREN
    	|	TREND LPAREN
    		(	ALL
    		|	DISTINCT
    		|
    		)
    		expression RPAREN
    	|	COUNT LPAREN
    		(	( (	ALL
    				|	DISTINCT
    				|
    				)
    				expression )
    		|	( STAR )
    		)
    		RPAREN
    	|	MEDIAN LPAREN
    		(	ALL
    		|	DISTINCT
    		|
    		)
    		expression RPAREN
    	|	STDDEV LPAREN
    		(	ALL
    		|	DISTINCT
    		|
    		)
    		expression RPAREN
    	|	AVEDEV LPAREN
    		(	ALL
    		|	DISTINCT
    		|
    		)
    		expression RPAREN
    	|	COALESCE LPAREN expression COMMA expression ( COMMA expression )* RPAREN
    	|	PREVIOUS LPAREN expression COMMA eventProperty RPAREN
    	|	PRIOR LPAREN NUM_INT COMMA eventProperty RPAREN
    	;

    arrayExpression
    	:	LCURLY
    		(	expression ( COMMA expression )*
    		|
    		)
    		RCURLY
    	;

    maxFunc
    	:	(	MAX
    		|	MIN
    		)
    		LPAREN expression
    		(	COMMA expression ( COMMA expression )*
    		|
    		)
    		RPAREN
    	;

    libFunction
    	:	(	classIdentifierNonGreedy DOT
    		|
    		)
    		funcIdent LPAREN
    		(	libFunctionArgs
    		|
    		)
    		RPAREN
    	;

    classIdentifierNonGreedy
    	:	IDENT ( DOT IDENT )*
    	;

    funcIdent
    	:	IDENT
    	|	MAX
    	|	MIN
    	;

    libFunctionArgs
    	:	(	ALL
    		|	DISTINCT
    		|
    		)
    		expression ( COMMA expression )*
    	;

    followedByExpression
    	:	orExpression ( (	FOLLOWED_BY
    			|	( FOLLOWED BY )
    			|	( NOT_EXPR FOLLOWED BY )
    			)
    			orExpression )*
    	;

    orExpression
    	:	andExpression ( OR_EXPR andExpression )*
    	;

    andExpression
    	:	qualifyExpression ( AND_EXPR qualifyExpression )*
    	;

    qualifyExpression
    	:	(	EVERY_EXPR
    		|	NOT_EXPR
    		|
    		)
    		guardPostFix
    	;

    guardPostFix
    	:	(	atomicExpression
    		|	LPAREN patternExpression RPAREN
    		)
    		(	WITHIN time_period
    		|
    		)

    	;

    atomicExpression
    	:	eventFilterExpression
    	;

    eventFilterExpression
    	:	(	IDENT ASSIGN
    		|
    		)
    		( classIdentifier )
    		(	LPAREN
    			(	filterParamSet
    			|
    			)
    			RPAREN
    		|
    		)

    	;

    parameterSet
    	:	parameter ( COMMA parameter )*
    	;

    parameter
    	:	singleParameter
    	|	numericParameterList
    	|	arrayParameterList
    	;

    singleParameter
    	:	rangeOperand
    	|	frequencyOperand
    	|	STAR
    	|	constant
    	|	time_period
    	;

    numericParameterList
    	:	LBRACK numericListParameter ( COMMA numericListParameter )* RBRACK
    	;

    arrayParameterList
    	:	LCURLY
    		(	constant ( COMMA constant )*
    		|
    		)
    		RCURLY
    	;

    rangeOperand
    	:	NUM_INT COLON NUM_INT
    	;

    frequencyOperand
    	:	STAR DIV NUM_INT
    	;

    numericListParameter
    	:	rangeOperand
    	|	frequencyOperand
    	|	NUM_INT
    	;

    filterParamSet
    	:	expression ( COMMA expression )*
    	;

    eventPropertyAtomic
    	:	IDENT
    	|	IDENT LBRACK NUM_INT RBRACK
    	|	IDENT LPAREN
    		(	STRING_LITERAL
    		|	QUOTED_STRING_LITERAL
    		)
    		RPAREN
    	;

    dayPart
    	:	number
    		(	DAYS
    		|	DAY
    		)

    	;

    hourPart
    	:	number
    		(	HOURS
    		|	HOUR
    		|	HR
    		)

    	;

    minutePart
    	:	number
    		(	MINUTES
    		|	MINUTE
    		|	MIN
    		)

    	;

    secondPart
    	:	number
    		(	SECONDS
    		|	SECOND
    		|	SEC
    		)

    	;

    millisecondPart
    	:	number
    		(	MILLISECONDS
    		|	MILLISECOND
    		|	MSEC
    		|	MS
    		)

    	;