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

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

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