compiler/PPCompiledParser.st
changeset 438 20598d7ce9fa
parent 431 dd353f15b0ef
child 452 9f4558b3be66
--- a/compiler/PPCompiledParser.st	Tue Apr 21 17:20:11 2015 +0100
+++ b/compiler/PPCompiledParser.st	Thu Apr 30 23:43:14 2015 +0200
@@ -3,13 +3,14 @@
 "{ NameSpace: Smalltalk }"
 
 PPParser subclass:#PPCompiledParser
-	instanceVariableNames:'startSymbol context failure error'
+	instanceVariableNames:'startSymbol context failure error currentTokenValue
+		currentTokenType'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'PetitCompiler-Core'
 !
 
-PPCompiledParser class instanceVariableNames:'parsers constants referringParser'
+PPCompiledParser class instanceVariableNames:'parsers constants referringParser startSymbol'
 
 "
  No other class instance variables are inherited by this class.
@@ -19,18 +20,12 @@
 !PPCompiledParser class methodsFor:'as yet unclassified'!
 
 addConstant: value as: id
-	self constants at: id ifPresent: [:ignored | 
+	self constants at: id ifPresent: [ 
 		((self constants at: id) = value) ifFalse: [self error: 'ooups']].	
 	
 	self constants at: id put: value.
 !
 
-addParser: aPPParser as: id
-	
-	"(self parsers includesKey: id) ifTrue: [self error: 'Ooups' ]."
-	self parsers at: id put: aPPParser.
-!
-
 constants
 	constants ifNil: [ constants := IdentityDictionary new ].
 	^ constants
@@ -40,17 +35,20 @@
 	^ self new parse: input
 !
 
-parsers
-	parsers ifNil: [ parsers := IdentityDictionary new ].
-	^ parsers
-!
-
 referringParser
-	^ referringParser 
+	^ referringParser ifNil: [ ^ PPSentinel new ]
 !
 
 referringParser: aPPParser
 	referringParser := aPPParser
+!
+
+startSymbol
+	^ startSymbol ifNil: [ ^ #start ]
+!
+
+startSymbol: symbol
+	startSymbol := symbol
 ! !
 
 !PPCompiledParser methodsFor:'as yet unclassified'!
@@ -91,10 +89,9 @@
 		self instVarNamed: key put: value.
 	].
 
-	startSymbol := #start.
+	startSymbol := self class startSymbol.
 
 	
-
 !
 
 isCompiled
@@ -116,10 +113,6 @@
 
 startSymbol: aSymbol
 	startSymbol := aSymbol
-!
-
-updateContext: aPPContext
-	self class referringParser allParsersDo: [ :p | p updateContext: aPPContext ].
 ! !
 
 !PPCompiledParser methodsFor:'parsing'!
@@ -141,3 +134,30 @@
 	^ retval
 ! !
 
+!PPCompiledParser methodsFor:'tokenizing'!
+
+consume: tokenType
+	(currentTokenType = tokenType) ifTrue: [ 
+		| retval |
+		retval := currentTokenValue.
+		self nextToken.
+		^ retval
+	] ifFalse: [ 
+		self error: 'expected: ', tokenType storeString, ' got ', currentTokenType storeString.
+	]
+!
+
+currentTokenType
+	currentTokenType isNil ifTrue: [ self nextToken ].
+	^ currentTokenType
+!
+
+currentTokenValue
+	currentTokenType isNil ifTrue: [ self nextToken ].
+	^ currentTokenType
+!
+
+nextToken
+	self shouldBeImplemented
+! !
+