task5 complete
This commit is contained in:
		
							parent
							
								
									a607f09f6b
								
							
						
					
					
						commit
						a59e60d2bc
					
				@ -28,6 +28,9 @@ import triangle.syntacticAnalyzer.Scanner;
 | 
				
			|||||||
import triangle.syntacticAnalyzer.SourceFile;
 | 
					import triangle.syntacticAnalyzer.SourceFile;
 | 
				
			||||||
import triangle.treeDrawer.Drawer;
 | 
					import triangle.treeDrawer.Drawer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Task 5b
 | 
				
			||||||
 | 
					import triangle.optimiser.SummaryStats;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Task 2
 | 
					// Task 2
 | 
				
			||||||
import com.sampullara.cli.Args;
 | 
					import com.sampullara.cli.Args;
 | 
				
			||||||
import com.sampullara.cli.Argument;
 | 
					import com.sampullara.cli.Argument;
 | 
				
			||||||
@ -56,6 +59,9 @@ public class Compiler {
 | 
				
			|||||||
	/** The AST representing the source program. */
 | 
						/** The AST representing the source program. */
 | 
				
			||||||
	private static Program theAST;
 | 
						private static Program theAST;
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 | 
						//Task5b
 | 
				
			||||||
 | 
						private static SummaryStats stats;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	//Task 2
 | 
						//Task 2
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	@Argument(alias = "file", description="Name of file you want to compile", required = true)
 | 
						@Argument(alias = "file", description="Name of file you want to compile", required = true)
 | 
				
			||||||
@ -112,9 +118,6 @@ public class Compiler {
 | 
				
			|||||||
		encoder = new Encoder(emitter, reporter);
 | 
							encoder = new Encoder(emitter, reporter);
 | 
				
			||||||
		drawer = new Drawer();
 | 
							drawer = new Drawer();
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		//Task 5b
 | 
					 | 
				
			||||||
		stats = new SummaryStats();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		theAST = parser.parseProgram(); // 1st pass
 | 
							theAST = parser.parseProgram(); // 1st pass
 | 
				
			||||||
		if (reporter.getNumErrors() == 0) {
 | 
							if (reporter.getNumErrors() == 0) {
 | 
				
			||||||
			System.out.println("Contextual Analysis ...");
 | 
								System.out.println("Contextual Analysis ...");
 | 
				
			||||||
@ -141,9 +144,13 @@ public class Compiler {
 | 
				
			|||||||
		if (successful) {
 | 
							if (successful) {
 | 
				
			||||||
			emitter.saveObjectProgram(objectName);
 | 
								emitter.saveObjectProgram(objectName);
 | 
				
			||||||
			System.out.println("Compilation was successful.");
 | 
								System.out.println("Compilation was successful.");
 | 
				
			||||||
 | 
								
 | 
				
			||||||
			//Task 5b
 | 
								//Task 5b
 | 
				
			||||||
 | 
								if (showStats) {
 | 
				
			||||||
 | 
									theAST.visit(stats = new SummaryStats());
 | 
				
			||||||
				System.out.println("[STATS] CharExpr: " + stats.getCharExprCount() + "!");
 | 
									System.out.println("[STATS] CharExpr: " + stats.getCharExprCount() + "!");
 | 
				
			||||||
				System.out.println("[STATS] IntExpr: " + stats.getIntExprCount() + "!");
 | 
									System.out.println("[STATS] IntExpr: " + stats.getIntExprCount() + "!");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			System.out.println("Compilation was unsuccessful.");
 | 
								System.out.println("Compilation was unsuccessful.");
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@ -160,24 +167,10 @@ public class Compiler {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		//Task 2
 | 
							//Task 2
 | 
				
			||||||
		Args.parseOrExit(Compiler.class, args);
 | 
							Args.parseOrExit(Compiler.class, args);
 | 
				
			||||||
		var compiledOK = compileProgram(Compiler.sourceName, Compiler.objectName, Compiler.showTree, false, Compiler.showTreeAfterFolding);
 | 
							var compiledOK = compileProgram(Compiler.sourceName, Compiler.objectName, Compiler.showTree, false, Compiler.showTreeAfterFolding, Compiler.showStats);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (!showTree) {
 | 
							if (!showTree) {
 | 
				
			||||||
			System.exit(compiledOK ? 0 : 1);
 | 
								System.exit(compiledOK ? 0 : 1);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	/* No longer needed */
 | 
					 | 
				
			||||||
	private static void parseArgs(String[] args) {
 | 
					 | 
				
			||||||
		for (String s : args) {
 | 
					 | 
				
			||||||
			var sl = s.toLowerCase();
 | 
					 | 
				
			||||||
			if (sl.equals("tree")) {
 | 
					 | 
				
			||||||
				showTree = true;
 | 
					 | 
				
			||||||
			} else if (sl.startsWith("-o=")) {
 | 
					 | 
				
			||||||
				objectName = s.substring(3);
 | 
					 | 
				
			||||||
			} else if (sl.equals("folding")) {
 | 
					 | 
				
			||||||
				folding = true;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -321,8 +321,8 @@ public class SummaryStats implements ActualParameterVisitor<Void, AbstractSyntax
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public AbstractSyntaxTree visitCharacterExpression(CharacterExpression ast, Void arg) {
 | 
						public AbstractSyntaxTree visitCharacterExpression(CharacterExpression ast, Void arg) {
 | 
				
			||||||
		countCharExpr++; //Increment the count for stats
 | 
					 | 
				
			||||||
		ast.CL.visit(this);
 | 
							ast.CL.visit(this);
 | 
				
			||||||
 | 
							countCharExpr++; //Increment the count for stats after visiting
 | 
				
			||||||
		return null;
 | 
							return null;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								checkstats.tri
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								checkstats.tri
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										18
									
								
								programs/checkstats.tri
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								programs/checkstats.tri
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,18 @@
 | 
				
			|||||||
 | 
					let
 | 
				
			||||||
 | 
					    var a : Integer;
 | 
				
			||||||
 | 
					    var b : Integer;
 | 
				
			||||||
 | 
					    var c : Integer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    var x : Char;
 | 
				
			||||||
 | 
					    var y : Char
 | 
				
			||||||
 | 
					in
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        a := 1;
 | 
				
			||||||
 | 
					        b := 2;
 | 
				
			||||||
 | 
					        a**;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        b := 100;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        x := 'A';
 | 
				
			||||||
 | 
					        y := 'Z';
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								simple.tri
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								simple.tri
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user