// File: /workspace/github_cpp_makefile_star2_O2/ssubrandon[P]460Project2/SyntacticalAnalyzer.cpp
// Function: SyntacticalAnalyzer::define()
int SyntacticalAnalyzer::define(){
  //This function deals with the defines rules(4) and will check for syntactical correctness,
  //this function will, depending on the token seen, send the program to param_list after
  //checking for the presence of some needed tokens for this rule.
  ruleFile << "Entering define function; Current token is: " << lex ->GetTokenName(token) << ", lexeme: " << lex->GetLexeme() << endl;

	int errors = 0;

	ruleFile << "Using  Rule 4" << endl;

	if(token != DEFINE_T){
		errors++;
		ReportError(string("expected a DEFINE_T in define, but found  " + lex->GetTokenName(token)));
	}

	token = lex->GetToken();
	if(token != LPAREN_T){
		errors++;
		ReportError(string("expected a LPAREN_T in define, but found  " + lex->GetTokenName(token)));
	}

	token = lex->GetToken();
	if(token != IDENT_T){
		errors++;
		ReportError(string("expected a IDENT_T in define, but found  " + lex->GetTokenName(token)));
	}

	token = lex->GetToken();
	errors += param_list();


	if(token != RPAREN_T){
		errors++;
		ReportError(string("expected a RPAREN_T in define, but found  " + lex->GetTokenName(token)));
	}
	token = lex->GetToken();
	errors += stmt();
	errors += stmt_list();


	if(token != RPAREN_T){
	  errors++;
	  ReportError(string("expected a RPAREN_T in define, but found  " + lex->GetTokenName(token)));
		token = lex->GetToken();
	}
	token = lex->GetToken();
	ruleFile << "Exiting Define function; current token is: " << lex ->GetTokenName (token) << endl;


	return errors;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
leaq 0x420(%rdi), %r14
leaq 0x40be(%rip), %rsi      # 0x8ac2
movq %r14, %rdi
callq 0x21f0
movq %rax, %r15
movq 0x8(%rbx), %rsi
movl 0x10(%rbx), %edx
leaq -0x48(%rbp), %r12
movq %r12, %rdi
callq 0x3df8
movq %r15, %rdi
movq %r12, %rsi
callq 0x21d0
leaq 0x3ebc(%rip), %rsi      # 0x88f0
movq %rax, %rdi
callq 0x21f0
movq %rax, %r15
movq 0x8(%rbx), %rsi
leaq -0x68(%rbp), %rdi
callq 0x3e22
leaq -0x68(%rbp), %rsi
movq %r15, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x2130
leaq -0x68(%rbp), %rdi
callq 0x2398
leaq -0x48(%rbp), %rdi
callq 0x2398
leaq 0x4076(%rip), %rsi      # 0x8aef
movq %r14, %rdi
callq 0x21f0
movq %rax, %rdi
callq 0x2130
movl 0x10(%rbx), %edx
xorl %r13d, %r13d
cmpl $0xd, %edx
je 0x4ad9
movq 0x8(%rbx), %rsi
leaq -0x68(%rbp), %r15
movq %r15, %rdi
callq 0x3df8
leaq 0x4052(%rip), %rsi      # 0x8afd
leaq -0x48(%rbp), %rdi
movq %r15, %rdx
callq 0x76ba
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x48e6
leaq -0x48(%rbp), %rdi
callq 0x2398
leaq -0x68(%rbp), %rdi
callq 0x2398
pushq $0x1
popq %r13
movq 0x8(%rbx), %rdi
callq 0x35fa
movl %eax, 0x10(%rbx)
cmpl $0x1f, %eax
je 0x4b30
movq 0x8(%rbx), %rsi
leaq -0x68(%rbp), %r15
movq %r15, %rdi
movl %eax, %edx
callq 0x3df8
leaq 0x4025(%rip), %rsi      # 0x8b28
leaq -0x48(%rbp), %rdi
movq %r15, %rdx
callq 0x76ba
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x48e6
incl %r13d
leaq -0x48(%rbp), %rdi
callq 0x2398
leaq -0x68(%rbp), %rdi
callq 0x2398
movq 0x8(%rbx), %rdi
callq 0x35fa
movl %eax, 0x10(%rbx)
cmpl $0x1, %eax
je 0x4b87
movq 0x8(%rbx), %rsi
leaq -0x68(%rbp), %r15
movq %r15, %rdi
movl %eax, %edx
callq 0x3df8
leaq 0x3ff9(%rip), %rsi      # 0x8b53
leaq -0x48(%rbp), %rdi
movq %r15, %rdx
callq 0x76ba
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x48e6
incl %r13d
leaq -0x48(%rbp), %rdi
callq 0x2398
leaq -0x68(%rbp), %rdi
callq 0x2398
movq 0x8(%rbx), %rdi
callq 0x35fa
movl %eax, 0x10(%rbx)
movq %rbx, %rdi
callq 0x51b4
movl %eax, %r12d
addl %r13d, %r12d
movl 0x10(%rbx), %edx
cmpl $0x20, %edx
je 0x4bed
movq 0x8(%rbx), %rsi
leaq -0x68(%rbp), %r15
movq %r15, %rdi
callq 0x3df8
leaq 0x3fbd(%rip), %rsi      # 0x8b7d
leaq -0x48(%rbp), %rdi
movq %r15, %rdx
callq 0x76ba
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x48e6
incl %r12d
leaq -0x48(%rbp), %rdi
callq 0x2398
leaq -0x68(%rbp), %rdi
callq 0x2398
movq 0x8(%rbx), %rdi
callq 0x35fa
movl %eax, 0x10(%rbx)
movq %rbx, %rdi
callq 0x53fe
movl %eax, %r13d
movq %rbx, %rdi
callq 0x4f92
movl %eax, %r15d
addl %r13d, %r15d
addl %r12d, %r15d
movl 0x10(%rbx), %edx
cmpl $0x20, %edx
je 0x4c6d
movq 0x8(%rbx), %rsi
leaq -0x68(%rbp), %r12
movq %r12, %rdi
callq 0x3df8
leaq 0x3f49(%rip), %rsi      # 0x8b7d
leaq -0x48(%rbp), %rdi
movq %r12, %rdx
callq 0x76ba
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x48e6
incl %r15d
leaq -0x48(%rbp), %rdi
callq 0x2398
leaq -0x68(%rbp), %rdi
callq 0x2398
movq 0x8(%rbx), %rdi
callq 0x35fa
movl %eax, 0x10(%rbx)
movq 0x8(%rbx), %rdi
callq 0x35fa
movl %eax, 0x10(%rbx)
leaq 0x3f28(%rip), %rsi      # 0x8ba8
movq %r14, %rdi
callq 0x21f0
movq %rax, %r14
movq 0x8(%rbx), %rsi
movl 0x10(%rbx), %edx
leaq -0x48(%rbp), %rbx
movq %rbx, %rdi
callq 0x3df8
movq %r14, %rdi
movq %rbx, %rsi
callq 0x21d0
movq %rax, %rdi
callq 0x2130
leaq -0x48(%rbp), %rdi
callq 0x2398
movl %r15d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4cdc
jmp 0x4cea
jmp 0x4cdc
jmp 0x4cea
jmp 0x4cdc
jmp 0x4cea
jmp 0x4cdc
jmp 0x4cea
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x2398
jmp 0x4ced
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
jmp 0x4d0c
jmp 0x4d05
jmp 0x4d05
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x2398
jmp 0x4d08
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x2398
movq %rbx, %rdi
callq 0x2330
nop