Computer Languages - Homework 1 |
---|
Please notice that you will get 2 hours supervision but that you are expected to spend more time with these exercises working on your own. See the instructions for the deadline. |
Purpose |
---|
These computer based exercises should help you gain familiarity with regular expressions and a tool that, given a regular expression, generates a program to recognize the words described by some regular expressions.
Regular Expressions |
---|
Where we use JFlex to generate programs that search for certain words and patterns in text files. |
jflex myName.flex javac MyName.java java MyName someFileOfTextAs you see, the program terminates without any output! In fact, the Java program MyName does nothing interesting! It just goes through every character in the file of text and does nothing for it!
name = [a-zA-Z][a-zA-Z_0-9\-]* server = [a-zA-Z][a-zA-Z]*Look at the manual to see how to make definitions and how to use them!
Hint Use the directive %implements with the name of a Java interface. In that interface declare some integer constants for the keywords, then you can use these names to index an array in your program to count the occurrences of each keyword. You might also want to declare an array of strings in the interface indexed by these constants so that you can print keyword and the number of occurrences. A short version of the interface could look like:
interface Kw{ int ABSTRACT = 0; int BOOLEAN = 1; int BREAK = 2; String[] kws = {"abstract","boolean","break"}; }Check this The command wc in unix counts the number of lines, words and characters in a file. Compare the number of keywords with the number of words in a Java program. What are the other words?
Submission |
---|
Who should submit? What should be submitted? How to submit? When? |