Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lexical Analyzer For this assignment, you will create your own lexical analyzer program. The analyzer should ask the user for the name of a source

Lexical Analyzer

For this assignment, you will create your own lexical analyzer program.

The analyzer should ask the user for the name of a source file and then report the types of tokens found and how many of each type of token were identified.

Here is the BNF of the language your program will analyze:

 < program> -> begin  end  ->  |  ; 

-> < var> = -> -> a | b | ... | z | A | B | C | ... | Z | -> + | + | + < var> | + | * | * | * < var> | * -> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |

Here is a description of the tokens your program will count:

Token Examples ID Dog, kittykat, Rat, a combination of letters, a-z and A-Z. START begin END end ADD_OP + MUL_OP * ASS_OP = INT A combination of digits such as 125 or 5 or 8675 SEMI_OP ;

Write your solution using C++ and submit it in a single, plain text source code file so we can download, compile, and test it.

If the file had Dog kittykat and Rat in it, then it would report something like:

ID 3

It's gonna have begin and end in it, so it would report something like:

START 1 END 1

If there is no + in the file then:

ADD_OP 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases DeMYSTiFieD

Authors: Andy Oppel

2nd Edition

0071747990, 978-0071747998

More Books

Students also viewed these Databases questions

Question

Example. Evaluate 5n+7 lim 7-00 3n-5

Answered: 1 week ago