0

I want to write a simple CSS parser that will extract identifiers from css file. I have a grammar, I compiled it to .cs file and now I need to write Main function. For now I have something like this:

var lex = new css21Lexer(new ANTLRStringStream("}"));
var tokens = new CommonTokenStream(lex);

var parser = new css21Parser(tokens);
parser.styleSheet();

But when I run the program nothing happens. As the input is incorrect I would expect some kind of exception. I also tried to add code to some productions, but that code is not executed. How do I actually use the generated parser?

Tomasz Grobelny
  • 2,666
  • 3
  • 33
  • 43

1 Answers1

2

One of the great things about ANTLR is that you can debug into the generated parser code and follow along as it parses. So fire up your debugger.

ANTLR will skip a token that doesn't parse correctly and report it as an error. How it is reported depends on the reportError() function, it may be doing nothing for your target language. Set a breakpoint there too to see what is happening.

monty0
  • 1,759
  • 1
  • 14
  • 22