[prev in list] [next in list] [prev in thread] [next in thread]
List: avalon-cvs
Subject: cvs commit: jakarta-avalon-cornerstone/apps/db/src/sql/javacc BasicSQLParser.jj
From: froehlich () apache ! org
Date: 2001-11-30 15:59:52
[Download RAW message or body]
froehlich 01/11/30 07:59:52
Modified: apps/db/src/sql/javacc BasicSQLParser.jj
Log:
SELECT,UPDATE,INSERT,DROP,DELETE and WHERE are parsed now. Halfway done ;)
Revision Changes Path
1.5 +112 -41 jakarta-avalon-cornerstone/apps/db/src/sql/javacc/BasicSQLParser.jj
Index: BasicSQLParser.jj
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/sql/javacc/BasicSQLParser.jj,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BasicSQLParser.jj 2001/11/29 20:21:06 1.4
+++ BasicSQLParser.jj 2001/11/30 15:59:52 1.5
@@ -7,6 +7,7 @@
*/
PARSER_BEGIN(BasicSQLParser)
+
package org.apache.avalon.db.basic.parser;
import org.apache.avalon.db.server.sql.AbstractSQLParser;
@@ -35,6 +36,8 @@
protected void getCustomRequestHandlers(AbstractRequestHandler[] handlers) {
}
+ public BasicSQLParser() { }
+
public void initializeAction(Action action) throws ActionException {
action.setDatabasePersistor(mDatabasePersistor);
setupLogger(action);
@@ -120,7 +123,7 @@
| <NOT: "not">
}
-TOKEN [IGNORE_CASE] : { /* Operators */
+TOKEN : { /* Operators */
<EQUAL: "=" >
| <GREATERTHAN: ">" >
| <SMALLERTHAN: "<" >
@@ -159,7 +162,7 @@
{
(
parseSQLString()
- ) ";"
+ )
}
String parseSQLString() :
@@ -170,24 +173,22 @@
(
stm = Select()
| stm = Update()
- /*
- | Rollback()
- | Insert()
- | Grant()
- | Drop()
- | Delete()
- | Commit()
- | Alter()
- */
+ | stm = Insert()
+ | stm = Drop()
+ | stm = Delete()
+ //| Commit()
+ //| Alter()
+ //| Rollback()
+ //| Grant()
)
( ";" | <EOF> )
+
{ return stm; }
}
String Select() :
{
String stm;
- Token token;
}
{
@@ -197,17 +198,25 @@
<FROM>
getTables()
[ Where() ]
+
{ return stm; }
}
String Update() :
{
String stm;
- Token token;
}
{
<UPDATE>
{ stm = "UPDATE"; }
+ getTables()
+ <SET>
+ ( <IDENTIFIER> "=" ExprValue()
+ [ "," { System.out.println(","); } ] )+
+ [ Where() ]
+
+ { System.out.println("Row(s) updated ;-)"); }
+
{ return stm; }
}
@@ -217,28 +226,58 @@
<EOF>
}
-void Insert() :
-{}
+String Insert() :
{
- <EOF>
+ String stm;
}
+{
+ <INSERT><INTO> { stm = "INSERT"; }
+ <IDENTIFIER>
+ [ ( "("
+ getColumns()
+ ")" )+ ]
+
+ ( <VALUES>
+ "("
+ getValues()
+ ")" )+
+ { return stm; }
+}
+
void Grant() :
{}
{
<EOF>
}
-void Drop() :
-{}
+String Drop() :
{
- <EOF>
+ String stm;
}
+{
+ <DROP>
+ { stm = "DROP"; }
+ <IDENTIFIER>
+
+ { System.out.println("Table droped ;-)"); }
+
+ { return stm; }
+}
-void Delete() :
-{}
+String Delete() :
{
- <EOF>
+ String stm;
+}
+{
+ <DELETE><FROM>
+ { stm = "DELETE"; }
+ <IDENTIFIER>
+ [ Where() ]
+
+ { System.out.println("Row(s) deleted ;-)"); }
+
+ { return stm; }
}
void Commit() :
@@ -257,19 +296,15 @@
{}
{
<WHERE>
- {
- OrExpr();
- }
+ { OrExpr(); }
}
void OrExpr() :
{}
{
AndExpr()
- ( <OR>
- AndExpr()
- { System.out.println("in or"); }
- )*
+ ( <OR> { System.out.println("in or"); }
+ AndExpr() )*
}
@@ -280,16 +315,14 @@
NotExpr()
( <AND>
{ System.out.println("in and"); }
- NotExpr() )*
+ NotExpr() )*
}
void NotExpr() :
{}
{
- [ <NOT>
- { System.out.println("in not"); }
- ]
+ [ <NOT> { System.out.println("in not"); } ]
CompareExpr()
}
@@ -297,18 +330,49 @@
{}
{
- (
- <IDENTIFIER><EQUAL><STRING_LITERAL> { System.out.println("EQUAL"); }
- | <GREATERTHAN> { System.out.println("GREATERTHAN"); }
- | <SMALLERTHAN> { System.out.println("SMALLERTHAN"); }
- | <GREATERTHANOREQUAL> { System.out.println("GREATERTHANOREQUAL"); }
- | <SMALLERTHANOREQUAL> { System.out.println("SMALLERTHANOREQUAL"); }
- | <LIKE> { System.out.println("LIKE"); }
- )
+ ExprValue() CompareOps() ExprValue()
+ | Term()
}
+void ExprValue() :
+{}
+{
+ <IDENTIFIER> { System.out.println("expr is <INDENTIFIER>"); }
+ | <STRING_LITERAL> { System.out.println("expr is <STRING_LITERAL>"); }
+ | <INTEGER_LITERAL> { System.out.println("expr is <INTEGER_LITERAL>"); }
+ | <FLOATING_POINT_LITERAL> { System.out.println("expr is <FLOATING_POINT_LITERAL>"); }
+}
+void UpdateValue() :
+{}
+
+{
+ <STRING_LITERAL> { System.out.println("value is <STRING_LITERAL>"); }
+ | <INTEGER_LITERAL> { System.out.println("value is <INTEGER_LITERAL>"); }
+ | <FLOATING_POINT_LITERAL> { System.out.println("value expr is <FLOATING_POINT_LITERAL>"); }
+}
+
+void CompareOps() :
+{}
+
+{
+ <EQUAL> { System.out.println("EQUAL"); }
+ | <GREATERTHAN> { System.out.println("GREATERTHAN"); }
+ | <SMALLERTHAN> { System.out.println("SMALLERTHAN"); }
+ | <GREATERTHANOREQUAL> { System.out.println("GREATERTHANOREQUAL"); }
+ | <SMALLERTHANOREQUAL> { System.out.println("SMALLERTHANOREQUAL"); }
+ | <LIKE> { System.out.println("LIKE"); }
+}
+
+void Term() :
+{}
+{
+ ( "(" { System.out.println("("); }
+ OrExpr()
+ ")" { System.out.println(")"); } )
+}
+
void getColumns() :
{
String col;
@@ -331,6 +395,13 @@
table = <IDENTIFIER> {System.out.println("table=" + table.image); }
( "," { System.out.println(",");}
table = <IDENTIFIER> {System.out.println("table=" + table.image); } )*
+}
+void getValues() :
+{ }
+{
+ UpdateValue()
+ ( "," { System.out.println(","); }
+ UpdateValue() )+
}
--
To unsubscribe, e-mail: <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic