-
Notifications
You must be signed in to change notification settings - Fork 133
Loop Command
The framework provides a loop command represented by the instruction for. Following the DSL (see DSL) we can see that to compose the for structure (S3) we need an S4.
To compose, in code, an AST that represents the script for(u) (build(Barrack,50,Down)), we have to compose the following:
line 1. iCommandDSL c1 = new CommandDSL("build(Barrack,50,Down)");
line 2. CDSL C1 = new CDSL(c1);
line 3. S4DSL s4emp = new S4DSL(C1, new S4DSL(empty));
line 4. S3DSL instance = new S3DSL(s4emp);
To compose, in code, an AST that represents the script
for(u) ( if(HaveQtdUnitsHarversting(20)) (attack(Worker,weakest)) (attack(Ranged,weakest) attack(Light,weakest))),
we have to compose the following:
empty = new EmptyDSL();//booleaniBooleanDSL boolC = new BooleanDSL("HaveQtdUnitsHarversting(20)");//thenCommandDSL c1 = new CommandDSL("attack(Worker,weakest)");CDSL cdslThen = new CDSL(c1);//elseCommandDSL c2 = new CommandDSL("attack(Ranged,weakest)");CommandDSL c3 = new CommandDSL("attack(Light,weakest)");CDSL cdsl2 = new CDSL(c3);CDSL cdslElse = new CDSL(c2, cdsl2);//composing S2S2DSL instance = new S2DSL(new S5DSL(boolC), cdslThen, cdslElse);//setting up S4S4DSL s4 = new S4DSL(instance, new S4DSL(empty));S3DSL S3_instance = new S3DSL(s4);
To compose, in code, an AST that represents the script for(u) (build(Barrack,50,Down,u)), we have to compose the following:
line 1. iCommandDSL c1 = new CommandDSL("build(Barrack,50,Down,u)");
line 2. CDSL C1 = new CDSL(c1);
line 3. S4DSL s4emp = new S4DSL(C1, new S4DSL(empty));
line 4. S3DSL instance = new S3DSL(s4emp);
Class BuilderDSLTreeSingleton provides a method to get the structure For (S4DSL) in a simple way:
BuilderDSLTreeSingleton.getInstance().buildS4Grammar(<include unit>);
BuilderDSLTreeSingleton.getInstance().buildS4RandomlyGrammar(<include unit>);
BuilderDSLTreeSingleton.getInstance().buildS4WithCGrammar(<include unit>);
BuilderDSLTreeSingleton.getInstance().buildS4WithS2Grammar(<include unit>);
-- Parameter <include unit> indicates that the commands that are part of the for, needs or not, to receives the parameter <unit>.