Skip to content

Commit 1b153cc

Browse files
Macro pieces of tree construction
Added some classes which will be used to construct the objects used for simulation.
1 parent 60a4ac0 commit 1b153cc

File tree

4 files changed

+189
-1
lines changed

4 files changed

+189
-1
lines changed

parser/Semantic_Actions.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package parser;
2+
3+
/**
4+
<b>
5+
Purpose: Semantic actions to be stored and used by {@link Tree_Assembler}}<br>
6+
Programmer: Gabriel Toban Harris<br>
7+
Date: 2021-08-04
8+
</b>
9+
*/
10+
11+
public enum Semantic_Actions
12+
{
13+
//TODO: finish
14+
START
15+
}

parser/Simulatation.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package parser;
2+
3+
import java.util.ArrayList;
4+
import java.util.HashMap;
5+
import structure.Scenario;
6+
7+
/**
8+
<b>
9+
Purpose: final step which performs the actual simulation.<br>
10+
Programmer: Gabriel Toban Harris<br>
11+
Date: 2021-08-04
12+
</b>
13+
*/
14+
15+
public class Simulatation<T, U>
16+
{
17+
/**
18+
* Main deck which the hand will be generated from.
19+
*/
20+
private final ArrayList<T> DECK;
21+
22+
/**
23+
* Stores the generated scenarios.
24+
*/
25+
private final HashMap<String, Scenario<U>> FOREST;
26+
27+
/**
28+
* Constructor, note creates a shallow copy.
29+
*
30+
* @param DECK which hands will be created from
31+
* @param FOREST the {@link Scenario} objects which will be tested.
32+
*/
33+
public Simulatation(final ArrayList<T> DECK, final HashMap<String, Scenario<U>> FOREST)
34+
{
35+
//shallow copy do to intended internal use.
36+
this.DECK = DECK;
37+
this.FOREST = FOREST;
38+
}
39+
40+
/**
41+
* Performs simulation.
42+
*
43+
* @param HAND_SIZE of the hand which will be used in the simulation
44+
* @param TEST_HAND_COUNT number of times to run simulation
45+
* @return the result of the simulation
46+
*/
47+
public String simulate(final int HAND_SIZE, final int TEST_HAND_COUNT)
48+
{
49+
//TODO: finish
50+
throw new UnsupportedOperationException("Not finished.");
51+
}
52+
}

parser/Token.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
<b>
5-
Purpose: Types of Tokens to be created by Lexical Analyzer.<br>
5+
Purpose: Types of Tokens to be created by {@link Tokenizer}.<br>
66
Programmer: Gabriel Toban Harris <br>
77
Date: 2021-07-26, 2021-7-30
88
</b>

parser/Tree_Assembler.java

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
package parser;
2+
3+
import java.io.PrintWriter;
4+
import java.util.ArrayList;
5+
import java.util.HashMap;
6+
import structure.Evaluable;
7+
import structure.Scenario;
8+
9+
/**
10+
<b>
11+
Purpose: assembles the parts of a configuration file for simulating.<br>
12+
Programmer: Gabriel Toban Harris<br>
13+
Date: 2021-08-04
14+
</b>
15+
*/
16+
17+
//TODO: figure out how to effectively handle VERBOSE, as would like to not recheck it, maybe just use lambda as function pointer.
18+
public class Tree_Assembler<T, U>
19+
{
20+
/**
21+
* Determines whether to output files, true for make files and false for no file creation.
22+
*/
23+
public final boolean VERBOSE;
24+
25+
/**
26+
* Derivation of the input.
27+
*/
28+
private StringBuilder derivation;
29+
30+
/**
31+
* stack like structure used by {@link Tree_Assembler#parse(Token)}
32+
*/
33+
private ArrayList<Semantic_Actions> semantic_stack;
34+
35+
/**
36+
* Represents stack like structure for building the {@link Scenario} and deck list, used by {@link Tree_Assembler#parse(Token)}
37+
*/
38+
private ArrayList<Evaluable<U>> syntactical_stack;
39+
40+
/**
41+
* Main deck which the hand will be generated from.
42+
*/
43+
private final ArrayList<T> DECK;
44+
45+
/**
46+
* Stores the generated scenarios.
47+
*/
48+
private final HashMap<String, Scenario<U>> FOREST;
49+
50+
/**
51+
* file to output syntactical errors to.
52+
*/
53+
private PrintWriter syntactical_error_output;
54+
55+
/**
56+
* file to output derivation
57+
*/
58+
private PrintWriter syntactical_derivation_output;
59+
60+
/**
61+
* Default constructor.
62+
*/
63+
public Tree_Assembler()
64+
{
65+
this.VERBOSE = false;
66+
this.DECK = new ArrayList<T>(40); //predicted average deck size
67+
this.FOREST = new HashMap<String, Scenario<U>>(10); //predicted average number of scenarios
68+
this.finish_construction();
69+
}
70+
71+
/**
72+
* Parameterized constructor. Which is implicitly setting {@link #VERBOSE} to true.
73+
*
74+
* @param EXPECTED_DECK_SIZE helps with memory management, but can be wrong
75+
* @param EXPECTED_SCENARIO_COUNT helps with memory management, but can be wrong
76+
* @param SYNTACTICAL_ERROR_OUTPUT {@link #syntactical_error_output}
77+
* @param SYNTACTICAL_DERIVATION_OUTPUT {@link #syntactical_derivation_output}
78+
*/
79+
public Tree_Assembler(final int EXPECTED_DECK_SIZE, final int EXPECTED_SCENARIO_COUNT, final PrintWriter SYNTACTICAL_ERROR_OUTPUT, final PrintWriter SYNTACTICAL_DERIVATION_OUTPUT)
80+
{
81+
this.VERBOSE = true;
82+
this.DECK = new ArrayList<T>(EXPECTED_DECK_SIZE);
83+
this.FOREST = new HashMap<String, Scenario<U>>(EXPECTED_SCENARIO_COUNT);
84+
this.derivation = new StringBuilder(Semantic_Actions.START.name());
85+
this.syntactical_error_output = SYNTACTICAL_ERROR_OUTPUT;
86+
this.syntactical_derivation_output = SYNTACTICAL_DERIVATION_OUTPUT;
87+
this.finish_construction();
88+
}
89+
90+
/**
91+
* True output of this object.
92+
*
93+
* @return culmination of this class, destroy the object afterwards
94+
*/
95+
public Simulatation<T, U> creat_result()
96+
{
97+
return new Simulatation<T, U>(this.DECK, this.FOREST);
98+
}
99+
100+
/**
101+
* Method for parsing tokens into an abstract syntax tree. Uses all data members.
102+
* Make sure to call {@link #finish_semantic_stack} once all the {@link Token} are are parsed.
103+
* @param INPUT current top token being looked at
104+
* @throws EmptySemanticStackException when internal semantic_stack is empty yet there is another token to parse.
105+
* @throws TerminalMatchException {@link #match_subroutine}
106+
*/
107+
public void parse(final Token INPUT) //throws EmptySemanticStackException, TerminalMatchException
108+
{
109+
//TODO: write
110+
}
111+
112+
/**
113+
* Centralize shared constructor code. Should only be called once by the constructor and never again.
114+
*/
115+
private void finish_construction()
116+
{
117+
this.semantic_stack = new ArrayList<Semantic_Actions>();
118+
this.semantic_stack.add(Semantic_Actions.START); // starting symbol
119+
this.syntactical_stack = new ArrayList<Evaluable<U>>();
120+
}
121+
}

0 commit comments

Comments
 (0)