首先下載JAVACC
SKIP :
{
|
|
|
|
}
TOKEN: /*RESERVED TOKENS FOR UQL */
{
<FROM:
| <FROM_OBJECT:([
}
void expression() :
{
Token tTable;
}
{
(
<FROM>
tTable = <FROM_OBJECT>
)
{
sqlSB
sqlSB
}
}
最後就是寫解析代碼
PARSER_BEGIN(HQLParser)
import java
import java
import java
public class HQLParser {
private static StringBuffer sqlSB;
/**
A String based constructor for ease of use
**/
public HQLParser(String s)
{
this((Reader)(new StringReader(s)));
sqlSB = new StringBuffer();
}
public String getSQL()
{
return sqlSB
}
public static void main(String args[])
{
try
{
String query = args[
HQLParser parser = new HQLParser(query);
parser
System
}
catch(Exception e)
{
e
}
}
public void parse()
{
try
{
expression();
}
catch(Exception e)
{
e
}
}
}
PARSER_END(HQLParser)
接下來到dos下輸入:
javacc
這時候會生成
這時候只需要
javac *
然後執行java HQLParser
這時候屏幕上就會顯示出
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19735.html