I'm learning antlr. I've gotten it working with Java but can't get anything to work in C#. I've created the simplest case I can find using an example from The Definitive Antlr Book and I'm still getting problems.
Here is my code and my grammar. I've hardcoded "hello parr" as the input and get
line 1:6 mismatched input 'parr' expecting ID
PreParser.g4
grammar PreParser;
import PreParseLex;
r: 'hello' ID;
PreParserLex.g4
lexer grammar PreParseLex;
ID: [a-z]+;
WS: [ \t\r\n]+ -> skip ;
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Antlr4.Runtime;
using Antlr4.Runtime.Misc;
using Antlr4.Runtime.Tree;
namespace PreparseApp
{
class Program
{
static void Main(string[] args)
{
string expression = "hello parr";
AntlrInputStream input = new AntlrInputStream(expression);
PreParseLex lexer = new PreParseLex(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
PreParserParser parser = new PreParserParser(tokens);
IParseTree tree = parser.r();
Console.WriteLine("Done");
}
}
}
I don't understand why 'parr' doesn't ID. Ideas?