Question: Using the descriptions below, write a scanner for numbers, symbols, comments, arithmetic operators, and parenthesis in Racket or scheme. - a number is one or
Using the descriptions below, write a scanner for numbers, symbols, comments, arithmetic operators, and parenthesis in Racket or scheme.
- a number is
one or more digits |
zero of more digits followed by a decimal point followed by one or more digits |
one or more digits followed by a decimal point followed by zero or more digits
- a symbol is one or more characters from the set [_A-Za-z] followed by zero or more characters from the set [_A-Za-z0-9]
- a comment is the literal string "#" followed by zero or more characters until the end of the line - an arithmetic operator is + | - | * | / - a parenthesis is ( | ) Your scanner must convert input text into the following tokens: NUM, SYM, ADD, SUBTRACT, MULTIPLY, DIVIDE, LPAREN, RPAREN, ERROR. Turn in your scanner implementations and test cases. Your test cases should show that your scanner produces a correct list of tokens when given valid input and the scanner output should contain an ERROR token when given invalid input. the output must all be list containing each output token.
Sample Racket return value from scanner: (NUM NUM NUM ADD NUM MULTIPLY NUM ADD NUM EOF) or (NUM NUM NUM ERROR NUM MULTIPLY NUM ADD NUM EOF)
For Racket, you may use the parser-tools/lex library that comes with Racket.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
