// File: /workspace/github_cpp_makefile_star2_O3/ssubrandon[P]460Project2/LexicalAnalyzer.cpp
// Function: LexicalAnalyzer::GetToken()
token_type LexicalAnalyzer::GetToken ()
{
	error_type = 1;
	lexeme = "";
	int state = 1;
	token_type token = NONE;
	map <string, token_type>::iterator itr;
	if (input.fail())
	{
		debug << '\t' << setw(16) << left << "EOF_T" << endl;
		p1file << '\t' << setw(16) << left << "EOF_T" << endl;
		return EOF_T;
	}
	static string valid = "acdrb0.()+-*/'=<>?_\"";
	while (isspace(line[pos]) || line[pos] == ';') // end of line or beginning of comment
		if (line[pos] == ';' || ++pos >= line.length())
		{
			getline (input, line);
			if (input.fail())
			{
				debug << '\t' << setw(16) << left << "EOF_T" << endl;
				p1file << '\t' << setw(16) << left << "EOF_T" << endl;
				return EOF_T;
			}
			linenum++;
			listing << setw(4) << right << linenum << ": " << line << endl;	
			debug << setw(4) << right << linenum << ": " << line << endl;	
			line += ' ';
			pos = 0;
		}
	while (token == NONE)
	{
		char c = line[pos++];
		lexeme += c;
		if (state == 12 && pos == line.length())
		{ // used if end of line found in a string literal
			token = ERROR_T;
			error_type = 2;
			break;	
		}
		if (isalpha(c) && (c != 'a' && c != 'c' && c != 'd' && c != 'r')) 
			c = 'b';
		else if (isdigit(c))
			c = '0';
		int col = 0;
		while (col < valid.length() && valid[col] != c)
			col++;
		state = table[state][col];
		switch (state)
		{
		    case 20: // car, cdr, cadr, cddr, and other list operators
			pos--;
			//cout << lexeme << endl;
			lexeme = lexeme.erase(lexeme.length()-1,1);
			//cout << lexeme << endl;
			token = LISTOP_T;
			break;
		    case 21: // symbol or keyword
			pos--;
			lexeme = lexeme.erase(lexeme.length()-1,1);
			itr = symbols.find (lexeme);
			if (itr != symbols.end())
				token = itr->second;
			else 
				token = IDENT_T;
			break;
		    case 22: // numeric literal
			pos--;
			lexeme = lexeme.erase(lexeme.length()-1,1);
			token = NUMLIT_T;
			break;
		    case 23: // operator/symbol with backup
			pos--;
			lexeme = lexeme.erase(lexeme.length()-1,1);
		    case 24: // operator/symbol without backup
			itr = symbols.find (lexeme);
			if (itr != symbols.end())
				token = itr->second;
			else if (lexeme[lexeme.length()-1] == '?') // allow ? at end of identifier
			{
				pos--;
				lexeme = lexeme.erase(lexeme.length()-1,1);
				token = IDENT_T;
			}
			else
				token = ERROR_T;
			break;
		    case 25: // string literal
			token = STRLIT_T;
			break;
		    case 31: // error with backup
			pos--;
			lexeme = lexeme.erase(lexeme.length()-1,1);
		    case 32: // error
			token = ERROR_T;
		}
		if (token == ERROR_T)
			switch (error_type)
			{
				case 1: ReportError (string("Invalid character found: ") + lexeme);
					break;
				case 2: ReportError (string("Unterminated string literal: ") + lexeme);
					break;
				default: ReportError (string("Unidentified error: ") + lexeme);
			}
	}
	debug << '\t' << setw(16) << left << token_names[token] << lexeme << endl;
	p1file << '\t' << setw(16) << left << token_names[token] << lexeme << endl;
	return token;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
movl $0x1, 0x850(%rdi)
leaq 0x830(%rdi), %r14
movq 0x838(%rdi), %rdx
leaq 0x771f(%rip), %rcx      # 0xb5e0
movq %r14, %rdi
xorl %esi, %esi
xorl %r8d, %r8d
callq 0x22e0
movq 0x400(%rbx), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x420(%rbx,%rax)
je 0x3ffc
movb $0x9, %al
leaq -0x48(%rbp), %r15
movb %al, (%r15)
movl $0x1, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2260
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rcx
movl $0x10, %r14d
movq %r14, 0x10(%r12,%rcx)
movq -0x18(%rax), %rax
movl $0xffffff4f, %r13d      # imm = 0xFFFFFF4F
movl 0x18(%r12,%rax), %ecx
andl %r13d, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%r12,%rax)
leaq 0x766d(%rip), %rsi      # 0xb5a3
movl $0x5, %edx
movq %r12, %rdi
callq 0x2260
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2170
addq $0x608, %rbx            # imm = 0x608
movb $0x9, %al
movb %al, (%r15)
leaq -0x48(%rbp), %rsi
movl $0x1, %edx
movq %rbx, %rdi
callq 0x2260
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rcx
movq %r14, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
andl 0x18(%rbx,%rax), %r13d
orl $0x20, %r13d
movl %r13d, 0x18(%rbx,%rax)
movl $0x5, %edx
movq %rbx, %rdi
leaq 0x75eb(%rip), %rsi      # 0xb5a3
callq 0x2260
movl $0x23, %r15d
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2170
movl %r15d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, -0x80(%rbp)
movb 0xb69a(%rip), %al       # 0xf6a0
testb %al, %al
je 0x4779
leaq 0x400(%rbx), %rax
movq %rax, -0x78(%rbp)
leaq 0x808(%rbx), %r15
leaq 0x200(%rbx), %rax
movq %rax, -0x70(%rbp)
movl 0x82c(%rbx), %r13d
movl $0x80, %r12d
movslq %r13d, %rax
movq (%r15), %rcx
movb (%rcx,%rax), %r14b
movsbl %r14b, %edi
callq 0x2070
testl %eax, %eax
je 0x406d
cmpb $0x3b, %r14b
je 0x4077
incl %r13d
movl %r13d, 0x82c(%rbx)
movslq %r13d, %rax
cmpq %rax, 0x810(%rbx)
ja 0x4038
jmp 0x4077
cmpb $0x3b, %r14b
jne 0x4203
movq 0x400(%rbx), %rax
movq -0x18(%rax), %rdi
movq -0x78(%rbp), %r14
addq %r14, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2370
movq 0x400(%rbx), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x420(%rbx,%rax)
jne 0x3ee7
movl 0x828(%rbx), %esi
incl %esi
movl %esi, 0x828(%rbx)
movq 0x200(%rbx), %rax
movq -0x18(%rax), %rcx
movl $0x4, %r14d
movq %r14, 0x210(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x218(%rbx,%rax), %ecx
movl $0xffffff4f, %edx       # imm = 0xFFFFFF4F
andl %edx, %ecx
orl %r12d, %ecx
movl %ecx, 0x218(%rbx,%rax)
movq -0x70(%rbp), %rdi
callq 0x2330
movq %rax, %r13
movl $0x2, %edx
movq %rax, %rdi
leaq 0x75b6(%rip), %rsi      # 0xb6ce
callq 0x2260
movq 0x808(%rbx), %rsi
movq 0x810(%rbx), %rdx
movq %r13, %rdi
callq 0x2260
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2170
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq %r14, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
movl $0xffffff4f, %edx       # imm = 0xFFFFFF4F
andl %edx, %ecx
orl %r12d, %ecx
movl %ecx, 0x18(%rbx,%rax)
movl 0x828(%rbx), %esi
movq %rbx, %rdi
callq 0x2330
movq %rax, %r13
movl $0x2, %edx
movq %rax, %rdi
leaq 0x752f(%rip), %rsi      # 0xb6ce
callq 0x2260
movq 0x808(%rbx), %rsi
movq 0x810(%rbx), %rdx
movq %r13, %rdi
callq 0x2260
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2170
movq %r15, %rdi
movl $0x20, %esi
callq 0x21b0
movl $0x0, 0x82c(%rbx)
xorl %r13d, %r13d
jmp 0x4038
leaq 0x858(%rbx), %rax
movq %rax, -0x78(%rbp)
leaq 0x860(%rbx), %rax
movq %rax, -0x70(%rbp)
movl $0x1, %r13d
leaq 0x6dfa(%rip), %r12      # 0xb020
movslq 0x82c(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x82c(%rbx)
movq 0x808(%rbx), %rcx
movsbl (%rcx,%rax), %r14d
movq -0x80(%rbp), %rdi
movl %r14d, %esi
callq 0x21b0
cmpl $0xc, %r13d
jne 0x4268
movslq 0x82c(%rbx), %rax
cmpq %rax, 0x810(%rbx)
je 0x43a3
movl %r14d, %edi
callq 0x22f0
movl %r14d, %ecx
andb $-0x3, %cl
leal -0x30(%r14), %edx
cmpl $0xa, %edx
movl %r14d, %edx
movl $0x30, %esi
cmovbl %esi, %edx
testl %eax, %eax
movl %edx, %eax
movl $0x62, %esi
cmovnel %esi, %eax
cmpb $0x61, %cl
cmovel %edx, %eax
cmpb $0x64, %r14b
cmovel %edx, %eax
cmpb $0x72, %r14b
cmovel %edx, %eax
movq 0xb3d9(%rip), %rdx      # 0xf688
testq %rdx, %rdx
je 0x42d6
movq 0xb3c5(%rip), %rsi      # 0xf680
xorl %ecx, %ecx
movq -0x80(%rbp), %r14
movsbl (%rsi,%rcx), %edi
cmpl %edi, %eax
je 0x42dc
incq %rcx
cmpq %rcx, %rdx
jne 0x42c1
movq %rdx, %rcx
jmp 0x42dc
xorl %ecx, %ecx
movq -0x80(%rbp), %r14
movslq %r13d, %rax
imulq $0x54, %rax, %rax
leaq 0x6d76(%rip), %rdx      # 0xb060
addq %rdx, %rax
movl (%rax,%rcx,4), %r13d
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
leal -0x14(%r13), %eax
cmpl $0xc, %eax
ja 0x4394
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
decl 0x82c(%rbx)
movq 0x838(%rbx), %rsi
decq %rsi
movl $0x1, %edx
movq %r14, %rdi
callq 0x20a0
movq %r14, %rdi
movq %rax, %rsi
callq 0x2130
movq -0x78(%rbp), %rdi
movq %r14, %rsi
callq 0x4e4a
cmpq -0x70(%rbp), %rax
jne 0x4386
jmp 0x43e8
decl 0x82c(%rbx)
movq 0x838(%rbx), %rsi
decq %rsi
movl $0x1, %edx
movq %r14, %rdi
callq 0x20a0
movq %r14, %rdi
movq %rax, %rsi
callq 0x2130
movq -0x78(%rbp), %rdi
movq %r14, %rsi
callq 0x4e4a
cmpq -0x70(%rbp), %rax
je 0x43b2
movl 0x40(%rax), %r15d
cmpl $0x22, %r15d
je 0x441b
cmpl $-0x1, %r15d
je 0x4226
jmp 0x4666
movl $0x2, 0x850(%rbx)
jmp 0x4660
movq 0x830(%rbx), %rax
movq 0x838(%rbx), %rsi
cmpb $0x3f, -0x1(%rax,%rsi)
jne 0x441b
decq %rsi
decl 0x82c(%rbx)
movl $0x1, %edx
movq %r14, %rdi
callq 0x20a0
movq %r14, %rdi
movq %rax, %rsi
callq 0x2130
movl $0x1, %r15d
jmp 0x4666
decl 0x82c(%rbx)
movq 0x838(%rbx), %rsi
decq %rsi
movl $0x1, %edx
movq %r14, %rdi
callq 0x20a0
movq %r14, %rdi
movq %rax, %rsi
callq 0x2130
movl 0x850(%rbx), %eax
cmpl $0x2, %eax
je 0x448f
cmpl $0x1, %eax
leaq -0x58(%rbp), %r14
leaq -0x38(%rbp), %r15
leaq -0x68(%rbp), %rdi
jne 0x44ef
movq %r14, (%rdi)
leaq 0x7272(%rip), %rsi      # 0xb6b7
leaq 0x7284(%rip), %rdx      # 0xb6d0
callq 0x4bce
movq 0x830(%rbx), %rsi
movq 0x838(%rbx), %rdx
leaq -0x68(%rbp), %rdi
callq 0x20e0
movq %r15, -0x48(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x45b4
movq %rdx, -0x48(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x38(%rbp)
jmp 0x45bb
leaq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %r14
movq %r14, (%rdi)
leaq 0x7230(%rip), %rsi      # 0xb6d1
leaq 0x7246(%rip), %rdx      # 0xb6ee
callq 0x4bce
leaq -0x38(%rbp), %r15
movq 0x830(%rbx), %rsi
movq 0x838(%rbx), %rdx
leaq -0x68(%rbp), %rdi
callq 0x20e0
movq %r15, -0x48(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x45e0
movq %rdx, -0x48(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x38(%rbp)
jmp 0x45e7
movq %r14, (%rdi)
leaq 0x71f6(%rip), %rsi      # 0xb6ef
leaq 0x7203(%rip), %rdx      # 0xb703
callq 0x4bce
movq 0x830(%rbx), %rsi
movq 0x838(%rbx), %rdx
leaq -0x68(%rbp), %rdi
callq 0x20e0
movq %r15, -0x48(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x460c
movq %rdx, -0x48(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x38(%rbp)
jmp 0x4613
decl 0x82c(%rbx)
movq 0x838(%rbx), %rsi
decq %rsi
movl $0x1, %edx
movq %r14, %rdi
callq 0x20a0
movq %r14, %rdi
movq %rax, %rsi
callq 0x2130
movl $0x2, %r15d
jmp 0x4666
decl 0x82c(%rbx)
movq 0x838(%rbx), %rsi
decq %rsi
movl $0x1, %edx
movq %r14, %rdi
callq 0x20a0
movq %r14, %rdi
movq %rax, %rsi
callq 0x2130
movl $0x9, %r15d
jmp 0x4666
movl $0x3, %r15d
jmp 0x4666
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
leaq -0x48(%rbp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %rbx, %rdi
callq 0x4840
jmp 0x4636
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
leaq -0x48(%rbp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %rbx, %rdi
callq 0x4840
jmp 0x4636
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
leaq -0x48(%rbp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %rbx, %rdi
callq 0x4840
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x464b
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0x68(%rbp), %rdi
cmpq %r14, %rdi
je 0x4660
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2210
movl $0x22, %r15d
movb $0x9, %al
leaq -0x48(%rbp), %rsi
movb %al, (%rsi)
movl $0x1, %edx
movq %rbx, %rdi
callq 0x2260
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movl $0x10, %esi
movq %rsi, 0x10(%rax,%rdx)
movq -0x18(%rcx), %rcx
movl $0xffffff4f, %r13d      # imm = 0xFFFFFF4F
movl 0x18(%rax,%rcx), %edx
andl %r13d, %edx
orl $0x20, %edx
movl %edx, 0x18(%rax,%rcx)
movslq %r15d, %r14
shlq $0x5, %r14
leaq 0xab4e(%rip), %rcx      # 0xf200
movq (%r14,%rcx), %rsi
movq 0x8(%r14,%rcx), %rdx
movq %rax, %rdi
callq 0x2260
movq 0x830(%rbx), %rsi
movq 0x838(%rbx), %rdx
movq %rax, %rdi
callq 0x2260
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2170
leaq 0x608(%rbx), %rdi
movb $0x9, %al
leaq -0x48(%rbp), %rcx
movb %al, (%rcx)
leaq -0x48(%rbp), %rsi
movl $0x1, %edx
callq 0x2260
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movl $0x10, %esi
movq %rsi, 0x10(%rax,%rdx)
movq -0x18(%rcx), %rcx
andl 0x18(%rax,%rcx), %r13d
orl $0x20, %r13d
movl %r13d, 0x18(%rax,%rcx)
leaq 0xaab6(%rip), %rcx      # 0xf200
movq (%r14,%rcx), %rsi
movq 0x8(%r14,%rcx), %rdx
movq %rax, %rdi
callq 0x2260
movq 0x830(%rbx), %rsi
movq 0x838(%rbx), %rdx
movq %rax, %rdi
callq 0x2260
movq %rax, %rbx
jmp 0x3fc3
leaq 0xaf20(%rip), %rdi      # 0xf6a0
callq 0x2360
testl %eax, %eax
je 0x400e
leaq 0xaefc(%rip), %rax      # 0xf690
movq %rax, 0xaee5(%rip)      # 0xf680
leaq 0xaede(%rip), %rdi      # 0xf680
leaq 0x6ef9(%rip), %rsi      # 0xb6a2
leaq 0x6f06(%rip), %rdx      # 0xb6b6
callq 0x4bce
movq 0xa804(%rip), %rdi      # 0xefc0
leaq 0xaebd(%rip), %rsi      # 0xf680
leaq 0xaa06(%rip), %rdx      # 0xf1d0
callq 0x21c0
leaq 0xaeca(%rip), %rdi      # 0xf6a0
callq 0x2160
jmp 0x400e
movq %rax, %rbx
leaq 0xaeb6(%rip), %rdi      # 0xf6a0
callq 0x2150
jmp 0x4838
jmp 0x47f5
jmp 0x47f5
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x4816
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2210
jmp 0x4816
jmp 0x4813
jmp 0x4813
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x4838
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2210
jmp 0x4838
jmp 0x4835
jmp 0x4835
movq %rax, %rbx
movq %rbx, %rdi
callq 0x2340