Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The program for Assignment 2 implements a lexical analyzer. The calling sequence for the lexical analyzer, a definition for all of the tokens, and a

image text in transcribedimage text in transcribedimage text in transcribed

The program for Assignment 2 implements a lexical analyzer. The calling sequence for the lexical analyzer, a definition for all of the tokens, and a class definition for Token, is included in the startercode for the assignment. The assignment is to write the lexical analyzer function and some test code around it. The test code takes several command line arguments: v (optional) if present, every token is printed when it is seen -stats (optional) if present, statistics are printed -sum (optional) if present, summary information is printed filename (optional) if present, read from the filename, otherwise read from standard in Note that no other flags (arguments that begin with a dash) are permitted. If an unrecognized flag is present, the program should print "Invalid argument (arg) where (arg) is whatever flag was given, and it should stop running. At most one filename can be provided, and it must be the last command line argument. If more than one filename is provided, the program should print "Too many file names" and it should stop running. If the program cannot open a filename that is given, the program should print "Could not open {arg)", where targ) is the filename given, and it should stop running. The program should repeatedly call the lexical analyzer function until it returns DONE or ERR. If it returns DONE, the program proceeds to handling the -stats and -sum options, if any, and then exits. it returns ERR, the program should print "Error on line N (lexeme)", where Nis the line number in the token and lexeme is the lexeme from the token, and it should stop running. If the -v option is present, the program should print each token as it is read and recognized, one token per line. The output format for the token is the token name in all capital letters (for example, the token LPAREN should be printed out as the string LPAREN. In the case of token ID, ICONST, FCONST and STRING, the token name should be followed by a space and the lexeme in parens. For example, if the identifier "hello" is recognized, the-v output for it would be ID (hello) If the -stats option is present, the program should, after seeing the DONE token, print out the following report: Total I N List of IDs: X Where N is the number of times the ID token was seen and X is a comma separated list of identifier lexemes. If N is 0, then List of IDs is not printed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Practical Issues In Database Management A Refernce For The Thinking Practitioner

Authors: Fabian Pascal

1st Edition

0201485559, 978-0201485554

More Books

Students also viewed these Databases questions