-1

My question is Can i use the patterns in the java code ?? I mean if i have this code can i use pdf word in java code i'm looking to use the pattern itself and manipulate it by java so is there any way to do so ?

    pdf = "."("full.pdf" | "full.pdf+html" | "pdf")

    <YYINITIAL>
    {
        {pdf}
       {
          String x=pdf; 
          return YYEOF;
       }
    }

I had tried searched but the resources is little, thanks for help.

Brian
  • 3,850
  • 3
  • 21
  • 37

1 Answers1

2

JFlex is not designed as a stand-alone pattern matcher. So, using that way is unlikely to work ... without significant modification to JFlex.

But the good news is that Java Pattern regexes are more expressive than JFlex regexes.


On the other hand, if you are asking how to extract the text that has been matched by a lexer regex ... so that you can use it in the Java code inside the { ... } in your parser, then just call yytext(); e.g. somewthinfg like this:

pdf = "."("full.pdf" | "full.pdf+html" | "pdf")

<YYINITIAL>
{
   {pdf}
   {
      String x=yytext(); 
      return YYEOF;
   }
}

See http://jflex.de/manual.html#ScannerMethods

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • thanks a lot Stephen i didn't mean that, my example should be like this : `{x} {pdf} { String x=yytext(); return YYEOF; }` then i need to extract the value of pdf. – Mohammad Asal Jul 03 '18 at 17:01