// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x40, %rsp
movq %rdi, %rbx
leaq 0x420(%rdi), %r14
leaq 0x385e(%rip), %rsi      # 0x8c7c
movq %r14, %rdi
callq 0x21f0
movq %rax, %r15
movq 0x8(%rbx), %rsi
movl 0x10(%rbx), %edx
leaq -0x40(%rbp), %r12
movq %r12, %rdi
callq 0x3df8
movq %r15, %rdi
movq %r12, %rsi
callq 0x21d0
leaq 0x34a2(%rip), %rsi      # 0x88f0
movq %rax, %rdi
callq 0x21f0
movq %rax, %r15
movq 0x8(%rbx), %rsi
leaq -0x60(%rbp), %rdi
callq 0x3e22
leaq -0x60(%rbp), %rsi
movq %r15, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x2130
leaq -0x60(%rbp), %rdi
callq 0x2398
leaq -0x40(%rbp), %rdi
callq 0x2398
movl 0x10(%rbx), %edx
cmpl $0x1, %edx
je 0x55eb
cmpl $0x2, %edx
je 0x5502
cmpl $0x3, %edx
je 0x553f
cmpl $0x1f, %edx
je 0x5566
cmpl $0x21, %edx
je 0x553f
movq 0x8(%rbx), %rsi
leaq -0x60(%rbp), %r15
movq %r15, %rdi
callq 0x3df8
leaq 0x3861(%rip), %rsi      # 0x8d30
leaq -0x40(%rbp), %rdi
movq %r15, %rdx
callq 0x76ba
leaq -0x40(%rbp), %rsi
movq %rbx, %rdi
callq 0x48e6
leaq -0x40(%rbp), %rdi
callq 0x2398
leaq -0x60(%rbp), %rdi
callq 0x2398
pushq $0x1
popq %r15
jmp 0x5611
leaq 0x37ef(%rip), %rsi      # 0x8cf8
movq %r14, %rdi
callq 0x21f0
movq %rax, %r15
movq 0x8(%rbx), %rsi
movl 0x10(%rbx), %edx
movq %r12, %rdi
callq 0x3df8
movq %r15, %rdi
movq %r12, %rsi
callq 0x21d0
movq %rax, %rdi
callq 0x2130
leaq -0x40(%rbp), %rdi
callq 0x2398
leaq 0x37dd(%rip), %rsi      # 0x8d23
movq %r14, %rdi
callq 0x21f0
movq %rax, %rdi
callq 0x2130
movq %rbx, %rdi
callq 0x6416
movl %eax, %r15d
jmp 0x5611
leaq 0x3747(%rip), %rsi      # 0x8cb4
movq %r14, %rdi
callq 0x21f0
movq %rax, %rdi
callq 0x2130
movq 0x8(%rbx), %rdi
callq 0x35fa
movl %eax, 0x10(%rbx)
movq %rbx, %rdi
callq 0x56a6
movl %eax, %r15d
movl 0x10(%rbx), %edx
cmpl $0x20, %edx
je 0x55dd
movq 0x8(%rbx), %rsi
leaq -0x60(%rbp), %r12
movq %r12, %rdi
callq 0x3df8
leaq 0x370e(%rip), %rsi      # 0x8cc1
leaq -0x40(%rbp), %rdi
movq %r12, %rdx
callq 0x76ba
leaq -0x40(%rbp), %rsi
movq %rbx, %rdi
callq 0x48e6
leaq -0x40(%rbp), %rdi
callq 0x2398
leaq -0x60(%rbp), %rdi
callq 0x2398
movq 0x8(%rbx), %rdi
callq 0x35fa
movl %eax, 0x10(%rbx)
jmp 0x5611
leaq 0x36b5(%rip), %rsi      # 0x8ca7
movq %r14, %rdi
callq 0x21f0
movq %rax, %rdi
callq 0x2130
movq 0x8(%rbx), %rdi
callq 0x35fa
movl %eax, 0x10(%rbx)
xorl %r15d, %r15d
leaq 0x374b(%rip), %rsi      # 0x8d63
movq %r14, %rdi
callq 0x21f0
movq %rax, %r14
movq 0x8(%rbx), %rsi
movl 0x10(%rbx), %edx
leaq -0x40(%rbp), %rbx
movq %rbx, %rdi
callq 0x3df8
movq %r14, %rdi
movq %rbx, %rsi
callq 0x21d0
movq %rax, %rdi
callq 0x2130
leaq -0x40(%rbp), %rdi
callq 0x2398
movl %r15d, %eax
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5666
jmp 0x5674
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x2398
jmp 0x5677
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
jmp 0x5698
jmp 0x5691
jmp 0x5691
jmp 0x5691
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x2398
jmp 0x5694
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x2398
movq %rbx, %rdi
callq 0x2330
nop