1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
# TINY session transcript
Local date/time: 2025-11-22 03:45
## Overall plan
- Adopt pyparsing best practices (naming, `Group` + named fields, punctuation suppression, `Forward` for recursion, `infix_notation`, enable packrat) and apply consistently.
- Build out TINY grammar incrementally: expressions/terms, statements, control flow, functions, and program.
- Make statement termination explicit: add trailing `SEMI` to simple statements; no semicolon after `if`/`repeat` constructs.
- Localize concerns: include trailing `SEMI` inside each statement `Group` so sequencing stays simple.
- Add tags (`pp.Tag`) to important nodes for easy downstream processing.
- Keep tests green; adjust tests only when grammar behavior changes intentionally.
- Provide a railroad diagram hook for `Program` and a README reference to the language spec.
- Maintain a living transcript documenting prompts, plans, and actual actions taken.
## Transcript
- User prompt:
We are going to develop a pyparsing parser for the TINY language. Begin by reading the pyparsing best practices by running "python -m pyparsing.show_best_practices"
Plan:
- Run `python -m pyparsing.show_best_practices` to review the official pyparsing best practices.
- Note key guidelines (naming, use of `Group`, suppression of punctuation, `Forward` for recursion, `infix_notation`, packrat, and testing patterns) and apply them throughout the TINY grammar development.
Actions taken:
- Applied best practices in `examples/tiny/tiny_parser.py`: enabled packrat, used `Suppress.using_each` for punctuation, used `Forward` for recursive elements, and built expressions with `infix_notation`. Results are grouped and named consistently.
- User prompt:
After defining "program" add "program.create_diagram('tiny_parser_diagram.html')" to create a railroad diagram.
Plan:
- Open `examples/tiny/tiny_parser.py` and locate the `Program` parser element definition.
- Add a call to `Program.create_diagram('tiny_parser_diagram.html')` immediately after the definition so an HTML railroad diagram is generated when executed.
Actions taken:
- Added the diagram generation hook after defining `Program`. The diagram file (`tiny_parser_diagram.html`) exists at the project root. The call is currently left as an optional/commented line to avoid side effects on import, but can be enabled when needed.
- User prompt:
Redo stmt_list definition to just use OneOrMore(statement). Add trailing semicolons explicitly to all statements except for If_statement and Repeat_statement.
Plan:
- Replace `stmt_list = DelimitedList(statement, delim=SEMI, allow_trailing_delim=True)` with `stmt_list = OneOrMore(statement)`.
- Add `SEMI` at the end of each simple statement (declaration, assignment, read, write, return, and function-call-as-statement) while leaving `If_Statement` and `Repeat_Statement` without trailing semicolons.
- Update tests in `examples/tiny/tests` to reflect the new semicolon rules where necessary.
Actions taken:
- Implemented `stmt_list = OneOrMore(statement)`. Added explicit trailing `SEMI` to all simple statements; kept `If_Statement` and `Repeat_Statement` without semicolons. Updated `examples/tiny/tests/test_tiny.py` where needed and verified tests.
- User prompt (update by user):
SEMI is already defined using Suppress, it is not necessary to use SEMI.suppress(), just use SEMI.
Plan:
- Ensure all affected grammar pieces use `+ SEMI` directly and remove any `SEMI.suppress()` calls.
Actions taken:
- Audited the grammar and replaced any `SEMI.suppress()` usage with bare `SEMI`. Confirmed behavior with tests.
- User prompt:
Insert the trailing SEMI terms inside each statement's Group definition. Insert SEMI terms in Declaration and Assignment statements, so that Simple_statement does not need to include any SEMI terms
Plan:
- Move the trailing `SEMI` inside the `Group(...)` for each simple statement (`Declaration_Statement`, `Assignment_Statement`, `Read_Statement`, `Write_Statement`, `Return_Statement`, and `Function_Call_Statement`).
- Simplify `Simple_Statement` so it no longer handles semicolon logic externally.
- Run existing tiny tests to confirm behavior is unchanged except for internal structuring.
Actions taken:
- Moved `SEMI` inside each statement `Group` and removed semicolon handling from the outer composition. Kept control-flow statements without semicolons. All tiny tests continued to pass.
- User prompt:
Insert a Tag expression in the new Function_Call_Statement
Plan:
- Modify `Function_Call_Statement` in `examples/tiny/tiny_parser.py` to prepend `pp.Tag("type", "call_stmt")` inside its `Group(...)`, retaining the inner `function_call` structure.
- Re-run tiny tests to ensure no regressions.
Actions taken:
- Added `pp.Tag("type", "call_stmt")` to `Function_Call_Statement`. Verified no regressions; tests passed.
- User prompt:
Add a reference to the TINY language definition at https://a7medayman6.github.io/Tiny-Compiler/Language-Description.html to the examples/tiny/README.md file
Plan:
- Edit `examples/tiny/README.md` to add a "Reference" section containing the given URL.
Actions taken:
- Appended a Reference section with the official TINY language definition link to `examples/tiny/README.md`.
|