// File: princelab[P]emass/parser.cpp
// Function: Parser::Tokenizer::get_token()
void Parser::Tokenizer::get_token()
{
  States s = START;
  _last = _i;
  for(;;)
    {
      wchar_t c = _input[_i];
      switch(s) {
      case START:
	if(iswspace(c)) {
	  ; // skip whitespace
	} else if(iswdigit(c) || c == L'-') {
	  _ttype = NUM;	
	  _tval = c;
	  s = NUMBER;
	} else if(iswupper(c)) {
	  _ttype = ELEMENT;
	  _tval = c;
	  s = ALPHA;
	} else if(c == L'[') {
	  _ttype = ELEMENT;
	  _tval = L"";
	  s = LITERAL;
	} else if(c == L'(') {
	  _ttype = LPAREN;
	  s = STOP;
	} else if(c == L')') {
	  _ttype = RPAREN;
	  s = STOP;
	} else if(c == L'%') {
	  _ttype = EOS;
	  s = END;
	} else {
	  error(L"Parse error");
	}
	break;
      case ALPHA:
	if(iswlower(c)) {
	  _tval += c;
	} else {
	  return; // we're done
	}
	break;
      case LITERAL:
	if(c == L'%') {
	  error(L"Missing left bracket");
	} else if(c != L']') {
	  _tval += c;
	} else {
	  ++_i; // skip the ']'
	  return; // we're done
	}	
	break;
      case NUMBER:
	if(iswdigit(c)) {
	  _tval += c;
	} else {
	  return; // we're done
	}
	break;
      case END:
	if(_input.find(ENDTOKEN) == _i - 1) {
	  s = STOP;
	} else {
	  error(L"Illegal character: \'%\'");
	}
	break;
      case STOP:
	return; // exit
      }
      ++_i;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movl $0x0, -0xc(%rbp)
movq 0x28(%rax), %rcx
movq %rcx, 0x30(%rax)
movq -0xa0(%rbp), %rax
movq %rax, %rdi
addq $0x38, %rdi
movq 0x28(%rax), %rsi
callq 0x44b0
movl (%rax), %eax
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
movq %rax, -0xa8(%rbp)
subq $0x5, %rax
ja 0xcb66
movq -0xa8(%rbp), %rax
leaq 0x59bd(%rip), %rcx      # 0x12194
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x10(%rbp), %edi
callq 0x4280
cmpl $0x0, %eax
je 0xc7f2
jmp 0xc974
movl -0x10(%rbp), %edi
callq 0x4720
cmpl $0x0, %eax
jne 0xc805
cmpl $0x2d, -0x10(%rbp)
jne 0xc82a
movq -0xa0(%rbp), %rdi
movl $0x3, (%rdi)
movl -0x10(%rbp), %esi
addq $0x8, %rdi
callq 0x46d0
movl $0x3, -0xc(%rbp)
jmp 0xc972
movl -0x10(%rbp), %edi
callq 0x45c0
cmpl $0x0, %eax
je 0xc85c
movq -0xa0(%rbp), %rdi
movl $0x4, (%rdi)
movl -0x10(%rbp), %esi
addq $0x8, %rdi
callq 0x46d0
movl $0x1, -0xc(%rbp)
jmp 0xc970
cmpl $0x5b, -0x10(%rbp)
jne 0xc88b
movq -0xa0(%rbp), %rdi
movl $0x4, (%rdi)
addq $0x8, %rdi
leaq 0x5a82(%rip), %rsi      # 0x122fc
callq 0x4670
movl $0x2, -0xc(%rbp)
jmp 0xc96e
cmpl $0x28, -0x10(%rbp)
jne 0xc8aa
movq -0xa0(%rbp), %rax
movl $0x0, (%rax)
movl $0x5, -0xc(%rbp)
jmp 0xc96c
cmpl $0x29, -0x10(%rbp)
jne 0xc8c9
movq -0xa0(%rbp), %rax
movl $0x1, (%rax)
movl $0x5, -0xc(%rbp)
jmp 0xc96a
cmpl $0x25, -0x10(%rbp)
jne 0xc8e8
movq -0xa0(%rbp), %rax
movl $0x2, (%rax)
movl $0x4, -0xc(%rbp)
jmp 0xc968
leaq -0x31(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x4150
movq -0xb0(%rbp), %rdx
leaq 0x5a06(%rip), %rsi      # 0x1230c
leaq -0x30(%rbp), %rdi
callq 0xd6c0
jmp 0xc911
movq -0xa0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xd030
jmp 0xc923
leaq -0x30(%rbp), %rdi
callq 0x4738
leaq -0x31(%rbp), %rdi
callq 0x4640
jmp 0xc968
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xc95a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x4738
leaq -0x31(%rbp), %rdi
callq 0x4640
jmp 0xcb87
jmp 0xc96a
jmp 0xc96c
jmp 0xc96e
jmp 0xc970
jmp 0xc972
jmp 0xc974
jmp 0xcb66
movl -0x10(%rbp), %edi
callq 0x46c0
cmpl $0x0, %eax
je 0xc99b
movq -0xa0(%rbp), %rdi
movl -0x10(%rbp), %esi
addq $0x8, %rdi
callq 0x4200
jmp 0xc9a0
jmp 0xcb7e
jmp 0xcb66
cmpl $0x25, -0x10(%rbp)
jne 0xca2f
leaq -0x69(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0x4150
movq -0xb8(%rbp), %rdx
leaq 0x596f(%rip), %rsi      # 0x1233c
leaq -0x68(%rbp), %rdi
callq 0xd6c0
jmp 0xc9d8
movq -0xa0(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xd030
jmp 0xc9ea
leaq -0x68(%rbp), %rdi
callq 0x4738
leaq -0x69(%rbp), %rdi
callq 0x4640
jmp 0xca64
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xca21
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x4738
leaq -0x69(%rbp), %rdi
callq 0x4640
jmp 0xcb87
cmpl $0x5d, -0x10(%rbp)
je 0xca4a
movq -0xa0(%rbp), %rdi
movl -0x10(%rbp), %esi
addq $0x8, %rdi
callq 0x4200
jmp 0xca62
movq -0xa0(%rbp), %rax
movq 0x28(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x28(%rax)
jmp 0xcb7e
jmp 0xca64
jmp 0xcb66
movl -0x10(%rbp), %edi
callq 0x4720
cmpl $0x0, %eax
je 0xca8b
movq -0xa0(%rbp), %rdi
movl -0x10(%rbp), %esi
addq $0x8, %rdi
callq 0x4200
jmp 0xca90
jmp 0xcb7e
jmp 0xcb66
movq -0xa0(%rbp), %rdi
addq $0x38, %rdi
leaq 0xe9d9(%rip), %rsi      # 0x1b480
xorl %eax, %eax
movl %eax, %edx
callq 0x4700
movq -0xa0(%rbp), %rcx
movq 0x28(%rcx), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0xcad0
movl $0x5, -0xc(%rbp)
jmp 0xcb62
leaq -0x91(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x4150
movq -0xc0(%rbp), %rdx
leaq 0x589f(%rip), %rsi      # 0x12390
leaq -0x90(%rbp), %rdi
callq 0xd6c0
jmp 0xcaff
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0xd030
jmp 0xcb14
leaq -0x90(%rbp), %rdi
callq 0x4738
leaq -0x91(%rbp), %rdi
callq 0x4640
jmp 0xcb62
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xcb54
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x4738
leaq -0x91(%rbp), %rdi
callq 0x4640
jmp 0xcb87
jmp 0xcb66
jmp 0xcb7e
movq -0xa0(%rbp), %rax
movq 0x28(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x28(%rax)
jmp 0xc799
addq $0xc0, %rsp
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x4620