3
votes

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\''
1
How are you testing this? With ANTLRWorks' interpreter (or with ANTLR IDE Eclipse)? I that case, try again with ANTLRWorks' debugger: it most probably matches string_literal: the interpreter from ANTLRWorks is rather buggy, to put it mildly. The debugger works great, however.Bart Kiers
I am using the ANTLR IDE in Eclipse. Thanks for the tip, I will try ANTLRWorks.user897210
No problem. Be sure to use the debugger (menu: Run->Debug, or CTRL+D), not the interpreter.Bart Kiers

1 Answers

1
votes

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.