Hi,
I am trying out the following but not able to print where exactly tokens are matching. I am using jjtree to create a grammer and parser file.
I want to set some
String or StringBuffer (preferably) and use it later in
parser. For example I have my grammar file like this
< DateTime: ("TIMESTAMP " ("'") ) <DATE> (" " <TIME>
? ("'")
| <DATE> (" " <TIME>
?
>
| < #DATE:
<SHORTMONTH1> "/" <SHORTDAY1> "/" <YEAR>
| <MEDMONTH> " " <SHORTDAY1> ", " <YEAR>
| <LONGDAY> ", " <LONGMONTH> " " <SHORTDAY2> ", " <YEAR>
>
| < #TIME:
<HOURSHORT1> ":" <MINUTE> " " <AMPM>
| <HOURSHORT1> ":" <MINUTE> ":" <SECOND> " " <AMPM>
| <HOURSHORT1> ":" <MINUTE> ":" <SECOND> " " <AMPM>
>
|
< #YEAR:
> ["0"-"9"] ["0"-"9"] ["0"-"9"] ["0"-"9"]
| < SHORTMONTH1:
["1"-"9"]
| ["1"] ["0"-"2"]
>
{ sb.append("M"); System.out.println("Matching short month 1 "+sb.toString());}
| < SHORTMONTH2:
["0"]["1"-"9"]
| ["1"] ["0"-"2"]
>
{ sb.append("MM"); System.out.println("Matching short month 2 "+sb.toString()); }
| < MEDMONTH:
"Jan" | "Feb" | "Mar" | "Apr" | "May" | "Jun" | "Jul" | "Aug" | "Sep" | "Oct" | "Nov" | "Dec"
>
{ sb.append("MMM"); System.out.println("Matching medium month "+sb.toString()); }
| <LONGMONTH:
"January" | "February" | "March" | "April" | "May" | "June" | "July" | "August" | "September" | "October" | "November" | "December"
>
{ sb.append("MMMM"); System.out.println("Matching long month "+sb.toString()); }
and so on. (keeping it short here)
As I have shown above, I would like to store the
pattern which is matching. Later I want to use this in parser.
There are few problems here.
1) First is I am not able to print whereever I have entered my print statements. But in the generated file I can see those statements in the switch case code. Am I doing something wrong while printing?
2) How do I pass something which I am setting in lexer to parser? This is because I need both the input string and the pattern which it is matching with so that I will be able to create a Date object directly.
3) Even if i get succeed in what I have tried above, I am not able to get date seperators. And when I tried to save something in stringbuffer (sb) in the internal tokens (like in # <DATE>
, it didn't allow me.
I hope I am able to explain my query here.
Can somebody please inform me where do I have to set my variables to use
it in parser to find the matched token?
Any help will be appreciated.
Thank you.