Assignment 1- How JFlex works?

Question:

Write comprehension notes not more than 5 pages on how JFlex works. Relate your notes with the execution of the simple.flex

Answer :

JFlex takes a JFlex program and creates a Java file. I give the JFlex program a suffix of “.jflex”, although this is not compulsory. The default name for the Java class generated is Yylex, and the code is written to a file called Yylex.java, although this can be changed, using the %class directive.

There are two provided constructors for the lexical analyser class. The primary one takes a Reader object as a parameter. The secondary one takes an InputStream, which it converts into a Reader and invokes the primary constructor. The parameter represents an object that provides the input to be lexically analysed. For example, the parameter can be a StringReader (if we want to obtain theinput from a String) or an InputStream (if we want to obtain the text from a file).

The lexical analyser class has a method for getting a token. The default name for this method is yylex(), although this can be changed, using the %function directive. The default return type is Yytoken, although this can be changed, using the %type directive. This method loops, matching the input to regular expressions, and performing the action associated with that regular expression. If the action contains a return statement, the method returns the value indicated.

Installation JFlex

Unzip the file you downloaded into the directory you want JFlex in. Open the bin folder then click the .bat jflex file and edit the where your directory install JAVA and JFLEX.





How to work with JFlex

Browse the lib folder and click on JFlex(Executable Jar file) to use .

Click the “Browse” button to select the file simple.flex from the location simple folder and click “Generate” button. After that, it will generate the Yylex.java


The massage will shown that analyser generator first read the simple.flex file. After that follows by constructing NFA in 165 states. Next step is to convert the NFA into DFA along with the process of minimized the states. Finally, the new path of the file Ylex.java is generate and process successfully done.

Yylex.java contains a scanner class that generated by simple.flex. The class can prints debugging information about each token until reached the end of file or an error is occurred. This scanner class will be used to check our input file.

You can by using BlueJ to open the Ylex.java Ylextoken.java and utility.java



1 comments:

Term Papers said...

I have been visiting various blogs for my term papers writing research. I have found your blog to be quite useful. Keep updating your blog with valuable information... Regards

Post a Comment

Related Posts with Thumbnails