Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!