t-gen-conflictstrategies.st

来自「編譯器的語法產生器」· ST 代码 · 共 60 行

ST
60
字号
Object subclass: #ConflictStrategy
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'T-gen-Conflict Strategies'!
ConflictStrategy comment:
'ConflictStrategy implements the action that a translator generator performs when it detects a conflict.

Subclasses must implement the following messages:
	resolving
		resolveReduceReduceFor:
		resolveShiftReduceFor:

'!


!ConflictStrategy methodsFor: 'resolving'!

resolveReduceReduceFor: aTerm atState: currState 
	self subclassResponsibility!

resolveShiftReduceFor: aTransitSymbol atState: currState 
	self subclassResponsibility! !

ConflictStrategy subclass: #ShiftingConflictStrategy
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'T-gen-Conflict Strategies'!
ShiftingConflictStrategy comment:
'ShiftingConflictStrategy resolves shift/reduce conflicts by always shifting, this handles most ambiguities correctly.'!


!ShiftingConflictStrategy methodsFor: 'resolving'!

resolveReduceReduceFor: aTerm atState: currState 
	^OrderedCollection with: currState!

resolveShiftReduceFor: aTransitSymbol atState: currState 
	currState reduceMap removeKey: aTransitSymbol.
	^OrderedCollection new.! !

ConflictStrategy subclass: #StandardConflictStrategy
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'T-gen-Conflict Strategies'!
StandardConflictStrategy comment:
'StandardConflictStrategy implements the standard conflict resolution present in the original T-Gen (i.e., none)'!


!StandardConflictStrategy methodsFor: 'resolving'!

resolveReduceReduceFor: aTerm atState: currState 
	^OrderedCollection with: currState!

resolveShiftReduceFor: aTransitSymbol atState: currState 
	^OrderedCollection with: currState! !

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?