// File: /workspace/github_cpp_makefile_star2_O1/baziotis[P]minijava-cpp/lex.cpp
// Function: lexer_test()
void lexer_test() {
    lexer_init("123 456 0x234", "test.java");
    assert_token_int(123);
    assert_token_int(456);
    assert_token_int(0x234);
    assert_token(TOK::EOI);
    assert_token(TOK::EOI);

    lexer_init("stefanos 456", "test.java");
    assert_token_id("stefanos");
    assert_token_int(456);
    assert_token(TOK::EOI);

    lexer_init("boolean class else if int return while System.out.println", "test.java");
    assert_token(TOK::BOOLEAN);
    assert_token(TOK::CLASS);
    assert_token(TOK::ELSE);
    assert_token(TOK::IF);
    assert_token(TOK::INT);
    assert_token(TOK::RETURN);
    assert_token(TOK::WHILE);
    assert_token(TOK::PRINT);
    assert_token(TOK::EOI);

    lexer_init("&& \0 another", "test.java");
    assert_token(TOK::AND_AND);
    assert_token(TOK::EOI);
    assert_token(TOK::EOI);

    lexer_init("&&  ( ) { } [ ] , ; ! = - + *", "test.java");
    assert_token(TOK::AND_AND);
    assert_token(TOK::LPAR);
    assert_token(TOK::RPAR);
    assert_token(TOK::LBRACE);
    assert_token(TOK::RBRACE);
    assert_token(TOK::LBRACKET);
    assert_token(TOK::RBRACKET);
    assert_token(TOK::COMMA);
    assert_token(TOK::SEMI);
    assert_token(TOK::NOT);
    assert_token(TOK::ASGN);
    assert_token(TOK::MINUS);
    assert_token(TOK::PLUS);
    assert_token(TOK::STAR);
    assert_token(TOK::EOI);

    // Note: No error!
    lexer_init("0r8", "test.java");
    assert_token_int(0);
    assert_token_id("r8");
    assert_token(TOK::EOI);

    // **  Warnings / Errors  ** //

    // Warning: floatings are not supported
    lexer_init(".45", "test.java");
    assert_token(TOK::DOT);
    assert_token_int(45);
    assert_token(TOK::EOI);
    // Syntax Error: Invalid hex constant
    lexer_init("0xw", "test.java");
    // Warning: Integer literal overflow
    lexer_init("0xffffffff", "test.java");
    // Warning: There's no `&` token.
    lexer_init("& +", "test.java");
    // Syntax Error: Invalid octal integer literal.
    lexer_init("085", "test.java");
    // Syntax Error: Digit `8` is out of range for base 8.
    lexer_init("058", "test.java");
}

// Assembly:
pushq %rax
leaq 0xc78c(%rip), %rdi      # 0x10c47
callq 0x43e6
movl $0x7b, %edi
callq 0x4331
movl $0x1c8, %edi            # imm = 0x1C8
callq 0x4331
movl $0x234, %edi            # imm = 0x234
callq 0x4331
movl $0x1, %edi
callq 0x4305
movl $0x1, %edi
callq 0x4305
leaq 0xc75c(%rip), %rdi      # 0x10c55
callq 0x43e6
leaq 0xc75d(%rip), %rdi      # 0x10c62
callq 0x4366
movl $0x1c8, %edi            # imm = 0x1C8
callq 0x4331
movl $0x1, %edi
callq 0x4305
leaq 0xc746(%rip), %rdi      # 0x10c6b
callq 0x43e6
movl $0x5, %edi
callq 0x4305
movl $0x16, %edi
callq 0x4305
movl $0xd, %edi
callq 0x4305
movl $0x9, %edi
callq 0x4305
movl $0x6, %edi
callq 0x4305
movl $0xe, %edi
callq 0x4305
movl $0xa, %edi
callq 0x4305
movl $0xb, %edi
callq 0x4305
movl $0x1, %edi
callq 0x4305
leaq 0xc45d(%rip), %rdi      # 0x109e8
callq 0x43e6
movl $0x1f, %edi
callq 0x4305
movl $0x1, %edi
callq 0x4305
movl $0x1, %edi
callq 0x4305
leaq 0xc6f0(%rip), %rdi      # 0x10ca5
callq 0x43e6
movl $0x1f, %edi
callq 0x4305
movl $0x3, %edi
callq 0x4305
movl $0x19, %edi
callq 0x4305
movl $0x7, %edi
callq 0x4305
movl $0x1a, %edi
callq 0x4305
movl $0x24, %edi
callq 0x4305
movl $0x1b, %edi
callq 0x4305
movl $0x1c, %edi
callq 0x4305
movl $0x1e, %edi
callq 0x4305
movl $0x4, %edi
callq 0x4305
movl $0x18, %edi
callq 0x4305
movl $0x22, %edi
callq 0x4305
movl $0x21, %edi
callq 0x4305
movl $0x23, %edi
callq 0x4305
movl $0x1, %edi
callq 0x4305
leaq 0xc66c(%rip), %rdi      # 0x10cc3
callq 0x43e6
xorl %edi, %edi
callq 0x4331
leaq 0xc65a(%rip), %rdi      # 0x10cc4
callq 0x4366
movl $0x1, %edi
callq 0x4305
leaq 0xc647(%rip), %rdi      # 0x10cc7
callq 0x43e6
movl $0x1d, %edi
callq 0x4305
movl $0x2d, %edi
callq 0x4331
movl $0x1, %edi
callq 0x4305
leaq 0xc621(%rip), %rdi      # 0x10ccb
callq 0x43e6
leaq 0xc619(%rip), %rdi      # 0x10ccf
callq 0x43e6
leaq 0xc618(%rip), %rdi      # 0x10cda
callq 0x43e6
leaq 0xc610(%rip), %rdi      # 0x10cde
callq 0x43e6
leaq 0xc608(%rip), %rdi      # 0x10ce2
popq %rax
jmp 0x43e6