Open AkhilAkkapelli opened 5 months ago
You need to take a step back before attempting this. You are trying to construct a grammar from a normative spec instead of thinking about the how grammar should be compatible with the normative spec. Start with this:
You will get nowhere with the lexer and parser you have right now and it will frustrate you. Take a look at some existing grammars to get a feel for it, and write yourself some small parsers like a calculator or equation parser or something else simple. The mistakes you make on the small tasks wil lguide you in creation of a larger system such as a Fortran parser.
Beware of X Y questions, which is what you have here.
I am developing a Fortran 2018 grammar in ANTLR4 using the ISO standard. I am encountering an issue during the lexing phase with some of the lexer rules. Specifically, certain keywords are being misclassified. Below is the minimal grammar demonstrating the problem:
Grammar:
FortranTestF18.g4
Test File:
FortranTest.f90
Commands:
Grun Output:
Here, token
I
is recognized asNAME
but I want it to be recognized as tokenI: 'I';
. But if I move the lexer ruleI
to top ofNAME
then the identifiers cannot be named as 'I'. How do I solve this problem?