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

Enable JSON ASTs when 4th grammar section detected #96

Merged
merged 1 commit into from
Apr 10, 2024

Conversation

StoneyJackson
Copy link
Member

@StoneyJackson StoneyJackson commented Jan 24, 2024

Template for Final Squash Commit Message

refactor: enable Python when grammar has 4 sections

This is in anticipation of a new hybrid Java/Python mode
in which the parser runs in Java and the semantics rep-loop
runs in Python.

In this commit, when an optional 4th section is detected,
plcc.py generates ParseJsonAst.json. Thus allowing the
parser to to generate JSON ASTs when the `--json_ast`
flag is passed. It also generates experimental Python files.

---

Closes #95

Co-authored-by: Reed Everis <[email protected]>
Co-authored-by: Akshar Patel <[email protected]>
Co-authored-by: Stoney Jackson <[email protected]>

@reedeveris reedeveris self-assigned this Jan 25, 2024
@AksharP5 AksharP5 self-assigned this Jan 25, 2024
@StoneyJackson
Copy link
Member Author

@reedeveris @reedeveris the build in CI has been fixed, and this branch has been synch'd.

@StoneyJackson StoneyJackson changed the title Add new semantics section to grammar files Enable JSON ASTs when 4th grammar section detected Jan 28, 2024
@reedeveris
Copy link
Collaborator

reedeveris commented Jan 31, 2024

Tentative to do:

  • Add global flag for "python_semantics" in plccInit() lines 116-136 (default True)
    (make the sempy routines separately toggled)
  • Add 'python_destdir' flag in plccInit() and set default to 'Python'
  • Add statement to sem() to break for loop at '%', and move 'done()' on line 970 up a level
  • Copy sem() into sempy() and refactor
  • Copy semFinishUp() into sempyFinishUp() and refactor

@reedeveris
Copy link
Collaborator

reedeveris commented Feb 2, 2024

As of now, plcc successfully detects the fourth section, and creates the Python directory, all automated based on whether the third section ends in a '%'.

For @StoneyJackson 's attention:
@AksharP5 and I were discussing how to utilize the json functionality, but ran into some confusion. We don't understand how the json parse tree comes into play. We want to generate Python files, correct?

@reedeveris
Copy link
Collaborator

Note for next meeting:

  • Look at makeStub(), consider that in this method, you could potentially generate py files in given format.
  • Consider instead of 4 sections, 3 sections with the option to work in either Java or Python

@StoneyJackson
Copy link
Member Author

@reedeveris @AksharP5 Please read #52 (comment)

@StoneyJackson
Copy link
Member Author

@reedeveris

When plcc.py processes a 4-section grammar, it will generate both Java and Python code. The Java code needs to include the ParseJsonAST.java file. Right now I think that's done by passing a --json_ast to plcc.py. We should change it so that it is done automatically if there is a 4th section.

I think all we should do in this PR is:

  1. detect the forth section
  2. copy ParseJsonAST.json to the Java/ directory
  3. remove the --json_ast option (since all this did was (2), and now we are doing that when a 4th section is detected).

Copy link
Member Author

@StoneyJackson StoneyJackson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tried running this. But here is some feedback.

src/plcc.py Outdated
if len(line) == 0 or line[0] == '#':
# skip just comments or blank lines
continue
if line == '%':
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this on both line 945 and line 950?

src/plcc.py Outdated
sempyFinishUp()
for line in nxt:
line = line.strip()
if line[:7] == 'include':
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not going to allow the classic 'include' in the new 4th section. So let's remove this section.

@@ -157,3 +157,4 @@ include val
include list
include class
include ref
%
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should leave this alone as it tests a traditional 3-section grammar. If you modify this, then we don't know if your changes break what was working before.

Instead, we need a separate test for a 4-section grammar. You could copy "compiles-obj" to something like "compiles-4-section-grammar", and then make this change.

@StoneyJackson
Copy link
Member Author

I see that there are updates. Excellent! I probably won't have a chance to look at them until Wednesday morning. So, if you are at the limits of what you can do in code without decisions from me, and you have more cycles for work, you can do some planning (next steps), design (Is there a design that would have made what you just did easer? Are the names the best they could be? How will the next step fit in with what you just did?), testing (write a test that passes when your new stuff works and fails when it doesn't), and/or documentation (how should README.md be updated to reflect the changes you just made).

@reedeveris
Copy link
Collaborator

Update:

  • Code injections should now be automatically normalized to a standard '\t' indent (this can be changed if we want)
    Next: (notes for next meeting)
  • Java injection code vs Python injection code (we need both?)
  • Figure out testing
  • Ensure that the detection of 4th section enables JSON AST functionality

@reedeveris
Copy link
Collaborator

Create test cases:

  • no fourth section: Python directory should not be generated
  • empty fourth section: empty Python directory

This is in anticipation of a new hybrid Java/Python mode
in which the parser runs in Java and the semantics rep-loop
runs in Python.

In this commit, when an optional 4th section is detected,
plcc.py generates ParseJsonAst.json. Thus allowing the
parser to to generate JSON ASTs when the `--json_ast`
flag is passed. It also generates experimental Python files.

---

Closes #95

Co-authored-by: Reed Everis <[email protected]>
Co-authored-by: Akshar Patel <[email protected]>
Co-authored-by: Stoney Jackson <[email protected]>
@reedeveris reedeveris force-pushed the stoneyjackson/add-new-semantics-95 branch from 13fa0f7 to 7cecc65 Compare April 10, 2024 15:58
@StoneyJackson StoneyJackson marked this pull request as ready for review April 10, 2024 17:14
@StoneyJackson StoneyJackson merged commit a1bc2d2 into main Apr 10, 2024
4 checks passed
@StoneyJackson StoneyJackson deleted the stoneyjackson/add-new-semantics-95 branch April 10, 2024 17:14
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

Successfully merging this pull request may close these issues.

3 participants