Implement the lexical analysis task

Assignment Help Computer Engineering
Reference no: EM132104941

Problem Description

In this problem, you should implement the lexical analysis task for a limited version(i.e., the depth of the nested loops) of a programming language. Lexical analysis is the ?rst stage that compilers parse and detect the possible syntax errors.

Ideally, any new (programming) languages can be designed and analyzed in the similarmanner. You will need to analyze a Pascal-and-C-like language in this programming assignment.

Given a segment of the source code, your C++ code should analyze the code and extract all tokens, which include:

• Keywords: keywords are the words reserved by the language. They are all upper-case. In the case of this simpli?ed language, the keywords are restricted to the set

{ "BEGIN", "END", "FOR" }

• Identi?ers: An identi?er is used to describe the variables, which are all lower-case• Constants: Numbers like 10, ... .

• Operators: all arithmetic operations (i.e., +, -, *, and /), "++" and "="

• Delimiters: like "," and ";"

Your C++ code should input a text ?le from user, which contains the expressionhe/she wants the compilers to analyze. Then, your code should parse the input, detect the tokens, classify them, and print out the results.

With this assignment, you will get practice with the stack implementation which isone of the most widely used data structures. Besides, you will be familiar with string processing and input parsing, which are of crucial importance in most C++ projects.

Details

1. (Data Structures:) You need to implement a stack data structure to keep track of theprocessing and compute the depth of the nested loops. Adding elements to the stack

(push) and removing objects from it (pop) are two essential methods that must beimplemented. You can use any data structure to implement the stack, e.g., arrays,linked-lists, etc.

2. (Algorithms:) Once the input expression is given, your program should decide whichcharacter should be inserted to the stack, and when the result needs to be computed.You need to detect the possible syntax errors while tracing the depth of the nested loops.

Example Run

Try to keep your output as close to the given format as possible: In this example, the input ?le is "code.txt" It contains the code segment below:

Text Case I
FOR (i, 10, ++)

BEGIN

FOR (j, 10, ++)

BEGAN

sum=sum + i + j;

END

END
> ./pa3.out

INPUT> Please enter the name of the input file:

code.txt
OUTPUT> The depth of nested loop(s) is 1
Keywords: FOR BEGIN END

Identifier: sum i j

Constant: 10

Operators: ++ = +

Delimiter: ; ,

Syntax Error(s): BEGAN

Reference no: EM132104941

Questions Cloud

Managerial accounting and financial accounting : What is the different between Managerial Accounting and Financial Accounting?
Fund managers in endeavors to raise money : What are the major challenges faced by fund managers in endeavors to raise money?
What is the size of the banks actual reserve : If a bank has access reserves of $8000 and checkable deposits of $150000. If the reserve ratio is 20% what is the size of the banks actual reserve?
Describe how use of the net present value technique : Describe how use of the net present value technique would assist the company in coming up with the best investment decision.
Implement the lexical analysis task : Your C++ code should input a text ?le from user, which contains the expressionhe/she wants the compilers to analyze.
Design a structure in c that contains data to model a state : Design a structure in C that contains data to model a state capital and write several functions that process and act on that data.
Write a python simulation to experimentally verify problem : Write a Python simulation to experimentally verify the Monty Hall problem. Your simulation should run a large number of trials for two scenarios.
Why pathology collector should follow communication protocol : CHCCOM005 Communicate and Work in Health or Community Services -HLT37215 Certificate III in Pathology Collection - Why is it important for you to listen
Assign the cost of the copy center to department : How would you assign the cost of the copy center to each department? Why?

Reviews

Write a Review

Computer Engineering Questions & Answers

  Give declaration and definition of a structure

Write down a program to display the initial values held by the structure (you must use a structure) on the screen.give declaration and definition of a structure.

  The second programming project comprises writing a program

the second programming project involves writing a program to calculate state income tax for a single taxpayer that uses

  Discuss how the three levels of management hierarchy

Discuss how the three levels of management hierarchy: strategic, management, and operational relates to the mission of a business.

  Sections of currency conversion development documentation

The Currency Conversion application is a menu-driven program that allows users to select one of five international currency types, input the amount of a foreign currency, and then convert the foreign currency to dollars. The program displays the e..

  The whole scope of internet users are forced change ipv6

till the whole scope of Internet users are forced to change to IPv6 there would be no acceleration of its deployment. The old saying comes into the forum; why stop using something that you know works and you are happy with this

  Study and analyze the principles of inheritance

Study and analyze the principles of inheritance

  What would be problem with using one of other architectures

Which of the types of storage architectures discussed in this section would you expect. What would be the problem with using one of the other architectures in the data center environment?

  Prepare a written review of an article from a recent

prepare a written review of an article from a recent business magazine. also prepare a powerpoint presentation as

  Determine the duties of the system administrator

Determine the duties of the system administrator. Explain the differences between the system administrator and the network administrator.

  Express why this algorithm favors i/o bound programs

express why this algorithm favors I/O bound programs and yet does not permanently deny processor time to processor bound programs.

  Geographic information system for storing point data

For this project you will build a simple Geographic Information System for storing point data. The focus is organizing city records into a database for fast search. For each city you will store the name and its location (X and Y coordinates). Sear..

  Use the branch-on-equal mips assembly instruction

Explain how to convert the address(hex) to words(bits) ? Is there any shortcut to do this type of conversion?

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