Answered step by step
Verified Expert Solution
Link Copied!

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.image text in transcribed

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 1

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

Step: 3

blur-text-image

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

Spatial Databases A Tour

Authors: Shashi Shekhar, Sanjay Chawla

1st Edition

0130174807, 978-0130174802

More Books

Students also viewed these Databases questions

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago