I am writing a parser for a language. After implementation I have found that there are so many parser rules. So, I split the grammars. I have added the lexer rules in both the grammars. But, now I have found that the lexer is generated from the first grammar and they are not matched in the other grammar and hence no viable alt exception.
Can anyone guide me how to use the same lexer rules in both the grammars?
You can use the same lexer, you can set the lexer file with the starting line, assuming 'SomeLanguage' as your language:
On your paser file(s) you should start with:
where 'options' makes a reference to the lexer for the grammar.
To compile let's assume the lexer is on a folder called 'the_lexer' and your parser in folder 'the_parser':