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

Questions Cloud

Rewrite the uncovered-interest-parity equation : Rewrite the uncovered-interest-parity equation to show how it is a guide for the future spot rate.
Find the magnitude of the new mutual force of attraction : Two charges are separated by a distance d and exert a mutual attractive force of magnitude F on each other. find the magnitude of the new mutual force of attraction
Find what max height does each ball achieve after collision : This assembly is made with mass less strings attached to balls. Ball A (m = 0.3kilogram) is released from height 0.2 meter above Ball B (m = 0.5kilogram) also at rest. Find what max height does each ball achieve after collision
The spot rate of exchange between the turkish iira : The spot rate of exchange between the Turkish Iira
The specification for the lexical structure : 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..
Find the child centripetal acceleration : A 50.0 kilogram child stands at the rim of a merry-go-round of radius 2.15 meter, rotating with an angular speed of 2.70 rad/s. Find the child centripetal acceleration
A noble prize with three coworkers : A noble prize with three coworkers
Estimate what is the elapsed time : A race car starts from rest on a circular track of radius 690 meter. The car's speed increases at the constant rate of 0.400 m/s2, estimate the elapsed time
Evaluate what the constant angular acceleration of wheel : A rotating wheel requires 8.00 second to rotate 30.0 revolutions. Its angular velocity at the end of the 8.00 second interval is100.0 rad/s. Evaluate what the constant angular acceleration of wheel

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identify the address of the neighboring gateway

What OBJECT TYPE would you use to identify the address of the neighboring gateway from your local gateway?

  Find optimal production amounts using graphical method

The daily demand for solution A lies between 30 and 150 units, and that for solution B between 40 and 200 units. Find the optimal production amounts of A and B using the Graphical Method.

  Convert each section using the formula

Convert each section using the formula b * 2^2 + b * 2^1 + b* 2^0 and you get the octal number 766. Similarly, 2^4 = 16 so to convert a number from binary to hexadecimal all that is necessary is to start at the right of the number,

  Write a program to manage a dictionary

Then ask whether the user wants to add this new word to the dictionary. If the answer is yes, do so and go back to request the next word.

  Is it possible free internet content might one day replace

Is it possible that free Internet content might one day replace textbooks

  Personal trainer

PERSONAL TRAINER, INC.

  Determine final contents of cache as hit or miss

Direct mapped cache with 4 word cache line size and total size of 16 word, i.e. initially empty, write each reference in list as hit or miss and illustrate final contents of cache.

  Create a class named vehicle that acts as a super class for

Create a class named Vehicle that acts as a super class for vehicle types

  What makes these pairs transitive

What I dont understand is how these pairs are considered transitive. My question is what makes these pairs transitive?

  Definite versus indefinite loops

Definite versus Indefinite Loops

  Explaining straight-line depreciation method

Explain in scholarly detail how to carry out Straight-line Depreciation Method calculations.

  Override the insert method in bst

You should override the insert method in BST. Your overriding method should first call the method it is overriding. When 50 insertions have been performed since the last rebalancing.

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