Discussion:
Redundant Kleenes
(too old to reply)
t***@engmail.uwaterloo.ca
2004-06-03 17:09:57 UTC
Permalink
Can we assume for problem 2 of assignment 2 that no adjacent (and hence
redundant) *s will occur in the given regex? i.e. Can we assume that regexes
of the form "a**" and the like will not be given?

If not, should we create a redundant Kleene object for every redundant *, or
should we just create one? i.e. Should "a**" become "new Kleene(new Kleene(new
Symbol("a")))", or just "new Kleene(new Symbol("a"))"?

----------------------------------------
This mail sent through www.mywaterloo.ca
Troy Mark Gonsalves
2004-06-03 19:03:31 UTC
Permalink
You shouldn't have to consider this as a special case...if you do then you
might have some other bug in your algorithm....make sure to test
thoroughly.

Whether a** is a valid regular expression is debatable...some tools will
return an error if you try to use it. Our definition of regular expression
from class would allow it though.

My code would produce nested Kleene objects, which is the safest thing to
do.

But I'll say again that your code _should_ naturally handle this case...if
it doesn't then you probably have a bug.

Try handling (a*) and (a)* which are both valid... ((a)) is also valid.
Post by t***@engmail.uwaterloo.ca
Can we assume for problem 2 of assignment 2 that no adjacent (and hence
redundant) *s will occur in the given regex? i.e. Can we assume that regexes
of the form "a**" and the like will not be given?
If not, should we create a redundant Kleene object for every redundant *, or
should we just create one? i.e. Should "a**" become "new Kleene(new Kleene(new
Symbol("a")))", or just "new Kleene(new Symbol("a"))"?
----------------------------------------
This mail sent through www.mywaterloo.ca
Loading...