Skip to content

Getting odd error message from ANTLR lab #96

@QGhd

Description

@QGhd

Hi ANTLR experts,

I have entered this grammar to the lab:

// ANTLR Grammar for identifiers decorated by zero or one prefix (separated by underscore) and zero, one or more suffixes (also separated by underscores).
grammar PropNaming;

options { caseInsensitive = false; }

propnames
  : propname (NEWLINE+ propname)* NEWLINE* EOF
  ;

propname
  : mathprefix?
    baseprop
    contsuffix?
    intenssuffix?
  ;

mathprefix 
  : PREFIXln
  | PREFIXlog
  ;

baseprop 
  : TOKENA
  | TOKENm
  ;

contsuffix
  : SUFFIXig
  | SUFFIXres
  ;

intenssuffix
  : SUFFIXV
  | SUFFIXm
  ;

PREFIXln  : FRAGMENTln US ;
PREFIXlog : FRAGMENTlog US ;
TOKENA   : FRAGMENTA ;
TOKENm   : FRAGMENTm ;
SUFFIXig  : US FRAGMENTig ;
SUFFIXres : US FRAGMENTres ;
SUFFIXV   : US FRAGMENTV ;
SUFFIXm   : US FRAGMENTm ;

NEWLINE : '\r'? '\n' ;

fragment US : '_' ;

fragment FRAGMENTln : 'ln' ;
fragment FRAGMENTlog : 'log' ;
fragment FRAGMENTA : 'A' ;
fragment FRAGMENTm : 'm' ;
fragment FRAGMENTig : 'ig' ;
fragment FRAGMENTres : 'res' ;
fragment FRAGMENTV : 'V' ;

// end of file

and applied to this (from my point of view valid) input:

A
ln_A
A_ig
ln_A_ig
ln_m_m

And I get this error message: 1:0 mismatched input 'A' expecting {'and', 'or', 'not', '='}

All sample lines seem to be wrong for ANTLR.

Where is the error(s) in my grammar?

Oliver

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions