@
@	Cego language definition
@	--------------------
@	by Bjoern Lemke
@
@	(C)opyright 2003-2010 by Bjoern Lemke
@
@	This language defintion can be used in combination with the dragon parser generator
@
@	Status: 2.16
@

HEADER
IGNORE	STRINGVAL
SEPIGNORE '\t'
SEPIGNORE ' '
SEPIGNORE '\n'
SEPSIGN ';'
SEPSIGN ','
SEPSIGN '='
SEPSIGN '<'
SEPSIGN '>'
SEPSIGN ')'
SEPSIGN '('
SEPSIGN '['
SEPSIGN ']'
SEPSIGN '/'
SEPSIGN '+'
SEPSIGN '-'
SEPSIGN '|'
SEPSIGN '*'
END

TOKENSET
add			:	ADD
and			:	AND
all			:	ALL
alter			:	ALTER
append			:	APPEND
as			:	AS
asc			:	ASC
authorize		:	AUTHORIZE
autocommit		:	AUTOCOMMIT
avg			:	AVG
begin			:	BEGIN
between			:	BETWEEN
bigint			:	BIGINT
bitand			:	BITAND
bitor			:	BITOR
bitxor			:	BITXOR
blob			:	BLOB
bool			:	BOOL
btree			:	BTREE
by			:	BY
call			:	CALL
case			:	CASE
check			:	CHECK
close			:	CLOSE
commit			:	COMMIT
column			:	COLUMN
constraint		:	CONSTRAINT
count			:	COUNT
counter			:	COUNTER
create			:	CREATE
cursor			:	CURSOR
date			:	DATE
date2str		:	DATE2STR
date2int		:	DATE2INT
datetime		:	DATETIME
decimal			:	DECIMAL
default			:	DEFAULT
delete			:	DELETETOK
desc			:	DESC
distinct		:	DISTINCT
div			:	DIV
double			:	DOUBLE
drop			:	DROP
else			:	ELSE
elsif			:	ELSIF
end			:	END_TOKEN
exception		:	EXCEPTION
exists			:	EXISTS
false			:	FALSEVAL
fetch			:	FETCH
fixed			:	FIXED
float			:	FLOAT
for			:	FOR
foreign			:	FOREIGN
from			:	FROM
getpos			:	GETPOS
group			:	GROUP
having			:	HAVING
identified		:	IDENTIFIED
if			:	IF
in			:	INTOK
index			:	INDEX
inner			:	INNER
int			:	INT
into			:	INTO
int2date		:	INT2DATE
insert			:	INSERT
is			:	IS
isolation		:	ISOLATION
jdbc			:	JDBC
join			:	JOIN
key			:	KEY
left			:	LEFT
length			:	LENGTH
like			:	LIKE
list			:	LIST
load			:	LOAD
locks			:	LOCKS
long			:	LONG
lower			:	LOWER
ltrim			:	LTRIM
min			:	MIN
max			:	MAX
mod			:	MOD
modify			:	MODIFY
nextcount		:	NEXTCOUNT
noop			:	NOOP
not			:	NOT
null			:	NULLTOKEN
off			:	OFF
on			:	ON
out			:	OUTTOK
outer			:	OUTER
or			:	OR
order			:	ORDER
plan			:	PLAN
pool			:	POOL
power			:	POWER
primary			:	PRIMARY
print			:	PRINT
procedure		:	PROCEDURE
querycache		:	QUERYCACHE
quit			:	QUIT
randstr			:	RANDSTR
randint			:	RANDINT
rbseg			:	RBSEG
references		:	REFERENCES
rename			:	RENAME
reorganize		:	REORGANIZE
return			:	RETURNTOKEN
remove			:	REMOVE
replace			:	REPLACE
right			:	RIGHT
rollback		:	ROLLBACK
round			:	ROUND
rowlimit		:	ROWLIMIT
rtrim			:	RTRIM
select			:	SELECT
set			:	SET
setcount		:	SETCOUNT
show			:	SHOW
smallint		:	SMALLINT
start			:	START_TOKEN
string			:	STRING
substr			:	SUBSTR
sum			:	SUM
sync			:	SYNC
sysdate			:	SYSDATE
systemspace		:	SYSTEMSPACE
sysobj			:	SYSOBJ
tableinfo		:	TABLEINFO
table			:	TABLE
tableset		:	TABLESET
then			:	THEN
tinyint			:	TINYINT
tmpobj			:	TMPOBJ
transaction		:	TRANSACTION
str2int			:	STR2INT
str2long		:	STR2LONG
to			:	TO
trim			:	TRIM
true			:	TRUEVAL
trunc			:	TRUNC
union			:	UNION
unique			:	UNIQUE
update			:	UPDATE
upper			:	UPPER
var			:	VAR
values			:	VALUES
view			:	VIEW
when			:	WHEN
where			: 	WHERE
while			:	WHILE
'|'			:	CONCAT
'='			:	EQU
','			:	KSEP
'('			:	LB
'<'			:	LT
'>'			:	MT
'!'			:	NEGATION
')'			:	RB
'['			:	LAB
']'			:	RAB
';'			: 	SEMICOLON
'*'			:	STAR
'/'			:	DIVISION
'-'			:	MINUS
'+'			:	PLUS
(0|[1-9]*[0-9])		:	INTVAL
(0|[1-9]*[0-9])'.'*[0-9]	:	FLOATVAL
[a-zA-Z$]*[a-zA-Z0-9_]		:	IDENTIFIER
':'[a-zA-Z]*[a-zA-Z0-9_]	:	VARREF
[a-zA-Z]*[a-zA-Z0-9_]'.'[a-zA-Z$]*[a-zA-Z0-9_]	:	QUALIFIEDOBJ
[a-zA-Z]*[a-zA-Z0-9_]'.'			:	QUALIFIEDPRE
[a-zA-Z$]*[a-zA-Z0-9_]'@'[a-zA-Z]*[a-zA-Z0-9_]	:	QUALIFIEDTS
END

PRODUCTIONSET
Start			: 	Statement SEMICOLON
Statement		:	SYNC ; execSync
Statement		:	LIST TABLESET ; execListTableSet
Statement		:	LIST TABLE TableSetOpt ; execListTable
Statement		:	LIST PROCEDURE  TableSetOpt ; execListProc
Statement		:	LIST VIEW TableSetOpt ; execListView
Statement		:	LIST INDEX TableSetOpt ; execListIndex
Statement		:	LIST BTREE TableSetOpt ; execListBTree
Statement		:	LIST KEY TableSetOpt ; execListKey
Statement		:	LIST COUNTER TableSetOpt ; execListCounter
Statement		:	LIST SYSOBJ TableSetOpt ; execListSysObj
Statement		:	LIST TMPOBJ TableSetOpt ; execListTmpObj
Statement		:	LIST CHECK TableSetOpt ; execListCheck
TableSetOpt		:	FOR IDENTIFIER ; setTableSetOpt 
TableSetOpt		:	
Statement		:	TABLEINFO ObjSpec ; execTableInfo
Statement		:	SHOW POOL ; execShowPool
Statement		:	SHOW SYSTEMSPACE ; execShowSystemSpace
Statement		:	DESC TABLE ObjSpec ; execTableDesc
Statement		:	DESC INDEX ObjSpec ; execIndexDesc
Statement		:	DESC BTREE ObjSpec ; execBTreeDesc
Statement		:	DESC VIEW ObjSpec ; execViewDesc
Statement		:	DESC FOREIGN KEY ObjSpec ; execKeyDesc
Statement		:	DESC CHECK ObjSpec ; execCheckDesc
Statement		:	DESC PROCEDURE ObjSpec ; execProcDesc
Statement		:	SHOW PROCEDURE ObjSpec ; execProcShow
Statement		:	SHOW VIEW ObjSpec ; execViewShow
Statement		:	SHOW CHECK ObjSpec ; execCheckShow
Statement		:	SET TABLESET IDENTIFIER ; execSetTableSet
Statement		:	AUTHORIZE IDENTIFIER IDENTIFIED BY STRINGVAL FOR IDENTIFIER ; execAuthUser
Statement		:	StartStatement ; execQuery
Statement		:	CommitStatement ; execQuery
Statement		:	RollbackStatement ; execQuery
Statement		:	SET APPEND ON ; execEnableAppendMode
Statement		:	SET APPEND OFF ; execDisableAppendMode
Statement		:	SET AUTOCOMMIT ON ; execEnableAutoCommit
Statement		:	SET AUTOCOMMIT OFF ; execDisableAutoCommit
Statement		:	SET ISOLATION IDENTIFIER ; execSetIsolation
Statement		:	SET QUERYCACHE ON ; execEnableQueryCache
Statement		:	SET QUERYCACHE OFF ; execDisableQueryCache
Statement		:	REORGANIZE TABLE ObjSpec ; execTableReorganize
Statement		:	REORGANIZE INDEX ObjSpec ; execIndexReorganize
Statement		:	SelectStatement ; execSelect
Statement		:	PLAN SelectStatement ; execSelectPlan
Statement		:	InsertStatement
Statement		:	DeleteStatement ; execQuery
Statement		:	UpdateStatement ; execQuery
Statement		:	AlterStatement ; execQuery
Statement		:	RenameStatement ; execQuery

# view execs
Statement		:	CREATE VIEW ObjSpec AS SelectStatement ; execViewCreate
Statement		:	LOAD VIEW ObjSpec AS SelectStatement ; execViewLoad
# procedure execs
Statement		:	CREATE ProcDef ; execProcCreate
Statement		:	LOAD ProcDef ; execProcLoad
Statement		:    	CALL ObjSpec LB ProcValueListOpt RB ; execProcCall
Statement		:    	VARREF EQU CALL ObjSpec LB ProcValueListOpt RB ; execFuncCall
# create execs
Statement		:	CREATE TABLE ObjSpec LB ColumnList RB  ; execUserTableCreate
Statement		:	CREATE PRIMARY IndexType ON ObjSpec LB SimpleAttrList RB ; execPrimaryIndexCreate
Statement		:	CREATE IndexOption IndexType IDENTIFIER ON ObjSpec LB SimpleAttrList RB ; execIndexCreate
Statement		:	DropOpt TABLE ObjSpec ; execTableDrop
Statement		:	DropOpt INDEX ObjSpec ; execIndexDrop
Statement		:	DropOpt VIEW ObjSpec ; execViewDrop
Statement		:	DropOpt PROCEDURE ObjSpec ; execProcDrop
Statement		:	DropOpt FOREIGN KEY ObjSpec ; execFKeyDrop
Statement		:	DropOpt CHECK ObjSpec ; execCheckDrop
Statement		:	DropOpt BTREE ObjSpec ; execBTreeDrop
DropOpt			:	DROP ; dropOpt1 
DropOpt			:	DROP IF EXISTS ; dropOpt2
Statement		:	ALTER TABLE ObjSpec ADD FOREIGN KEY IDENTIFIER LB SimpleAttrList RB  REFERENCES IDENTIFIER LB SimpleAttrList RB ; execForeignKeyCreate

Statement		:	ALTER TABLE ObjSpec ADD CHECK IDENTIFIER ON QueryCondition ; execCheckCreate


Statement		:	SET IDENTIFIER EQU Expr ; execAssignStatement
Statement		:	PRINT Expr ; execPrint
Statement		:	CHECK INDEX IDENTIFIER ; execIndexCheck
# Counter 
Statement		:	CREATE COUNTER CounterId ; execCreateCounter
Statement		:	DropOpt COUNTER CounterId ; execDropCounter
Statement		:	SET COUNTER CounterId TO Expr ; execSetCounter
CounterId		:	IDENTIFIER ; execCounterId
# JDBC info calls
Statement		:	JDBC JdbcArgList ; jdbcInfo
JdbcArgList		:	JdbcArgList IDENTIFIER ; jdbcArg1
JdbcArgList		:	IDENTIFIER ; jdbcArg2

#
# Union All
#
UnionAllOpt		:	UNION ALL SelectStatement ; unionAllStore 
UnionAllOpt		:	

#
# Procedures
#
ProcHead		:	PROCEDURE ObjSpec LB ProcArgOpt RB ReturnOpt ; procHead
ProcDef			:    	ProcHead  BEGIN ProcStmtBlock END_TOKEN ; procStore
ReturnOpt		:	RETURNTOKEN DataTypeProd ; procReturnOpt
ReturnOpt		:	
ProcArgOpt		:	ProcArgList
ProcArgOpt		:
ProcArgList		:	ProcArgList KSEP ProcArg
ProcArgList		:	ProcArg 
ProcArg			:	IDENTIFIER INTOK DataTypeProd ; procArg1
ProcArg			:	IDENTIFIER OUTTOK DataTypeProd ; procArg2
ProcStmtBlock		:	ProcStatementList ProcExceptionList 
ProcStatementList	:	ProcStatementList ProcStatement SEMICOLON
ProcStatementList	:	ProcStatement SEMICOLON ; procStoreBlock
ProcStatement		:	VAR IDENTIFIER DataTypeProd ProcInitialAssignment ; procVarStatement
ProcStatement		:	CURSOR IDENTIFIER AS SelectStatement ; procCursorCreateStatement
ProcStatement		:	CLOSE IDENTIFIER ; procCursorCloseStatement
ProcStatement		:	VARREF EQU Expr ; procAssignStatement
ProcStatement		:	Expr ; procAssign2NullStatement
ProcStatement		:	NOOP ; procNoopStatement
ProcInitialAssignment	:	EQU Expr ; procInitialAssignment1
ProcInitialAssignment	:	ProcNoAssignment ; procInitialAssignment2
ProcNoAssignment	:	

# procedure queries
ProcStatement		:	InsertStatement ; procQueryStatement
ProcStatement		:	DeleteStatement ; procQueryStatement
ProcStatement		:	UpdateStatement ; procQueryStatement
ProcStatement		:	StartStatement ; procQueryStatement
ProcStatement		:	CommitStatement ; procQueryStatement
ProcStatement		:	RollbackStatement ; procQueryStatement
#
# Procedure return statement
#
ProcStatement		:	RETURNTOKEN ; procReturnStatement1
ProcStatement		:	RETURNTOKEN Expr ; procReturnStatement2
#
# Procedure nested block
#
ProcStatement		:	ProcBlockStart ProcStmtBlock END_TOKEN ; procBlockStatement
ProcBlockStart		:	BEGIN ; procBlockStart
#
# Procedure exception handling
#
ProcExceptionList	:	ProcExceptionList ProcExceptionStmt
ProcExceptionList	:	
ProcExceptionStmt	:	EXCEPTION WHEN ProcExceptionType THEN ProcStatementList ; procExceptionStatement
ProcValueListOpt	: 	ProcValueList ; procValueSpec
ProcValueListOpt	:
ProcValueList		:	ProcValueList KSEP Expr ; procExprValue
ProcValueList		:	Expr ; procExprValue
ProcExceptionType	:	IDENTIFIER ; procExceptionCondition
#
# Procedure if condition
#
ProcStatement		:	ProcIfPart ProcElsIfList ProcElseOpt END_TOKEN ; procIfStatement
ProcIfPart		:	IF ProcIfCondition THEN ProcStmtBlock ; procStoreIfBlock
ProcElsIfList		:	ProcElsIfOpt ProcElsIfList
ProcElsIfList		:	
ProcElsIfOpt		:	ELSIF ProcElsIfCondition THEN ProcStmtBlock ; procStoreIfBlock
ProcElseOpt		:	ProcElsePart ProcStmtBlock ; procStoreElseBlock
ProcElseOpt		:
ProcElsePart		:	ELSE ; procElsePart
ProcIfCondition		:	ProcCondition ; procIfCondition
ProcElsIfCondition	:	ProcCondition ; procElsIfCondition
#
# Procedure while loop
#
ProcStatement		:	WHILE ProcWhileCondition BEGIN ProcStmtBlock END_TOKEN ; procWhileStatement
ProcWhileCondition	:	ProcCondition ; procWhileCondition
#
# Procedure condition and predicate
#
ProcCondition		: 	ProcCondition OR ProcPredicate  ; procCondition1
ProcCondition		: 	ProcCondition AND ProcPredicate  ; procCondition2
ProcCondition		:	ProcPredicate ; procCondition3
ProcPredicate		:	LB ProcCondition RB ; procPredicate1
ProcPredicate		:	Expr Comparison Expr ; procPredicate2
ProcPredicate		:	Expr IS NULLTOKEN ; procPredicate3
ProcPredicate		:	Expr IS NOT NULLTOKEN ; procPredicate4
#
# Expression, Term and Factor definitions
#
Expr			:	Expr PLUS Term ; procExpr1
Expr			:	Expr MINUS Term ; procExpr2
Expr			:	Term ; procExpr3
Expr			:	Expr CONCAT Term ; procExpr4
Term			:	Term STAR Factor ; procTerm1
Term			:	Term DIVISION Factor ; procTerm2
Term			:	Factor ; procTerm3
Factor			:	VARREF ; procFactor1
Factor			:	Constant ; procFactor2
Factor			:	FETCH IDENTIFIER INTO LB FetchArgList RB ; procFactor3
Factor			:	Attribute ; procFactor4
Factor			:	Function ; procFactor5
Factor			:	LB Expr RB ; procFactor6
Factor			:	LB SelectStatement RB ; procFactor7
Factor			:	CaseClause ; procFactor8
Factor			:	COUNT LB STAR RB ; procFactor9
Factor			:	SUM LB Expr RB ; procFactor10
Factor			:	AVG LB Expr RB ; procFactor11
Factor			:	COUNT LB DistinctOpt Expr RB ; procFactor12
Factor			:	MIN LB Expr RB ; procFactor13
Factor			:	MAX LB Expr RB ; procFactor14
#
CaseClause		:	CasePrepare CaseConditionList ELSE Expr END_TOKEN ; caseClause
CaseConditionList	:	CaseConditionList CaseCondition ; caseConditionList1
CaseConditionList	:	CaseCondition ; caseConditionList2
CaseCondition		:	WHEN QueryCondition THEN Expr ; caseCondition
CasePrepare		:   	CASE ; casePrepare
#
FetchArgList		:       FetchArgList KSEP VARREF ; procStoreFetchArg1
FetchArgList		:       VARREF  ; procStoreFetchArg2

#
# Object Creation
#
ColumnList		:	ColumnList KSEP KeyColumn
ColumnList		:	KeyColumn
KeyColumn		:	PRIMARY ColumnDesc ; setPrimaryColumn
KeyColumn		:	ColumnDesc ; setOrdinaryColumn
ColumnDesc		:	IDENTIFIER DataTypeProd DefaultOpt NullOpt ; setColumnDesc
NullOpt			:	NULLTOKEN ; setNullOpt
NullOpt			:	NOT NULLTOKEN ; setNotNullOpt
NullOpt			:       DefaultNullOpt ; setNullOpt
DefaultNullOpt		:		
DefaultOpt		:	DEFAULT Constant ; defaultOpt
DefaultOpt		:	DefaultDefOpt ; defaultNullOpt
DefaultDefOpt		:
# 
SimpleAttrList		:	SimpleAttr  KSEP SimpleAttrList
SimpleAttrList		:	SimpleAttr ; createSimpleAttrList
SimpleAttr		:	IDENTIFIER ; createSimpleAttr
IndexOption		:	UNIQUE ; setUniqueIndex
IndexOption		:
IndexType		:	INDEX ; setAVLIndex
IndexType		:	BTREE ; setBTreeIndex
#
# TA Statement
# 
StartStatement		:	START_TOKEN TRANSACTION ; startStore
CommitStatement		:	COMMIT ; commitStore
RollbackStatement	:	ROLLBACK ; rollbackStore
#
# Insert Statement
# 
InsertStatement		:	INSERT INTO ObjSpec InsertArgSpec InsertPrepare InsertValueSpecList ; insertStore
InsertStatement		:	INSERT INTO ObjSpec InsertArgSpec SelectStatement ; insertBySelectStore
InsertArgSpec		:	LB InsertArgList RB
InsertArgSpec		:
InsertPrepare		:	VALUES ; insertPrepare
#
InsertValueSpecList	:	InsertValueSpecList KSEP InsertValueSpec
InsertValueSpecList	:	InsertValueSpec
#
InsertValueSpec		:	LB InsertValueList RB ; insertValueSpecStoreExecute
InsertArgList		:	InsertArgList KSEP IDENTIFIER ; insertArg 
InsertArgList		:	IDENTIFIER ; insertArg 
InsertValueList		:	InsertValueList KSEP Expr ; insertExprValue 
InsertValueList		:	Expr ; insertExprValue 
#
# Select Statement
#
SelectStatement		:	SELECT Selection FROM TableSource WhereClause GroupClause OrderingClause LimitOpt UnionAllOpt ; selectStore
Selection		:	DistinctOpt SelectionList ; selectSelectionStore1
Selection		:	STAR ; selectSelectionStore2
SelectionList		:	SelectionList KSEP SelectItem ; selectionList1 
SelectionList		:	SelectItem ; selectionList2
SelectItem		:	Expr AliasOpt ; selectItem

TableSource		:	TableList ; selectTableListStore
TableSource		:	JoinSpecList ; selectJoinSpecStore
JoinSpecList		:	JoinSpecList JoinSpec 
JoinSpecList		:	Table JoinSpec
JoinSpec		:	InnerJoin Table JoinTableOn QueryCondition ; selectInnerJoinStore 
JoinSpec		:	LEFT OUTER JOIN Table JoinTableOn QueryCondition ; selectLeftOuterJoinStore 
JoinSpec		:	RIGHT OUTER JOIN Table JoinTableOn QueryCondition ; selectRightOuterJoinStore 
InnerJoin		:	INNER JOIN
InnerJoin		:	JOIN
TableList		:	Table KSEP TableList
TableList		:	Table 
Table			:	ObjSpec ; selectTable1
Table			:	ObjSpec IDENTIFIER ; selectTable2

JoinTableOn		:	ON ; selectStackJoinTable

AliasOpt		:	AS IDENTIFIER ; aliasOpt
AliasOpt		:	NoAliasOpt ; noAliasOpt
NoAliasOpt		:	

GroupClause		:	GROUP BY GroupList HavingClause ; selectGroupClause
GroupClause		:	NoGroup ; selectEmptyGroupClause
NoGroup			:	
GroupList		:	GroupList KSEP Attribute  ; selectGroupList1
GroupList		:	Attribute ; selectGroupList2

HavingClause		:	HAVING Expr Comparison Expr ; selectHavingClause
HavingClause		:	NoHaving ; selectEmptyHavingClause
NoHaving		:

OrderingClause		:	ORDER BY OrderingList ; selectOrderingClause
OrderingClause		:	NoOrdering ; selectEmptyOrderingClause
NoOrdering		:
OrderingList		:       OrderingList KSEP Expr OrderingOpt ; selectOrderingList1
OrderingList		:	Expr OrderingOpt ; selectOrderingList2
OrderingOpt		:	DefaultOrderOpt ; selectOrderingAsc
OrderingOpt		:	DESC ; selectOrderingDesc
DefaultOrderOpt 	:	ASC
DefaultOrderOpt 	:	
DistinctOpt		:	DISTINCT ; selectDistinctOpt
DistinctOpt		:	

LimitOpt		:	ROWLIMIT INTVAL ; selectLimitOpt1
LimitOpt		:	NoLimit ; selectLimitOpt2
NoLimit			:

#
# Update Statement
# 

UpdateStatement		:	UPDATE ObjSpec UpdDelAlias SET UpdateList WhereClause UpdReturnOpt ; updateStore
UpdateList		:	UpdateList KSEP Assignment
UpdateList		:	Assignment
Assignment		:	IDENTIFIER EQU Expr ; updateAssignment
UpdReturnOpt		:	RETURNTOKEN ReturnVarList
UpdReturnOpt		:
ReturnVarList		:	ReturnVarList KSEP ReturnVar
ReturnVarList		:	ReturnVar
ReturnVar		:	VARREF EQU Expr ; returnVarAssignment

#
# Delete Statement
# 

DeleteStatement		:	DELETETOK FROM ObjSpec UpdDelAlias WhereClause ; deleteStore

UpdDelAlias		:	IDENTIFIER ; setUpdDelAlias
UpdDelAlias		:

#
# Alter Statement
# 

AlterStatement		:	ALTER TABLE ObjSpec AlterList ; alterStore
AlterList		:       AlterOption KSEP AlterList
AlterList		:       AlterOption
AlterOption		:	DROP COLUMN IDENTIFIER ; alterDropCol
AlterOption		:	ADD COLUMN ColumnDesc ; alterAddCol
AlterOption		:	MODIFY COLUMN ColumnDesc ; alterModCol
AlterOption		:	RENAME COLUMN IDENTIFIER TO IDENTIFIER ; alterRenameCol

#
# Rename Statement
# 

RenameStatement		:	RENAME TABLE ObjSpec TO IDENTIFIER ; renameTable
RenameStatement		:	RENAME INDEX ObjSpec TO IDENTIFIER ; renameIndex
RenameStatement		:	RENAME KEY ObjSpec TO IDENTIFIER ; renameKey
RenameStatement		:	RENAME PROCEDURE ObjSpec TO IDENTIFIER ; renameProcedure
RenameStatement		:	RENAME VIEW ObjSpec TO IDENTIFIER ; renameView
RenameStatement		:	RENAME CHECK ObjSpec TO IDENTIFIER ; renameCheck

#
# Functions
#

Function		:	TRIM LB ExpressionList RB ; functionNative
Function		:	RTRIM LB ExpressionList RB ; functionNative
Function		:	LTRIM LB ExpressionList RB ; functionNative
Function		:	ROUND LB ExpressionList RB ; functionNative
Function		:	DATE2STR LB ExpressionList RB ; functionNative
Function		:	DATE2INT LB ExpressionList RB ; functionNative
Function		:	INT2DATE LB ExpressionList RB ; functionNative
Function		:	LOWER LB ExpressionList RB ; functionNative
Function		:	UPPER LB ExpressionList RB ; functionNative
Function		:	LEFT LB ExpressionList RB ; functionNative
Function		:	RIGHT LB ExpressionList RB ; functionNative
Function		:	GETPOS LB ExpressionList RB ; functionNative
Function		:	SUBSTR LB ExpressionList RB ; functionNative
Function		:	REPLACE LB ExpressionList RB ; functionNative
Function		:	LENGTH LB ExpressionList RB ; functionNative
Function		:	TRUNC LB ExpressionList RB ; functionNative
Function		:	STR2INT LB ExpressionList RB ; functionNative
Function		:	STR2LONG LB ExpressionList RB ; functionNative
Function		:	RANDSTR LB ExpressionList RB ; functionNative
Function		:	RANDINT LB ExpressionList RB ; functionNative
#
Function		:	MOD LB ExpressionList RB ; functionNative
Function		:	DIV LB ExpressionList RB ; functionNative
Function		:	POWER LB ExpressionList RB ; functionNative
Function		:	BITAND LB ExpressionList RB ; functionNative
Function		:	BITOR LB ExpressionList RB ; functionNative
Function		:	BITXOR LB ExpressionList RB ; functionNative
Function		:	NEXTCOUNT LB IDENTIFIER RB ; functionNextCount
Function		:	SETCOUNT LB IDENTIFIER KSEP Expr RB ; functionSetCount
#
Function		:	ObjSpec LB ExpressionList RB ; functionUserDef1
Function		:	ObjSpec LB RB ; functionUserDef2
ExpressionList		:	ExpressionList KSEP Expr ; functionExprList1
ExpressionList		:	Expr ; functionExprList2

#
# Where Clause
#

WhereClause		:	WHERE QueryCondition ; wcWhereClause
WhereClause		:       NoWhere ; wcEmptyClause
NoWhere			:
QueryCondition		: 	QueryCondition AND QueryPredicate  ; wcConditionAnd
QueryCondition		: 	QueryCondition OR QueryPredicate  ; wcConditionOr
QueryCondition		:	QueryPredicate ; wcConditionPredicate
# QueryCondition		:	NOT QueryPredicate ; wcConditionNotPredicate
QueryPredicate		: 	EXISTS LB SelectStatement RB ; wcPredicateQueryExists
# QueryPredicate		: 	NOT EXISTS LB SelectStatement RB ;  wcPredicateQueryNotExists
# QueryPredicate		:	Expr Comparison LB SelectStatement RB ; wcPredicateQueryComp
QueryPredicate		:	Expr INTOK LB SelectStatement RB ; wcPredicateQueryIn
QueryPredicate		:	Expr NOT INTOK LB SelectStatement RB ; wcPredicateQueryNotIn 
QueryPredicate		:	Expr Comparison Expr ; wcPredicateExprComp
QueryPredicate		:	Expr BETWEEN Expr AND Expr ; wcPredicateBetween
QueryPredicate		:	Expr IS NULLTOKEN ; wcPredicateNullComp
QueryPredicate		:	Expr IS NOT NULLTOKEN ; wcPredicateNotNullComp
QueryPredicate		:	Expr LIKE STRINGVAL ; wcPredicateLikeComp
QueryPredicate		:	Expr NOT LIKE STRINGVAL ; wcPredicateNotLikeComp
QueryPredicate		:	LB QueryCondition RB ; wcPredicateCondition
QueryPredicate		:	NOT QueryPredicate ; wcPredicateNotPredicate

#
# Other
#

DataTypeProd		:	INT ; miscIntType
DataTypeProd		:	LONG ; miscLongType
DataTypeProd		:	STRING LB INTVAL RB ; miscStringType
DataTypeProd		:	DATETIME ; miscDateTimeType
DataTypeProd		:	BOOL ; miscBoolType
DataTypeProd		:	BIGINT LB INTVAL RB ; miscBigIntType
DataTypeProd		:	FLOAT ; miscFloatType
DataTypeProd		:	DOUBLE ; miscDoubleType
DataTypeProd		:	SMALLINT ; miscSmallIntType
DataTypeProd		:	TINYINT ; miscTinyIntType
DataTypeProd		:	DECIMAL LB INTVAL RB ; miscDecimalType
DataTypeProd		:	FIXED LB INTVAL RB ; miscFixedType
DataTypeProd		:	BLOB ; miscBlobType
Comparison		:	EQU ; miscEqualComp
Comparison		:	NEGATION EQU ; miscNotEqualComp
Comparison		:	LT ; miscLessComp
Comparison		:	MT ; miscMoreComp
Comparison		:	LT EQU ; miscLessEqualComp
Comparison		:	MT EQU ; miscMoreEqualComp
Attribute		:	IDENTIFIER ; miscAttribute1
Attribute		:	QUALIFIEDOBJ ; miscAttribute2
Attribute		:	QUALIFIEDPRE STAR ; miscAttribute3
SignedInt		:	INTVAL ; miscIntString
SignedInt		:	MINUS INTVAL ; miscNegatedIntString
SignedFloat		:	FLOATVAL ; miscFloatString
SignedFloat		:	MINUS FLOATVAL ; miscNegatedFloatString
Constant		:	SignedInt ; miscIntValue
Constant		:	LB LONG RB SignedInt ; miscLongValue
Constant		:	LB BIGINT RB SignedInt ; miscBigIntValue
Constant		:	LB SMALLINT RB SignedInt ; miscSmallIntValue
Constant		:	LB TINYINT RB SignedInt ; miscTinyIntValue
Constant		:	STRINGVAL ; miscStringValue
Constant		:	SignedFloat ; miscFloatValue 
Constant		:	LB DOUBLE RB SignedFloat ; miscDoubleValue
Constant		:	LB DECIMAL RB SignedFloat ; miscDecimalValue
Constant		:	LB FIXED RB SignedFloat ; miscFixedValue
Constant		:	DATE LB DateFormat KSEP DateValue RB ; miscFormatDate
Constant		:	SYSDATE ; miscSysDate
Constant		:	NULLTOKEN ; miscNull
Constant		:	TRUEVAL ; miscTrueValue
Constant		:	FALSEVAL ; miscFalseValue
Constant		:	LAB INTVAL KSEP INTVAL RAB ; miscBlobRef
DateFormat		:	STRINGVAL ; miscDateFormat
DateValue		:	STRINGVAL ; miscDateValue
ObjSpec			:	IDENTIFIER ; setObject1
ObjSpec			:	QUALIFIEDOBJ ; setObject2
ObjSpec			:	QUALIFIEDTS ; setObject3
END




