// File: ssubrandon[P]460Project2/SyntacticalAnalyzer.cpp
// Function: SyntacticalAnalyzer::stmt()
int SyntacticalAnalyzer::stmt(){
  //This function deals with the stmt rules (7-9) and will check for syntactical correctness,
  //this function will then, depending on the token seen, send the program to literal, action, or will return. 
	ruleFile << "Entering stmt function; Current token is: " << lex ->GetTokenName(token) << ", lexeme: " << lex->GetLexeme() << endl;

	int errors = 0;

	switch(token){
		case IDENT_T:
			ruleFile << "Using Rule 8" << endl;
			token = lex->GetToken();
			break;


		case LPAREN_T:
			ruleFile << "Using Rule 9" << endl;
			//ruleFile << "stmt function complete. Current token is: " << lex->GetTokenName(token) << endl;
			token = lex->GetToken();
			errors += action();
			//returned token should be a RPAREN?
			if(token == RPAREN_T){
			  token=lex->GetToken();
			}
			else{
			  ReportError(string("RPAREN_T expected in stmt function, current token is: " + lex->GetTokenName(token)));
			  token=lex->GetToken();
			}
			break;


		case NUMLIT_T: 
			ruleFile << "stmt function complete. Current token is: " << lex->GetTokenName(token) << endl;
			ruleFile << "Using Rule 7"  << endl;
			errors += literal();
			break;

		case STRLIT_T:
			//ruleFile << "stmt function complete. Current token is: " << lex->GetTokenName(token) << endl;
			ruleFile << "Using Rule 7"  << endl;
			errors += literal();
			break;

		case SQUOTE_T:
			//ruleFile << "stmt function complete. Current token is: " << lex->GetTokenName(token) << endl;
			ruleFile << "Using Rule 7"  << endl;
			errors += literal();
			break;

			
		default: //no rule found
			errors++;
			ReportError(string("No rule found in stmt function, current token is: " + lex->GetTokenName(token)));
			break;

	}
	ruleFile << "Exiting stmt function; current token is: " << lex ->GetTokenName (token) << endl;
	return errors;	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x140(%rbp)
addq $0x420, %rdi            # imm = 0x420
leaq 0x60d8(%rip), %rsi      # 0x107e0
callq 0x3270
movq %rax, %rcx
movq -0x140(%rbp), %rax
movq %rcx, -0x138(%rbp)
movq 0x8(%rax), %rsi
movl 0x10(%rax), %edx
leaq -0x28(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x6f40
movq -0x138(%rbp), %rdi
movq -0x130(%rbp), %rsi
callq 0x3240
movq %rax, -0x128(%rbp)
jmp 0xa751
movq -0x128(%rbp), %rdi
leaq 0x5cf5(%rip), %rsi      # 0x10454
callq 0x3270
movq %rax, -0x148(%rbp)
jmp 0xa76d
movq -0x140(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0x58(%rbp), %rdi
callq 0x6f80
jmp 0xa783
movq -0x148(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x3240
movq %rax, -0x150(%rbp)
jmp 0xa79c
movq -0x150(%rbp), %rdi
movq 0xa816(%rip), %rsi      # 0x14fc0
callq 0x32c0
jmp 0xa7b1
leaq -0x58(%rbp), %rdi
callq 0x34b8
leaq -0x28(%rbp), %rdi
callq 0x34b8
movq -0x140(%rbp), %rax
movl $0x0, -0x5c(%rbp)
movl 0x10(%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x158(%rbp)
subl $0x20, %eax
ja 0xab0f
movq -0x158(%rbp), %rax
leaq 0x5afa(%rip), %rcx      # 0x102f0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0xa822
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x34b8
leaq -0x28(%rbp), %rdi
callq 0x34b8
jmp 0xac60
movq -0x140(%rbp), %rdi
addq $0x420, %rdi            # imm = 0x420
leaq 0x5fc6(%rip), %rsi      # 0x1080b
callq 0x3270
movq %rax, %rdi
movq 0xa76c(%rip), %rsi      # 0x14fc0
callq 0x32c0
movq -0x140(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x5fd0
movl %eax, %ecx
movq -0x140(%rbp), %rax
movl %ecx, 0x10(%rax)
jmp 0xabba
movq -0x140(%rbp), %rdi
addq $0x420, %rdi            # imm = 0x420
leaq 0x5f89(%rip), %rsi      # 0x10818
callq 0x3270
movq %rax, %rdi
movq 0xa722(%rip), %rsi      # 0x14fc0
callq 0x32c0
movq -0x140(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x5fd0
movq -0x140(%rbp), %rdi
movl %eax, 0x10(%rdi)
callq 0xac70
movl %eax, %ecx
movq -0x140(%rbp), %rax
addl -0x5c(%rbp), %ecx
movl %ecx, -0x5c(%rbp)
cmpl $0x20, 0x10(%rax)
jne 0xa8f8
movq -0x140(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x5fd0
movl %eax, %ecx
movq -0x140(%rbp), %rax
movl %ecx, 0x10(%rax)
jmp 0xa9ab
movq -0x140(%rbp), %rax
movq 0x8(%rax), %rsi
movl 0x10(%rax), %edx
leaq -0xa0(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x6f40
movq -0x160(%rbp), %rdx
leaq 0x5efe(%rip), %rsi      # 0x10825
leaq -0x80(%rbp), %rdi
callq 0xf1b0
jmp 0xa932
movq -0x140(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x91a0
jmp 0xa944
leaq -0x80(%rbp), %rdi
callq 0x34b8
leaq -0xa0(%rbp), %rdi
callq 0x34b8
movq -0x140(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x5fd0
movl %eax, %ecx
movq -0x140(%rbp), %rax
movl %ecx, 0x10(%rax)
jmp 0xa9ab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0xa99a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x34b8
leaq -0xa0(%rbp), %rdi
callq 0x34b8
jmp 0xac60
jmp 0xabba
movq -0x140(%rbp), %rdi
addq $0x420, %rdi            # imm = 0x420
leaq 0x5e97(%rip), %rsi      # 0x1085c
callq 0x3270
movq %rax, %rcx
movq -0x140(%rbp), %rax
movq %rcx, -0x178(%rbp)
movq 0x8(%rax), %rsi
movl 0x10(%rax), %edx
leaq -0xc0(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x6f40
movq -0x178(%rbp), %rdi
movq -0x170(%rbp), %rsi
callq 0x3240
movq %rax, -0x168(%rbp)
jmp 0xaa11
movq -0x168(%rbp), %rdi
movq 0xa5a1(%rip), %rsi      # 0x14fc0
callq 0x32c0
jmp 0xaa26
leaq -0xc0(%rbp), %rdi
callq 0x34b8
movq -0x140(%rbp), %rdi
addq $0x420, %rdi            # imm = 0x420
leaq 0x5e40(%rip), %rsi      # 0x10887
callq 0x3270
movq %rax, %rdi
movq 0xa56a(%rip), %rsi      # 0x14fc0
callq 0x32c0
movq -0x140(%rbp), %rdi
callq 0xcba0
addl -0x5c(%rbp), %eax
movl %eax, -0x5c(%rbp)
jmp 0xabba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x34b8
jmp 0xac60
movq -0x140(%rbp), %rdi
addq $0x420, %rdi            # imm = 0x420
leaq 0x5de3(%rip), %rsi      # 0x10887
callq 0x3270
movq %rax, %rdi
movq 0xa50d(%rip), %rsi      # 0x14fc0
callq 0x32c0
movq -0x140(%rbp), %rdi
callq 0xcba0
addl -0x5c(%rbp), %eax
movl %eax, -0x5c(%rbp)
jmp 0xabba
movq -0x140(%rbp), %rdi
addq $0x420, %rdi            # imm = 0x420
leaq 0x5da3(%rip), %rsi      # 0x10887
callq 0x3270
movq %rax, %rdi
movq 0xa4cd(%rip), %rsi      # 0x14fc0
callq 0x32c0
movq -0x140(%rbp), %rdi
callq 0xcba0
addl -0x5c(%rbp), %eax
movl %eax, -0x5c(%rbp)
jmp 0xabba
movq -0x140(%rbp), %rax
movl -0x5c(%rbp), %ecx
incl %ecx
movl %ecx, -0x5c(%rbp)
movq 0x8(%rax), %rsi
movl 0x10(%rax), %edx
leaq -0x100(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0x6f40
movq -0x180(%rbp), %rdx
leaq 0x5d4e(%rip), %rsi      # 0x10894
leaq -0xe0(%rbp), %rdi
callq 0xf1b0
jmp 0xab54
movq -0x140(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x91a0
jmp 0xab69
leaq -0xe0(%rbp), %rdi
callq 0x34b8
leaq -0x100(%rbp), %rdi
callq 0x34b8
jmp 0xabba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0xaba9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x34b8
leaq -0x100(%rbp), %rdi
callq 0x34b8
jmp 0xac60
movq -0x140(%rbp), %rdi
addq $0x420, %rdi            # imm = 0x420
leaq 0x5cf8(%rip), %rsi      # 0x108c7
callq 0x3270
movq %rax, %rcx
movq -0x140(%rbp), %rax
movq %rcx, -0x198(%rbp)
movq 0x8(%rax), %rsi
movl 0x10(%rax), %edx
leaq -0x120(%rbp), %rdi
movq %rdi, -0x190(%rbp)
callq 0x6f40
movq -0x198(%rbp), %rdi
movq -0x190(%rbp), %rsi
callq 0x3240
movq %rax, -0x188(%rbp)
jmp 0xac1b
movq -0x188(%rbp), %rdi
movq 0xa397(%rip), %rsi      # 0x14fc0
callq 0x32c0
jmp 0xac30
leaq -0x120(%rbp), %rdi
callq 0x34b8
movl -0x5c(%rbp), %eax
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x34b8
movq -0x30(%rbp), %rdi
callq 0x3430
nopl (%rax)