antlr / grammars-v4

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

Powerbuilder Parser Grammer Bug #1664

Open wegoodwin opened 4 years ago

wegoodwin commented 4 years ago

I have made some changes(hacks to be more precise) to the powerbuilder grammar. Appeon(the current owner of powerbuilder) did not release any language specs. So the code generated by the tool is pretty wacky looking. There is one part of the grammer that I have not been able to understand. The parser rule for 'assignment_statement'. I am getting an error in ANTLRWorks 2.1 that there is no viable alternate at input 'ST_OS.TEXT = "WINDOWS " + STRING(GE_ENVIRONMENT'. But I am not able to make heads nor tails of this rule. I have attached a copy of the powerbuilder grammer/lexer as well as a copy of the input file. I did want to mention that I have to change all the characters in the input file(append.txt) to uppercase letters or nothing will get recognized.

append.txt PowerBuilderLexer.txt PowerBuilderParser.txt

gmai2006 commented 3 years ago

The current PB grammar will not work with most of production PB sources. I am in process of making changes to the grammar.

Here is a modified version of PB grammar that supports mix cases based on suggestion from Dr. Parr so the users do not have to change the source to uppercase, which may accidentally change the variable names, or use CaseChangingCharStream.

Reference:

case-insensitive

Please note that this grammar is being updated because there are issues needed be addressed while I am continue to test against PB source files. It is best to wait for the a thoroughly tested version

PowerBuilderLexer.txt PowerBuilderParser.txt

gmai2006 commented 3 years ago

The up-to-date PB grammar with the unit tests can be found here. This repo will be updated regularly until all the issues are resolved

om198 commented 3 years ago

The up-to-date PB grammar with the unit tests can be found here. This repo will be updated regularly until all the issues are resolved

The up-to-date PB grammar with the unit tests can be found here. This repo will be updated regularly until all the issues are resolved

Thanks for this version. Datawindows works well, but There's still a problem with the functions implemention. In the attached examples, i found only one srw file, but it does not contain function implemention. Could you check the grammar and attach an example with srw file that contains functions?

gmai2006 commented 3 years ago

Just updated [the grammar project] (https://github.com/gmai2006/grammar) with more 300 test files. This test suite should contain following file types .sra - Application Object (The entry point to the application) .srd - DataWindow Object (Retrieves, represents and modifies data in the database) .srw - Window Object .sru - User Object .srm - Menu Object (List of commands and handlers) .srf - Function Object .srs - Structure Object (Structure definition)

Please note that the uploaded PB grammar should handle most cases but still needed to be updated to handle embedded SQL. Will finish the embedded SQL soon. Please check back in a few days. Thanks

om198 commented 3 years ago

Thank you for your quick response! I am waiting for the new version with the embedded SQL.

om198 commented 3 years ago

I have checked the latest version. Here are some problems in function body: -Try- Catch block is not supproted. -Variable decaleration with default value ,in the same row with other variables. Example: Int i, j=100, k

gmai2006 commented 3 years ago

A new version has been pushed. it should support embedded SQL, try-catch, multiple variables decl etc.

om198 commented 3 years ago

Thanks for this version. There is still problem with צultiple variables decl. As a grammar expert , Do you have any idea how to move from PB AST to another languge AST?

gmai2006 commented 3 years ago

Just updated last night. Have you pulled the latest update from last night? Have tested against a few hundred PB source. if you find an issue please provide a sample so I can add it to the unit test. Otherwise, it is hard to know which version of PB that you are referring to

About the transformation, what are your end goals? to transform one AST to another AST one can use ANTLR4 Visitor to transform one language to another language then use that language ANTLR4 grammar to generate an AST

Also, suggest taking a look at the StringTemplate. Combining ANTLR4 visitor pattern, Xpath, and StringTemplate one can do pretty much anything.

BTW, this forum is strictly for bug submission. Other questions you can consult me directly at my GitHub branch.

om198 commented 3 years ago

Thanks for youre quick response. Multiple function decl works perfectly. There are stil some problems:

  1. Short If- condition example: If test(param) <1 Then Return -1

About the transformation, my main goal is to transform the source file from PB to C#. Do you have a code example for me?

gmai2006 commented 3 years ago

The simple if statement works just fine. I added a new unit test to the grammar repo and tested it. It works. It should be something else in your source usually right before that statement. You need to provide that source if you want me to test.

You can also check out the branch, create a new unit test and test it yourself https://github.com/gmai2006/grammar/blob/main/src/test/java/com/datascience9/pb/parse/ParserFragmentTest.java Example: @Test public void testSimpleIfStmt() throws IOException { InputStream in = PbParserTest.class.getResourceAsStream("/pb/test_simple_if.txt"); PowerBuilderParser parser = PbHelper.getParser(in); parser.statement(); } For other questions please contact me directly on my Github repo

om198 commented 3 years ago

I am sorry about the question here. How can I contact you directly? I have not found this option.

gmai2006 commented 3 years ago

You can go to my GitHub account and submit bugs or have questions https://github.com/gmai2006/grammar/issues

om198 commented 3 years ago

What about comments in the grammar? Now, I lost all the comments from the source code.

gmai2006 commented 3 years ago

None of the official grammars will include comments in the parse tree. I have a modified version of the grammar that extracts the comments and store them in a dictionary for transformation purposes but that version will not be accepted by the community. You may have to request to have multiple versions such a based grammar (official), grammar with comments, etc.
Please also note that comments can cause a huge performance on the parse tree so you will have to devise a mechanism to store comments somewhere else and substitute them later when you are generating the final target. If you can convince the community to have multiple versions then I can submit another modified version of PB grammar that has a mechanism to handle the comments because comments are a big concern for application migration.

om198 commented 3 years ago

I agree with you, comments are important issue in migration. I am not familiar with the community rules. What about creation new project for this grammar?