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

I'm not getting the root node to get the AST. Do I need to manually print the AST ?? #95

Open
panky1998 opened this issue Jun 19, 2023 · 4 comments

Comments

@panky1998
Copy link

Since I'm trying to get the AST elements . I'm unable to get them. If you have any suggestions please help!

@uwol
Copy link
Owner

uwol commented Jun 19, 2023

Hi @panky1998 ,

you should be able to call getCtx on each ASG element to retrieve the corresponding AST element. So for each ASG element there should be an AST element named ctx. The AST ctx element should always be an ANTLR class.

The interface is in ASGElement.java

Best
Ulrich

@uwol
Copy link
Owner

uwol commented Jun 19, 2023

An arbitrary example for such a call would be this line.

@panky1998
Copy link
Author

Hi @uwol ,
As you said I'm calling each AST element with getCtx(). But when I'm trying to call AST elements it is returning numbers. Am I calling in improper way? Please help me as am a novice...

         // navigate on ASG
        CompilationUnit compilationUnit = program.getCompilationUnit("HelloWorld");
        ProgramUnit programUnit = compilationUnit.getProgramUnit();
        DataDivision dataDivision = programUnit.getDataDivision();
        DataDescriptionEntry dataDescriptionEntry = dataDivision
        .getWorkingStorageSection().getDataDescriptionEntry("ITEMS");
        Integer levelNumber = dataDescriptionEntry.getLevelNumber();
        
        
        System.out.println("Compilation unit => "+compilationUnit.getCtx());
        System.out.println("Program Unit => "+programUnit.getCtx());
        System.out.println("Data Division => "+dataDivision.getCtx());
        System.out.println("Data Description Entry => "+dataDescriptionEntry.getCtx());
        System.out.println("Level number =--> "+levelNumber);

I'm getting output as

Compilation unit => [1198]
Program Unit => [1201 1198]
Data Division => [1211 1201 1198]
Data Description Entry => [3171 2286 2005 1997 1211 1201 1198]
Level number =--> 1

Regards,
Pankaj

@uwol
Copy link
Owner

uwol commented Jun 21, 2023

Hi @panky1998 ,

this is correct, those are the ANTLR ParserRuleContext elements. In Eclipse debugger you can introspect them.

You can use them to navigate to children, to the parent element etc. For this the normal ANTLR documentation applies, nothing COBOL- or ProLeap-specific.

Best
Ulrich

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants