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

  Create a database and then secure it

The goal is simple; you are to install the O/S, the Database Server and create a database and then secure it all as best you can.

  Conventions in database modeling

In 300-500 words, describe how important are naming conventions in database modeling? What comes first: the need for a report or the data?

  Create database model using ms visio database model diagram

You have been asked to create a database model using MS Visio Database Model Diagram Template. The purpose of this lab is to provide experience designing, with limited instructions, a simple database based on a list of data requirements and associ..

  Working database that supports the tables

The students are lodged in one of four houses, with a designated professor in change of each house. But, since some professors, such as Snape, have some problems standing some students, such as Harry, you should keep track of that too.

  What is the assignment operator

What is the problem with the following statement? 60 + 5 = grade, What is the problem with the following statement? lastName = "smith, What is the assignment operator

  Develop an e-r diagram for the library database

Develop an E-R diagram for the library database. The relation schemas for the library database.

  Database design proposal product in the final phase of the

in the final phase of the database design proposal assignment you are required to design a working prototype of the

  Write one sql statement to implement

Write ONE SQL statement to implement each of the tasks. Please do not hardcode to skip joins (your code need to work regardless of rows in the tables) - write an anonymous PL/SQL program to print out the room size of room 400. Please use implicit c..

  Describe the purpose of the database

Describe the purpose of the database. Based on your research and / or common knowledge of a college and the information tracked by a college, describe the entities of the database and the attributes of each entity.

  Create database of measured meteorological data

You are creating a database of measured meteorological data for use in weather and climate research. Explain a structure type measured_data_t with components site_id_num.

  Create a fourth column labeled metcalfe value

Create a fourth column labeled Metcalfe Value that calculates the value of each social media outlet based on the number of users it has

  How to connect to the oracle database

Instructions: You can use any source you prefer, the text, Internet, etc. The answers should not take more than 1 - 2 paragraphs of text, please submit a word processing document, please make sure it's compatible with MS Word.

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