I am using javaCC to parse through sql statements and put the data in corresponding lists. I have made the grammar for a create table that works well but now I need help on making a insert statement grammar.
This is the create table grammar that I have used but I don't have anything to go off to make an insert statement or select so any suggestions would help.
options
{
STATIC = false ;
}
PARSER_BEGIN (SqlParser)
package sqlParserDemo;
import java.util.ArrayList;
import java.util.HashMap;
class SqlParser {
ArrayList<TableStruct> initParser()throws ParseException, TokenMgrError
{ return(init()) ; }
}
PARSER_END (SqlParser)
SKIP: { "\n" | "\r" | "\r\n" |"\\"|"\t"|" "}
TOKEN [IGNORE_CASE]:
{
<CTCMD :("Create Table")>
|<NUMBER :(["0"-"9"])+ >
|<TNAME:(["a"-"z"])+ >
|<OBRA:("(")+>
|<CBRA:(")")+>
|<COMMA:(",")>
}
SPECIAL_TOKEN : {<COMMENT:("#")+(<TNAME>)+("#")+>}
ArrayList<TableStruct> init():
{
Token T;
ArrayList<TableStruct> tableList = new ArrayList<TableStruct>();
TableStruct tableStruct;
}
{
(
<CTCMD>
T =<TNAME>
{ tableStruct = new TableStruct ();
tableStruct.TableName = T.image ;}
<OBRA>
tableStruct.Variables = Variables()
<CBRA>
{tableList.add (tableStruct) ;}
)*
<EOF>
{return tableList;}
}
HashMap Variables():
{
Token TName;
Token TType;
HashMap<String,String> var = new HashMap<String, String>();
}
{
(
TName = <TNAME>
TType = DType()
<COMMA>
{var.put(TName.image,TType.image);}
)*
{return var;}
}
Token DType():
{
Token TDType;
}
{
TDType=<TNAME>
[<OBRA><NUMBER><CBRA>]
{return TDType;}
}
Thanks in advance