About Smacc

Marcus Denker denker at iam.unibe.ch
Fri May 26 07:27:47 UTC 2006


On 26.05.2006, at 02:58, Andrew P. Black wrote:

> Let me try and re-ask this question.  (Maybe this is Sebastien's  
> problem, maybe not).  It's certainly mine ;-)
>
> I've downloaded SmaCC from Squeakmap. I've gone through the  
> calculator tutorial (very nice) and generated a scanner and parser  
> (two classes, CalculatorScanner and CalulatorParser).  There are  
> also nice examples StScanner and StParser.  I can run them in the  
> UI tool.  So far, so good.
>
> I am completely at a loss to know how to use the Scanner and the  
> Parser from other code.  I remember having the same problem with  
> TGen years ago, and eventually giving up.  The generated code has  
> no obvious entry point ...
>
> I tried STParser parseMethod: sourceString and got an immediate  
> walkback.  The answer is probably obvious when you know, but it is  
> decidedly NON-obvious when you don't.  Can someone help?  Better  
> still, can someone put this information in the documentation.
>


the SmaCCParser superclass provides the method #parseStream:startingAt:

First parameter is the stream to parse, second the starting state of  
the parser. SmaCC
generates accessors for the possible starting states automatically  
(see method category
'generate starting states')

For the SqueakParser (part of NewCompiler), this method was  
implemented to make it
easy to use from other code:

parseMethod: stringOrStream

	^ (self
		parseStream: stringOrStream readStream
		startingAt: self startingStateForMethod)
		source: stringOrStream contents

Thus,

  SqueakParser parseMethod: 'hello ^1'

will give you an RB AST.

For experiments, do not use the STParser. It's kind of broken *and*  
it just
generates a parse tree, which is not what's needed in most cases. The
SqueakParser (part of NewCompiler) can actually parse the whole image
*and* it directly generates an RB AST.

     Marcus





More information about the Squeak-dev mailing list