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

  User interface design guidelines used for new system

Design a suitable source document for ads that are telephoned or mailed in. Suggest at least four user interface design guidelines that could be used for the new system.

  Evaluate an expression and display one value

What function would you use in Access to evaluate an expression and display one value when the expression is true, and another value when the expression is false?

  Facilitate assembly of information for business decisions

This module is about "business intelligence" and tools which facilitate assembly of information/knowledge in ways which enable "better" business decisions to be made.

  Create cron file which will regularly perform backup

Create a cron file that will regularly perform the following back ups: performs a level 0 backup once per month and performs a level 2 dump one day per week

  What opportunities enabled team to accomplish its goals

What motivational theories do you think could have been used to encourage the team to be more successful? What specific rewards or opportunities would have enabled the team to accomplish its goals? Why?

  Extended grep for regular expressions

That contain the word "as" exactly onceb) that contain the word "sa" more than once

  Create your own function that accepts one input parameter

Using Pseudocode, create your own function that accepts one input parameter and returns a float number. You decide the theme.

  Receiver initiated distributed scheduling algorithms

Receiver initiated distributed scheduling algorithms suppose task pre-emption at the sender site.

  Question based on artificial intelligence

If the brain is a computer and the mind its workings, is this fitting analogy of the computer and its software? What would happen if we had dedicated computers with a huge number of neuron circuits?

  What are two possible ways to achieve this goal

You need to relocate the existing user and computer objects in your company to different organizational units. What are two possible ways to achieve this goal? (Note: not the two "options" in the book.)

  Shortest path between each pair of nodes using floyd''s metho

find the shortest path between each pair of nodes using Floyd's method

  The query output to only in-active members

Modify the query to limit the query output to only in-active members, and then run the query. Convert the query to a make table query. Name the new table In-Active Members, and then run the query. Open the In-Active Members table and observe t..

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