简体   繁体   中英

ANTLR4 grammar doesn't recognize declaration

I have a problem with my ANTLR grammar.

In SQL there are declaration types like UNSIGNED INT or UNSIGNED BIGINT . If I run my grammar with ANTLRWorks in Testrig the parser has a problem with the UNSIGNED .

This is my grammar part for declare_type

declare_type
    : BIT
    | BOOLEAN
    | CHAR ('(' expression ')')?
    | CHARACTER ('(' expression ')')?
    ...

Attempt 1:

    ...
    | UNSIGNED? INT
    | UNSIGNED? BIGINT
    ;

Attempt 2:

    ...
    | INT
    | BIGINT
    | UNSIGNED INT
    | UNSIGNED BIGINT
    ;

Attempt 3:

    ...
    | INT
    | BIGINT
    | unsigned_separable_element
    ;

unsigned_separable_element
    : UNSIGNED INT 
    | UNSIGNED BIGINT
    ;

I hope you guys know what I my problem is, thanks.

EDITED: I uploaded the full grammar to GitHub

Example: DECLARE value UNSIGNED INT; doesn't work because the grammar doesn't recognize UNSIGNED

If I use only INT then it works

I went through the grammar and the problem is not poetic at all. Just a typo in the UNSIGNED lexer rule... It was " UNSIGND" - missing E

Could you specify what kind of a problem do you have? Or at least post whole grammar file? The way lexer rules are specified is important in solving a lot of problems in ANTLR. Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM