Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser fails at INCLUDE statements #1

Open
fkraushofer opened this issue Jun 3, 2020 · 5 comments
Open

Parser fails at INCLUDE statements #1

fkraushofer opened this issue Jun 3, 2020 · 5 comments
Labels
parser-fail Defect in the parser component

Comments

@fkraushofer
Copy link

Hi,
I tried to run the parser on (part of) this package, and got the following error:

> fsource parse ref-calc.v1.6.f --fixed-form


ref-calc.v1.6.f:42:7: parser error: malformed statement inside program
|
|             INCLUDE "PARAM"
|             ^~~~~~~

The ref-calc.v1.6.f file begins:

      program leed

C  include parameter statements for dimensions etc

      INCLUDE "PARAM"

C  set unchangeable constants

      INCLUDE "GLOBAL"

Am I missing some option to run the parser on the entire project in a way that would make the INCLUDE statements work, or is this simply not implemented yet?

@mwallerb
Copy link
Owner

mwallerb commented Jun 3, 2020

No, this is not implemented yet. Thanks for the pointer!

@mwallerb mwallerb added the parser-fail Defect in the parser component label Jun 3, 2020
@apthorpe
Copy link
Contributor

Would this be added to _DECLARATION_HANDLERS and STMT_HANDLERS in parser.py? Typically it's found in the declaration section but INCLUDE can show up almost anywhere - see https://www.ibm.com/docs/en/xffbg/121.141?topic=descriptions-include

@apthorpe
Copy link
Contributor

I managed to patch around the error by adding

def include_stmt(tokens):
    expect(tokens, 'include')
    ignore_stmt(tokens)
    return tokens.produce('include_stmt')

(based on data_stmt())

then added

'include':     include_stmt,

to both _DECLARATION_HANDLERS and STMT_HANDLERS

This is admittedly a partial effort; it doesn't attempt to implement INCLUDE but does avoid the error and adds include_stmt to the AST.

@mwallerb
Copy link
Owner

Hmm, the problem is that the standard specifies that include is not a statement at all -- it is called "include line" and is much closer in spirit to a preprocessor statement. I think it would therefore be better to treat it as preprocessor statement.

@apthorpe
Copy link
Contributor

That's reasonable; that's the interpretation I remember from looking at the spec. I approached this from a "how do I make this error stop" perspective rather than a "how do I accurately interpret this entity" perspective so there's likely a better (standards-compliant) way of handling this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parser-fail Defect in the parser component
Projects
None yet
Development

No branches or pull requests

3 participants