Question: ( Please make all files, and make sure the code compiles and produces teh given output. ) - - - - - - Implement the
Please make all files, and make sure the code compiles and produces teh given output.Implement the REDFA algorithm using the PLY package. The contextfree grammar for the language of regular expressions is shown below.
re : re PLUS term
re : term
term : term factor
term : factor
factor : factor STAR
factor : niggle
niggle : LETTER
niggle : LPAREN re RPAREN
Since the expression tree nodes have various attributes associated with them, such as nullable, firstpos, lastpos, etc., this problem can benefit from building a traditional tree data structure with nodes and pointers to children nodes. I am providing a skeletal file, RENode.py below, which you should use to construct the tree data structure in REParser.py and also use in the main program to compute the various functions such as nullable, firstpos, and lastpos. For this assignment, we will assume that there are no epsi or phi regular expressions.
class RENode:
def initself:
self.operator # 'leaf'
self.symbol # only for leaf nodes
self.position # only for leaf nodes
self.lchild None
self.rchild None # only for and
self.nullable False
self.firstpos set
self.lastpos set
# Your methods go here
def tostringselfn:
result n
if self.operator 'leaf':
result 'SYMBOL: self.symbol
result NULLABLEstrselfnullable
result FIRSTPOSstrselffirstpos
result LASTPOSstrselflastpos
elif self.operator :
result 'OPERATOR: STAR'
result NULLABLEstrselfnullable
result FIRSTPOSstrselffirstpos
result LASTPOSstrselflastpos
result self.lchild.tostringn
elif self.operator :
result 'OPERATOR: DOT'
result NULLABLEstrselfnullable
result FIRSTPOSstrselffirstpos
result LASTPOSstrselflastpos
result self.lchild.tostringn
result self.rchild.tostringn
elif self.operator :
result 'OPERATOR: PLUS'
result NULLABLEstrselfnullable
result FIRSTPOSstrselffirstpos
result LASTPOSstrselflastpos
result self.lchild.tostringn
result self.rchild.tostringn
else:
result 'SOMETHING WENT WRONG'
return result
def strself:
return self.tostring
Submit REpy RELexer.py REParser.py RENode.py and DFA.py A sample run is shown below:
$ python REDFA.py aabbaaa
start
final
:a:
:b:
:a:
:b:EMPTY
:a:EMPTY
:b:
:a:
:b:
:a:
:b:EMPTY
EMPTY:a:EMPTY
EMPTY:b:EMPTY
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
