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