Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
lfa:2024:lab05 [2024/11/03 02:06]
stefan.sterea
lfa:2024:lab05 [2024/11/04 11:58] (current)
stefan.sterea
Line 29: Line 29:
   * ''​initState():​ State'' ​ returns the initial state of the NFA   * ''​initState():​ State'' ​ returns the initial state of the NFA
   * ''​endState():​ State'' ​  ​returns a distinguished state of the NFA   * ''​endState():​ State'' ​  ​returns a distinguished state of the NFA
-  * ''​toggleEpsilon():​ NFA'' ​ returns the same NFA, but if ''​initState()'' ​is a final state, it makes it non-final ​and vice-versa +  ​* ''​generatesEpsilon():​ bool''​ returns whether or not the initial state is a final state 
-  * ''​merge(nfa2:​ NFA): NFA'' ​ returns an NFA constructed from this one by replacing all transitions to ''​endState()'' ​with transitions to ''​nfa2.initState()''​, deleting ​the  ​current ​''​endState()'' ​and replacing ​it with ''nfa2.endState()''​ +  ​* ''​toggleEpsilon(final: bool): NFA'' ​ returns the same NFA, but makes ''​initState()''​ final or non-final ​based on the parameter ''​final''​ 
-  * ''​adjoin(nfa2:​ NFA): NFA''​ returns an NFA constructed from this one by replacing all transitions from ''​nfa2.initState()''​ with transitions from ''​initState()'' ​and all transitions to ''​nfa2.endState()'' ​with transitions to ''​endState()'',​ then deleting ''​nfa2.initState()''​ and ''​nfa2.endState()''​; ''​initState()'' ​and ''​endState()''​ remain ​the same+  * ''​merge(nfa2:​ NFA): NFA'' ​ returns an NFA constructed from this one and ''​nfa2''​ where ''​endState()'' ​and ''​initState()'' ​are merged together into a single state; ​the new end state will be ''​nfa2.endState()'' ​unless ​it's been merged, in which case it will be the new merged state
 +  * ''​adjoin(nfa2:​ NFA): NFA''​ returns an NFA constructed from this one and ''​nfa2'' ​by merging the ''​initState()''​s together ​and the ''​endState()''​s together into 2 new states that will be the init state and end state of the new NFA.
  
-Using only these operations to create NFAs from other NFAs, try to find a recursive algorithm to convert a Regular Expression to an NFA without epsilon-transitions. Discuss base cases, construction steps and justify them. It may be useful to consider some invariants of the algorithm.+Using only these operations to create NFAs from other NFAs, try to find a recursive algorithm to convert a Regular Expression to an NFA without epsilon-transitions. Discuss base cases, construction steps and justify them. It may be useful to consider some invariants of the algorithm ​(one such invariant is, of course, the lack of epsilon-transitions,​ which explains the names of the ''​generatesEpsilon''​ and ''​toggleEpsilon''​ methods).