-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwinzigc.java
More file actions
42 lines (37 loc) · 1.54 KB
/
Copy pathwinzigc.java
File metadata and controls
42 lines (37 loc) · 1.54 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
import java.io.IOException;
import java.util.ArrayList;
public class winzigc{
public static void main(String[] args){
Lexer lexer = new Lexer(); //tokenizer
Parser parser = new Parser(); //syntax analysis
CodeGenerator codegen = new CodeGenerator(); //semantic analysis and code geneneration
try{
String flag = args[0];
String inputPath = args[1];
try {
ArrayList<Token> scannedTokens = lexer.scan(inputPath);
ArrayList<Token> screenedTokens = lexer.screen(scannedTokens);
// to get the tokens
if (flag.equals("-tokens")){
for (Token token : screenedTokens) {
System.out.println(token.tokenType + " -> " + token.value);
}
// to get the AST
} else if (flag.equals("-ast")){
AST ast = parser.getAST(screenedTokens);
ast.traverseTree(ast.root, 0);
// to get the machine code. assembly code is dumped to the current directory as "asmfile"
} else if (flag.equals("-code")){
AST ast = parser.getAST(screenedTokens);
codegen.generateCode(ast);
}
}
catch(IOException e) {
System.out.println("Invalid File!");
}
}
catch(ArrayIndexOutOfBoundsException e){
System.out.println("Incompatible Args!");
}
}
}