otterkit / otterkit-cobol

A free and open source Standard COBOL compiler for 64-bit environments
https://otterkit.com
Apache License 2.0
249 stars 15 forks source link

Parser should honor literals #25

Closed birojnayak closed 1 year ago

birojnayak commented 1 year ago

Describe the bug 01 Num2 PIC 9 values zeros. The Language parser failing for numeral literals

To Reproduce https://gist.github.com/birojnayak/4bd0d4332d98170f74803b3e217ca4f8

Expected behavior Parser should honor it.

Screenshots If applicable, add screenshots to help explain the issue. This could be terminal screenshots that can help us find the source of the issue.

Platform Information (please complete the following information):

Additional context Add any other context about the problem here.

KTSnowy commented 1 year ago

Hey @birojnayak sorry for the late reply, was refactoring a few things in the runtime library.

I'll start working on a fix for this right now.

The parsing method for the value clause currently doesn't check for figurative literals, but the lexer should be generating the tokens for them. So it shouldn't take too long to fix.

KTSnowy commented 1 year ago

Oh also, the value clause in those variables should be value instead of values.

The standard syntax rules for single data items are: VALUE [IS] literal.

VALUES can only be used for variables with multiple possible values, such as tables and 88-level conditions.

We should add appropriate error messages for this.

KTSnowy commented 1 year ago

@birojnayak, this is now fixed in the latest commit on the main branch.

The following working-storage will now successfully parse:

       working-storage section.
           01 UserName PIC X(30)  value "you".
           01 Num1     PIC 9 value zeros.
           01 Num2     PIC 9 value zeros.
           01 Total    PIC 99 value 0.
           01 SsnNum.
               05  SSArea  PIC 999. 
               05  SSGroup PIC 99. 
               05  SSSerial PIC 9999. 

Note: Type checking for the literals is still missing, working on name resolution for the whole parser right now, which will include type checking for this as well.

birojnayak commented 1 year ago

@KTSnowy closing this.. I am going to test a bit more and create few more issues. Also as a general guidelines you need to create some sample COBOL projects for users to try and help everyone where it stands now.

KTSnowy commented 1 year ago

@birojnayak, We need to get more parts of the codegen working to be able to provide runnable samples for users.

I was planning to make a sample collection with algorithm examples written in Standard COBOL, but we'll have to get classes and objects working first. Would be awesome if we could provide examples of generic collections in COBOL as well!

birojnayak commented 1 year ago

sure I will do some sample COBOL programs and submit a PR over weekend... we should include them as a part of tests...