Provide a main program to test the lexical analyzer

Assignment Help Database Management System
Reference no: EM131347133

Assignment

It's sometimes useful to make a little language for a simple problem. We are making a language to let us play with strings and numbers, and for this assignment we are building a lexical analyzer for this simple language. Here are the lexical rules for the language:

1. The language has identifiers. An identifier starts with a letter and is followed by zero or more letters.

2. The language has string constants. A string constant is a sequence of characters, all on one line, enclosed in double quotes. You do not have to support special handling for escape characters between the quotes.

3. The language has integer constants, defined as a sequence of digits.

4. The language has 3 operators: +, * and [ ]. This requires 4 tokens.

5. The language has 2 keywords: "print" and "set".

6. Statements in the language end in a semicolon.

7. The language supports parentheses.

8. White space is used to separate tokens and lines for readability.

9. A comment begins with two slashes (//) and ends at a newline.

The lexical analyzer is to be implemented in a C++ function. The function will be passed a pointer to an input stream to read from. It will return a Token representing the token and lexeme that has been recognized.

The definitions for the Token class and unique values for each of the tokens (TokenType) that you must recognize is provided in the header file p2lex.h, which is on the course website. There is also a testmain.cpp program that shows how to include p2lex.h and use tokens.

The lexical analyzer must ignore white space and comments. Whitespace and comments serve only as separation between tokens.

The program should maintain an external integer named "linenum", which should be initialized to 0 and incremented whenever a newline is seen by getToken().

A lexical error should cause the token ERR to be returned. An end of file should cause DONE to be returned. You MUST use the p2lex.h header file for your assignment. You may not change it. You do not need to hand in p2lex.h, but it doesn't matter if you do. I will compile and test your program against the distributed p2lex.h header file.

You must produce and submit three files:

1. p2lex.cpp

This file should #include p2lex.h and must provide: an implementation for << operator to print a Token

o The printed version of the token must be a string representation of the TokenType. We define the string representation of a TokenType to be the symbol for the TokenType in lowercase letters. For example, the string representation of the TokenType value INT should be "int".o For the ID, STR, INT and ERR tokens, the string representation must be followed by the lexeme for the token. The lexeme should be printed in parentheses.

an implementation for the getToken function

o The getToken() function should read characters from the stream pointed to by the first argument and return the token that it recognizes.

2. project2.cpp

This file should #include p2lex.h and provide a main program to test the lexical analyzer

The specifications for the main program are as follows:

1. The program should accept at most one command line argument. If present, this one command line argument is the name of a file to open and read for input. If not present, the program should read from the standard input.

2. There may also, optionally, be an initial command line argument equal to the string "-v". If it is, then your program should be in "verbose mode" and should print each token that it recognizes in addition to the remaining items.

3. The program should loop repeatedly, calling getToken(), until getToken returns an ERR or

DONE token

4. If the loop stopped because of an ERR token, it should print out the token

5. The program should print out a count of the number of times each type of token was seen.

6. The program should print out the number of unique lexemes for the ID, STR and INT that appear in the input.

Reference no: EM131347133

Questions Cloud

Determine the equilibrium mole fraction : The equilibrium constant for the water?carbon monoxide reaction CO + H2O ? CO2 + H2 at 0.100 MPa and 1000. K is Ke = 1.442. Determine the equilibrium mole fraction of each gas present under these conditions. Assume ideal gas behavior.
Explain concept of maximum sustainable yield for a fishery : Explain the concept of maximum sustainable yield for a fishery. Is maximum sustainable yield required to preserve biodiversity? Is it the most efficient rate of harvest for a renewable natural resource?
Determine the maximum reversible electrical work output : Determine the maximum reversible electrical work output of the fuel cell shown in given Figure, where g is the specific Gibbs free energy.
What is the price of the put option at that time : Assume the Black-Scholes framework. Consider a 9-month at-the-money European put option on a futures contract. If three months later the futures price is 17.7, what is the price of the put option at that time?
Provide a main program to test the lexical analyzer : The getToken() function should read characters from the stream pointed to by the first argument and return the token that it recognizes. This file should #include p2lex.h and provide a main program to test the lexical analyzer
What is the yield to maturity on this bond : (Yield to maturity) The Saleemi Corporation's ?$1,000 bonds pay 9 percent interest annually and have 13 years until maturity. You can purchase the bond for $ 895. a. What is the yield to maturity on this bond? b. Should you purchase the bond if the y..
What recommendations can you make to assist the company : Is Lobo using the lowest cost combination of workers to produce its targeted output? If not, what recommendations can you make to assist the company?
Determine the maximum theoretical reaction efficiency : Determine the maximum theoretical reaction efficiency, open circuit voltage, and maximum theoretical work output per mole of hydrogen consumed.
Explain approach you will take to ensure adequate nutrition : You are the registered nurse performing a health assessment on a newborn infant. From the functional health pattern portion of the assessment, you learn the mother is reluctant to breastfeed her baby. How do you respond? Explain the approach you w..

Reviews

Write a Review

Database Management System Questions & Answers

  Frequent k-mer problem

The most frequent k-mer problem seeks the set of substrings of length k (where integer k is an input) that occur most frequently

  Write a monitor using to implement readers-writers problem

Suppose that we replace the wait and signal operations of monitors with a single construct await(B), where B is a general Boolean expression. Write a monitor using this scheme to implement the readers--writers problem.

  How is a sequential file different from a database

How is a sequential file different from a database? Describe any changes you would make to a sequential access code to make it work for a database

  Create a database for the application

Perform the following tasks to create the database required for the application: Create a database for the application.

  Create and maintain a database server

Create appropriate tablespace for the above scenario as per OFA and create a Schema with appropriate privileges and use the above created (1i)tablespace as default table space.

  Expanded entity relationship model diagram

Each department has many employees assigned to it, but each employee works for only one department at one of the factories. An employee cannot work at more than one factory at a time.

  Write a join query that for every order

Write a join query that for every order placed on September 5, 1998, (use '05-SEP-1998') will list the order number and order date along with the customer number, last name, and first name of the customer who placed the order.

  Attribute to another entity type

Give a practical example when you would move an attribute to another entity type. Describe in detail.

  Explain how principles of database management are applied

Create a 4- to 6-slide Microsoft® PowerPoint® presentation in which you explain how the principles of database management and your recommendations were applied to the project.

  Compose conceptual data modeling techniques

Prepare database design documents using the data definition, data manipulation, and data control language components of the SQL language.

  Patients post cardiac bypass surgery

Monitor Renal Outcomes in patients post cardiac bypass surgery?

  Write down a 350-word summary explaining two of the most

write a 350-word summary describing two of the most popular database vendors in the marketplace. answer the following

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd