
www.Usenet.com
| <-- __Chronological__ --> | <-- __Thread__ --> |
Hi,
I am new to javacc and have a question to ask. I wrote a very simple javacc
code but it could not parse a simple input with ".".
The javacc code:
PARSER_BEGIN(SimpleTest)
public class SimpleTest {
public static void main(String args[]) throws ParseException {
SimpleTest parser = new SimpleTest(System.in);
parser.Input();
}
}
PARSER_END(SimpleTest)
SKIP :
{
" "
| "\t"
| "\f"
| "\n"
| "\r"
}
TOKEN :
{
< FIND : "find" >
|
< AS : "as" >
|
< DOT: ".">
|
< ID: ["a"-"z","A"-"Z","_","@"] ( ["a"-"z","A"-"Z","_","0"-"9","@"] )* >
|
< STRING_LITERAL:
"\""
( (~["\"","\n","\r"])
)*
"\""
>
}
void Input() :
{
Token type;
Token subType;
Token name;
Token id;
}
{
LOOKAHEAD(<ID> <DOT>)
<FIND> type=<ID> <DOT> subType=<ID> name=<STRING_LITERAL> <AS> id=<ID> ";"
{
System.out.println("find "+type+"."+subType+" "+name+" as "+id);
}
|
<FIND> type=<ID> name=<STRING_LITERAL> <AS> id=<ID> ";"
{
System.out.println("find "+type+" "+name+" as "+id);
}
}
The input I wanted to test is(from System.in):
find Server.SSL "server.ssl" as s2;
find Server "server" as s1;
Somehow the generated parser could not parse the first line. It kept
complaining:
Encountered "." at line 1 column 12
Was expecting:
<STRING_LITERAL> ...
I do not understand why the LOOKAHEAD does not work. Could anyone give my
some help here? Thanks a lot!
Larry
| <-- __Chronological__ --> | <-- __Thread__ --> |