negative matching using Smacc

Lukas Renggli renggli at gmail.com
Sun Dec 31 09:52:51 UTC 2006


> > You should be able to define a priority between rules.
>
> I don't know how besides ordering them. But does it really solve my
> problem, since the two rules still match (and the junk one possibly
> matches a longer input since it is much more generic) ?

Yes, rules defined first match first. As far as I experienced this is
only true for the parser and not the scanner, but I don't know the
details.

> In fact I'm getting an error while compiling the parser: "A block
> compiles more than 1K bytes of code"

This means that one of your scanner reg-exp is too complicated, so
that it cannot be compiled into one method. VisualWorks doesn't have
this problem, as their methods work up to a couple of GB.

To come back to your original problem, I think that the following code
should do what you request (not actually tried out):

Scanner:
<newline>	: \r \n | \n | \r ;
<any>	: [^\r\n]+ ;

Parser:
Start
	:
	| Line
	| Start <newline> Line
	| Start <newline> ;
	
Line
	: "abc" <any> { Transcript show: '--> '; show: '2' value; cr }
	| <any> { Transcript show: '1' value; cr } ;

-- 
Lukas Renggli
http://www.lukas-renggli.ch



More information about the Squeak-dev mailing list