Write a program that does the following: Tokens for lab 4 will be numerals, iden
ID: 3640238 • Letter: W
Question
Write a program that does the following:Tokens for lab 4 will be numerals, identifiers, special tokens, and white space tokens, where
a numeral is a string of one or more digits,
an identifier is a string of letters, digits, and underscores, beginning with a letter, and
the allowed special characters are ~ & ^ * + - ( ) [ ] : , < > =
a special token is a string of length 1, whose only member is an allowed special character
a white space token is a string of one or more white space characters (tab, space, line feed, or new line).
For Lab 4, implement the following algorithm or something functionally equivalent to it (i.e., that does the same thing):
input S: a stack of characters (reversed from original input)
initialize: stack(stack(char)) T = [], stack<char> P = []
while(true)
if S is empty, halt and return T
if the last character of S is the first character of some token then
set P to []
while can_push(top(S),P)
remove the last character from S and push it onto the ack of P
If P holds a valid token
push P onto the back of T
else
halt and print 'tokenizing error'
else
halt and print 'tokenizing error'
Explanation / Answer
if this is an assignment your professor will give you a zero for using someone else's code what specific problems do you have with your program.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.