Hi,
I'm developing tools for generating various C source files from a simple DSL.
I've got the lexing/parsing/tree-creation part of it working to my
satisfaction, and am comfortable with my level of understanding (though I will
continue to work my way all the way through Terence's book). But I'm confused
about the best approach to generating one of the output files I need, which
should look like this:
toplevel name = {
{ // begin group1
{ // begin block1
item 1,
item 2
}, // end block1
{ // begin block2
item 1,
item 2
} // end block2
}, // end group1
{ // begin block3
item 1,
item 2,
item 3
}, // end block3
{ // begin group2
{ // begin block4
item 1,
item 2
}, // end block4
{ // begin block5
item 1,
item 2
} // end block5
} // end group2
};
The problem is putting the "," characters on all elements in the nested
structure except for the last one at that level, and I'm wondering what the
best approach to the problem is. It seems like I could pass a "last one"
parameter down to subrules when the item invoking the subrule is the last in
the list of a rule, and use that as a way to avoid printing the ",".
Alternatively, I get the feeling that this could be handled by the right
StringTemplate magic, but I haven't found the right StringTemplate tutorials to
get comfortable with this problem, which is obviously recursive, and where the
items in a list are not all of the same type. The toplevel structure can
contain groups or blocks, and groups can contain other groups:
group: 'group'^ ID '{'! (block | group)+ '}'! ;
block: 'block'^ ID '{'! (assign)+ '}'! ;
What would be the right way to get the output I'm looking for?
- Andy
________________________________
CONFIDENTIALITY NOTICE: This e-mail transmission, and any documents, files or
previous e-mail messages attached to it, may contain information that is
confidential and/or legally privileged. If you are not the intended recipient,
or a person responsible for delivering it to the intended recipient, please DO
NOT disclose the contents to another person, store or copy the information in
any medium, or use any of the information contained in or attached to this
transmission for any purpose. If you have received this transmission in error,
please immediately notify the sender by reply email or at
[email protected], and destroy the original transmission and its
attachments without reading or saving in any manner.
For further information about Plantronics - the Company, its products, brands,
partners, please visit our website www.plantronics.com.
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en.