antlr / grammars-v4

Grammars written for ANTLR v4; expectation that the grammars are free of actions.
MIT License
10.19k stars 3.71k forks source link

Error while Parsing Valid Fortran90 Program using Grammer #3500

Open AkhilAkkapelli opened 1 year ago

AkhilAkkapelli commented 1 year ago

@cyrillemidingoyi @kaby76

The Parser cannot able to parse successfully Access Statements like PUBLIC, PRIVATE etc. in the Fortran90 code.

This is the Fortran90 Grammar file: https://github.com/AkhilAkkapelli/grammars-v4/blob/AkhilAkkapelli-patch/fortran90/Fortran90.g4

This is the File I am Parsing: https://github.com/AkhilAkkapelli/grammars-v4/blob/AkhilAkkapelli-patch/fortran90/Module3.f90

This is the Error in Parse Tree I got:

antlr4_parse_tree

gruFortran90 programle -gui ../ModuleDependencyDiagram/MDDFortranLib/Module3.f90 line 5:0 mismatched input 'PRIVATE' expecting {ENDMODULE, END} line 40:0 no viable alternative at input 'MODULEModule3'

It could parse well until Access Statements like PUBLIC/PRIVATE are specified in the module file. Adding the access statements in module is creating the error in Parsing.

Also, PUBLIC statement is not creating any error, there is a problem only with the PRIVATE statement. Here, is the Parse tree of the same example which I got error with Public Statement:

antlr4_parse_tree

kaby76 commented 1 year ago

We should get this grammar added to the repo. @AkhilAkkapelli are you going to add this, or should I? Otherwise, it's not officially in the repo, and we can't track issues (and fixes) like this properly.

AkhilAkkapelli commented 1 year ago

Thank you for the clarification. My apologies for the confusion. Since the grammar file was created by @cyrillemidingoyi and if there is no issue, I kindly request that you please add this file to the grammar repository.

kaby76 commented 1 year ago

I am adding the grammar now. For information on it, refer back to https://github.com/antlr/grammars-v4/issues/3399. The hardest part of adding the grammar at the moment is coming up with a test suite. For now, I am settling on the .f90 files in https://github.com/flang-compiler/flang that parse with success.

kaby76 commented 1 year ago

@AkhilAkkapelli The grammar has been added, and all targets except Typescript work fine. https://github.com/antlr/grammars-v4/pull/3501

cyrillemidingoyi commented 1 year ago

Good job

cyrillemidingoyi commented 1 year ago

@kaby76 Hello, Please can you change the author of the fortran90 Parser. It is not Olivier Dragon. I have just used the header of Fortran 77 to create the grammar. Please change it by Cyrille MIDINGOYI and you as contributor. Thank you.