Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// Compiler Theory // Using Flex and Bison book as reference: ISBN: 978-0-596-15597-1 Create a (f)lex program that will recognize numbers. For the purposes of

// Compiler Theory

// Using Flex and Bison book as reference: ISBN: 978-0-596-15597-1

Create a (f)lex program that will recognize numbers.

For the purposes of this exercise, define a number to be: // Rules

1. A finite string of decimal digits, with an optional leading "-", without

leading zeros, containing at least one digit. If there is only one digit, that

digit may be a zero.

or

2. A finite string of decimal digits containing at least one digit, without

leading zeros, with an optional leading "-", followed by a decimal point,

followed by a finite string of decimal digits containing at least one digit.

If there is only one digit preceding the decimal point, that digit may be a

zero.

or

3. A number of the form identied in 1. or 2., followed by an "e" or an "E",

followed by a number of the form identified in 1.

or

4. A finite string of decimal digits "0" through "7", with an optional leading

"-", with exactly one leading zero, containing at least two digits. If there

are exactly two digits, they may both be zeros.

or

5. A finite string of hexadecimal (upper case only) digits containing at least

one hexadecimal digit, with no leading zeros, preceded by the string "0x"

or "0X", optionally preceded by a leading "-". If there is only one hex-

adecimal digit, that digit may be zero.

No numbers may contain white-space.

Assume that the input to your program will consist only of (ascii) digits,

letters (upper or lower case), spaces, decimal points, "-", and new-lines.

The output of your program should be a report, telling whether "possible

numbers" are actually numbers or not. A "possible number" is a string of non-

white-space characters preceded by beginning-of-file, a space, or a new-line, and

followed by a space, a new-line, or end-of-file. Your program should also report

the number possible numbers, the number of numbers found, and the number

of "possible numbers" that were not numbers.

Your group should submit two les through the cs homework submission

system: a (f)lex program (named numbers.l), and a test data fille (which you

should name test-data.txt) containing appropriate test data to conrm that your

program does the right thing

//Example:

If the input file contains

123 123a 0123 12.3 12.03 -123 0 12.3e-5 0x123 0xabc 0XA9B 0.12E5 -1.0023e4

-0xA98F 0XA98H 0.123e-18 0128 00123 goodbye

Your program output should contain the report:

123 number

123a not number

0123 number

12.3 number

12.03 number

-123 number

0 number

12.3e-5 number

0x123 number

0xabc not number

0XA9B number

0.12E5 number

-1.0023e4 number

-0xA98F number

0XA98H not number

0.123e-18 number

0128 not number

00123 not number

goodbye not number

Out of 19 possible numbers, there were 13 numbers, and 6 not numbers.

Note: example does not cover all possible cases

Note: your (f)lex program should contain appropriate comments,

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

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago