Professional Documents
Culture Documents
%%
baaa ba baaa /* Options and Declaration part */
hello %class SheepLanguage
this is the sheep language %char
ba baa baaa aabaabaaaabababaaaabbb %line
%column
%standalone
Match found baaa Length: 4 at location 0
Match found ba Length: 2 at location 5 //Define regular expressions
Match found baaa Length: 4 at location 8 word = ba+
Match found ba Length: 2 at location 50
Match found baa Length: 3 at location 53 %%
Match found baaa Length: 4 at location 57 /* this is the third part (Lexical rules) */
Match found baa Length: 3 at location 64
Match found baaaa Length: 5 at location 67 {word} {System.out.println("Match found " + yytext() + " Length: "
Match found ba Length: 2 at location 72 + yylength() + " at location " + yychar);}
Match found ba Length: 2 at location 74 \n {}
Match found baaaa Length: 5 at location 76 . {}
Using Command line
Step 1 JFlex_examples>jflex MyFirstJfelxSpecsFile.flex
Reading "MyFirstJfelxSpecsFile.flex"
>jflex SpecsFileName.flex Constructing NFA : 14 states in NFA
• {number} {System.out.println("NUM(%d)\n",
Integer.parseInt(yytext()));}
• {identifier} {System.out.println("ID(%s)\n",
yytext());}
Whitespaces, comments, newlines, and
others
{whitespace} {/* skip white spaces */}
\{[^}]*\} {/* skip comments */}
{newline} {/* skip new lines */}
. {System.out.println("UNKNOWN SYMBOL(%s)\n", yytext();}