Skip to content

Programming by Design

If you're not prepared to be wrong, you'll never come up with anything original. – Sir Ken Robinson

  • About
  • Java-PbD
  • C-PbD
  • ASM-PbD
  • Algorithms
  • Other

CISS-110 Project 6a

Posted on October 16, 2019January 20, 2025 By William Jojo
CISS-110-Project
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 identify 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 return 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 specific patterns in strings. This will be discussed during the 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.

Post navigation

❮ Previous Post: CISS-110 Project 5
Next Post: CISS-110 Project 6b ❯

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Copyright © 2018 – 2025 Programming by Design.