Skip to content

Composing a AST manually

Rubens de Oliveira Moraes Filho edited this page Apr 30, 2021 · 2 revisions

To create an AST without the method, as presented in How to create an AST, there are two ways:

Method 1: Creating by hand

line 1. EmptyDSL empty = new EmptyDSL();
line 2. CommandDSL c1 = new CommandDSL("harvest(1)");
line 3. CommandDSL c2 = new CommandDSL("train(Worker,50,EnemyDir)");
line 4. CommandDSL c3 = new CommandDSL("attack(Worker,closest)");
line 5. BooleanDSL b1 = new BooleanDSL("HaveUnitsToDistantToEnemy(Worker,3)");
line 6. CDSL C1 = new CDSL(c1);
line 7. CDSL C2 = new CDSL(c2);
line 8. CDSL C3 = new CDSL(c3);
line 9. S5DSL S5 = new S5DSL(b1);
line 10. S2DSL S2 = new S2DSL(S5, C3);
line 11. S1DSL S13 = new S1DSL(S2, new S1DSL(empty));
line 12. S1DSL S12 = new S1DSL(C2, S13);
line 13. iDSL root = new S1DSL(C1, S12);

Method 2: Using a translator

One of the collaborators, Tassiana, developed a class that converts a textual AST( produced by translate() method) to an iDSL. iDSL example = new TradutorDSL("build(Barrack,1,Up) train(Ranged,10,Right) attack(Ranged,closest) train(Worker,3,EnemyDir) for(u) (if(!HaveEnemiesinUnitsRange(Heavy,u)) then(moveaway(Ranged,u) harvest(2,u) moveToUnit(Worker,Enemy,lessHealthy,u) moveaway(Heavy,u))) if(!HaveQtdUnitsHarversting(3)) then(moveToUnit(Ranged,Enemy,strongest) moveToUnit(Ranged,Ally,strongest) attack(Worker,strongest) train(Heavy,1,Right)) else(build(Barrack,1,Up) moveToUnit(Heavy,Enemy,farthest))").getAST();

Clone this wiki locally