// File: /workspace/github_c_makefile_star2_O2/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 0xb131(%rip), %rdi      # 0xdbce
callq 0x6a1e
movq %rax, %rbx
movq %rax, 0x30(%rsp)
leaq 0xb128(%rip), %rdi      # 0xdbd9
callq 0x6a1e
movq %rax, %r14
leaq 0xb121(%rip), %rdi      # 0xdbe1
callq 0x6a1e
movq %rax, %r15
leaq 0xa82b(%rip), %rdi      # 0xd2fa
callq 0x6a1e
movq %rax, %r13
movq %rax, 0x28(%rsp)
leaq 0xb104(%rip), %rsi      # 0xdbe7
xorl %edi, %edi
movq %r14, %rdx
movq %r14, 0x40(%rsp)
xorl %eax, %eax
callq 0xa901
movq %rbx, %rdi
movq %rax, %rsi
callq 0x6cbd
leaq 0xb106(%rip), %rsi      # 0xdc0c
xorl %edi, %edi
movq %r15, 0x38(%rsp)
movq %r15, %rdx
xorl %eax, %eax
callq 0xa901
movq %r14, %rdi
movq %rax, %rsi
callq 0x6cbd
leaq 0xb108(%rip), %rsi      # 0xdc31
xorl %edi, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xa901
movq %r15, %rdi
movq %rax, %rsi
callq 0x6cbd
movq %rbx, %rdi
callq 0xa28b
movq %r13, %rdi
movq %rax, %rsi
callq 0x6cbd
leaq 0xb116(%rip), %rdi      # 0xdc70
leaq 0xb0f2(%rip), %rsi      # 0xdc53
callq 0x9743
movq %rax, 0x20(%rsp)
leaq 0xb0ee(%rip), %r15      # 0xdc60
leaq 0xd988(%rip), %rbx      # 0x10501
movq %r15, %rdi
movq %rbx, %rsi
callq 0x9743
movq %rax, %r14
leaq 0xb0d7(%rip), %rdi      # 0xdc65
leaq 0xb256(%rip), %rsi      # 0xddeb
callq 0x9743
movq %rax, %r13
leaq 0xcb72(%rip), %rsi      # 0xf716
movq %r15, %rdi
callq 0x9743
leaq 0xb0d9(%rip), %rsi      # 0xdc8c
pushq $0x3
popq %rdi
movq %r14, %rdx
movq %r13, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x97b5
leaq 0xb089(%rip), %rsi      # 0xdc56
pushq $0x1
popq %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x97b5
movq %rax, 0x18(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x9743
movq %rax, 0x10(%rsp)
leaq 0xb082(%rip), %rbx      # 0xdc78
leaq 0xa842(%rip), %rsi      # 0xd43f
movq %rbx, %rdi
callq 0x9743
movq %rax, %r14
leaq 0xcd55(%rip), %r13      # 0xf964
movq %r15, %rdi
movq %r13, %rsi
callq 0x9743
movq %rax, %r12
leaq 0xa996(%rip), %rsi      # 0xd5ba
movq %rbx, %rdi
callq 0x9743
movq %rax, %rbp
movq %r15, %rdi
movq %r13, %rsi
callq 0x9743
movq %rax, %r13
leaq 0xb05d(%rip), %rsi      # 0xdca1
movq %rbx, %rdi
callq 0x9743
movq %rax, (%rsp)
pushq $0x5
popq %rdi
leaq 0xaffc(%rip), %rsi      # 0xdc56
movq %r14, %rdx
movq %r12, %rcx
movq %rbp, %r8
movq %r13, %r9
xorl %eax, %eax
callq 0x97b5
movq %rax, %rbx
leaq 0xc50f(%rip), %r13      # 0xf186
movq %r15, %rdi
movq %r13, %rsi
callq 0x9743
movq %rax, %r14
leaq 0xafe4(%rip), %r12      # 0xdc70
movq %r12, %rdi
leaq 0xa924(%rip), %rsi      # 0xd5ba
callq 0x9743
leaq 0xaff2(%rip), %rsi      # 0xdc94
pushq $0x3
popq %rbp
movl %ebp, %edi
movq %rbx, %rdx
movq %r14, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x97b5
movq %rax, %rbx
movq %r15, %rdi
leaq 0xca52(%rip), %rsi      # 0xf716
callq 0x9743
leaq 0xafb4(%rip), %rsi      # 0xdc84
movl %ebp, %edi
movq 0x10(%rsp), %rdx
movq %rbx, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x97b5
movq %rax, %rbx
movq %r15, %rdi
movq %r13, %rsi
callq 0x9743
movq %rax, %r14
movq %r12, %rdi
leaq 0xb0ec(%rip), %rsi      # 0xddeb
callq 0x9743
leaq 0xd7c7(%rip), %rsi      # 0x104d2
movl %ebp, %edi
movq %rbx, %rdx
movq %r14, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x97b5
movq %rax, %rbx
movq %rax, 0x10(%rsp)
leaq 0xaf78(%rip), %rsi      # 0xdca4
leaq 0x6be9(%rip), %r15      # 0x991c
leaq 0x69b9(%rip), %rbp      # 0x96f3
leaq 0x6db4(%rip), %r9       # 0x9af5
movq 0x28(%rsp), %r12
movq %r12, %rdi
movq 0x20(%rsp), %r14
movq %r14, %rdx
movq %r15, %rcx
movq %rbp, %r8
movq %r9, %r13
callq 0x9642
leaq 0xaf44(%rip), %rsi      # 0xdcaa
leaq 0xafcd(%rip), %rdx      # 0xdd3a
pushq $0x2e
popq %rcx
movl %eax, %edi
callq 0x4040
leaq 0xa5c0(%rip), %rsi      # 0xd33e
movq %r12, %rdi
movq 0x18(%rsp), %rdx
movq %r15, %rcx
movq %rbp, %r8
movq %r13, %rbp
movq %r13, %r9
callq 0x9642
leaq 0xafac(%rip), %rsi      # 0xdd4a
pushq $0x2f
popq %rcx
movl %eax, %edi
leaq 0xaf90(%rip), %r13      # 0xdd3a
movq %r13, %rdx
callq 0x4040
leaq 0xb01f(%rip), %rsi      # 0xddd8
movq %r12, %rdi
movq %rbx, %rdx
movq %r15, %rcx
leaq 0x692a(%rip), %r8       # 0x96f3
movq %r8, %rbx
movq %rbp, %r9
callq 0x9642
leaq 0xb012(%rip), %rsi      # 0xdded
pushq $0x30
popq %rcx
movl %eax, %edi
movq %r13, %rdx
callq 0x4040
leaq 0xd6ad(%rip), %rsi      # 0x1049c
movq %r12, %rdi
movq %r14, %rdx
movq %r15, %rcx
movq %rbx, %r8
movq %rbp, %r9
callq 0x95e0
leaq 0xb082(%rip), %rsi      # 0xde8c
pushq $0x31
popq %rcx
movl %eax, %edi
movq %r13, %rdx
callq 0x4040
leaq 0xa61e(%rip), %rsi      # 0xd43c
movq %r12, %rdi
movq %r14, %rdx
movq %r15, %rcx
movq %rbx, %r8
movq %rbp, %r9
callq 0x95e0
leaq 0xb0df(%rip), %rsi      # 0xdf18
pushq $0x32
popq %rcx
movl %eax, %edi
movq %r13, %rdx
callq 0x4040
movq %r14, %rdi
callq 0x96f3
movq 0x18(%rsp), %rdi
callq 0x96f3
movq 0x10(%rsp), %rdi
callq 0x96f3
pushq $0x4
popq %rdi
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 0x6e12