Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
lfa:lab02-dfa [2021/10/07 10:44] pdmatei |
lfa:lab02-dfa [2021/10/13 16:13] (current) ioana.georgescu [Classes in Python] |
||
---|---|---|---|
Line 10: | Line 10: | ||
class Example: | class Example: | ||
# the class constructor. | # the class constructor. | ||
- | def __init___(self,param1,param2): | + | def __init__(self,param1,param2): |
# the keyword self is similar to this from Java | # the keyword self is similar to this from Java | ||
# it is the only legal mode of initialising and referring class member variables | # it is the only legal mode of initialising and referring class member variables | ||
Line 62: | Line 62: | ||
where: | where: | ||
- | - the initial state is given on the first line of the input | + | * the initial state is given on the first line of the input |
- | - each of the subsequent lines encode transitions (states are integers) | + | * each of the subsequent lines encode transitions (states are integers) |
- | - the last line encodes the set of final states. | + | * the last line encodes the set of final states. |
Example: | Example: | ||
Line 105: | Line 105: | ||
</code> | </code> | ||
- | ---- | ||
- | |||
- | ** How to choose between lists and sets during the implementation?** | ||
- | * Do you need to make sure elements are unique? (go for sets) | ||
- | * Do you need to iterate a lot over elements, and the collection size is not really big (go for lists) | ||
- | |||
- | ---- | ||
<blockquote>** How to choose between lists and sets during the implementation?** | <blockquote>** How to choose between lists and sets during the implementation?** | ||
* Do you need to make sure elements are unique? (go for sets) | * Do you need to make sure elements are unique? (go for sets) | ||
Line 122: | Line 115: | ||
* the set of final states | * the set of final states | ||
- | **2.2.2.** Define a function which takes a string of the following form showed below, and returns a DFA: | + | |
+ | ---- | ||
+ | |||
+ | **2.2.2.** Define a function which takes a string of the following form showed below, and returns a DFA **with states as integers**: | ||
<code> | <code> | ||
<initial_state> | <initial_state> | ||
Line 132: | Line 128: | ||
where: | where: | ||
- | - the initial state is given on the first line of the input | + | * the initial state is given on the first line of the input |
- | - each of the subsequent lines encode transitions (states are integers) | + | * each of the subsequent lines encode transitions (states are integers) |
- | - the last line encodes the set of final states. | + | * the last line encodes the set of final states. |
Example: | Example: | ||
Line 144: | Line 140: | ||
1 2 | 1 2 | ||
</code> | </code> | ||
+ | |||
+ | **Hint:** Use ''splitBy'' from PP. | ||
+ | ---- | ||
+ | |||
**2.2.3.** Enroll the DFA type in class Show. | **2.2.3.** Enroll the DFA type in class Show. | ||
Line 149: | Line 149: | ||
**2.2.4.** Implement function which takes a DFA and a **configuration** (pair of state and rest of word) and returns the next configuration. | **2.2.4.** Implement function which takes a DFA and a **configuration** (pair of state and rest of word) and returns the next configuration. | ||
- | **2.2.5.** Implement a function which verifies if a word is **accepted** by a Dfa. | + | **2.2.5.** Implement a function which verifies if a word is **accepted** by a Dfa. What kind of general list-operation best matches the accepting process? |