Order of input and Duplicates

Nov 17, 2011 at 2:34 PM
Edited Nov 17, 2011 at 2:35 PM

Hi, I have a question regarding my project where i'm using Irony.

What i currently have is the following 

NonTerminal addblockcmd = new NonTerminal("addblock");



addblockcmd.Rule = ToTerm("addblock") + nameoptions + getpos + getrot + getsize + getdsize + getcog + getdmass + getmass + ";"

I was wondering whether there is a way (besides writing a rule for every single option) to be able to accept input  so that the order after nameoptions, is independant but also can only occur once.

so to make it more clear:


addblock block1 pos 1 rot 2 size 3, dsize 4 cog 5 dmass 6 mass 7;  (this is acceptabel according to rule)


addblock block1  rot 2 pos 1 size 3, dsize 4 cog 5 dmass 6 mass 7; (this is NOT acceptabel according to rule, because pos should be before rot)

However, if i change the rule so that all to options (getpos, getrot, getsize, getdsize ......) is in a makestarrule it would create the problem of people being able to put getpos twice or even more times for one instance of addblock.

is there a way to define the rule so that all the options after nameoptions can be given without a specific order, but also can be entered only once for every command (like getpos)????????











Nov 17, 2011 at 3:24 PM

Just a thought, but do you need to do the check for "only once" at parse time?  Or can that be done post-parsing?  My gut feel is that you would make life a lot easier if you can do the checking later.  As you say, I think that even if you could express this in a simple way, I dont think the parser would have an easy time with it.

The other thing with a star rule is that it would also accept zero input (ie missing terms).  Would that also be an issue?

Nov 17, 2011 at 5:02 PM

Agree with wmh, this is something that should be checked in post-parse analysis. Syntactic rules are not fit to express no-repeat rules, this is semantics, and better implemented by post-parse methods. Just define the statement as a list of options using MakeStar/PlusRule method, and then use iterator/visitor after parsing is complete.


Nov 18, 2011 at 6:53 AM

Thanks for the info guys, that's what i thought, but i just needed to make sure :). Thanks for creating and supporting this package guys, it's awesome. I tried to user ANTLR before finding Irony, and irony is alot better (especially when working with .NET Framework).