// File: /workspace/github_c_makefile_star2_O1/orangeduck[P]mpc/tests/grammar.c
// Function: test_grammar
void test_grammar(void) {

  mpc_parser_t *Expr, *Prod, *Value, *Maths;
  mpc_ast_t *t0, *t1, *t2;
  
  Expr  = mpc_new("expression");
  Prod  = mpc_new("product");
  Value = mpc_new("value");
  Maths = mpc_new("maths");
  
  mpc_define(Expr,  mpca_grammar(MPCA_LANG_DEFAULT, " <product> (('+' | '-') <product>)* ", Prod));
  mpc_define(Prod,  mpca_grammar(MPCA_LANG_DEFAULT, " <value>   (('*' | '/')   <value>)* ", Value));
  mpc_define(Value, mpca_grammar(MPCA_LANG_DEFAULT, " /[0-9]+/ | '(' <expression> ')' ", Expr));
  mpc_define(Maths, mpca_total(Expr));
  
  t0 = mpc_ast_new("product|value|regex", "24");
  t1 = mpc_ast_build(1, "product|>",
    mpc_ast_build(3, "value|>",
      mpc_ast_new("char", "("),
      mpc_ast_new("expression|product|value|regex", "5"),
      mpc_ast_new("char", ")")));
  
  t2 = mpc_ast_build(3, ">",
      
      mpc_ast_build(3, "product|value|>",
        mpc_ast_new("char", "("),
        mpc_ast_build(3, "expression|>",
          
          mpc_ast_build(5, "product|>", 
            mpc_ast_new("value|regex", "4"),
            mpc_ast_new("char", "*"),
            mpc_ast_new("value|regex", "2"),
            mpc_ast_new("char", "*"),
            mpc_ast_new("value|regex", "11")),
            
          mpc_ast_new("char", "+"),
          mpc_ast_new("product|value|regex", "2")),
        mpc_ast_new("char", ")")),
      
      mpc_ast_new("char", "+"),
      mpc_ast_new("product|value|regex", "5"));
  
  PT_ASSERT(mpc_test_pass(Maths, "  24 ", t0, (int(*)(const void*,const void*))mpc_ast_eq, (mpc_dtor_t)mpc_ast_delete, (void(*)(const void*))mpc_ast_print));
  PT_ASSERT(mpc_test_pass(Maths, "(5)", t1, (int(*)(const void*,const void*))mpc_ast_eq, (mpc_dtor_t)mpc_ast_delete, (void(*)(const void*))mpc_ast_print));
  PT_ASSERT(mpc_test_pass(Maths, "(4 * 2 * 11 + 2) + 5", t2, (int(*)(const void*,const void*))mpc_ast_eq, (mpc_dtor_t)mpc_ast_delete, (void(*)(const void*))mpc_ast_print));
  PT_ASSERT(mpc_test_fail(Maths, "a", t0, (int(*)(const void*,const void*))mpc_ast_eq, (mpc_dtor_t)mpc_ast_delete, (void(*)(const void*))mpc_ast_print));
  PT_ASSERT(mpc_test_fail(Maths, "2b+4", t0, (int(*)(const void*,const void*))mpc_ast_eq, (mpc_dtor_t)mpc_ast_delete, (void(*)(const void*))mpc_ast_print));

  mpc_ast_delete(t0);
  mpc_ast_delete(t1);
  mpc_ast_delete(t2);
  
  mpc_cleanup(4, Expr, Prod, Value, Maths);
  
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
leaq 0xd0f5(%rip), %rdi      # 0xfbce
callq 0x7191
movq %rax, %rbx
movq %rax, 0x30(%rsp)
leaq 0xd0ec(%rip), %rdi      # 0xfbd9
callq 0x7191
movq %rax, %r14
leaq 0xd0e5(%rip), %rdi      # 0xfbe1
callq 0x7191
movq %rax, %r15
leaq 0xc7ef(%rip), %rdi      # 0xf2fa
callq 0x7191
movq %rax, %r13
movq %rax, 0x28(%rsp)
leaq 0xd0c8(%rip), %rsi      # 0xfbe7
xorl %edi, %edi
movq %r14, %rdx
movq %r14, 0x40(%rsp)
xorl %eax, %eax
callq 0xc477
movq %rbx, %rdi
movq %rax, %rsi
callq 0x7478
leaq 0xd0ca(%rip), %rsi      # 0xfc0c
xorl %edi, %edi
movq %r15, 0x38(%rsp)
movq %r15, %rdx
xorl %eax, %eax
callq 0xc477
movq %r14, %rdi
movq %rax, %rsi
callq 0x7478
leaq 0xd0cc(%rip), %rsi      # 0xfc31
xorl %edi, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xc477
movq %r15, %rdi
movq %rax, %rsi
callq 0x7478
movq %rbx, %rdi
callq 0xb95f
movq %r13, %rdi
movq %rax, %rsi
callq 0x7478
leaq 0xd0da(%rip), %rdi      # 0xfc70
leaq 0xd0b6(%rip), %rsi      # 0xfc53
callq 0xab6f
movq %rax, 0x20(%rsp)
leaq 0xd0b2(%rip), %r15      # 0xfc60
leaq 0xf92c(%rip), %r14      # 0x124e1
movq %r15, %rdi
movq %r14, %rsi
callq 0xab6f
movq %rax, %rbx
leaq 0xd09b(%rip), %rdi      # 0xfc65
leaq 0xd21a(%rip), %rsi      # 0xfdeb
callq 0xab6f
movq %rax, %r13
leaq 0xeb36(%rip), %rsi      # 0x11716
movq %r15, %rdi
callq 0xab6f
leaq 0xd09d(%rip), %rsi      # 0xfc8c
movl $0x3, %edi
movq %rbx, %rdx
movq %r13, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xabe9
leaq 0xd04b(%rip), %rsi      # 0xfc56
movl $0x1, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0xabe9
movq %rax, 0x18(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0xab6f
movq %rax, 0x10(%rsp)
leaq 0xd042(%rip), %r14      # 0xfc78
leaq 0xc802(%rip), %rsi      # 0xf43f
movq %r14, %rdi
callq 0xab6f
movq %rax, %rbp
leaq 0xed15(%rip), %rbx      # 0x11964
movq %r15, %rdi
movq %rbx, %rsi
callq 0xab6f
movq %rax, %r12
leaq 0xc956(%rip), %rsi      # 0xf5ba
movq %r14, %rdi
callq 0xab6f
movq %rax, %r13
movq %r15, %rdi
movq %rbx, %rsi
callq 0xab6f
movq %rax, %rbx
leaq 0xd01d(%rip), %rsi      # 0xfca1
movq %r14, %rdi
callq 0xab6f
movq %rax, (%rsp)
movl $0x5, %edi
leaq 0xcfba(%rip), %rsi      # 0xfc56
movq %rbp, %rdx
movq %r12, %rcx
movq %r13, %r8
movq %rbx, %r9
xorl %eax, %eax
callq 0xabe9
movq %rax, %r14
leaq 0xe4cd(%rip), %rbx      # 0x11186
movq %r15, %rdi
movq %rbx, %rsi
callq 0xab6f
movq %rax, %r12
leaq 0xcfa2(%rip), %r13      # 0xfc70
movq %r13, %rdi
leaq 0xc8e2(%rip), %rsi      # 0xf5ba
callq 0xab6f
leaq 0xcfb0(%rip), %rsi      # 0xfc94
movl $0x3, %edi
movq %r14, %rdx
movq %r12, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xabe9
movq %rax, %r14
movq %r15, %rdi
leaq 0xea10(%rip), %rsi      # 0x11716
callq 0xab6f
leaq 0xcf72(%rip), %rsi      # 0xfc84
movl $0x3, %edi
movq 0x10(%rsp), %rdx
movq %r14, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xabe9
movq %rax, %r14
movq %r15, %rdi
movq %rbx, %rsi
callq 0xab6f
movq %rax, %rbx
movq %r13, %rdi
leaq 0xd0a7(%rip), %rsi      # 0xfdeb
callq 0xab6f
leaq 0xf762(%rip), %rsi      # 0x124b2
movl $0x3, %edi
movq %r14, %rdx
movq %rbx, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xabe9
movq %rax, %rbx
movq %rax, 0x10(%rsp)
leaq 0xcf30(%rip), %rsi      # 0xfca4
leaq 0x801e(%rip), %r15      # 0xad99
leaq 0x7d95(%rip), %rbp      # 0xab17
leaq 0x81f5(%rip), %r9       # 0xaf7e
movq 0x28(%rsp), %r12
movq %r12, %rdi
movq 0x20(%rsp), %r14
movq %r14, %rdx
movq %r15, %rcx
movq %rbp, %r8
movq %r9, %r13
callq 0xaa3c
leaq 0xcefc(%rip), %rsi      # 0xfcaa
leaq 0xcf85(%rip), %rdx      # 0xfd3a
movl %eax, %edi
movl $0x2e, %ecx
callq 0x4050
leaq 0xc576(%rip), %rsi      # 0xf33e
movq %r12, %rdi
movq 0x18(%rsp), %rdx
movq %r15, %rcx
movq %rbp, %r8
movq %r13, %rbp
movq %r13, %r9
callq 0xaa3c
leaq 0xcf62(%rip), %rsi      # 0xfd4a
movl %eax, %edi
leaq 0xcf49(%rip), %r13      # 0xfd3a
movq %r13, %rdx
movl $0x2f, %ecx
callq 0x4050
leaq 0xcfd3(%rip), %rsi      # 0xfdd8
movq %r12, %rdi
movq %rbx, %rdx
movq %r15, %rcx
leaq 0x7d02(%rip), %r8       # 0xab17
movq %r8, %rbx
movq %rbp, %r9
callq 0xaa3c
leaq 0xcfc6(%rip), %rsi      # 0xfded
movl %eax, %edi
movq %r13, %rdx
movl $0x30, %ecx
callq 0x4050
leaq 0xf63f(%rip), %rsi      # 0x1247c
movq %r12, %rdi
movq %r14, %rdx
movq %r15, %rcx
movq %rbx, %r8
movq %rbp, %r9
callq 0xa9c0
leaq 0xd034(%rip), %rsi      # 0xfe8c
movl %eax, %edi
movq %r13, %rdx
movl $0x31, %ecx
callq 0x4050
leaq 0xc5ce(%rip), %rsi      # 0xf43c
movq %r12, %rdi
movq %r14, %rdx
movq %r15, %rcx
movq %rbx, %r8
movq %rbp, %r9
callq 0xa9c0
leaq 0xd08f(%rip), %rsi      # 0xff18
movl %eax, %edi
movq %r13, %rdx
movl $0x32, %ecx
callq 0x4050
movq %r14, %rdi
callq 0xab17
movq 0x18(%rsp), %rdi
callq 0xab17
movq 0x10(%rsp), %rdi
callq 0xab17
movl $0x4, %edi
movq 0x30(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x38(%rsp), %rcx
movq %r12, %r8
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x75e0