Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Below is the first assignment and following is my source code, which is working fine. And the question I want to aks is about another
Below is the first assignment and following is my source code, which is working fine.
And the question I want to aks is about another assignment related to it. here you can see it below:
I am really thank you if you can help me out with the details. I am really confused right now! Oh and please don't just copy other answers here! I am grateful!
REGULAR EXPRESSION CHARACTER CHECKER This programming assignment is a user input validator. Acceptable input is zero or more characters from the alphabet of {a,b,+,,(),}. (Or the alphabet of your choice which includes the elementary regular expression operators of {+,,()}, The program will allow the user to enter multiple lines of "words" from the console, each word will be delimitec by a carriage return or a maximum of 1,000 characters. Blanks or tabs should be ignored. Following each word of input, the program will display the word along with an indication of whether the word consists of valid characters and which characters, if any, are invalid. The user will indicate the end of input by entering an empty word (a blank line). The following is an example run with the input in bold. Regular expression validator over the alphabet {a,b,+,,(), Enter regular expression: ab VALID: ab Enter regular expression: ab ( ba) VALID: ab(ba) * Enter regular expression: ab ( ba) x+ba ( bb INVALID: ab(ba)x+ba(bb Enter regular expression: ) &0#$b(bba)X+ba(bb INVALID: ) &a#$b(ba)X+ba(bb blank line> Program terminated. Design and implement your program for future extensions, with a minimal amount of unessential complexity. This will permit the addition of expression processing functionality in the future assignments. Submit the solution in a convenient package which includes properly documented source code and an executable, if appropriate. valid_chars = " [ab+)]" \# define the valid characters while True: input_string = input("Enter regular expression: ") input_string = input_string.replace (" "," " ") \# remove whitespaces input_string = input_string.replace("\t","") \# remove tabs if input_string ==" ": \# check for empty input print("Program terminated.") break match = re.search(valid_chars, input_string) \# check for valid characters if match: print("VALID: ", input_string) else: print("INVALID: ", input_string) REGULAR EXPRESSION RECOGNIZER This programming assignment builds on previous assignment which validated the symbols of the regular expression alphabet. Write a program to recognize a specific form of regular expressions. The regular expressions are over the alphabet {a,b,1,,(),}. Note that is the Kleene closure operator and ' I ' is the regular expression OR operator. The ' $ ' character is used to terminate an expression. Accept only those strings that can be generated by the following language grammar. Start > Expression \$ Expression > Expression | Term Expression > Term Term > Term Factor Term > Factor Factor > a Factor b Factor > Factor Factor > ( Expression) Your program should allow the user to enter multiple regular expressions, delimited by a carriage return. The program will classify each expression as either VALID or INVALID. For each input string, output its classification followed by a copy of the string. Be sure to output a reason if a given string is classified as invalid. Additional credit will be given for particularly intuitive/helpful interfaces. Sample Input ab ab(ba) ((ab)(aa)) b a(b a() Sample Output VALID:VALID:VALID:INVALID:INVALID:INVALID:abab(ba)((ab)(aa))ba(ba() Pseudo code for Recognizer Grammar (after removing left recursion S>TQ if(!T) return FALSE if(!Q) return FALSE if(end of input) return TRUE return FALSE ETQ if(!T) return FALSE if(!Q) return FALSE if(next_char is ' ') and not at end of input) return TRUE return FALSE TFR if(next_char is '('or " a ' or " b ') if(!F) return FALSE if(!R) return FALSE return TRUE return FALSE FaU or bU or (E)U if(next_char is '('or 'a' or ' b ') if(next_char is ' a ' or ' b ') get next_char if(!U) return FALSE return TRUE else if(next_char is '(') get next_char if(!E) return FALSE if(next_char is ')') get next_char else return FALSE if(!U) return FALSE return TRUE; return FALSE; Q>TQ or nil if(next_char is ' ') get next_char if(!T) return FALSE if(!Q) return FALSE return TRUE R F R or nil if(next_char is '(' or ' a ' or " b ') if(!F) return FALSE if(!R) return FALSE return TRUE U>U or nil if(next_char is 11 ) get next_char U return TRUEStep 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