Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Datalog Engines In Databases

Authors: Bas Ketsman ,Paraschos Koutris

1st Edition

1638280428, 978-1638280422

More Books

Students also viewed these Databases questions