简体   繁体   中英

NoViableAltException when parsing string literals with ANTLR

I am very new to ANTLR, trying to parse a simple PL/SQL function. My apologies if this is a silly question.

function MyFunc return boolean is 
begin

    IF :USER_ID_P IS NULL THEN
        :USER_ID_P := 'PUBLIC'; 
    END IF;
return (TRUE);
end;

Grammar excerpt that is supposed to catch it:

atom
: variable_or_function_call ( PERCENT attribute )?
    | SQL PERCENT attribute
    | string_literal
    | numeric_atom
    | boolean_atom
    | NULL
    | LPAREN expression RPAREN
    ;


string_literal
    : QUOTED_STRING
    ;

QUOTED_STRING
    :    ( 'n' )? '\'' ( '\'\'' | ~('\'') )* '\''
    ;

It gets to the "atom" rule and then gives this error:

NoViableAltException: line 6:0 no viable alternative for input 'END'

The string gets picked up if I add the following to the "atom" rule:

| '\'PUBLIC\''

I think you are getting this error because of other rules (or lack of them.) It says it got as far as the END token but couldn't match any rule. You might have missed a semicolon token somewhere in your rules for instance. In any case, the full grammar is needed to understand it.

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