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

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

TOKENSET
[aA][dD][dD]	: ADD
[aA][fF][tT][eE][rR]	: AFTER
[aA][lL][iI][aA][sS]	: ALIAS
[aA][nN][dD]	: AND
[aA][lL][lL]	: ALL
[aA][lL][tT][eE][rR]	: ALTER
[aA][pP][pP][eE][nN][dD]	: APPEND
[aA][sS]	: AS
[aA][sS][cC]	: ASC
[aA][sS][cC]2[iI][nN][tT]	: ASC2INT
[aA][uU][tT][hH][oO][rR][iI][zZ][eE]	: AUTHORIZE
[aA][uU][tT][oO][cC][oO][mM][mM][iI][tT]	: AUTOCOMMIT
[aA][vV][gG]	: AVG
[aA][vV][lL][tT][rR][eE][eE]	: AVLTREE
[bB][eE][fF][oO][rR][eE]	: BEFORE
[bB][eE][gG][iI][nN]	: BEGIN
[bB][eE][tT][wW][eE][eE][nN]	: BETWEEN
[bB][iI][gG][iI][nN][tT]	: BIGINT
[bB][iI][tT][aA][nN][dD]	: BITAND
[bB][iI][tT][oO][rR]	: BITOR
[bB][iI][tT][xX][oO][rR]	: BITXOR
[bB][lL][oO][bB]	: BLOB
[bB][lL][oO][bB][sS][iI][zZ][eE]	: BLOBSIZE
[bB][lL][oO][bB][rR][eE][fF]	: BLOBREF
[bB][oO][oO][lL]	: BOOL
[bB][tT][rR][eE][eE]	: BTREE
[bB][yY]	: BY
[cC][aA][cC][hH][eE][dD]	: CACHED
[cC][aA][lL][lL]	: CALL
[cC][aA][sS][eE]	: CASE
[cC][hH][eE][cC][kK]	: CHECK
[cC][lL][oO][bB]	: CLOB
[cC][lL][oO][bB][sS][iI][zZ][eE]	: CLOBSIZE
[cC][lL][oO][bB][rR][eE][fF]	: CLOBREF
[cC][lL][oO][bB]2[sS][tT][rR]	: CLOB2STR
[cC][lL][oO][sS][eE]	: CLOSE
[cC][oO][mM][mM][iI][tT]	: COMMIT
[cC][oO][lL][uU][mM][nN]	: COLUMN
[cC][oO][nN][dD][iI][tT][iI][oO][nN]	: CONDITION
[cC][oO][nN][sS][tT][rR][aA][iI][nN][tT]	: CONSTRAINT
[cC][oO][uU][nN][tT]	: COUNT
[cC][oO][uU][nN][tT][eE][rR]	: COUNTER
[cC][rR][eE][aA][tT][eE]	: CREATE
[cC][uU][rR][sS][oO][rR]	: CURSOR
[dD][aA][tT][eE]2[sS][tT][rR]	: DATE2STR
[dD][aA][tT][eE]2[lL][oO][nN][gG]	: DATE2LONG
[dD][aA][tT][eE][tT][iI][mM][eE]	: DATETIME
[dD][eE][cC][iI][mM][aA][lL]	: DECIMAL
[dD][eE][fF][aA][uU][lL][tT]	: DEFAULT
[dD][eE][lL][eE][tT][eE]	: DELETETOK
[dD][eE][sS][cC]	: DESC
[dD][iI][sS][tT][iI][nN][cC][tT]	: DISTINCT
[dD][iI][vV]	: DIV
[dD][oO][uU][bB][lL][eE]	: DOUBLE
[dD][rR][oO][pP]	: DROP
[dD][uU][mM][pP]	: DUMP
[eE][lL][sS][eE]	: ELSE
[eE][lL][sS][iI][fF]	: ELSIF
[eE][nN][dD]	: END_TOKEN
[eE][xX][cC][eE][pP][tT][iI][oO][nN]	: EXCEPTION
[eE][xX][iI][sS][tT][sS]	: EXISTS
[fF][aA][lL][sS][eE]	: FALSEVAL
[fF][eE][tT][cC][hH]	: FETCH
[fF][iI][rR][sS][tT]	: FIRST
[fF][lL][oO][aA][tT]	: FLOAT
[fF][oO][rR]	: FOR
[fF][oO][rR][eE][iI][gG][nN]	: FOREIGN
[fF][rR][oO][mM]	: FROM
[gG][eE][tT][cC][oO][uU][nN][tT] : GETCOUNT
[gG][eE][tT][pP][oO][sS]	: GETPOS
[gG][rR][aA][cC][eE]	: GRACE
[gG][rR][oO][uU][pP]	: GROUP
[hH][aA][vV][iI][nN][gG]	: HAVING
[iI][dD][eE][nN][tT][iI][fF][iI][eE][dD]	: IDENTIFIED
[iI][fF]	: IF
[iI][nN][dD][eE][xX]	: INDEX
[iI][nN]	: INTOK
[iI][nN][nN][eE][rR]	: INNER
[iI][nN][tT]	: INT
[iI][nN][tT][oO]	: INTO
[lL][oO][nN][gG]2[dD][aA][tT][eE]	: LONG2DATE
[nN][eE][wW][dD][aA][tT][eE]	: NEWDATE
[iI][nN][sS][eE][rR][tT]	: INSERT
[iI][nN][tT]2[aA][sC][cC]	: INT2ASC
[iI][sS]	: IS
[iI][sS][oO][lL][aA][tT][iI][oO][nN]	: ISOLATION
[jJ][dD][bB][cC]	: JDBC
[jJ][oO][iI][nN]	: JOIN
[kK][eE][yY]	: KEY
[lL][eE][fF][tT]	: LEFT
[lL][eE][nN][gG][tT][hH]	: LENGTH
[lL][iI][kK][eE]	: LIKE
[lL][iI][sS][tT]	: LIST
[lL][dD][iI][vV]	: LDIV
[lL][mM][oO][dD]	: LMOD
[lL][oO][aA][dD]	: LOAD
[lL][oO][cC][kK]	: LOCK
[uU][nN][lL][oO][cC][kK]	: UNLOCK
[lL][oO][nN][gG]	: LONG
[lL][oO][wW][eE][rR]	: LOWER
[lL][tT][rR][iI][mM]	: LTRIM
[mM][iI][nN]	: MIN
[mM][aA][xX]	: MAX
[mM][oO][dD]	: MOD
[mM][oO][dD][iI][fF][yY]	: MODIFY
[nN][cC][lL][iI][kK][eE]	: NCLIKE
[nN][eE][xX][tT][cC][oO][uU][nN][tT]	: NEXTCOUNT
[nN][oO][oO][pP]	: NOOP
[nN][oO][tT]	: NOT
[nN][uU][lL][lL]	: NULLTOKEN
[oO][fF][fF]	: OFF
[oO][nN]	: ON
[oO][uU][tT]	: OUTTOK
[oO][uU][tT][eE][rR]	: OUTER
[oO][rR]	: OR
[oO][rR][dD][eE][rR]	: ORDER
[pP][lL][aA][nN]	: PLAN
[pP][oO][oO][lL]	: POOL
[pP][oO][wW][eE][rR]	: POWER
[pP][rR][iI][mM][aA][rR][yY]	: PRIMARY
[pP][rR][iI][nN][tT]	: PRINT
[pP][rR][oO][cC][eE][dD][uU][rR][eE]	: PROCEDURE
[qQ][uU][iI][tT]	: QUIT
[rR][aA][nN][dD][sS][tT][rR]	: RANDSTR
[rR][aA][nN][dD][iI][nN][tT]	: RANDINT
[rR][bB][sS][eE][gG]	: RBSEG
[rR][eE][fF][eE][rR][eE][nN][cC][eE][sS]	: REFERENCES
[rR][eE][gG][mM][aA][tT][cC][hH]	: REGMATCH
[rR][eE][nN][aA][mM][eE]	: RENAME
[rR][eE][oO][rR][gG][aA][nN][iI][zZ][eE]	: REORGANIZE
[rR][eE][tT][uU][rR][nN]	: RETURNTOKEN
[rR][eE][mM][oO][vV][eE]	: REMOVE
[rR][eE][pP][lL][aA][cC][eE]	: REPLACE
[rR][iI][gG][hH][tT]	: RIGHT
[rR][oO][lL][lL][bB][aA][cC][kK]	: ROLLBACK
[rR][oO][uU][nN][dD]	: ROUND
[rR][oO][wW][lL][iI][mM][iI][tT]	: ROWLIMIT
[rR][tT][rR][iI][mM]	: RTRIM
[sS][cC][aA][nN][dD][aA][tT][eE]	: SCANDATE
[sS][eE][lL][eE][cC][tT]	: SELECT
[sS][eE][tT]	: SET
[sS][eE][tT][cC][oO][uU][nN][tT]	: SETCOUNT
[sS][hH][oO][wW]	: SHOW
[sS][mM][aA][lL][lL][iI][nN][tT]	: SMALLINT
[sS][tT][aA][rR][tT]	: START_TOKEN
[sS][tT][rR][iI][nN][gG]	: STRING
[sS][uU][bB][sS][tT][rR]	: SUBSTR
[sS][uU][mM]	: SUM
[sS][yY][nN][cC]	: SYNC
[sS][yY][sS][dD][aA][tT][eE]	: SYSDATE
[sS][yY][sS][tT][eE][mM][sS][pP][aA][cC][eE]	: SYSTEMSPACE
[sS][yY][sS][oO][bB][jJ]	: SYSOBJ
[tT][aA][bB][lL][eE][iI][nN][fF][oO]	: TABLEINFO
[tT][aA][bB][lL][eE][sS][iI][zZ][eE]	: TABLESIZE
[tT][aA][bB][lL][eE]	: TABLE
[tT][aA][bB][lL][eE][sS][eE][tT]	: TABLESET
[tT][hH][eE][nN]	: THEN
[tT][hH][rR][oO][wW]	: THROW
[tT][iI][nN][yY][iI][nN][tT]	: TINYINT
[tT][mM][pP][oO][bB][jJ]	: TMPOBJ
[tT][rR][aA][nN][sS][aA][cC][tT][iI][oO][nN]	: TRANSACTION
[tT][rR][iI][gG][gG][eE][rR]	: TRIGGER
[tT][uU][pP][lL][eE][iI][nN][fF][oO]	: TUPLEINFO
[sS][tT][rR]2[iI][nN][tT]	: STR2INT
[sS][tT][rR]2[lL][oO][nN][gG]	: STR2LONG
[tT][oO]	: TO
[tT][rR][iI][mM]	: TRIM
[tT][rR][uU][eE]	: TRUEVAL
[tT][rR][uU][nN][cC]	: TRUNC
[tT][rR][uU][nN][cC][aA][tT][eE]	: TRUNCATE
[uU][nN][iI][oO][nN]	: UNION
[uU][nN][iI][qQ][uU][eE]	: UNIQUE
[uU][pP][dD][aA][tT][eE]	: UPDATE
[uU][pP][tT][iI][mM][eE]	: UPTIME
[uU][pP][pP][eE][rR]	: UPPER
[vV][aA][rR]	: VAR
[vV][aA][lL][uU][eE][sS]	: VALUES
[vV][iI][eE][wW]	: VIEW
[wW][hH][eE][nN]	: WHEN
[wW][hH][eE][rR][eE]	: WHERE
[wW][hH][iI][lL][eE]	: 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 ; setSyncMethod
Statement		:	LIST TABLESET ; setListTableSetMethod
Statement		:	LIST TABLE TableSetOpt ; setListTableMethod
Statement		:	LIST PROCEDURE  TableSetOpt ; setListProcMethod
Statement		:	LIST VIEW TableSetOpt ; setListViewMethod
Statement		:	LIST AVLTREE TableSetOpt ; setListIndexMethod
Statement		:	LIST BtreeType TableSetOpt ; setListBTreeMethod
Statement		:	LIST KEY TableSetOpt ; setListKeyMethod
Statement		:	LIST COUNTER TableSetOpt ; setListCounterMethod
Statement		:	LIST SYSOBJ TableSetOpt ; setListSysObjMethod
Statement		:	LIST TMPOBJ TableSetOpt ; setListTmpObjMethod
Statement		:	LIST CHECK TableSetOpt ; setListCheckMethod
Statement		:	LIST TRIGGER TableSetOpt ; setListTriggerMethod
Statement		:	LIST ALIAS TableSetOpt ; setListAliasMethod
TableSetOpt		:	FOR IDENTIFIER ; setTableSetOpt 
TableSetOpt		:	
Statement		:	TABLEINFO ObjSpec ; setTableInfoMethod
Statement		:	TABLESIZE ObjSpec ; setTableSizeMethod
Statement		:	TUPLEINFO ObjSpec ; setTupleInfoMethod
Statement		:	UPTIME ; setShowUptimeMethod
Statement		:	SHOW POOL ; setShowPoolMethod
Statement		:	SHOW SYSTEMSPACE ; setShowSystemSpaceMethod
Statement		:	DESC TABLE ObjSpec ; setTableDescMethod
Statement		:	DESC AVLTREE ObjSpec ; setIndexDescMethod
Statement		:	DESC BtreeType ObjSpec ; setBTreeDescMethod
Statement		:	DESC VIEW ObjSpec ; setViewDescMethod
Statement		:	DESC FOREIGN KEY ObjSpec ; setKeyDescMethod
Statement		:	DESC CHECK ObjSpec ; setCheckDescMethod
Statement		:	DESC ALIAS ObjSpec ; setAliasDescMethod
Statement		:	DESC PROCEDURE ObjSpec ; setProcDescMethod
Statement		:	SHOW PROCEDURE ObjSpec ; setProcShowMethod
Statement		:	SHOW VIEW ObjSpec ; setViewShowMethod
Statement		:	SHOW CHECK ObjSpec ; setCheckShowMethod
Statement		:	SHOW TRIGGER ObjSpec ; setTriggerShowMethod
Statement		:	SET TABLESET IDENTIFIER ; setSetTableSetMethod
Statement		:	AUTHORIZE IDENTIFIER IDENTIFIED BY STRINGVAL FOR IDENTIFIER ; setAuthUserMethod
Statement		:	StartStatement ; setQueryMethod
Statement		:	CommitStatement ; setQueryMethod
Statement		:	RollbackStatement ; setQueryMethod
Statement		:	LockStatement ; setQueryMethod
Statement		:	UnlockStatement ; setQueryMethod
Statement		:	SET GRACE ON ; setEnableGraceModeMethod
Statement		:	SET GRACE OFF ; setDisableGraceModeMethod
Statement		:	SET APPEND ON ; setEnableAppendModeMethod
Statement		:	SET APPEND OFF ; setDisableAppendModeMethod
Statement		:	SET AUTOCOMMIT ON ; setEnableAutoCommitMethod
Statement		:	SET AUTOCOMMIT OFF ; setDisableAutoCommitMethod
Statement		:	SET ISOLATION IDENTIFIER ; setSetIsolationMethod
Statement		:	REORGANIZE TABLE ObjSpec ; setTableReorganizeMethod
Statement		:	REORGANIZE AVLTREE ObjSpec ; setIndexReorganizeMethod
Statement		:	SelectStatement ; setSelectMethod
Statement		:	PLAN SelectStatement ; setSelectPlanMethod
Statement		:	InsertStatement ; setQueryMethod
Statement		:	DeleteStatement ; setQueryMethod
Statement		:	UpdateStatement ; setQueryMethod
Statement		:	AlterStatement ; setQueryMethod
Statement		:	RenameStatement ; setQueryMethod
# view execs
Statement		:	CREATE VIEW ObjSpec AS SelectStatement ; setViewCreateMethod
Statement		:	LOAD VIEW ObjSpec AS SelectStatement ; setViewLoadMethod
# procedure execs
Statement		:	CREATE ProcDef ; setProcCreateMethod
Statement		:	LOAD ProcDef ; setProcLoadMethod
Statement		:    	CALL ObjSpec LB ProcValueListOpt RB ; setProcCallMethod
Statement		:    	VARREF EQU CALL ObjSpec LB ProcValueListOpt RB ; setFuncCallMethod
# table
Statement		:	CREATE TABLE ObjSpec LB ColumnList RB  ; setUserTableCreateMethod
Statement		:	CREATE PRIMARY IndexType ON ObjSpec LB SimpleAttrList RB CachedOpt ; setPrimaryIndexCreateMethod
Statement		:	CREATE IndexOption IndexType IDENTIFIER ON ObjSpec LB SimpleAttrList RB CachedOpt ; setIndexCreateMethod
CachedOpt		:	CACHED ; setCachedOption
CachedOpt		:
# alias
Statement		:	CREATE ALIAS IDENTIFIER ON ObjSpec LB AliasAttrList RB  ; setAliasCreateMethod
AliasAttrList		:	AliasAttrList KSEP AliasAttr
AliasAttrList		:	AliasAttr
AliasAttr		:	IDENTIFIER AS IDENTIFIER ; setAliasAttr
# query condition load
Statement		:	LOAD CONDITION Condition ; setQueryCondLoadMethod
# trigger
Statement		:	CREATE TriggerDef ; setTriggerCreateMethod
Statement		:	LOAD TriggerDef ; setTriggerLoadMethod
#
Statement		:	TRUNCATE TABLE ObjSpec ; setTableTruncateMethod
Statement		:	DropOpt TABLE ObjSpec ; setTableDropMethod
Statement		:	DropOpt AVLTREE ObjSpec ; setIndexDropMethod
Statement		:	DropOpt VIEW ObjSpec ; setViewDropMethod
Statement		:	DropOpt PROCEDURE ObjSpec ; setProcDropMethod
Statement		:	DropOpt FOREIGN KEY ObjSpec ; setFKeyDropMethod
Statement		:	DropOpt CHECK ObjSpec ; setCheckDropMethod
Statement		:	DropOpt TRIGGER ObjSpec ; setTriggerDropMethod
Statement		:	DropOpt BtreeType ObjSpec ; setBTreeDropMethod
Statement		:	DropOpt ALIAS ObjSpec ; setAliasDropMethod
DropOpt			:	DROP ; dropOpt1 
DropOpt			:	DROP IF EXISTS ; dropOpt2
Statement		:	ALTER TABLE ObjSpec ADD FOREIGN KEY IDENTIFIER LB SimpleAttrList RB  REFERENCES IDENTIFIER LB SimpleAttrList RB ; setForeignKeyCreateMethod
Statement		:	ALTER TABLE ObjSpec ADD CHECK IDENTIFIER ON Condition ; setCheckCreateMethod
Statement		:	SET IDENTIFIER EQU Expr ; setAssignStatementMethod
Statement		:	PRINT Expr ; setPrintMethod
Statement		:	CHECK AVLTREE IDENTIFIER ; setIndexCheckMethod
# Counter 
Statement		:	CREATE COUNTER CounterId ; setCreateCounterMethod
Statement		:	DropOpt COUNTER CounterId ; setDropCounterMethod
Statement		:	SET COUNTER CounterId TO Expr ; setSetCounterMethod
CounterId		:	IDENTIFIER ; setCounterId
# JDBC info calls
Statement		:	JDBC JdbcArgList ; setJDBCInfoMethod
JdbcArgList		:	JdbcArgList IDENTIFIER ; jdbcArg1
JdbcArgList		:	IDENTIFIER ; jdbcArg2
#
# Statements for debugging
#
Statement		:	DUMP TABLE ObjSpec ; setDumpTableMethod
Statement		:	DUMP BTREE ObjSpec ; setDumpBtreeMethod
#
# Triggers
#
TriggerDef		:    	TriggerHead BEGIN ProcStmtBlock END_TOKEN ; triggerStore
TriggerHead		:	TRIGGER ObjSpec TriggerEvent TriggerCondition ON ObjSpec ; triggerHead
TriggerEvent		:	BEFORE ; setTriggerBefore 
TriggerEvent		:	AFTER ; setTriggerAfter 
TriggerCondition	:	TriggerCondition OR TriggerOp 
TriggerCondition	:	TriggerOp
TriggerOp		:	INSERT ; addInsertTrigger
TriggerOp		:	UPDATE ; addUpdateTrigger
TriggerOp		:	DELETETOK ; addDeleteTrigger
#
CaseClause		:	CasePrepare CaseConditionList ELSE Expr END_TOKEN ; caseClause
CaseConditionList	:	CaseConditionList CaseCondition ; caseConditionList1
CaseConditionList	:	CaseCondition ; caseConditionList2
CaseCondition		:	WHEN Condition 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		:	AVLTREE ; setAVLIndex
IndexType		:	BtreeType ; setBTreeIndex
BtreeType		:	BTREE
BtreeType		:	INDEX
#
# Transaction Statement
# 
StartStatement		:	START_TOKEN TRANSACTION ; startStore
CommitStatement		:	COMMIT ; commitStore
RollbackStatement	:	ROLLBACK ; rollbackStore
#
# Lock Statement
#
LockStatement		:	LOCK TABLE ObjSpec ; lockStore
UnlockStatement		:	UNLOCK TABLE ObjSpec ; unlockStore
#
# 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 ; insertValueSpecStore
InsertArgList		:	InsertArgList KSEP IDENTIFIER ; insertArg 
InsertArgList		:	IDENTIFIER ; insertArg 
InsertValueList		:	InsertValueList KSEP Expr ; insertExprValue 
InsertValueList		:	Expr ; insertExprValue 
#
# Update Statement
# 
UpdateStatement		:	UPDATE ObjSpec UpdDelAlias SET UpdateList WhereClause UpdReturnOpt ; updateStore
UpdateList		:	UpdateList KSEP Assignment
UpdateList		:	Assignment
Assignment		:	IDENTIFIER EQU Expr ; updateAssignment
UpdReturnOpt		:	RETURNTOKEN ON FIRST ReturnVarList ; returnOnFirstTrue
UpdReturnOpt		:	RETURNTOKEN ReturnVarList ; returnOnFirstFalse
UpdReturnOpt		:       NoUpdateReturnOpt ; returnOnFirstFalse
NoUpdateReturnOpt	:
ReturnVarList		:	ReturnVarList KSEP ReturnVar
ReturnVarList		:	ReturnVar
ReturnVar		:	VARREF EQU Expr ; returnVarAssignment
#
# Delete Statement
# 
DeleteStatement		:	DELETETOK FROM ObjSpec UpdDelAlias WhereClause ; deleteStore
UpdDelAlias		:	IDENTIFIER ; setUpdDelAlias
UpdDelAlias		:
#
#
# Select Statement
#
SelectStatement         :       SELECT Selection FromOption ; selectStore
FromOption              :       FROM TableSource WhereClause GroupClause OrderingClause LimitOpt UnionAllOpt
FromOption              :       NoFromOption ; noFromOption
NoFromOption            :
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 JoinTable ; selectInnerJoinStore1
JoinSpec		:	InnerJoin JoinTable ON Condition ; selectInnerJoinStore2
JoinSpec		:	LEFT OUTER JOIN JoinTable ; selectLeftOuterJoinStore1
JoinSpec		:	LEFT OUTER JOIN JoinTable ON Condition ; selectLeftOuterJoinStore2
JoinSpec		:	RIGHT OUTER JOIN JoinTable ; selectRightOuterJoinStore1
JoinSpec		:	RIGHT OUTER JOIN JoinTable ON Condition ; selectRightOuterJoinStore2
#
InnerJoin		:	INNER JOIN
InnerJoin		:	JOIN
TableList		:	Table KSEP TableList
TableList		:	Table 
Table			:	ObjSpec ; selectTable1
Table			:	ObjSpec IDENTIFIER ; selectTable2
JoinTable		:	Table ; 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 Condition ; 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		:	NoDistinctOpt ; selectNoDistinctOpt
NoDistinctOpt		:
LimitOpt		:	ROWLIMIT INTVAL ; selectLimitOpt1
LimitOpt		:	NoLimit ; selectLimitOpt2
NoLimit			:
#
# Union All
#
UnionAllOpt		:	UNION ALL SelectStatement ; unionAllStore 
UnionAllOpt		:	
#
# Where Clause
#
WhereClause		:	WHERE Condition ; wcWhereClause
WhereClause		:       NoWhere ; wcEmptyClause
NoWhere			:
#
# 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		:	MODIFY COLUMN IDENTIFIER DEFAULT Constant ; alterModDefault
AlterOption		:	RENAME COLUMN IDENTIFIER TO IDENTIFIER ; alterRenameCol
#
# Rename Statement
# 
RenameStatement		:	RENAME TABLE ObjSpec TO IDENTIFIER ; renameTable
RenameStatement		:	RENAME AVLTREE ObjSpec TO IDENTIFIER ; renameIndex
RenameStatement		:	RENAME BtreeType ObjSpec TO IDENTIFIER ; renameBTree
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
RenameStatement		:	RENAME TRIGGER ObjSpec TO IDENTIFIER ; renameTrigger
#
# 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	:	
ProcStatement		:	THROW Expr ; procThrowStatement
# procedure queries
ProcStatement		:	InsertStatement ; procQueryStatement
ProcStatement		:	DeleteStatement ; procQueryStatement
ProcStatement		:	UpdateStatement ; procQueryStatement
ProcStatement		:	StartStatement ; procQueryStatement
ProcStatement		:	CommitStatement ; procQueryStatement
ProcStatement		:	RollbackStatement ; procQueryStatement
ProcStatement		:	LockStatement ; procQueryStatement
ProcStatement		:	UnlockStatement ; 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		:	Condition ; procIfCondition
ProcElsIfCondition	:	Condition ; procElsIfCondition
#
# Procedure while loop
#
ProcStatement		:	WHILE ProcWhileCondition BEGIN ProcStmtBlock END_TOKEN ; procWhileStatement
ProcWhileCondition	:	Condition ; procWhileCondition
#
Condition		: 	Condition OR Conjunction ; conditionOr
Condition		: 	Conjunction
Conjunction		: 	Conjunction AND Predicate ; conditionAnd
Conjunction		: 	Predicate ; conditionPredicate
#
Predicate		: 	EXISTS LB SelectStatement RB ; wcPredicateQueryExists
#
Predicate		:	Expr INTOK LB ExpressionList RB ; wcPredicateIn
Predicate		:	Expr NOT INTOK LB ExpressionList RB ; wcPredicateNotIn
#
Predicate		:	Expr INTOK LB SelectStatement RB ; wcPredicateQueryIn
Predicate		:	Expr NOT INTOK LB SelectStatement RB ; wcPredicateQueryNotIn 
Predicate		:	Expr Comparison Expr ; wcPredicateExprComp
Predicate		:	Expr BETWEEN Expr AND Expr ; wcPredicateBetween
Predicate		:	Expr IS NULLTOKEN ; wcPredicateNullComp
Predicate		:	Expr IS NOT NULLTOKEN ; wcPredicateNotNullComp
Predicate		:	Expr LIKE STRINGVAL ; wcPredicateLikeComp
Predicate		:	Expr NOT LIKE STRINGVAL ; wcPredicateNotLikeComp
Predicate		:	Expr NCLIKE STRINGVAL ; wcPredicateNcLikeComp
Predicate		:	Expr NOT NCLIKE STRINGVAL ; wcPredicateNotNcLikeComp
Predicate		:	Expr ; wcPredicateExprOnly
Predicate		:	NOT Predicate ; wcPredicateNotPredicate
#
# 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 Condition 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 Expr RB ; procFactor12
Factor			:	MIN LB Expr RB ; procFactor13
Factor			:	MAX LB Expr RB ; procFactor14
#
# Functions
#
Function		:	INT2ASC LB ExpressionList RB ; functionNative
Function		:	ASC2INT LB ExpressionList RB ; functionNative
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		:	SCANDATE LB ExpressionList RB ; functionNative
Function		:	DATE2STR LB ExpressionList RB ; functionNative
Function		:	DATE2LONG LB ExpressionList RB ; functionNative
Function		:	LONG2DATE LB ExpressionList RB ; functionNative
Function		:	NEWDATE 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		:	LMOD LB ExpressionList RB ; functionNative
Function		:	LDIV 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		:	BLOBSIZE LB ExpressionList RB ; functionNative
Function		:	BLOBREF LB ExpressionList RB ; functionNative
Function		:	CLOBSIZE LB ExpressionList RB ; functionNative
Function		:	CLOBREF LB ExpressionList RB ; functionNative
Function		:	CLOB2STR LB ExpressionList RB ; functionNative	
Function		:	REGMATCH LB ExpressionList RB ; functionNative
Function		:	NEXTCOUNT LB IDENTIFIER RB ; functionNextCount
Function		:	SETCOUNT LB IDENTIFIER KSEP Expr RB ; functionSetCount
Function		:	GETCOUNT LB IDENTIFIER RB ; functionGetCount

#
Function		:	ObjSpec LB ExpressionList RB ; functionUserDef1
Function		:	ObjSpec LB RB ; functionUserDef2
ExpressionList		:	ExpressionList KSEP Expr ; storeExprList1
ExpressionList		:	Expr ; storeExprList2
#
# 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 DecimalDim RB ; miscDecimalType
DataTypeProd		:	BLOB ; miscBlobType
DataTypeProd		:	CLOB ; miscClobType
DecimalDim		:	INTVAL ; miscDecimalDim1
DecimalDim		:	INTVAL KSEP INTVAL ; miscDecimalDim2
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 DATETIME RB STRINGVAL ; miscDatetimeValue	
Constant		:	SYSDATE ; miscSysDate
Constant		:	NULLTOKEN ; miscNull
Constant		:	TRUEVAL ; miscTrueValue
Constant		:	FALSEVAL ; miscFalseValue
Constant		:	BLOB LAB INTVAL RAB ; miscBlobRef
Constant		:	CLOB LAB INTVAL RAB ; miscClobRef
ObjSpec			:	IDENTIFIER ; setObject1
ObjSpec			:	QUALIFIEDOBJ ; setObject2
ObjSpec			:	QUALIFIEDTS ; setObject3
END
