Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
lfa:2024:lab04 [2024/10/29 09:13] cata_chiru [Your Task] |
lfa:2024:lab04 [2024/10/29 09:27] (current) cata_chiru |
||
---|---|---|---|
Line 152: | Line 152: | ||
self.components = arg | self.components = arg | ||
- | # TODO 3: Completati metodele __str__, gen, __len__ si eval_gen pentru clasa Union | + | # TODO 3: Completati metodele __str__, gen, __len__ si eval_gen pentru clasa Union |
+ | |||
+ | # Hint: Look at the str.join method to create (expr1|expr2|...) | ||
def __str__(self) -> str: | def __str__(self) -> str: | ||
pass | pass | ||
Line 193: | Line 195: | ||
def __init__(self, regex: Regex): | def __init__(self, regex: Regex): | ||
self.regex = regex | self.regex = regex | ||
+ | |||
+ | # To memorize the base words generated by the regex inside the star, we store them in a list | ||
self.base_words = [""] | self.base_words = [""] | ||
- | self.base_gen() | ||
self.words = [] | self.words = [] | ||
Line 201: | Line 204: | ||
pass | pass | ||
- | def base_gen(self) -> [str]: | ||
- | '''To memorize the base words generated by the regex inside the star, we store them in a list''' | ||
- | | ||
- | # Exemplu de cum comparam tipul unui Obiect cu o clasa | ||
- | if type(self.regex) == Star: | ||
- | # Implement Star.gen with a limiting threshold | ||
- | pass | ||
- | |||
- | # Implement Regex.gen for the rest | ||
- | pass | ||
- | |||
def gen(self, no_items = 10) -> [str]: | def gen(self, no_items = 10) -> [str]: | ||
pass | pass | ||
Line 244: | Line 236: | ||
last_expr = Concat(Star(Union(Symbol('a'), Symbol('b'))), Symbol('b'), Star(Symbol('c'))) | last_expr = Concat(Star(Union(Symbol('a'), Symbol('b'))), Symbol('b'), Star(Symbol('c'))) | ||
last_expr.eval_gen() | last_expr.eval_gen() | ||
- | </code> | + | </code> |
| | ||
The output should be similar to: | The output should be similar to: |