compiler/PEGFsaDeterminizator.st
changeset 515 b5316ef15274
equal deleted inserted replaced
502:1e45d3c96ec5 515:b5316ef15274
       
     1 "{ Package: 'stx:goodies/petitparser/compiler' }"
       
     2 
       
     3 "{ NameSpace: Smalltalk }"
       
     4 
       
     5 PEGFsaAbstractDeterminizator subclass:#PEGFsaDeterminizator
       
     6 	instanceVariableNames:''
       
     7 	classVariableNames:''
       
     8 	poolDictionaries:''
       
     9 	category:'PetitCompiler-FSA'
       
    10 !
       
    11 
       
    12 !PEGFsaDeterminizator methodsFor:'checking'!
       
    13 
       
    14 checkPriorities
       
    15     self assert: ((fsa states select: [ :s | s hasPriority  ]) allSatisfy: [ :s | s priority == 0 ]).
       
    16     self assert: (fsa allTransitions allSatisfy: [ :s | s priority == 0 ]).
       
    17 ! !
       
    18 
       
    19 !PEGFsaDeterminizator methodsFor:'determinization'!
       
    20 
       
    21 determinize
       
    22     self checkPriorities.
       
    23     super determinize.	
       
    24 ! !
       
    25 
       
    26 !PEGFsaDeterminizator methodsFor:'joining'!
       
    27 
       
    28 joinInfo: info with: anotherInfo into: newInfo
       
    29     "nothing to do"
       
    30 !
       
    31 
       
    32 joinRetval: state with: anotherState into: newState
       
    33     "Different retvals cannot merge their info"
       
    34 
       
    35     state retvalsAndInfosDo: [:retval :info |
       
    36         retval isNil ifFalse: [ 
       
    37             newState addInfo: info for: retval.
       
    38         ]
       
    39     ].
       
    40 
       
    41     anotherState retvalsAndInfosDo: [:retval :info |
       
    42         retval isNil ifFalse: [ 
       
    43             self assert: (newState retvals includes: retval) not.
       
    44             newState addInfo: info for: retval.
       
    45         ]
       
    46     ].
       
    47 !
       
    48 
       
    49 joinState: state with: anotherState
       
    50     self assert: state hasZeroPriorityOnly.
       
    51     self assert: anotherState hasZeroPriorityOnly.
       
    52     
       
    53     ^ super joinState: state with: anotherState
       
    54 !
       
    55 
       
    56 joinTransitions: state with: anotherState into: newState
       
    57     newState transitions addAll: (state transitions collect: #copy).
       
    58     newState transitions addAll: (anotherState transitions collect: #copy).
       
    59     ^ self
       
    60 ! !
       
    61