Question: Given the simple calculator, give an example of input code that produces exactly three errors from the scanner. The scanner encounters an error when reading


Given the simple calculator,
give an example of input code that produces exactly three errors from the scanner. The scanner encounters an error when reading an invalid token. When that happens, assume that the scanner skips everything until the next white space (\ ,\t, ). Your three invalid tokens should start with three different characters. Your input code will be a string over the alphabet {a,b,...,z,0,1,...,9,.,:,=,+,-,*,/,(,),\ ,\t, }. Explain in detail how the three errors are produced from the scanner.
. Example: simple calculator language ++ assign (Algol style; C has =') plus minus + - times * div Iparen ( rparen ) id - letter (letter | digit )* (except for read and write) number digit digit* | digit* ( . digit | digit . ) digit* comment /* ( non-* | * non-/ )* *+/ 177 (non-newline)* newline 16 skip any initial white space (spaces, tabs, and newlines) if cur_char E {'(',')','+','-','*'} return the corresponding single-character token if cur_char =':' read the next character if it is '=' then return assign else announce an error if cur_char = '/' peek at the next character if it is '*' or '/ read additional characters until "*/" or newline is seen, respectively jump back to top of code else return div if cur_char = . read the next character if it is a digit read any additional digits return number else announce an error if cur_char is a digit read any additional digits and at most one decimal point return number if cur_char is a letter read any additional letters and digits check to see whether the resulting string is read or write if so then return the corresponding token else return id else announce an error 17 . Example: simple calculator language ++ assign (Algol style; C has =') plus minus + - times * div Iparen ( rparen ) id - letter (letter | digit )* (except for read and write) number digit digit* | digit* ( . digit | digit . ) digit* comment /* ( non-* | * non-/ )* *+/ 177 (non-newline)* newline 16 skip any initial white space (spaces, tabs, and newlines) if cur_char E {'(',')','+','-','*'} return the corresponding single-character token if cur_char =':' read the next character if it is '=' then return assign else announce an error if cur_char = '/' peek at the next character if it is '*' or '/ read additional characters until "*/" or newline is seen, respectively jump back to top of code else return div if cur_char = . read the next character if it is a digit read any additional digits return number else announce an error if cur_char is a digit read any additional digits and at most one decimal point return number if cur_char is a letter read any additional letters and digits check to see whether the resulting string is read or write if so then return the corresponding token else return id else announce an error 17
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
