[antlr-interest] Problem with Self 4.1 grammar

Carter Cheng carter_cheng at yahoo.com
Mon Mar 24 05:14:21 PDT 2008


Thanks both for the advice I was actually looking for something closer to Jim's solution in this case and that's what I ended up implementing. It seems to solve the problem I was having and with a bit more work I seem to be cleanly parsing most of the files that make up Self 4.1 World in the Self4Linux package.

I have one question about backtracking though which hopefully can fix the last remaining problem which I have at the moment sort of hacked around by disabling an operator. The block-

[ | :i | fileDescriptor = (selectVec at: i) ifTrue: [^true]]

doesnt parse properly because in Self | is both a divider and potentially an operator. The closely related code however does parse- 

[ | | fileDescriptor = (selectVec at: i) ifTrue: [^true]]

If I remove | from the operator list the code parses properly. I am curious why ANTLR can't backtrack this. Is there a way to force the parser to prefer the non-operator interpretation?

The relevant parse rules are as follows-

block
	: '[' code? ']' -> ^(BLOCK code?) 
	| '[' '|' slotList? '|' code? ']' -> ^(BLOCK slotList? code?) 
	;

slotList
	: ( unannotatedSlotList | annotatedSlotList )*
	;

unannotatedSlotList
	: slot ('.' slot)* '.'? -> slot+
	;

code
	: '^'? expression ('.' '^'? expression )* '.'? 
	;

slot
	: argSlot 
	| dataSlot 
	| binarySlot
	| keywordSlot
	;

argSlot
	: ArgumentName -> ^(SLOT_ARG ArgumentName)
	;
binarySlot
	: operator Identifier? '=' regularObject -> ^(SLOT_BINARY operator Identifier? regularObject) 
	;



      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ


More information about the antlr-interest mailing list