// File: /workspace/github_cpp_makefile_star2_O1/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 0x3fc8
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, %r13d
jmp 0x47be
movq %r14, -0x50(%rbp)
movb 0xb6ce(%rip), %al       # 0xf6a0
testb %al, %al
je 0x47f7
movslq 0x82c(%rbx), %r14
movq 0x808(%rbx), %rax
movsbl (%rax,%r14), %r13d
movl %r13d, %edi
callq 0x2070
cmpl $0x3b, %r13d
je 0x4003
testl %eax, %eax
je 0x41f7
leaq 0x400(%rbx), %rax
movq %rax, -0x80(%rbp)
leaq 0x808(%rbx), %r12
leaq 0x200(%rbx), %rax
movq %rax, -0x78(%rbp)
movl $0xffffff4f, %r15d      # imm = 0xFFFFFF4F
cmpb $0x3b, %r13b
je 0x4046
incl %r14d
movl %r14d, 0x82c(%rbx)
movslq %r14d, %rax
cmpq %rax, 0x810(%rbx)
ja 0x41ca
movq 0x400(%rbx), %rax
movq -0x18(%rax), %rdi
movq -0x80(%rbp), %r14
addq %r14, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %edx
movq %r14, %rdi
movq %r12, %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
andl %r15d, %ecx
movl $0x80, %edx
orl %edx, %ecx
movl %ecx, 0x218(%rbx,%rax)
movq -0x78(%rbp), %rdi
callq 0x2330
movq %rax, %r13
movl $0x2, %edx
movq %rax, %rdi
leaq 0x75e7(%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
andl %r15d, %ecx
movl $0x80, %edx
orl %edx, %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 0x7560(%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 %r12, %rdi
movl $0x20, %esi
callq 0x21b0
movl $0x0, 0x82c(%rbx)
movslq 0x82c(%rbx), %r14
movq 0x808(%rbx), %rax
movsbl (%rax,%r14), %r13d
movl %r13d, %edi
callq 0x2070
cmpl $0x3b, %r13d
je 0x4026
testl %eax, %eax
jne 0x4026
leaq 0x858(%rbx), %rax
movq %rax, -0x80(%rbp)
leaq 0x860(%rbx), %rax
movq %rax, -0x78(%rbp)
movl $0x1, %r12d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
leaq 0x6e00(%rip), %r14      # 0xb020
cmpl $-0x1, %r13d
jne 0x46b0
movslq 0x82c(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x82c(%rbx)
movq 0x808(%rbx), %rcx
movsbl (%rcx,%rax), %r13d
movq -0x50(%rbp), %rdi
movl %r13d, %esi
callq 0x21b0
cmpl $0xc, %r12d
jne 0x4286
movslq 0x82c(%rbx), %rax
cmpq %rax, 0x810(%rbx)
jne 0x4286
movl $0x2, 0x850(%rbx)
movl $0xc, %r12d
movl $0x22, %r13d
xorl %r15d, %r15d
jmp 0x46a7
movl %r13d, %edi
callq 0x22f0
movl %r13d, %ecx
andb $-0x3, %cl
leal -0x30(%r13), %edx
cmpl $0xa, %edx
movl %r13d, %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, %r13b
cmovel %edx, %eax
cmpb $0x72, %r13b
cmovel %edx, %eax
movq 0xb3bb(%rip), %rdx      # 0xf688
testq %rdx, %rdx
je 0x42f0
movq 0xb3a7(%rip), %rsi      # 0xf680
xorl %ecx, %ecx
movsbl (%rsi,%rcx), %edi
cmpl %edi, %eax
je 0x42f2
incq %rcx
cmpq %rcx, %rdx
jne 0x42db
movq %rdx, %rcx
jmp 0x42f2
xorl %ecx, %ecx
movslq %r12d, %rax
imulq $0x54, %rax, %rax
leaq 0x6d60(%rip), %rdx      # 0xb060
addq %rdx, %rax
movl (%rax,%rcx,4), %r12d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
leal -0x14(%r12), %eax
cmpl $0xc, %eax
ja 0x44a6
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
decl 0x82c(%rbx)
movq 0x838(%rbx), %rsi
decq %rsi
movl $0x1, %edx
movq -0x50(%rbp), %r15
movq %r15, %rdi
callq 0x20a0
movq %r15, %rdi
movq %rax, %rsi
callq 0x2130
movl $0x9, %r13d
jmp 0x44a6
movl $0x3, %r13d
jmp 0x44a6
decl 0x82c(%rbx)
movq 0x838(%rbx), %rsi
decq %rsi
movl $0x1, %edx
movq -0x50(%rbp), %r15
movq %r15, %rdi
callq 0x20a0
movq %r15, %rdi
movq %rax, %rsi
callq 0x2130
movq -0x80(%rbp), %rdi
movq %r15, %rsi
callq 0x4ece
cmpq -0x78(%rbp), %rax
jne 0x445a
jmp 0x44a0
decl 0x82c(%rbx)
movq 0x838(%rbx), %rsi
decq %rsi
movl $0x1, %edx
movq -0x50(%rbp), %r15
movq %r15, %rdi
callq 0x20a0
movq %r15, %rdi
movq %rax, %rsi
callq 0x2130
movl $0x22, %r13d
jmp 0x44a6
decl 0x82c(%rbx)
movq 0x838(%rbx), %rsi
decq %rsi
movl $0x1, %edx
movq -0x50(%rbp), %r15
movq %r15, %rdi
callq 0x20a0
movq %r15, %rdi
movq %rax, %rsi
callq 0x2130
movl $0x2, %r13d
jmp 0x44a6
decl 0x82c(%rbx)
movq 0x838(%rbx), %rsi
decq %rsi
movl $0x1, %edx
movq -0x50(%rbp), %r15
movq %r15, %rdi
callq 0x20a0
movq %r15, %rdi
movq %rax, %rsi
callq 0x2130
movq -0x80(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x4ece
cmpq -0x78(%rbp), %rax
je 0x4460
movl 0x40(%rax), %r13d
jmp 0x44a6
movq 0x830(%rbx), %rax
movq 0x838(%rbx), %rsi
movl $0x22, %r13d
cmpb $0x3f, -0x1(%rax,%rsi)
jne 0x44a6
decq %rsi
decl 0x82c(%rbx)
movl $0x1, %edx
movq -0x50(%rbp), %r15
movq %r15, %rdi
callq 0x20a0
movq %r15, %rdi
movq %rax, %rsi
callq 0x2130
movl $0x1, %r13d
movb $0x1, %r15b
cmpl $0x22, %r13d
jne 0x46a7
movl 0x850(%rbx), %eax
cmpl $0x2, %eax
je 0x4531
cmpl $0x1, %eax
leaq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
jne 0x459b
movq %rax, -0x70(%rbp)
leaq 0x71dd(%rip), %rsi      # 0xb6b7
leaq 0x71ef(%rip), %rdx      # 0xb6d0
movq %rdi, %r14
callq 0x4c4c
movq 0x830(%rbx), %rsi
movq 0x838(%rbx), %rdx
movq %r14, %rdi
callq 0x20e0
leaq -0x38(%rbp), %rsi
movq %rsi, -0x48(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
leaq 0x6b05(%rip), %r14      # 0xb020
je 0x45f6
movq %rdx, -0x48(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x38(%rbp)
jmp 0x45fc
leaq -0x60(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq -0x70(%rbp), %r14
movq %r14, %rdi
leaq 0x718a(%rip), %rsi      # 0xb6d1
leaq 0x71a0(%rip), %rdx      # 0xb6ee
callq 0x4c4c
movq 0x830(%rbx), %rsi
movq 0x838(%rbx), %rdx
movq %r14, %rdi
callq 0x20e0
leaq -0x38(%rbp), %rsi
movq %rsi, -0x48(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
leaq 0x6a9b(%rip), %r14      # 0xb020
je 0x4621
movq %rdx, -0x48(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x38(%rbp)
jmp 0x4627
movq %rax, -0x70(%rbp)
leaq 0x7149(%rip), %rsi      # 0xb6ef
leaq 0x7156(%rip), %rdx      # 0xb703
movq %rdi, %r14
callq 0x4c4c
movq 0x830(%rbx), %rsi
movq 0x838(%rbx), %rdx
movq %r14, %rdi
callq 0x20e0
leaq -0x38(%rbp), %rsi
movq %rsi, -0x48(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
leaq 0x6a39(%rip), %r14      # 0xb020
je 0x464c
movq %rdx, -0x48(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x38(%rbp)
jmp 0x4652
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, -0x40(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %rbx, %rdi
leaq -0x48(%rbp), %rsi
callq 0x48c2
jmp 0x4675
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, -0x40(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %rbx, %rdi
leaq -0x48(%rbp), %rsi
callq 0x48c2
jmp 0x4675
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, -0x40(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %rbx, %rdi
leaq -0x48(%rbp), %rsi
callq 0x48c2
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x468e
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x46a7
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2210
testb %r15b, %r15b
jne 0x4220
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, %r12d      # imm = 0xFFFFFF4F
movl 0x18(%rax,%rcx), %edx
andl %r12d, %edx
orl $0x20, %edx
movl %edx, 0x18(%rax,%rcx)
movslq %r13d, %r14
shlq $0x5, %r14
leaq 0xab04(%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, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %r15, %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), %r12d
orl $0x20, %r12d
movl %r12d, 0x18(%rax,%rcx)
leaq 0xaa6c(%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
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 %r13d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xaea2(%rip), %rdi      # 0xf6a0
callq 0x2360
testl %eax, %eax
je 0x3fda
leaq 0xae7e(%rip), %rax      # 0xf690
movq %rax, 0xae67(%rip)      # 0xf680
leaq 0xae60(%rip), %rdi      # 0xf680
leaq 0x6e7b(%rip), %rsi      # 0xb6a2
leaq 0x6e88(%rip), %rdx      # 0xb6b6
callq 0x4c4c
movq 0xa786(%rip), %rdi      # 0xefc0
leaq 0xae3f(%rip), %rsi      # 0xf680
leaq 0xa988(%rip), %rdx      # 0xf1d0
callq 0x21c0
leaq 0xae4c(%rip), %rdi      # 0xf6a0
callq 0x2160
jmp 0x3fda
movq %rax, %rbx
leaq 0xae38(%rip), %rdi      # 0xf6a0
callq 0x2150
jmp 0x48ba
jmp 0x487b
jmp 0x4899
jmp 0x48b7
jmp 0x487b
jmp 0x4899
jmp 0x48b7
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x489c
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2210
jmp 0x489c
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x48ba
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2210
jmp 0x48ba
movq %rax, %rbx
movq %rbx, %rdi
callq 0x2340