Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please use C or C++ to implement this project. In this project, you will implement a simple lexical analyzer to scan a small set of
please use C or C++ to implement this project.
In this project, you will implement a simple lexical analyzer to scan a small set of expressions. This set of expressions has the following tokens: identifier, integer constant, left parenthesis, right parenthesis, addition operator, and multiplication operator. Specifically, assume we have the following lexical definition. LETTER rightarrow a | b | ... |z|A| ... | Z DIGIT rightarrow 0 | 1 | ... | 9 We define a set of tokens as follows. ID rightarrow LETTER {LETTER | DIGIT} INT rightarrow DIGIT {DIGIT} LEFT_PARENTHESIS rightarrow (RIGHT_PARENTHESIS rightarrow) ADD_OP rightarrow ' + '| '-' MUL_OP rightarrow '+' | '/' Note that blank is a character that should be skipped by the program. Given an expression as input, your program should accomplish the following requirements: If the expression has error, for example, undefined token, unequal numbers of left parenthesis and right parenthesis, the program should output an error message. Print out all identifiers and all integer constants; Counting how many left parenthesis, right parenthesis, addition, and multiplication operators. For example, for the input expression (number1 + number2) * (number3 + 1000) your program should output ID: number1, number2, number3 INT: 1000 The numbers of LEFT PARENTHESIS, RIGHT PARENTHESIS, ADD_OP and MUL_OP; 2, 2, 2, and 1Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started