0
votes

I have an existing grammar I'm converting to Antlr4 using the C# output. It's failing on the first token with the message mismatched input 'Begin' expecting ANY_WORD. Strangely though when I print out the tokens to see what token it is being recognised as, it indicates it has identified it correctly.

            string text = File.ReadAllText(fi.FullName);
            var fs = new Antlr4.Runtime.AntlrInputStream(text);
            var lexer = new TestLexer(fs);
            var tokens = new Antlr4.Runtime.CommonTokenStream(lexer);
            tokens.Fill();
            var tokenList = tokens.GetTokens();
            yRLogger.Info("Printing tokens");
            foreach(IToken tok in tokenList)
            {
                Logger.Info(tok.ToString()); //prints [@0,13:17='Begin',<28>,1:13] 28 In TestLexer.tokens, 28 corresponds to ANY_WORD

            }
            var parser = new TestParser(tokens);
            parser.start(); //throws 'mismatched input 'Begin' expecting ANY_WORD. '

Checking the same grammar and input in AntlrWorks also behaves as expected - it finds the first token without an error.

From TestParser.tokens ANY_WORD=28.

The input file is

Begin parsing now

The Antlr file is

   start : ANY_WORD+;

   ANY_WORD
: 
~('\r'|'\n'|' '|'\t'|'\u000C')+
;

    WS  : (' '|'\t'|'\u000C') -> skip 
;
1

1 Answers

1
votes
  1. This belongs on the issue tracker for the C# target.

  2. I just tried to reproduce this issue, configuring the C# target as described in the Readme instructions for the latest version of the project, and parsing worked correctly on the first try.