OpenFortranProject / ofp-sdf

SDF grammar for Fortran 2008 with constructors for AST
Other
23 stars 7 forks source link

`make check` in ofp-sdf/fortran/traverse fail #13

Closed xg-wang closed 7 years ago

xg-wang commented 8 years ago
sglri -i testfile.f90 -p ../syntax/Fortran.tbl -o testfile.f90.aterm
./traverse testfile.f90.aterm

Program("!! Hellno\n!\n",[MainProgram(ProgramStmt("33","main",eos("\n  ")),initial-spec-part([],[]),SpecAndExecPart([TypeDeclarationStmt(no-label,IntrinsicType(INTEGER(no-kind)),comma-list([ASYNCHRONOUS]),[EntityDecl("i",no-list,no-list,no-char-length,no-init)],eos("\n"))]),no-subprogram-part,EndProgramStmt("13","main",eos("\n")))])

Program: Program("!! Hellno\n!\n",[MainProgram(ProgramStmt("33","main",eos("\n  ")),initial-spec-part([],[]),SpecAndExecPart([TypeDeclarationStmt(no-label,IntrinsicType(INTEGER(no-kind)),comma-list([ASYNCHRONOUS]),[EntityDecl("i",no-list,no-list,no-char-length,no-init)],eos("\n"))]),no-subprogram-part,EndProgramStmt("13","main",eos("\n")))])

ProgramUnit: MainProgram(ProgramStmt("33","main",eos("\n  ")),initial-spec-part([],[]),SpecAndExecPart([TypeDeclarationStmt(no-label,IntrinsicType(INTEGER(no-kind)),comma-list([ASYNCHRONOUS]),[EntityDecl("i",no-list,no-list,no-char-length,no-init)],eos("\n"))]),no-subprogram-part,EndProgramStmt("13","main",eos("\n")))

make: *** [check] Error 1

It seems the MainProgram match failed.

rasmussn commented 8 years ago

Can you provide the input program and a little information on what you are trying to do? Just looking at the command line it looks like you are not piping the output of the parse to the AST builder ofp2fast.

All transformation we ultimately do are on the Fortran AST not the parse tree.

-craig

On Sun, Apr 3, 2016 at 9:04 PM, Xingan Wang notifications@github.com wrote:

sglri -i testfile.f90 -p ../syntax/Fortran.tbl -o testfile.f90.aterm ./traverse testfile.f90.aterm

Program("!! Hellno\n!\n",[MainProgram(ProgramStmt("33","main",eos("\n ")),initial-spec-part([],[]),SpecAndExecPart([TypeDeclarationStmt(no-label,IntrinsicType(INTEGER(no-kind)),comma-list([ASYNCHRONOUS]),[EntityDecl("i",no-list,no-list,no-char-length,no-init)],eos("\n"))]),no-subprogram-part,EndProgramStmt("13","main",eos("\n")))])

Program: Program("!! Hellno\n!\n",[MainProgram(ProgramStmt("33","main",eos("\n ")),initial-spec-part([],[]),SpecAndExecPart([TypeDeclarationStmt(no-label,IntrinsicType(INTEGER(no-kind)),comma-list([ASYNCHRONOUS]),[EntityDecl("i",no-list,no-list,no-char-length,no-init)],eos("\n"))]),no-subprogram-part,EndProgramStmt("13","main",eos("\n")))])

ProgramUnit: MainProgram(ProgramStmt("33","main",eos("\n ")),initial-spec-part([],[]),SpecAndExecPart([TypeDeclarationStmt(no-label,IntrinsicType(INTEGER(no-kind)),comma-list([ASYNCHRONOUS]),[EntityDecl("i",no-list,no-list,no-char-length,no-init)],eos("\n"))]),no-subprogram-part,EndProgramStmt("13","main",eos("\n")))

make: *\ [check] Error 1

It seems the MainProgram match failed.

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/OpenFortranProject/ofp-sdf/issues/13

xg-wang commented 8 years ago

I wanted to traverse the AST so I looked into fortran/traverse folder, in the makefile there exists:

check: traverse
    sglri -i testfile.f90 -p ../syntax/Fortran.tbl -o testfile.f90.aterm
    ./traverse testfile.f90.aterm

in the main(), Program.term = ATreadFromTextFile(file); So the file should be a .aterm file (correct me if wrong). It should match the programunit in https://github.com/OpenFortranProject/ofp-sdf/blob/master/fortran/traverse/ofp_traverse_productions.c#L97 but it didn't so I was confused.

Since the api doc on the website is missing, could you tell me where can I find the usage of functions such as ATmatch()?

rasmussn commented 8 years ago

Sorry about the lack of documentation, We are currently spending most of our time in getting the infrastructure up and running. Now we are at the point where it has become very useful to people and we need to start improving user support.

The best for now is for you to look at the files in the ofp-sdf/fortran/trans directory. This is where the core transformations take place to develop the Fortran AST. You can look at the Makefile. Most transformations and tests run using the file testfile.f90 so you can test things out using changes to this file.

Also, you can look at the files in the trans directory of ofp-sdf/OCR. I'm starting up a collaboration with the Intel Open Community Runtime community to transform Fortran coarray code to OCR Event Driven Tasks (EDTs). This is just starting a currently just adds a use statement to each module and procedure scope.

In summary, the traverse directory is no longer relevant and should be moved (thanks for reminding me to do that). Also the best place to get an idea of the capabilities are to look in the OFP core directory ofp-sdf/fortran/trans.

Please ask more questions if you need further guidance. I'm happy to help. This stuff is really becoming powerful and thus many uses (and users) are showing up (which is swamping resources on the project a bit).

-craig

On Mon, Apr 4, 2016 at 5:20 PM, Xingan Wang notifications@github.com wrote:

I wanted to traverse the AST so I looked into fortran/traverse folder, in the makefile https://github.com/OpenFortranProject/ofp-sdf/blob/master/fortran/traverse/Makefile#L55 there exists:

check: traverse sglri -i testfile.f90 -p ../syntax/Fortran.tbl -o testfile.f90.aterm ./traverse testfile.f90.aterm

in the main() https://github.com/OpenFortranProject/ofp-sdf/blob/master/fortran/traverse/traverse.c#L25, Program.term = ATreadFromTextFile(file); So the file should be a .aterm file (correct me if wrong). It should match the programunit in https://github.com/OpenFortranProject/ofp-sdf/blob/master/fortran/traverse/ofp_traverse_productions.c#L97 but it didn't so I was confused.

Since the api doc on the website is missing, could you tell me where can I find the usage of functions such as ATmatch()?

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/OpenFortranProject/ofp-sdf/issues/13#issuecomment-205555763

xg-wang commented 8 years ago

Thank you @rasmussn . I noticed that in the ofp-sdf/fortran/trans it is about manipulating the ast, using ast2text to unparse the fast file. What I'd like to do is to traverse the ast and perform some analysis on it, so I'm more interested in something like fortran/traverse or fortran/rose_traverse (however they seem to be deprecated already). So how should I make use of the .aterm or .fast file to obtain the ast structure in my program? Or, will you provide Java interface like the antlr version ofp did in https://github.com/OpenFortranProject/open-fortran-parser/blob/master/src/fortran/ofp/parser/java/IFortranParserAction.java? If the interface will remain the same, it would be fine to use the deprecated version now.

rasmussn commented 7 years ago

The file ofp-sdf/fortran/trans/fast2pp.str shows how to the AST is traversed in preparation to unparsing (pretty printing). The format for OFP Fortran AST (FAST) will be defined by the file ofp-sdf/fortran/syntax/FAST.rtg (and FAST.str). One can traverse any ATerm file that follows the regular tree grammar defined in ofp-sdf/fortran/syntax/FAST.rtg using strategies defined in an *.str file with the tools in StrategoXT.

The file fop-sdf/fortran/trans/fast2pp.str demonstrates how to rewrite a file containing FAST ATerms to a file containing ATerms that can be printing using the pretty printing rules in the file ofp-sdf/fortran/pp/Fortran.pp

This is a much improved way to work with an AST than the actions provided by the Java interface.