// File: navrajsaini[P]PL_Compiler_design_project/scanner.cpp
// Function: Scanner::tokenLine(char*, int)
void Scanner::tokenLine(char now[], int y)
{
   out.open(tokenFileName.c_str(), ios::app);
   string token;
   int prnt, i, b=0;
   //TOKENLINE BLOCK 0
   for(i=0; i<=255; i++)
   {
      ahead=now[i+1];      
      if(isComment(now[i])==true)
      {
	 out.close();
	 return;
      }
      //wiping token for next iteration
      token="";
      while(isSpace(now[i])==true)
      {
	 i++;
	 ahead=now[i+1];
      }
      //TOKENLINE BLOCK 1
      if(isAlpha(now[i])==true)
      {
	 while(isAlpha(now[i])==true)
	 {
	    token.push_back(now[i]);
	    i++;
	    ahead=now[i+1];
	    //just incase there is a numeral inside the word
	    while(isNumeric(now[i])==true)
	    {
	       token.push_back(now[i]);
	       i++;
	       ahead=now[i+1];
	    }	    
	 }
	 //call to store token and move to next token, in this case an alpha
	 prnt = getToken(token);
	 out<<prnt<<" ";
	 i--;
	 ahead=now[i+1];
      }
      //TOKENLINE BLOCK 2
      else if(isNumeric(now[i])==true)
      {
	 while(isNumeric(now[i])==true)
	 {	    
	    token.push_back(now[i]);
	    i++;
	    ahead=now[i+1];	    
	 }
	 if(isAlpha(now[i]==true))
	 {	    
	    cout<<endl<<spellS(BADNAME)<<" on line:" ;
	    return;
	 }
	 //call to store token and move to next token, in this case a numeric
	 prnt = getNum(token);
	 //minus 1 becasue it was incrimnted inside getnum
	 lineToke[TN-1][2] = numericVAl(token);
	 out<<prnt<<" ";
	 i--;
	 ahead=now[i+1];
      }
      //TOKENLINE BLOCK 3
      else if(isSpecial(now[i])==true)
      {
	 token.push_back(now[i]);
	 if(now[i]==':'&&ahead=='=')
	 {
	    token.push_back(ahead);
	    i++;
	    ahead=now[i+1];	    
	 }
	 else if(now[i]=='-'&&ahead=='>')
	 {
	    token.push_back(ahead);
	    i++;
	    ahead=now[i+1];	    
	 }
	 else if(now[i]=='['&&ahead==']')
	 {
	    token.push_back(ahead);
	    i++;
	    ahead=now[i+1];
	    
	 }else
	 {
	 }
	 if(now[i]==92)
	 {
	    prnt = getToken("%");
	    out<<prnt<<" ";
	 }
	 else
	 {
	    //call to store token and move to next token, in this case an alpha
	    prnt = getToken(token);
	    out<<prnt<<" ";
	 }
      }
      //TOKENLINE BLOCK 4
      else if(token=="")
      {
	 //the case of if token is empty is the same as if now[i] is empty
	 //since token has not been initialised to anything from before.
      }
      else
      {	 
	 cout<<endl<<token<<" is a not identified token on line: "<<LN;
	 cout<<endl;
      }
      
   }
   out.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x130(%rbp)
movq %rdi, %rax
addq $0xc30, %rax            # imm = 0xC30
movq %rax, -0x128(%rbp)
addq $0xe50, %rdi            # imm = 0xE50
callq 0x20c0
movq -0x128(%rbp), %rdi
movq %rax, %rsi
movl $0x1, %edx
callq 0x2040
leaq -0x38(%rbp), %rdi
callq 0x22a0
movl $0x0, -0x44(%rbp)
movl $0x0, -0x40(%rbp)
cmpl $0xff, -0x40(%rbp)
jg 0x14539
movq -0x130(%rbp), %rdi
movq -0x10(%rbp), %rcx
movslq -0x40(%rbp), %rax
movb 0x1(%rax,%rcx), %al
movb %al, (%rdi)
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %esi
callq 0x14580
movb %al, -0x131(%rbp)
jmp 0x13cf3
movb -0x131(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x13d35
movq -0x130(%rbp), %rdi
addq $0xc30, %rdi            # imm = 0xC30
callq 0x22b0
jmp 0x13d18
movl $0x1, -0x58(%rbp)
jmp 0x14555
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x14567
leaq 0xbd25(%rip), %rsi      # 0x1fa61
leaq -0x38(%rbp), %rdi
callq 0x2280
jmp 0x13d47
jmp 0x13d49
movq -0x130(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %esi
callq 0x138f0
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x13d8f
movq -0x130(%rbp), %rax
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x40(%rbp)
movq -0x10(%rbp), %rcx
movl -0x40(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movb (%rcx,%rdx), %cl
movb %cl, (%rax)
jmp 0x13d49
movq -0x130(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %esi
callq 0x13920
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x13f26
jmp 0x13db7
movq -0x130(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %esi
callq 0x13920
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x13e78
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %esi
leaq -0x38(%rbp), %rdi
callq 0x2170
jmp 0x13df4
movq -0x130(%rbp), %rax
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x40(%rbp)
movq -0x10(%rbp), %rcx
movl -0x40(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movb (%rcx,%rdx), %cl
movb %cl, (%rax)
movq -0x130(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %esi
callq 0x13970
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x13e73
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %esi
leaq -0x38(%rbp), %rdi
callq 0x2170
jmp 0x13e4f
movq -0x130(%rbp), %rax
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x40(%rbp)
movq -0x10(%rbp), %rcx
movl -0x40(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movb (%rcx,%rdx), %cl
movb %cl, (%rax)
jmp 0x13e16
jmp 0x13db7
leaq -0x78(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x20d0
jmp 0x13e87
movq -0x130(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x13b30
movl %eax, -0x138(%rbp)
jmp 0x13e9f
movl -0x138(%rbp), %eax
movl %eax, -0x3c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x2130
movq -0x130(%rbp), %rdi
addq $0xc30, %rdi            # imm = 0xC30
movl -0x3c(%rbp), %esi
callq 0x2320
movq %rax, -0x140(%rbp)
jmp 0x13ed0
movq -0x140(%rbp), %rdi
leaq 0xbb82(%rip), %rsi      # 0x1fa60
callq 0x21b0
jmp 0x13ee5
movq -0x130(%rbp), %rax
movl -0x40(%rbp), %ecx
addl $-0x1, %ecx
movl %ecx, -0x40(%rbp)
movq -0x10(%rbp), %rcx
movl -0x40(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movb (%rcx,%rdx), %cl
movb %cl, (%rax)
jmp 0x14529
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x2130
jmp 0x14567
movq -0x130(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %esi
callq 0x13970
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x1419c
jmp 0x13f4e
movq -0x130(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %esi
callq 0x13970
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x13fab
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %esi
leaq -0x38(%rbp), %rdi
callq 0x2170
jmp 0x13f87
movq -0x130(%rbp), %rax
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x40(%rbp)
movq -0x10(%rbp), %rcx
movl -0x40(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movb (%rcx,%rdx), %cl
movb %cl, (%rax)
jmp 0x13f4e
movq -0x130(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x1, %eax
sete %al
andb $0x1, %al
movsbl %al, %esi
callq 0x13920
testb $0x1, %al
jne 0x13fd7
jmp 0x1406c
movq 0x12fea(%rip), %rdi     # 0x26fc8
movq 0x12fd3(%rip), %rsi     # 0x26fb8
callq 0x21d0
movq %rax, -0x148(%rbp)
jmp 0x13ff3
leaq -0x98(%rbp), %rdi
movl $0x103, %esi            # imm = 0x103
callq 0x5c50
jmp 0x14006
movq -0x148(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x2190
movq %rax, -0x150(%rbp)
jmp 0x14022
movq -0x150(%rbp), %rdi
leaq 0xb638(%rip), %rsi      # 0x1f668
callq 0x21b0
jmp 0x14037
leaq -0x98(%rbp), %rdi
callq 0x2130
movl $0x1, -0x58(%rbp)
jmp 0x14555
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x2130
jmp 0x14567
leaq -0xb8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x20d0
jmp 0x1407e
movq -0x130(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x13bc0
movl %eax, -0x154(%rbp)
jmp 0x14099
movl -0x154(%rbp), %eax
movl %eax, -0x3c(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x2130
leaq -0xd8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x20d0
jmp 0x140c0
movq -0x130(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x145b0
movl %eax, -0x158(%rbp)
jmp 0x140db
movq -0x130(%rbp), %rax
movl -0x158(%rbp), %edx
movl 0xc2c(%rax), %ecx
decl %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
movl %edx, 0x30(%rax,%rcx,4)
leaq -0xd8(%rbp), %rdi
callq 0x2130
movq -0x130(%rbp), %rdi
addq $0xc30, %rdi            # imm = 0xC30
movl -0x3c(%rbp), %esi
callq 0x2320
movq %rax, -0x160(%rbp)
jmp 0x14126
movq -0x160(%rbp), %rdi
leaq 0xb92c(%rip), %rsi      # 0x1fa60
callq 0x21b0
jmp 0x1413b
movq -0x130(%rbp), %rax
movl -0x40(%rbp), %ecx
addl $-0x1, %ecx
movl %ecx, -0x40(%rbp)
movq -0x10(%rbp), %rcx
movl -0x40(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movb (%rcx,%rdx), %cl
movb %cl, (%rax)
jmp 0x14527
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x2130
jmp 0x14567
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x2130
jmp 0x14567
movq -0x130(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %esi
callq 0x139f0
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x14477
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %esi
leaq -0x38(%rbp), %rdi
callq 0x2170
jmp 0x141d9
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3a, %eax
jne 0x14235
movq -0x130(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3d, %eax
jne 0x14235
movq -0x130(%rbp), %rax
movsbl (%rax), %esi
leaq -0x38(%rbp), %rdi
callq 0x2170
jmp 0x1420e
movq -0x130(%rbp), %rax
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x40(%rbp)
movq -0x10(%rbp), %rcx
movl -0x40(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movb (%rcx,%rdx), %cl
movb %cl, (%rax)
jmp 0x142ed
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2d, %eax
jne 0x1428e
movq -0x130(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3e, %eax
jne 0x1428e
movq -0x130(%rbp), %rax
movsbl (%rax), %esi
leaq -0x38(%rbp), %rdi
callq 0x2170
jmp 0x1426a
movq -0x130(%rbp), %rax
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x40(%rbp)
movq -0x10(%rbp), %rcx
movl -0x40(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movb (%rcx,%rdx), %cl
movb %cl, (%rax)
jmp 0x142eb
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x5b, %eax
jne 0x142e7
movq -0x130(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5d, %eax
jne 0x142e7
movq -0x130(%rbp), %rax
movsbl (%rax), %esi
leaq -0x38(%rbp), %rdi
callq 0x2170
jmp 0x142c3
movq -0x130(%rbp), %rax
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x40(%rbp)
movq -0x10(%rbp), %rcx
movl -0x40(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movb (%rcx,%rdx), %cl
movb %cl, (%rax)
jmp 0x142e9
jmp 0x142e9
jmp 0x142eb
jmp 0x142ed
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x5c, %eax
jne 0x143dd
leaq -0xf9(%rbp), %rdi
movq %rdi, -0x168(%rbp)
callq 0x2350
movq -0x168(%rbp), %rdx
leaq 0xafa7(%rip), %rsi      # 0x1f2ca
leaq -0xf8(%rbp), %rdi
callq 0x2290
jmp 0x14331
movq -0x130(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x13b30
movl %eax, -0x16c(%rbp)
jmp 0x1434c
movl -0x16c(%rbp), %eax
movl %eax, -0x3c(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x2130
leaq -0xf9(%rbp), %rdi
callq 0x21e0
movq -0x130(%rbp), %rdi
addq $0xc30, %rdi            # imm = 0xC30
movl -0x3c(%rbp), %esi
callq 0x2320
movq %rax, -0x178(%rbp)
jmp 0x1438c
movq -0x178(%rbp), %rdi
leaq 0xb6c6(%rip), %rsi      # 0x1fa60
callq 0x21b0
jmp 0x143a1
jmp 0x14472
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x143cc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x2130
leaq -0xf9(%rbp), %rdi
callq 0x21e0
jmp 0x14567
leaq -0x120(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x20d0
jmp 0x143ef
movq -0x130(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x13b30
movl %eax, -0x17c(%rbp)
jmp 0x1440a
movl -0x17c(%rbp), %eax
movl %eax, -0x3c(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x2130
movq -0x130(%rbp), %rdi
addq $0xc30, %rdi            # imm = 0xC30
movl -0x3c(%rbp), %esi
callq 0x2320
movq %rax, -0x188(%rbp)
jmp 0x1443e
movq -0x188(%rbp), %rdi
leaq 0xb614(%rip), %rsi      # 0x1fa60
callq 0x21b0
jmp 0x14453
jmp 0x14472
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x2130
jmp 0x14567
jmp 0x14525
leaq 0xb5e3(%rip), %rsi      # 0x1fa61
leaq -0x38(%rbp), %rdi
callq 0x10ea0
movb %al, -0x189(%rbp)
jmp 0x1448f
movb -0x189(%rbp), %al
testb $0x1, %al
jne 0x1449b
jmp 0x144a0
jmp 0x14523
movq 0x12b21(%rip), %rdi     # 0x26fc8
movq 0x12b0a(%rip), %rsi     # 0x26fb8
callq 0x21d0
movq %rax, -0x198(%rbp)
jmp 0x144bc
movq -0x198(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x2190
movq %rax, -0x1a0(%rbp)
jmp 0x144d5
movq -0x1a0(%rbp), %rdi
leaq 0xb18f(%rip), %rsi      # 0x1f672
callq 0x21b0
movq %rax, -0x1a8(%rbp)
jmp 0x144f1
movq -0x1a8(%rbp), %rdi
movq -0x130(%rbp), %rax
movl 0xc28(%rax), %esi
callq 0x2320
jmp 0x1450c
movq 0x12ab5(%rip), %rdi     # 0x26fc8
movq 0x12a9e(%rip), %rsi     # 0x26fb8
callq 0x21d0
jmp 0x14521
jmp 0x14523
jmp 0x14525
jmp 0x14527
jmp 0x14529
jmp 0x1452b
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x13cb8
movq -0x130(%rbp), %rdi
addq $0xc30, %rdi            # imm = 0xC30
callq 0x22b0
jmp 0x1454e
movl $0x0, -0x58(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x2130
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x2130
movq -0x50(%rbp), %rdi
callq 0x2340
nopl (%rax)