// File: Blaze2305[P]Compiler-Design-2021-Assignment/main.cpp
// Function: main
int main(int argc, char *argv[]){
	// Check if the file is passed as an argument or not
	// if not then error out
 	if(argc != 2){
		std::cout<<"\nFile Missing , Invalid number of arguments\n";
		return 1;
	}
	std::cout<<"----------------------------------------------------------------------------\n";
	std::cout<<argv[1]<<std::endl;
	std::cout<<"----------------------------------------------------------------------------\n";
	

	// TESTING SCANNER 
	// Scanner scanner = Scanner(argv[1]);
	// while(true){
	// 	TokenRecord val = scanner.getToken();
	// 	std::cout<<val;
	// 	if(val.tokenType==EOT){
	// 		break;
	// 	}
	// }

	Parser parser = Parser(argv[1]);
	try{
		parser.parse();
	}catch(std::runtime_error err){
		std::cout<<"INVALID \n";
		std::cout<<err.what();
		exit(1);
	}
	std::cout<<"VALID CODE\n";
	parser.showSymbolTable();

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
je 0xb3ee
movq 0x16bf2(%rip), %rdi     # 0x21fc8
leaq 0xdd16(%rip), %rsi      # 0x190f3
callq 0x3290
movl $0x1, -0x4(%rbp)
jmp 0xb614
movq 0x16bd3(%rip), %rdi     # 0x21fc8
movq %rdi, -0x100(%rbp)
leaq 0xdd60(%rip), %rsi      # 0x19163
movq %rsi, -0xf8(%rbp)
callq 0x3290
movq -0x100(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x3290
movq %rax, %rdi
movq 0x16b73(%rip), %rsi     # 0x21fa0
callq 0x32e0
movq -0x100(%rbp), %rdi
movq -0xf8(%rbp), %rsi
callq 0x3290
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xf0(%rbp)
leaq -0xb9(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x3510
movq -0xf0(%rbp), %rsi
movq -0xe8(%rbp), %rdx
leaq -0xb8(%rbp), %rdi
callq 0xb640
jmp 0xb483
leaq -0x98(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0xd4c0
jmp 0xb498
leaq -0xb8(%rbp), %rdi
callq 0x3558
leaq -0xb9(%rbp), %rdi
callq 0x3300
leaq -0x98(%rbp), %rdi
callq 0xdb40
jmp 0xb4be
jmp 0xb5bc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
jmp 0xb4f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x3558
leaq -0xb9(%rbp), %rdi
callq 0x3300
jmp 0xb620
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
movl -0xcc(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0xb606
movq -0xc8(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x33a0
movq %rax, %rsi
leaq -0xe0(%rbp), %rdi
callq 0x3110
movq -0x108(%rbp), %rdi
callq 0x30f0
movq 0x16a68(%rip), %rdi     # 0x21fc8
leaq 0xdbb9(%rip), %rsi      # 0x19120
callq 0x3290
jmp 0xb56e
leaq -0xe0(%rbp), %rdi
callq 0x3400
movq %rax, %rsi
movq 0x16a44(%rip), %rdi     # 0x21fc8
callq 0x3290
jmp 0xb58b
movl $0x1, %edi
callq 0x3370
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x3560
callq 0x3480
jmp 0xb5ba
jmp 0xb606
movq 0x16a05(%rip), %rdi     # 0x21fc8
leaq 0xdb60(%rip), %rsi      # 0x1912a
callq 0x3290
jmp 0xb5d1
leaq -0x98(%rbp), %rdi
callq 0xd650
jmp 0xb5df
movl $0x0, -0x4(%rbp)
leaq -0x98(%rbp), %rdi
callq 0xd5e0
jmp 0xb614
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
leaq -0x98(%rbp), %rdi
callq 0xd5e0
jmp 0xb620
movl -0x4(%rbp), %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0xc8(%rbp), %rdi
callq 0x3500
movq %rax, %rdi
callq 0xbc80
nopw %cs:(%rax,%rax)
nop