Question: Write a function scan(num_string) IN LUA that reads in a single character at a time, and when it reaches end of the string, reports whether

Write a function scan(num_string) IN LUA that reads in a single character at a time, and when it reaches end of the string, reports whether it has read in a decimal, octal, or hexadecimal number, and what that number is (as a string), or "NONSENSE" if it isn't a well-formed number.

For the purposes of this assignment, use the following definitions of decimal, octal, and hexadecimal numbers

decimal - A single zero, or any continous sequence of decimal digits that starts with a non-zero decimal digit and includes 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

octal - An octal number always starts with a 0, and is followed by a single 0 or a non-empty sequence of octal digits that does not start with 0. The octal digits are 0, 1, 2, 3, 4, 5, 6, and 7.

hexadecimal - A hexadecimal number always starts with a 0 followed by a lowercase 'x' and either a single 0 or a sequence of hexadecimal digits. Hexadecimal digts include 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f, A, B, C, D, E, and F.

All forms can have an optional positive or negative sign directly infront of the number, with no space between the symbol and the number.

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!