Need help to resolve error in antlr compile grammar

60 views
Skip to first unread message

alex;

unread,
Mar 2, 2018, 1:23:10 PM3/2/18
to antlr-discussion
Hi, friends.

Please, help.

I don't know how to resolvw errors

warning(200): c:\dev\antlr3\grammar\harbour\Harbour.g:53:83:
Decision can match input such as "{EQ, Equal, NE}" using multiple alternatives: 1, 2

As a result, alternative(s) 2 were disabled for that input
warning(200): c:\dev\antlr3\grammar\harbour\Harbour.g:62:73:
Decision can match input such as "{GE..GT, LE, LT}" using multiple alternatives: 1, 2

As a result, alternative(s) 2 were disabled for that input
error(211): c:\dev\antlr3\grammar\harbour\Harbour.g:69:79:
[fatal] rule expressionLogicalRelationalLiteral has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2. 
Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
error(211): c:\dev\antlr3\grammar\harbour\Harbour.g:74:73:
[fatal] rule expressionLogicalRelationalMath has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2. 
Resolve by left-factoring or using syntactic predicates or using backtrack=true option.

In antlr3 grammar:
grammar Harbour;

fileProgram
   
:
   
(expression crlfStmnt)*
    EOF
   
;

commonExpression
   
: simpleCommonExpression
   
;

simpleCommonExpression
   
: macroAny
   
| identName
   
| nilValue
   
| '(' commonExpression ')'
   
;

//--
expressionAdditiveLiteral
   
: primaryLiteralExpression (Plus primaryLiteralExpression)*
   
;

primaryLiteralExpression
options
{backtrack=true;}
   
: literalValue
   
| dateValue
   
| timeStampValue
   
| commonExpression
   
| '(' expressionAdditiveLiteral ')'
   
;

//--

extExpressionLogical
options
{backtrack=true;}
   
: '(' expressionLogicalOr ')'
   
| expressionLogicalOr
   
;

expressionLogicalOr
   
: expressionLogicalAnd (OR expressionLogicalAnd)*
   
;

expressionLogicalAnd
   
: expressionLogicalEQ (AND expressionLogicalEQ)*
   
;

expressionLogicalEQ
options
{backtrack=true;}
   
: expressionLogicalRelational ((EQ | Equal) | NE) commonExpression
   
| expressionLogicalRelational (((EQ | Equal) | NE) expressionLogicalRelational)*
//    | '(' assignmentExpression ')' ((EQ | Equal) | NE) expression
   
;
   
expressionLogicalRelational
options
{backtrack=true;}
   
: expressionLogicalRelationalLiteral
//    | commonExpression ((LT | GT | LE | GE | (EQ | Equal) | NE) commonExpression)+
   
| expressionLogicalRelationalMath
   
| expressionLogicalUnary ((LT | GT | LE | GE) expressionLogicalUnary)*
//    | '(' assignmentExpression ')' (LT | GT | LE | GE) expression
   
;

expressionLogicalRelationalLiteral
options
{backtrack=true;}
   
: expressionAdditiveLiteral INOP expressionAdditiveLiteral
   
| expressionAdditiveLiteral ((LT | GT | LE | GE) expressionAdditiveLiteral)+
   
;
   
expressionLogicalRelationalMath
options
{backtrack=true;}
   
: expressionAdditiveMath ((LT | GT | LE | GE) expressionAdditiveMath)+
   
;

   
expressionLogicalUnary  
   
: postfixLogicalExpression
   
| NOT expressionLogicalEQ
   
;

postfixLogicalExpression
options
{backtrack=true;}
   
: primaryLogicalExpression
   
| commonExpression
   
;
   
primaryLogicalExpression
   
: logicalValue
   
| '(' expressionLogicalOr ')'
   
;

//-
expressionAdditiveMath
   
: expressionMultiplicativeMath (additiveOperator expressionMultiplicativeMath)*
   
;

expressionMultiplicativeMath
   
: exprMathPOWER (('*' | '/' | '%') exprMathPOWER)*
   
;

exprMathPOWER  
   
: expressionMathUnary (POWER expressionMathUnary)*
   
;

expressionMathUnary
   
: (INC | DEC) extID
   
| additiveOperator? postfixMathExpression
   
;

postfixMathExpression
options
{backtrack=true;}
   
: primaryMathExpression
   
| extID (INC | DEC)
   
| commonExpression
   
;

primaryMathExpression
   
: numValue
   
| HexadecimalConstant
   
| '(' expressionAdditiveMath ')'
   
;

//--
expression
options
{backtrack=true;}
   
: expressionAdditiveMath (Comma expressionAdditiveMath)*
   
;


//--

macroAny
   
: macroVar
   
| macroExpr
   
;
   
macroVar
   
: Ampersand variable
//         | MACROTEXT
   
;

macroExpr
   
: Ampersand pareExpList
   
;

pareExpList
   
: '(' expList ')'
   
;

expList    
   
: expressionAdditiveMath (Comma expressionAdditiveMath)*
   
;

//---

variable
   
: identName
   
;

logicalValue  
   
: TRUEVALUE          
   
| FALSEVALUE        
   
;

nilValue  
   
: NIL                    
   
;

literalValue
   
: LITERAL
   
| LITERALe
   
| LITERALt
   
;

dateValue  
   
: '"' num_date '"'
   
;

timeStampValue
   
:'"' num_date NumDayMonthYear ':' NumDayMonthYear NUM_DOUBLE? '"'
   
;

num_date
   
: NumYear dateDelim NumDayMonthYear dateDelim NumDayMonthYear
   
| NumDayMonthYear dateDelim NumDayMonthYear dateDelim NumYear
   
| NumDayMonthYear dateDelim NumDayMonthYear dateDelim NumDayMonthYear
   
;

dateDelim
:    '/'|'.'|'-'|':';

numValue  
   
: NUM_DOUBLE
   
| NUM_LONG
   
;

additiveOperator
   
: Plus | Minus;

crlfStmnt
   
: Crlf+
   
;

extID
   
: identName
   
| '(' identName ')'
   
;

identName  
   
: ID
   
| DO
   
| AS_ARRAY
   
| STEP
   
| TO  
   
| LOOP
   
| EXIT
   
| IN  
   
| OPTIONAL
   
| EXTERN  
   
| DYNAMIC
   
| ANNOUNCE
   
| LOCAL  
   
| MEMVAR  
   
| STATIC  
   
| PRIVATE
   
| PUBLIC  
   
| PARAMETERS
   
| PROCREQ  
   
| DESCEND  
   
| THREAD
   
| BREAK
   
;

aS_OBJECT
:                             OBJECT;

//Lexer

ANYTYPE
:                               A N Y T (Y (P E?)?)?;
AS_ARRAY
:                              A R R A Y?;
AS_BLOCK
:                              B L O C K? | C O D E (B (L (O (C K?)?)?)?)?;
AS_CHARACTER
:                          C H A R (A (C (T (E R?)?)?)?)? | S T R I (N G?)?;
AS_CLASS
:                              C L A S S?;
AS_DATE
:                               D A T E;
AS_DATETIME
:                           D A T E T (I (M E?)?)? | T I M E S (T (A (M P?)?)?)?;
AS_HASH
:                               H A S H;
AS_LOGICAL
:                            L O G I (C (A L?)?)?;
AS_POINTER
:                            P O I N (T (E R?)?)?;
AS_SYMBOL
:                             S Y M B (O L?)?;
AS_VARIANT
:                            U S U A L?;
AS_NUMERIC
:                            N U M E (R (I C?)?)?;

AS_NUMERIC_ARRAY
:                      N U M E R I C A (R (R (A Y?)?)?)?;
AS_CHARACTER_ARRAY
:                    (C H A R A C T E R | S T R I N G) A (R (R (A Y?)?)?)?;
AS_DATE_ARRAY
:                         D A T E A (R (R (A Y?)?)?);
AS_LOGICAL_ARRAY
:                      L O G I C A L A (R (R (A Y?)?)?)?;
AS_ARRAY_ARRAY
:                        A R R A Y A (R (R (A Y?)?)?)?;
AS_BLOCK_ARRAY
:                        B L O C K A (R (R (A Y?)?)?)?;
AS_OBJECT_ARRAY
:                       O B J E C T A (R (R (A Y?)?)?)?;
AS_CLASS_ARRAY
:                        C L A S S A (R (R (A Y?)?)?)?;


// Basic keywords

ALWAYS
:                                A L W A (Y S?)?;
ANNOUNCE
:                              A N N O (U (N (C E?)?)?)?;
AS
:                                    A S;
BEGIN:                                 B E G I N?;
BREAK
:                                 B R E A K?;
CASE
:                                  C A S E;
DECLARE
:                               D E C L (A (R E?)?)?;
DESCEND
:                               D E S C E N D;//minlen=7
DO
:                                    D O;
DYNAMIC
:                               D Y N A M I C;//minlen=7
ELSE
:                                  E L S E;
ELSEIF
:                                E L S E I F?;
END:                                   E N D;
ENDCASE
:                               E N D C (A (S E?)?)?;
ENDDO
:                                 E N D D O?;
ENDIF
:                                 E N D I F?;
ENDSEQ
:                                E N D S E Q (U (E (N (C E?)?)?)?)?;//minlen=6
ENDSWITCH
:                             E N D S W (I (T (C H?)?)?)?;//minlen=5
ENDWITH
:                               E N D W (I (T H?)?)?;
EXIT
:                                  E X I T;
EXTERN
:                                E X T E (R (N (A L?)?)?)?;
FIELD
:                                 '_'? F I E L D?;
FOR
:                                   F O R;
FUNCTION
:                              F U N C (T (I (O N?)?)?)?;
IF
:                                    I F;
IIF
:                                   I I F;
IN
:                                    I N;
INIT
:                                  I N I T;
LOCAL
:                                 L O C A L?;
LOOP
:                                  L O O P;
MEMVAR
:                                M E M V (A R?)?;
NEXT
:                                  N E X T;
NIL
:                                   N I L;
OPTIONAL
:                              O P T I (O (N (A L?)?)?)?;
OTHERWISE
:                             O T H E (R (W (I (S E)?)?)?)?;
PARAMETERS
:                            P A R A (M (E (T (E (R S?)?)?)?)?)?;
PRIVATE
:                               P R I V (A (T E?)?)?;
PROCEDURE
:                             P R O C (E (D (U (R E?)?)?)?)?;
PUBLIC
:                                P U B L (I C?)?;
QSELF
:                                 Q S E L F;//minlen=5
RECOVER
:                               R E C O (V (E R?)?)?;
RETURN
:                                R E T U (R N?)?;
STATIC
:                                S T A T (I C?)?;
STEP
:                                  S T E P;
DOSWITCH
:                              S W I T (C H?)?;
THREAD
:                                T H R E (A D?)?;
TO
:                                    T O;
WHILE
:                                 W H I L E?;
WITH
:                                  W I T H;
PROCREQ
:                               '_' P R O C R E Q '_';//minlen=9
DECLARE_CLASS
:                         '_' H B '_' C L A S S;//minlen=9
DECLARE_MEMBER
:                        '_' H B '_' M E M B E R;//minlen=10
SEQUENCE
:                              S E Q U (E (N (C E?)?)?)?;
 
// Additional keywords
       
OBJECT
:                                O B J E (C T?)?;
EACH
:                                  E A C H;
USING
:                                 U S I N G?;

SELF
:                                  S E L F;

MACROVAR
:                              M A C R (O (V (A R?)?)?)?;
//MACROTEXT:                             M A C R O T E X T;//?



ID
:                  ( ('a'..'z'|'A'..'Z'|'_') | FullWidthLetter) ( ('a'..'z' | 'A'..'Z' | '_' | '#' | '$' | '0'..'9' ) | FullWidthLetter )*;

LITERAL
:              '"' (SChar1 | '""')* '"'
       
|              '\'' (SChar2 | '\'\'')* '\''
       
;

LITERALe:             'e"' (SChar1 | '\\"')* '"';
LITERALt:             't"' DEC_DIGIT DEC_DIGIT ':' DEC_DIGIT DEC_DIGIT '"';

fragment
SChar1
   
:   ~('"');

fragment
SChar2
   
:   ~('\'');

NumYear
   
: DEC_DIGIT DEC_DIGIT DEC_DIGIT DEC_DIGIT
   
;
   
NumDayMonthYear
   
: DEC_DIGIT DEC_DIGIT?
   
;

NUM_DOUBLE
   
:   DEC_DOT_DEC
   
;

NUM_LONG
   
:   DEC_DIGIT+
   
;

//LEFT_PB_DOUBLE : '((';
//RIGHT_PB_DOUBLE : '))';

LEFT_PB
: '(';//LeftParen
RIGHT_PB
: ')';//RightParen
LEFT_SB
: '[';//LeftBracket
RIGHT_SB
: ']';//RightBracket
LEFT_CB
: '{';//LeftBrace
RIGHT_CB
: '}';//RightBrace

LT
: '<';
LE
: '<=';
GT
: '>';
GE
: '>=';

Plus : '+';
INC
: '++';
Minus : '-';
DEC
: '--';
Star : '*';
Div : '/';
Mod : '%';

Ampersand : '&';
Pipe : '|';
AndAnd : '&&';
OrOr : '||';
POWER
: '^' | '**';
NOT
: NotSymbol | '.NOT.';
fragment
NotSymbol:'!';
//Tilde : '~';
AND
: '.AND.';
OR
: '.OR.';
TRUEVALUE
: '.T.' | '.Y.';
FALSEVALUE
: '.F.' | '.N.';

Question : '?';
Colon : ':';
Comma : ',';

INASSIGN
: ':=';
MULTEQ
: '*=';
DIVEQ
: '/=';
MODEQ
: '%=';
PLUSEQ
: '+=';
MINUSEQ
: '-=';
EXPEQ
: '^=';

EQ
: '==';
Equal : '=';

NE
: (NE1 | NE2 | NE3);

fragment
NE1
: '!=';
fragment
NE2
: '<>';
fragment
NE3
: SHARP;

ALIASOP
: '->';
HASHOP  
: '=>';

INOP
: '$';

DefLine: SHARP L I N E;

fragment SHARP
: '#';

Dot : '.';
EPSILON
: '...';

AtOP:'@';

Tilde:'~';

Qoute: '"';

CBSTART
: '{|';

PragmaDirective
   
:   '#pragma' (options {greedy=false;}:.)* ('\r' | '\n')
       
{$channel=HIDDEN;}
   
;

IncludeDirective
   
:   '#include' (options {greedy=false;}:.)* ('\r' | '\n')
       
{$channel=HIDDEN;}
   
;

//Whitespace

Whitespace
   
: (' ' | '\t' | '\r' | '\n') +
       
{$channel=HIDDEN;}
   
;

Crlf
   
: ( '\r' | '\n' | ';' )
   
;
   
BlockComment
   
:   '/*' ( options {greedy=false;} : . )* '*/'
       
{$channel=HIDDEN;}
   
;


LineComment
   
:   '//' (options {greedy=false;}:.)* ('\r' | '\n')
       
{$channel=HIDDEN;}
   
;

fragment DEC_DIGIT
:    ('0'..'9');
fragment DEC_DOT_DEC
:  (DEC_DIGIT+ '.' DEC_DIGIT+ |  DEC_DIGIT+ '.' | '.' DEC_DIGIT+);

HexadecimalConstant
   
:   HexadecimalPrefix HEX_DIGIT+
   
;

fragment
HexadecimalPrefix
   
:   '0' X
   
;
fragment HEX_DIGIT
:    ('a'..'f'|'A'..'F'|'0'..'9');

fragment LETTER
:       ('a'..'z'|'A'..'Z'|'_');

fragment A
: ('a' | 'A');
fragment B
: ('b' | 'B');
fragment C
: ('c' | 'C');
fragment D
: ('d' | 'D');
fragment E
: ('e' | 'E');
fragment F
: ('f' | 'F');
fragment G
: ('g' | 'G');
fragment H
: ('h' | 'H');
fragment I
: ('i' | 'I');
fragment J
: ('j' | 'J');
fragment K
: ('k' | 'K');
fragment L
: ('l' | 'L');
fragment M
: ('m' | 'M');
fragment N
: ('n' | 'N');
fragment O
: ('o' | 'O');
fragment P
: ('p' | 'P');
fragment Q
: ('q' | 'Q');
fragment R
: ('r' | 'R');
fragment S
: ('s' | 'S');
fragment T
: ('t' | 'T');
fragment U
: ('u' | 'U');
fragment V
: ('v' | 'V');
fragment W
: ('w' | 'W');
fragment X
: ('x' | 'X');
fragment Y
: ('y' | 'Y');
fragment Z
: ('z' | 'Z');
fragment
FullWidthLetter
   
: '\u00c0'..'\u00d6'
   
| '\u00d8'..'\u00f6'
   
| '\u00f8'..'\u00ff'
   
| '\u0100'..'\u1fff'
   
| '\u2c00'..'\u2fff'
   
| '\u3040'..'\u318f'
   
| '\u3300'..'\u337f'
   
| '\u3400'..'\u3fff'
   
| '\u4e00'..'\u9fff'
   
| '\ua000'..'\ud7ff'
   
| '\uf900'..'\ufaff'
   
| '\uff00'..'\ufff0'
   
// | '\u10000'..'\u1F9FF'  //not support four bytes chars
   
// | '\u20000'..'\u2FA1F'
   
;
Введите код...



alex;

unread,
Mar 2, 2018, 1:55:44 PM3/2/18
to antlr-discussion
succeed only with warnings

warning(200): c:\dev\antlr3\grammar\harbour\Harbour.g:39:83:
Decision can match input such as "{EQ, Equal, NE}" using multiple alternatives: 1, 2

As a result, alternative(s) 2 were disabled for that input
warning(200): c:\dev\antlr3\grammar\harbour\Harbour.g:48:73:
Decision can match input such as "{GE..GT, LE, LT}" using multiple alternatives: 1, 2

As a result, alternative(s) 2 were disabled for that input


Replace on
expressionLogicalRelational
options
{backtrack=true;}
   
: commonExpression ((LT | GT | LE | GE) commonExpression)
   
| expressionLogicalRelationalLiteral
   
| expressionLogicalRelationalMath
   
| expressionLogicalUnary ((LT | GT | LE | GE) expressionLogicalUnary)*

//    | '(' assignmentExpression ')' (LT | GT | LE | GE) expression
   
;

//--

expressionLogicalRelationalMath
options
{backtrack=true;}
   
: expressionAdditiveMath ((LT | GT | LE | GE) expressionAdditiveMath)

   
;

 

Reply all
Reply to author
Forward
0 new messages