[antlr-interest] Beginner needing help with rewrite rules

Yves Weißig weissig at rbg.informatik.tu-darmstadt.de
Wed Oct 19 02:52:08 PDT 2011


Hi!

Thanks for the answers!
That was a good rough guess Jim... I finally came up with this:

group		:	(OPEN
				children+=space*
				(
				children+=group children+=space* |
				children+=plaintext children+=space* |
				children+=command children+=space* |
				children+=escape children+=space*
				)+
			CLOSE) -> ^(GROUP $children*) ;

Works like a charme, subgroups are created automatically... I had to add
everything to "children" because I need to remain the order of the elements.

Thanks again!

Yves

Am 18.10.2011 23:11, schrieb Jim Idle:
> Looks like you need:
> 
> group		:	(OPEN
> 				space*
> 				(
> 				sg=group space* |
> 				p=plaintext space* |
> 				((c1=command)+ space) |
> 				(e=escape) space*
> 				)+
> 				((c2=command)+)?
> 			CLOSE) -> ^(GROUP ^(GROUP $sg)* $p+ $c1+ $e+ $c2+)
> 
> At a rough guess.
> 
> 
> Jim
> 
> 
>> -----Original Message-----
>> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
>> bounces at antlr.org] On Behalf Of Yves Weißig
>> Sent: Tuesday, October 18, 2011 12:11 AM
>> To: antlr-interest at antlr.org
>> Subject: [antlr-interest] Beginner needing help with rewrite rules
>>
>> Hi ANTLR list,
>> I'm using ANTLR within my master's thesis in order to parse the RTF
>> file format. Everything is fine so far, I can parse simple RTF
>> documents. The next step is to generate an AST. Here is where the
>> problems start, it seems as if I have an error in one of my rewrite-
>> rules. If you look at the grammar, what I want to do, is nest the
>> groups. This means, a "group" is child of a "group" if the subrule
>> group in the rule group is
>> called: sg=group space* -> ^(GROUP $sg+). Maybe you try the grammar
>> using a simple RTF snippet, e.g.
>>   {\pard\fs32\b NOTES\par}
>>   {\pard\fs26 Recently I skimmed {\i Structure and Interpretation of
>>    Computer Programs}, by Sussman and Abelson, and I think there should
>>    have been more pictures.
>>   \line I like pictures.  Is that so na\'efve?
>>   \par}
>> from: http://search.cpan.org/~sburke/RTF-Writer/lib/RTF/Cookbook.pod
>> Do you have any comments or ideas what I'm doing wrong?
>> Best regards, Yves
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address


More information about the antlr-interest mailing list