The specification for the lexical structure

Assignment Help Basic Computer Science
Reference no: EM13670481

The first project involves writing the lexical analyzer with lexical error checking, and the compilation listing generator for the compiler.

The specification for the lexical structure of the language is the following: Comments begin with -- and end with the end of the line.

White space between tokens is permitted but not required. Identifiers must begin with a letter, followed by letters or digits. Integer literals consist of a sequence of digits.

Real literals consist of a sequence of digits containing a decimal point. At least one digit must be before the decimal point. Boolean literals are true and false The logical operators are not, and and or. Each logical operator should be a separate token. The relational operators are =, /=, >, >=, <, and <=. All six lexemes should be represented by a single token. The adding operators are the binary + and -. Both lexemes should be represented by a single token. The multiplying operators are * and /.

Both lexemes should be represented by a single token. The following punctuation symbols should be accepted: commas, colons, semicolons, and parentheses.

The following are reserved words: begin, boolean, else, end, endif, function, if, is, integer, real, returns, then The lexical analyzer should be created using flex. The compiler should produce a listing of the program with lexical error messages included after the line in which they occur. Any character than cannot start any token should be considered a lexical error.

It should also generate a file containing the lexeme-token pairs as a means to verify that the lexical analyzer is working correctly. Only token numbers are required, not token names.

The token numbers for the punctuation symbols should be the ASCII value of the character. The remaining tokens should be numbered sequentially beginning at 256.

Decoupling the listing code

As a matter of good object-oriented design, it is a good idea to decouple the code that displays the error messages from the flex source code. In the later stages of this project, there will be syntactic and semantic errors. The code for displaying and counting these errors should be separate from the flex and bison code since it will be called from both places.

In the skeleton code that I have provided you I am calling the functions as members of a Listing class. If defined as a class, this would really be defining a singleton object. One way to create a singleton is to make all the functions and data static. The standard practice in C++ is to put the class definition in the header file listing.h and the bodies of the member functions in a corresponding .cc file.

Because, unlike Java, C++ does not require all functions to be put in classes, another alternative would be to define these as ordinary functions that are not members of any class. In that case the function prototypes would still go in listing.h and the function bodies in the corresponding .cc file.

In the call to the appendError function I have passed in a parameter named LEXICAL. This is to designate that this error is a lexical error. My suggestion would be to define an enumerated type as follows:

enumErrorType {LEXICAL, SYNTAX, SEMANTIC};

The listing.h file would be a good place to put this enumerated type definition. By supplying the error type, the Listing class can keep a count of the number of messages of each kind, which should be displayed when the end of the program is reached. Adding another function to the Listing class to display the error count is best way to accomplish this.

Finally, let me explain the purpose of the appendError function. It should queue up the error messages so they are displayed at the end of the line. All error messages that occurred on that line can then be displayed by the nextLine function once the line is complete.

Reference no: EM13670481

Semi-annual deposits into a fund earning interest

Mrs.Tong makes semi-annual deposits into a fund earning interest at j2= 8% p.a. Her first deposit is $2500 and each succeeding deposit is 6% higher than preceding deposit. Wha

Physical and chemical characteristics of incinerator

What are the physical and chemical characteristics of incinerator ash and flue gases that result from incineration? Briefly explain how leachability and destruction and remo

Ethics and values in healthcare

Conduct an Internet search to find cases where an organization or individual has been penalized for improperly accessing patient information. There have been several cases o

Create the needed constructors

In this assignment you will be implementing three classes -Date (you would reuse the Date class after implementing toString() and equals() method), Employee and EmployeeTest

When installing utp cable for a horizotnal link

When installing UTP cable for a horizotnal link, it is very important to minimize crosstalk. Explain what crosstalk is, why crosstalk can be a problem, and how it is minimiz

Describe the different types of database requests and

Describe the different types of database requests and transactions.  Explain the need for the two-phase commit protocol. Then describe the two phases.  What is the objective o

Write a program that creates two vectors from x-one

write a program that creates two vectors from x-one (call it P) that contains the positive elements of x, and a second (call it N) that contains the negative elements of x.

Write a recursive method that accepts an integer n and

Write a recursive method that accepts an integer n and returns the product of the first n even integers. For example if n = 4, it should return 384 (2*4*6*8). The method shoul

Reviews

Write a Review

 
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