Thanks. The concern was mainly about calling yybegin(MyJFlexer.THISSTATE) before yylex() had started, since the docs only mention calling it in the middle of a lex. I wasn't sure whether that would mess up its bookkeeping or something.
-Ken
________________________________________
From: Steve Rowe [sa...@od...]
Sent: Thursday, April 21, 2011 11:12 PM
To: jfl...@li...
Subject: Re: [jflex-users] Accessing grammar rules from Java
Hi Ken,
Looks fine to me. I do this (temporarily) when I'm debugging a new
grammar, so I can follow match paths.
Was there some particular concern you had? That is, what are you
worried about going wrong?
Steve
On 4/21/2011 2:15 PM, Ken...@th... wrote:
> Hi,
>
> I have a situation in which I have a big long grammar with lots of macros& rules of various types, and it works fine. I also want to take a few of the rules and expose them individually to a caller through a Java API. Here's my method, which does seem to work, but I haven't seen people use states like this to expose rules externally.
>
> ====== in the grammar file =======
> %class MyJFlexer
> <YYINITIAL> {
> ...various other rules...
> {MACRO_999} { return newToken("MACRO_999"); }
> ...various other rules...
> }
> <THISSTATE> {
> {MACRO_999} { return newToken("MACRO_999"); }
> }
> =============================
>
> ====== in Java =================
> lex = new MyJFlexer(new StringReader("foo"));
> lex.yybegin(MyJFlexer.THISSTATE);
> tok = lex.yylex();
> assertEquals("MACRO_999", tok.type);
> =============================
>
> Does that look kosher?
>
> Thanks.
>
> -Ken
------------------------------------------------------------------------------
Fulfilling the Lean Software Promise
Lean software platforms are now widely adopted and the benefits have been
demonstrated beyond question. Learn why your peers are replacing JEE
containers with lightweight application servers - and what you can gain
from the move. http://p.sf.net/sfu/vmware-sfemails
--
jflex-users mailing list
https://lists.sourceforge.net/lists/listinfo/jflex-users
|