From: owner-smallwiki(a)iam.unibe.ch
[mailto:owner-smallwiki@iam.unibe.ch]
On Behalf Of Lukas Renggli
I am trying to parse Smalltalk code inside a completely different
grammar, similar to what you did with the SmallWiki parser. My parser
stripped down to the problem is the following, the scanner is similar
to StScanner in the SmaCC examples:
Method : Selector Condition? Body { ... } ;
Selector : (<keyword> Pattern)+ { ... } ;
Pattern : <name> { ... } ;
Condition : "if:" "[" { parse smalltalk block } ;
Body : { parse smalltalk method body } ;
When giving input like
a: anA b: aB
if: [ ... ]
^self
I get
a: anA b: aB
if: [ Token not expected ->... ]
^self
Essentially, you want a LR(0) parser. If you override the #handleError:
method, you can simulate LR(0) behavior -- I've attached it below. If you
have multiple reductions for the same state, it will just pick one to
reduce. For example, if you have:
Run : A "A" | B "B" ;
A : "1" {Transcript show: 'a' ;cr; flush};
B : "1" {Transcript show: 'b'; cr; flush};
And you enter "1C" it may pick either A or B to reduce. However, if you have
valid string (1A or 1B), then it reduces properly.
John Brant
--------------------------
handleError: anInteger
| result |
1 to: self emptySymbolTokenId
do:
[:i |
result := self actionFor: i.
(result bitAnd: self actionMask) = self reduceAction
ifTrue: [^self reduce: (result bitShift:
-2)]].
super handleError: anInteger