Question: In java JLex(or JFlex) code first import java.io.*; %% %{ public static void main(String argv[]) throws java.io.IOException { MyLexer yy = new MyLexer(new FileReader(me.txt)); while

In java JLex(or JFlex)

code first

import java.io.*; %% %{ public static void main(String argv[]) throws java.io.IOException { MyLexer yy = new MyLexer(new FileReader("me.txt")); while (yy.yylex()>=0){ yy.yylex(); } } %} %notunix %integer %line %class MyLexer %eofval{ return; %eofval}

ID = [a-zA-Z_][a-zA-Z0-9_]*

%%

{ID} {System.out.println("ID is ..."+ yytext()); } | {} . {}

what i want is to count how many ID is in that file, i dont know how to make the count +1, its easy in all languages, something like i+1 in a for or while loop, but how to do that in JLex? our prof gives us a hint but i dont know how to do that.In java JLex(or JFlex) code first import java.io.*; %% %{ public static

ID count incorrect: probably your regular expression for ID is wrong. In some examples we have " [azAZ][azAZ09]" as the RE for ID, which is incorrect according to our language definition: we do not allow underscore, hence you need to change the RE accordingly. There are some other subtle errors, e.g., in [azaZ] the second 'a' should be in upper case. Another possible cause is that you put ID in front of KEYWORD like below: \{ID \} \{idCount ++ ; { KEYWORD\} \{keywordCount ++} In this case, keywords like INT will be recognized as an ID instead of a keyword. To solve the problem, put the line for KEYWORD in front of the line for ID

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!