- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeGenerator.java
More file actions
Latest commit
42 lines (34 loc) · 1.09 KB
/
Copy pathCodeGenerator.java
File metadata and controls
42 lines (34 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
publicclassCodeGenerator
{
Scannerscanner; // This was my way of informing CG about Constant Values detected by Scanner, you can do whatever you like
// Define any variables needed for code generation
publicCodeGenerator(Scannerscanner)
{
this.scanner = scanner;
}
publicvoidGenerate(Stringsem)
{
System.out.println(sem); // Just for debug
if (sem.equals("NoSem"))
return;
/*
* else if (sem.equals("SemanticRoutine1"))
* {
* ...
* }
* else if (sem.equals("SemanticRoutine2"))
* {
* ...
* }
*/
}
publicvoidFinishCode() // You may need this
{
}
publicvoidWriteOutput(StringoutputName)
{
// Can be used to print the generated code to output
// I used this because in the process of compiling, I stored the generated code in a structure
// If you want, you can output a code line just when it is generated (strongly NOT recommended!!)
}
}