Skip to content
Rubens de Oliveira Moraes Filho edited this page Apr 30, 2021 · 5 revisions

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.

Simple Example

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);

For + IF Example

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:

  1. empty = new EmptyDSL();
  2. //boolean
  3. iBooleanDSL boolC = new BooleanDSL("HaveQtdUnitsHarversting(20)");
  4. //then
  5. CommandDSL c1 = new CommandDSL("attack(Worker,weakest)");
  6. CDSL cdslThen = new CDSL(c1);
  7. //else
  8. CommandDSL c2 = new CommandDSL("attack(Ranged,weakest)");
  9. CommandDSL c3 = new CommandDSL("attack(Light,weakest)");
  10. CDSL cdsl2 = new CDSL(c3);
  11. CDSL cdslElse = new CDSL(c2, cdsl2);
  12. //composing S2
  13. S2DSL instance = new S2DSL(new S5DSL(boolC), cdslThen, cdslElse);
  14. //setting up S4
  15. S4DSL s4 = new S4DSL(instance, new S4DSL(empty));
  16. S3DSL S3_instance = new S3DSL(s4);

For + Parameter '' Example

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);

Using BuilderDSLTreeSingleton

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>.

Clone this wiki locally