CISS-110 Project 6
For this project you will continue to work with files.
Learning outcomes
- Implementing user-defined methods.
- Working with regular expressions.
- Working with files.
- Using
Scanner
with files. - Confirmation program produces desired results.
The file format will be similar to a source code program. You will tokenize the contents. Simply put, tokenizing is recognizing the value of each component of a source program by classifying each token. The file will be formatted such that each token is surrounded by whitespace.
Create methods to perform the identification of punctuation, integer constants, floating point constants, reserved words and identifiers. Perhaps each method could be an “is” method like isPunct
, isIntegral
, isDouble
, isReserved
, isIdentifier
. Each of these will take a token of type String
and returns a boolean
.
In addition to the five methods noted above, create one more method called classify
which is responsible for taking the String
token and printing its classification and value. Example output is provided at the end.
Using the matches()
method of the String
class, you will be able to identify certain patterns in strings. This will be discussed during lecture.
The following patterns are provided for identification:
Punctuation -> \p{Punct} Integral -> \d+ Floating -> \d+\.\d+ Identifier -> [a-zA-Z]+[0-9a-zA-Z_]* Reserved -> (int|double|long|if|else|void|while|for|return)
Using the following test data for your input file:
int x ; int y = 35 ; for ( x = 0 ; x < 10 ; x ++ ) { y = y * 3.14 ; }
Your program will produce the following output to the screen:
RESERVED int IDENT x PUNCT ; RESERVED int IDENT y PUNCT = INTCONST 35 PUNCT ; RESERVED for PUNCT ( IDENT x PUNCT = INTCONST 0 PUNCT ; IDENT x PUNCT < INTCONST 10 PUNCT ; IDENT x UNKNOWN ++ PUNCT ) PUNCT { IDENT y PUNCT = IDENT y PUNCT * DBLCONST 3.14 PUNCT ; PUNCT }
Submit the project to the Learning Management System as Project6_lastname.java.