// File: /workspace/github_cpp_makefile_star2_O1/melop[P]admixem/./parser/parser.cpp
// Function: Parser::Primary(bool)
const double Parser::Primary (const bool get)   // primary (base) tokens
  {
  
  if (get)
    GetToken ();    // one-token lookahead  
  
  switch (type_)
    {
    case NUMBER:  
      {
      double v = value_; 
      GetToken (true);  // get next one (one-token lookahead)
      return v;
      }
    
    case NAME:
      {
      std::string word = word_;
      GetToken (true); 
      if (type_ == LHPAREN)
        {
        // might be single-argument function (eg. abs (x) )
        std::map<std::string, OneArgFunction>::const_iterator si;
        si = OneArgumentFunctions.find (word);
        if (si != OneArgumentFunctions.end ())
          {
          double v = Expression (true);   // get argument
          CheckToken (RHPAREN);
          GetToken (true);        // get next one (one-token lookahead)
          return si->second (v);  // evaluate function
          }
        
        // might be double-argument function (eg. roll (6, 2) )
        std::map<std::string, TwoArgFunction>::const_iterator di;
        di = TwoArgumentFunctions.find (word);
        if (di != TwoArgumentFunctions.end ())
          {
          double v1 = Expression (true);   // get argument 1 (not commalist)
          CheckToken (COMMA);
          double v2 = Expression (true);   // get argument 2 (not commalist)
          CheckToken (RHPAREN);
          GetToken (true);            // get next one (one-token lookahead)
          return di->second (v1, v2); // evaluate function
          }
  
       // might be double-argument function (eg. roll (6, 2) )
        std::map<std::string, ThreeArgFunction>::const_iterator ti;
        ti = ThreeArgumentFunctions.find (word);
        if (ti != ThreeArgumentFunctions.end ())
          {
          double v1 = Expression (true);   // get argument 1 (not commalist)
          CheckToken (COMMA);
          double v2 = Expression (true);   // get argument 2 (not commalist)
          CheckToken (COMMA);
          double v3 = Expression (true);   // get argument 3 (not commalist)
          CheckToken (RHPAREN);
          GetToken (true);  // get next one (one-token lookahead)
          return ti->second (v1, v2, v3); // evaluate function
          }
        
        throw std::runtime_error ("Function '" + word + "' not implemented.");
        }
		
		

      
      // not a function? must be a symbol in the symbol table
      double & v = symbols_ [word];  // get REFERENCE to symbol table entry
      // change table entry with expression? (eg. a = 22, or a = 22)
	  
	  
      switch (type_)
        {
        // maybe check for NaN or Inf here (see: isinf, isnan functions)
        case ASSIGN:     v  = Expression (true); break;   
        case ASSIGN_ADD: v += Expression (true); break;   
        case ASSIGN_SUB: v -= Expression (true); break;   
        case ASSIGN_MUL: v *= Expression (true); break;   
        case ASSIGN_DIV: 
            {
            double d = Expression (true); 
            if (d == 0.0)
              throw std::runtime_error ("Divide by zero");
            v /= d;
            break;   // change table entry with expression
            } // end of ASSIGN_DIV
        default: break;   // do nothing for others
        } // end of switch on type_              
      return v;               // and return new value
      }
    
    case MINUS:               // unary minus
      return - Primary (true);
    
    case NOT:   // unary not
      return (Primary (true) == 0.0) ? 1.0 : 0.0;;
    
    case LHPAREN:
      {
      double v = CommaList (true);    // inside parens, you could have commas
      CheckToken (RHPAREN);
      GetToken (true);                // eat the )
      return v;
      }
    
    default:   
      throw std::runtime_error ("Unexpected token: " + word_);
    
    } // end of switch on type
  
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x80, %rsp
movq %rdi, %rbx
testl %esi, %esi
je 0x9042
movq %rbx, %rdi
xorl %esi, %esi
callq 0x889e
movl 0x30(%rbx), %eax
cmpl $0x20, %eax
jle 0x9077
cmpl $0x21, %eax
je 0x90a5
cmpl $0x28, %eax
je 0x90cc
cmpl $0x2d, %eax
jne 0x93a3
movq %rbx, %rdi
movl $0x1, %esi
callq 0x9022
xorpd 0x2c01e(%rip), %xmm0    # 0x35090
jmp 0x92e9
cmpl $0x1, %eax
je 0x9102
cmpl $0x2, %eax
jne 0x93a3
movsd 0x58(%rbx), %xmm0
movapd %xmm0, (%rsp)
movq %rbx, %rdi
movl $0x1, %esi
callq 0x889e
jmp 0x92e4
movq %rbx, %rdi
movl $0x1, %esi
callq 0x9022
xorpd %xmm1, %xmm1
cmpeqsd %xmm0, %xmm1
movsd 0x2bf55(%rip), %xmm0    # 0x35018
andpd %xmm1, %xmm0
jmp 0x92e9
movq %rbx, %rdi
movl $0x1, %esi
callq 0x961a
movsd %xmm0, (%rsp)
movq %rbx, %rdi
movl $0x29, %esi
callq 0x9a7a
movq %rbx, %rdi
movl $0x1, %esi
callq 0x889e
movsd (%rsp), %xmm0
jmp 0x92e9
leaq 0x28(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x38(%rbx), %rsi
movq 0x40(%rbx), %rdx
addq %rsi, %rdx
leaq 0x18(%rsp), %rdi
callq 0xa916
movq %rbx, %rdi
movl $0x1, %esi
callq 0x889e
cmpl $0x28, 0x30(%rbx)
jne 0x918d
leaq 0x4028e(%rip), %rdi     # 0x493c8
leaq 0x18(%rsp), %rsi
callq 0xad26
movq %rax, %r14
leaq 0x40282(%rip), %rax     # 0x493d0
cmpq %rax, %r14
je 0x91cf
movq %rbx, %rdi
movl $0x1, %esi
callq 0x9598
movsd %xmm0, (%rsp)
movq %rbx, %rdi
movl $0x29, %esi
callq 0x9a7a
movq %rbx, %rdi
movl $0x1, %esi
callq 0x889e
movsd (%rsp), %xmm0
callq *0x40(%r14)
jmp 0x92c8
leaq 0x68(%rbx), %rdi
leaq 0x18(%rsp), %rsi
callq 0x9b86
movq %rax, %r14
movl 0x30(%rbx), %eax
addl $-0x3d, %eax
cmpl $0xb, %eax
ja 0x92c3
leaq 0x2be8c(%rip), %rcx     # 0x35040
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
movl $0x1, %esi
callq 0x9598
jmp 0x92be
leaq 0x40222(%rip), %rdi     # 0x493f8
leaq 0x18(%rsp), %rsi
callq 0xad6c
movq %rax, %r14
leaq 0x40216(%rip), %rax     # 0x49400
cmpq %rax, %r14
je 0x92f9
movq %rbx, %rdi
movl $0x1, %esi
callq 0x9598
movsd %xmm0, (%rsp)
movq %rbx, %rdi
movl $0x2c, %esi
callq 0x9a7a
movq %rbx, %rdi
movl $0x1, %esi
callq 0x9598
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
movl $0x29, %esi
callq 0x9a7a
movq %rbx, %rdi
movl $0x1, %esi
callq 0x889e
movsd (%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq *0x40(%r14)
jmp 0x92c8
movq %rbx, %rdi
movl $0x1, %esi
callq 0x9598
movapd %xmm0, %xmm1
movsd (%r14), %xmm0
subsd %xmm1, %xmm0
jmp 0x92be
movq %rbx, %rdi
movl $0x1, %esi
callq 0x9598
addsd (%r14), %xmm0
jmp 0x92be
movq %rbx, %rdi
movl $0x1, %esi
callq 0x9598
mulsd (%r14), %xmm0
jmp 0x92be
movq %rbx, %rdi
movl $0x1, %esi
callq 0x9598
movapd %xmm0, %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x92b5
jnp 0x93f5
movsd (%r14), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%r14)
movsd (%r14), %xmm0
movq 0x18(%rsp), %rdi
cmpq %r15, %rdi
je 0x92e9
movq 0x28(%rsp), %rsi
incq %rsi
movapd %xmm0, (%rsp)
callq 0x7390
movapd (%rsp), %xmm0
addq $0x80, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x40128(%rip), %rdi     # 0x49428
leaq 0x18(%rsp), %rsi
callq 0xadb2
movq %rax, %r14
leaq 0x4011c(%rip), %rax     # 0x49430
cmpq %rax, %r14
je 0x942c
movq %rbx, %rdi
movl $0x1, %esi
callq 0x9598
movsd %xmm0, (%rsp)
movq %rbx, %rdi
movl $0x2c, %esi
callq 0x9a7a
movq %rbx, %rdi
movl $0x1, %esi
callq 0x9598
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
movl $0x2c, %esi
callq 0x9a7a
movq %rbx, %rdi
movl $0x1, %esi
callq 0x9598
movsd %xmm0, 0x38(%rsp)
movq %rbx, %rdi
movl $0x29, %esi
callq 0x9a7a
movq %rbx, %rdi
movl $0x1, %esi
callq 0x889e
movsd (%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x38(%rsp), %xmm2
callq *0x40(%r14)
jmp 0x92c8
movl $0x10, %edi
callq 0x7180
movq %rax, %r14
addq $0x38, %rbx
leaq 0x2bda6(%rip), %rsi     # 0x35161
leaq 0x18(%rsp), %rdi
movq %rbx, %rdx
callq 0x9981
movb $0x1, %bpl
leaq 0x18(%rsp), %rsi
movq %r14, %rdi
callq 0x75d0
xorl %ebp, %ebp
movq 0x3fc0f(%rip), %rsi     # 0x48ff0
movq 0x3fb98(%rip), %rdx     # 0x48f80
movq %r14, %rdi
callq 0x7660
jmp 0x94d1
movl $0x10, %edi
callq 0x7180
movq %rax, %r14
leaq 0x2bd49(%rip), %rsi     # 0x35152
movq %rax, %rdi
callq 0x7140
movq 0x3fbd8(%rip), %rsi     # 0x48ff0
movq 0x3fb61(%rip), %rdx     # 0x48f80
movq %r14, %rdi
callq 0x7660
jmp 0x94d1
movl $0x10, %edi
callq 0x7180
movq %rax, %r14
leaq 0x2bcf4(%rip), %rsi     # 0x35134
leaq 0x60(%rsp), %rdi
leaq 0x18(%rsp), %rdx
callq 0x9981
leaq 0x2bce9(%rip), %rsi     # 0x3513f
leaq 0x60(%rsp), %rdi
callq 0x76f0
leaq 0x50(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
jne 0x9485
movupd (%rcx), %xmm0
movupd %xmm0, (%r12)
jmp 0x9492
movq %rdx, 0x40(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x50(%rsp)
movq 0x8(%rax), %rdx
leaq 0x40(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movb $0x1, %bpl
movq %r14, %rdi
callq 0x75d0
xorl %ebp, %ebp
movq 0x3fb2e(%rip), %rsi     # 0x48ff0
movq 0x3fab7(%rip), %rdx     # 0x48f80
movq %r14, %rdi
callq 0x7660
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x94f3
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x7390
jmp 0x94f3
movq %rax, %rbx
movb $0x1, %bpl
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9516
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x7390
jmp 0x9516
movq %rax, %rbx
movb $0x1, %bpl
testb %bpl, %bpl
jne 0x9520
jmp 0x9578
movq %rax, %rbx
movq %r14, %rdi
callq 0x72a0
jmp 0x9578
jmp 0x9575
jmp 0x9575
jmp 0x9575
jmp 0x9575
jmp 0x9575
jmp 0x9575
jmp 0x9575
jmp 0x9575
jmp 0x9575
movq %rax, %rbx
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9562
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x7390
jmp 0x9562
movq %rax, %rbx
movb $0x1, %bpl
testb %bpl, %bpl
je 0x958f
movq %r14, %rdi
callq 0x72a0
jmp 0x958f
jmp 0x9575
jmp 0x9575
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %r15, %rdi
je 0x958f
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x7390
movq %rbx, %rdi
callq 0x76a0
nop