Question: sample input should have a $ at the end of each statement to recognize that that is the end of the statement and the next

 sample input should have a $ at the end of each

statement to recognize that that is the end of the statement and

sample input should have a $ at the end of each statement to recognize that that is the end of the statement and the next is a new one

here is the code of the first one that this builds off of, it is written in python

import re

valid_chars = "[ab*|()]"

print("Regular expression validator over the alphabet {a, b, |, *, (, )}")

while True: expression = input("Enter regular expression: ")

if expression == "": break

# remove all valid characters from the expression using re.sub() invalid_chars = re.sub(valid_chars, "", expression)

if invalid_chars == "": print("VALID:", expression)

else: print("INVALID:", expression) print("Program terminated.")

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. 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 VATTD: ab VALID: ab(ba) VALID: (ab)(aa)) INVALID: * b INVALID: a(b INVALID: a() Pseudo code for Recognizer Grammar (after removing left recursion) STQ if(!T) return FALSE if(!Q) return FALSE if(end of input) return TRUE return FALSE ETQ if(IT) 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(IF) 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; QTQ or nil if(next_char is 'I') get next_char if(!T) return FALSE if(!Q) return FALSE return TRUE RF R or nil if(next_char is '(' or ' a ' or ' b ') if(!F) return FALSE if(!R) return FALSE return TRUE UU or nil if(next_char is 1 ') get next_char U return TRUE

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!