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

  Discuss social engineering attack based on provide technique

Discuss social engineering attacks based on the provided techniques. Discuss why social engineering attacks are particularly difficult to prevent.

  Wap that receives a series of numbers from the user

Given an integer number, find the sum of all the numbers from 1 to this number.Example: If the number given is 5, the program should display 1+2+3+4+5=15.

  Outline a brief business continuity plan

Outline a brief business continuity plan, including controls to reduce the risks in advance as well as a disaster recovery plan

  Would it always be the result of one''s experience

How do you envision the ways program verification and performance tuning will be accomplished in the future? Will it still be a work of art? Will it always be the result of one's experience? Or do you forecast more and more automatic ways (algorit..

  Write a program that simulates inventory bins in a warehouse

Write a program that simulates inventory bins in a warehouse. Each bin holds a number of the same type of parts.

  Find a way to simulate different cache architectures

find a way to simulate different cache architectures through premade address accessing files. this task includes

  Design a flowchart and pseudocode using control breaks

design a flowchart and pseudocode using control breaks that enable the user to print invoices for any raw material that is selected.

  Determine the forced motion velocity

Consider a 5-m-long vertical plate at 60°C in water at 25°C. Determine the forced motion velocity above which natural convection heat transfer.

  What is the history of osi model and benefits

Why you will recommend either asymmetric key encryption, symmetric key encryption, or no encryption at all for the Email correspondence.

  Find the phase distortion when the input is given

You are given the system shown in Fig. The output of the system is ;(/). Find the phase distortion when the input is given by.

  For which purposes is a digital secure certificate not used

cis407a- For which of the following purposes is a digital secure certificate not used? Which of the following SQL statements will search for a given last name in the tblEmployees table based on a search variable name's strSearch?

  Kind of constraint that stipulates

Kind of constraint that stipulates that a user can be assigned to a role only if that user was already given another role.

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