Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A2.class program will read a text file named A2.input, and produce a file named A2.output which contains following five lines: identifiers : NumberOfIdentifiers keywords :

 

A2.class program will read a text file named "A2.input", and produce a file named "A2.output" which contains following five lines:

identifiers : NumberOfIdentifiers

keywords : NumberOfKeyowrds

numbers : NumberOfIntergersOrRealNumbers

comments : NumberOfComments

quotedString : NumberOfQuotedStrings


  • Keywords: WRITE READ IF ELSE RETURN BEGIN END MAIN STRING INT REAL
  • Single-character separators: ; , ( )
  • Single-character operators: + - * /
  • Multi-character operators: := == !=
  • Identifier: An identifier consists of a letter followed by any number of letters or digits. The following are examples of identifiers: x, x2, xx2, x2x, End, END2.Note that End is an identifier while END is a keyword. The following are not identifiers:
    • IF, WRITE, READ, .... (keywords are not counted as identifiers)
    • 2x (identifier can not start with a digit)
    • Strings in comments are not identifiers.


here is the sample(A2.input)

/** keywords (such as read and if) and identifiers should not be counted in * comments. * Comments can be longer than one line. **/ MAIN f() BEGIN you are not required to check the syntax of the program; so all these words are identifiers; except "quoted" strings and keywords; to check how many lines and words I have; type "wc A2.input" in "luna.cs"; your number of characters and lines may vary from sample output, depends on how you save this file; to count the identifers and keywords; you have to count me one by one; note that A1_A2 is not ONE identifier; as defined in the language lexicon specification; A1 and A2 should returned as two identifiers; special characters such as !@#$% and tab may also appear to test your program; both 123 and 123.45 are numbers; while 12,34 are two numbers; /** you can put more than one comment line with characters like * and ) **/

here is some more tricky part: " /** this is a quoted string **/ " but /** "this is a comment " **/ END



and here is what A2.out should look like:

identifiers: 116 keywords: 3 numbers: 4 comments: 3 quotedString: 4


Step by Step Solution

There are 3 Steps involved in it

Step: 1

Heres the Java program implementing the logic to analyze the A2input file and generate the A2output file Java import javaioBufferedReaderimport javaio... 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

Starting Out With Python Global Edition

Authors: Tony Gaddis

4th Edition

1292225750, 9781292225753

Students also viewed these Programming questions

Question

What is an input file?

Answered: 1 week ago