changeset 524 | f6f68d32de73 |
parent 515 | b5316ef15274 |
child 525 | 751532c8f3db |
515:b5316ef15274 | 524:f6f68d32de73 |
---|---|
62 startState |
62 startState |
63 self assert: (states includes: startState). |
63 self assert: (states includes: startState). |
64 ^ startState |
64 ^ startState |
65 ! |
65 ! |
66 |
66 |
67 stateNamed: name |
67 stateNamed: stateName |
68 ^ states detect: [ :e | e name = name ] |
68 ^ states detect: [ :e | e name = stateName ] |
69 ! |
69 ! |
70 |
70 |
71 states |
71 states |
72 ^ states |
72 ^ states |
73 ! |
73 ! |
201 ]) ifTrue: [ ^ true ]. |
201 ]) ifTrue: [ ^ true ]. |
202 |
202 |
203 ^ false |
203 ^ false |
204 ! |
204 ! |
205 |
205 |
206 hasNoRetvals |
|
207 ^ self finalStates isEmpty |
|
208 ! |
|
209 |
|
206 is: state furtherThan: anotherState |
210 is: state furtherThan: anotherState |
207 |
211 |
208 ^ (distances at: state) >= (distances at: anotherState) |
212 ^ (distances at: state) >= (distances at: anotherState) |
209 ! |
213 ! |
210 |
214 |
292 ! |
296 ! |
293 |
297 |
294 topologicalOrder |
298 topologicalOrder |
295 | collection | |
299 | collection | |
296 collection := OrderedCollection new. |
300 collection := OrderedCollection new. |
301 |
|
297 self statesReachableFrom: startState openSet: collection. |
302 self statesReachableFrom: startState openSet: collection. |
298 ^ collection |
303 ^ collection |
299 ! ! |
304 ! ! |
300 |
305 |
301 !PEGFsa methodsFor:'comparing'! |
306 !PEGFsa methodsFor:'comparing'! |
319 ]. |
324 ]. |
320 ^ true |
325 ^ true |
321 ! |
326 ! |
322 |
327 |
323 hash |
328 hash |
324 ^ states hash bitXor: (startState bitXor: name) |
329 ^ states hash bitXor: (startState hash bitXor: name hash) |
325 ! |
330 ! |
326 |
331 |
327 isIsomorphicTo: anotherFsa |
332 isIsomorphicTo: anotherFsa |
328 | topologicalOrder anotherTopologicalOrder | |
333 | topologicalOrder anotherTopologicalOrder | |
329 |
334 |
358 states do: [ :s | |
363 states do: [ :s | |
359 map at: s put: s copy. |
364 map at: s put: s copy. |
360 ]. |
365 ]. |
361 |
366 |
362 states := map values asIdentitySet. |
367 states := map values asIdentitySet. |
363 startState := map at: startState. |
368 startState isNil ifFalse: [ |
369 startState := map at: startState. |
|
370 ]. |
|
364 |
371 |
365 states do: [ :s | |
372 states do: [ :s | |
366 s transitions do: [:t | |
373 s transitions do: [:t | |
367 t destination: (map at: t destination) |
374 t destination: (map at: t destination) |
368 ] |
375 ] |
369 ] |
376 ] |
370 ! ! |
377 ! ! |
371 |
378 |
372 !PEGFsa methodsFor:'gt'! |
|
373 |
|
374 gtGraphViewIn: composite |
|
375 <gtInspectorPresentationOrder: 0> |
|
376 composite roassal2 |
|
377 title: 'Graph'; |
|
378 initializeView: [ RTMondrian new ]; |
|
379 painting: [ :view | |
|
380 self viewGraphOn: view. |
|
381 ]. |
|
382 ! |
|
383 |
|
384 gtStringViewIn: composite |
|
385 <gtInspectorPresentationOrder: 40> |
|
386 |
|
387 composite text |
|
388 title: 'Textual Representation'; |
|
389 display: [ :fsa | fsa asString ] |
|
390 ! |
|
391 |
|
392 viewGraphOn: b |
|
393 b shape circle size: 50. |
|
394 b shape color: Color gray muchLighter muchLighter. |
|
395 b shape withText: #gtName. |
|
396 b nodes: (self nonFinalStates). |
|
397 |
|
398 b shape circle size: 50. |
|
399 b shape color: Color gray muchLighter. |
|
400 b shape withText: #gtName. |
|
401 b nodes: (self finalStates). |
|
402 |
|
403 b shape arrowedLine. |
|
404 b edges |
|
405 connectToAll: [ :state | |
|
406 state transitions select: [:t | (self isBackTransition:t) not] |
|
407 thenCollect: #destination ] |
|
408 labelled: [ :t | (self transitionFrom: t key to: t value) gtName ]. |
|
409 |
|
410 b shape arrowedLine. |
|
411 b shape color: Color red. |
|
412 b edges |
|
413 connectToAll: [ :state | |
|
414 state transitions select: [:t | (self isBackTransition: t) ] |
|
415 thenCollect: #destination ] |
|
416 labelled: [ :t | (self transitionFrom: t key to: t value) gtName ]. |
|
417 |
|
418 |
|
419 b layout horizontalTree . |
|
420 b layout layout horizontalGap: 30. |
|
421 |
|
422 ^ b |
|
423 ! ! |
|
424 |
|
425 !PEGFsa methodsFor:'ids'! |
379 !PEGFsa methodsFor:'ids'! |
426 |
380 |
427 defaultName |
381 defaultName |
428 ^ #fsa |
382 ^ #fsa |
429 ! |
383 ! |
431 hasName |
385 hasName |
432 ^ name isNil not |
386 ^ name isNil not |
433 ! |
387 ! |
434 |
388 |
435 prefix |
389 prefix |
436 ^ nil |
390 ^ 'scan' |
437 ! |
391 ! |
438 |
392 |
439 suffix |
393 suffix |
440 ^ nil |
394 ^ nil |
441 ! ! |
395 ! ! |
494 yourself. |
448 yourself. |
495 |
449 |
496 fromState addTransition: transition |
450 fromState addTransition: transition |
497 ! |
451 ! |
498 |
452 |
499 addTransitionFrom: fromState to: toState onPredicate: block |
|
500 self addTransitionFrom: fromState to: toState onPredicate: block priority: 0 |
|
501 ! |
|
502 |
|
503 addTransitionFrom: fromState to: toState onPredicate: block priority: priority |
453 addTransitionFrom: fromState to: toState onPredicate: block priority: priority |
504 | transition | |
454 | transition | |
505 transition := PEGFsaPredicateTransition new |
455 transition := PEGFsaPredicateTransition new |
506 predicate: block; |
456 predicate: block; |
507 destination: toState; |
457 destination: toState; |
556 ] |
506 ] |
557 ! |
507 ! |
558 |
508 |
559 minimize |
509 minimize |
560 ^ PEGFsaMinimizator new minimize: self |
510 ^ PEGFsaMinimizator new minimize: self |
511 ! |
|
512 |
|
513 removeFinals |
|
514 self finalStates do: [ :s | |
|
515 s final: false |
|
516 ] |
|
561 ! |
517 ! |
562 |
518 |
563 removePriorities |
519 removePriorities |
564 self states select: [ :s| s hasPriority ] thenDo: [ :s | |
520 self states select: [ :s| s hasPriority ] thenDo: [ :s | |
565 s priority: 0 |
521 s priority: 0 |
773 ^ true |
729 ^ true |
774 ! |
730 ! |
775 |
731 |
776 checkConsistency |
732 checkConsistency |
777 self assert: (states includes: startState). |
733 self assert: (states includes: startState). |
734 |
|
778 states do: [ :s | s transitions do: [ :t | |
735 states do: [ :s | s transitions do: [ :t | |
779 self assert: (states includes: t destination). |
736 self assert: (states includes: t destination). |
780 ] ]. |
737 ] ]. |
781 ^ true |
738 ^ true |
782 ! |
739 ! |