我们想 实现 select * from b 的 功能 ,但是好像解析 select 语句出了问题 ,希望大家帮助我一下,真的需要帮助啊/**
* JavaCC file
*/options {
JDK_VERSION = "1.5";
}
PARSER_BEGIN( Select )import java.io.*;public class Select {
public static void main(String args[]) throws ParseException {
Select parser = new Select(System.in); System.out.println("Reading from standard input...");
System.out.print("Enter an select expression :");
try {
switch (parser.one_line()) {
case 0:
System.out.println("OK.");
break;
case 1:
System.out.println("Goodbye.");
break;
default:
break;
}
} catch (Exception e) {
System.out.println("NOK.");
System.out.println(e.getMessage());
parser.ReInit(System.in);
} catch (Error e) {
System.out.println("Oops.");
System.out.println(e.getMessage());
}
}
}
PARSER_END( Select )SKIP :
{
" "
| "\r"
| "\t"
| "\n"
}TOKEN :
{
< IDENTIFIER: (<LETTER>)+ (<LETTER> | <DIGIT> | <SPECIAL_CHARS>)*
| "["(~["]","\r","\n"])*"]"
| "\""(~["\"","\r","\n"])*"\""
>
| < #LETTER: ["a"-"z","A"-"Z"] >
| < #DIGIT: ["0"-"9"] >
| < #SPECIAL_CHARS: ["@","#","$","_"] >
| < ALL_COLUMN: "*" >
| < ALL_DISTINCT: "all" | "distinct" >
}
TOKEN :
{
< SELECT: "select" >
| < WHERE: "where" >
| < FROM: "from" >
}
int one_line() :
{}
{
parse() ";" { return 0; }
| ";" { return 1; }
}void parse() :
{}
{
SelectStatement()
}void print(String s) :
{
String str;
}
{
{str = s;
System.out.print(str);}
}
void SelectStatement() :
{
Token t;
}
{
<SELECT> ( <ALL_DISTINCT> )?
// {System.out.print(t.image);}
// {System.out.print(t.image);}
Select_List() From_Clause() //(Where_Clause())?
<EOF>
}void Select_List() :
{
Token t;
}
{
t=<ALL_COLUMN>
{System.out.print(t.image);}
| Column_List()
}
void Column_List() :
{}
{
Column() ("," Column())*
}void Column() :
{
Token t;
}
{
t=<IDENTIFIER>
{System.out.print(t.image);}
}void From_Clause() :
{
Token t;
}
{
{System.out.println();}
t=<FROM>
{System.out.print(t.image);}
From_List()
}void From_List() :
{}
{
Table() ("," Table())*
}void Table() :
{
Token t;
}
{
t=<IDENTIFIER>
{System.out.print(t.image);}
}
* JavaCC file
*/options {
JDK_VERSION = "1.5";
}
PARSER_BEGIN( Select )import java.io.*;public class Select {
public static void main(String args[]) throws ParseException {
Select parser = new Select(System.in); System.out.println("Reading from standard input...");
System.out.print("Enter an select expression :");
try {
switch (parser.one_line()) {
case 0:
System.out.println("OK.");
break;
case 1:
System.out.println("Goodbye.");
break;
default:
break;
}
} catch (Exception e) {
System.out.println("NOK.");
System.out.println(e.getMessage());
parser.ReInit(System.in);
} catch (Error e) {
System.out.println("Oops.");
System.out.println(e.getMessage());
}
}
}
PARSER_END( Select )SKIP :
{
" "
| "\r"
| "\t"
| "\n"
}TOKEN :
{
< IDENTIFIER: (<LETTER>)+ (<LETTER> | <DIGIT> | <SPECIAL_CHARS>)*
| "["(~["]","\r","\n"])*"]"
| "\""(~["\"","\r","\n"])*"\""
>
| < #LETTER: ["a"-"z","A"-"Z"] >
| < #DIGIT: ["0"-"9"] >
| < #SPECIAL_CHARS: ["@","#","$","_"] >
| < ALL_COLUMN: "*" >
| < ALL_DISTINCT: "all" | "distinct" >
}
TOKEN :
{
< SELECT: "select" >
| < WHERE: "where" >
| < FROM: "from" >
}
int one_line() :
{}
{
parse() ";" { return 0; }
| ";" { return 1; }
}void parse() :
{}
{
SelectStatement()
}void print(String s) :
{
String str;
}
{
{str = s;
System.out.print(str);}
}
void SelectStatement() :
{
Token t;
}
{
<SELECT> ( <ALL_DISTINCT> )?
// {System.out.print(t.image);}
// {System.out.print(t.image);}
Select_List() From_Clause() //(Where_Clause())?
<EOF>
}void Select_List() :
{
Token t;
}
{
t=<ALL_COLUMN>
{System.out.print(t.image);}
| Column_List()
}
void Column_List() :
{}
{
Column() ("," Column())*
}void Column() :
{
Token t;
}
{
t=<IDENTIFIER>
{System.out.print(t.image);}
}void From_Clause() :
{
Token t;
}
{
{System.out.println();}
t=<FROM>
{System.out.print(t.image);}
From_List()
}void From_List() :
{}
{
Table() ("," Table())*
}void Table() :
{
Token t;
}
{
t=<IDENTIFIER>
{System.out.print(t.image);}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货