Skip to content

Improved Grammar, Implemented Parsing to IR#10

Merged
fpham0701 merged 21 commits intomainfrom
struct_grammar
Feb 5, 2025
Merged

Improved Grammar, Implemented Parsing to IR#10
fpham0701 merged 21 commits intomainfrom
struct_grammar

Conversation

@Nikil-Shyamsunder
Copy link
Collaborator

Grammar and Lexing Changes:

  • Removed all operators more complex than bitwise.
  • Eliminated else if statements and other complexities for now.
  • Introduced struct syntax in the grammar.
  • Functions now require a struct type parameter, specified using angle bracket syntax (<T>).
  • Added assert_eq as a new statement type.

IR Changes:

  • Separated Binary and Unary operations for better structure and clarity.
  • Introduced BoxedExpr:
    • Serves as an intermediate representation before full parsing into Expr.
    • Ensures compatibility with pest’s PrattParser, avoiding Rust’s compilation issues when mutating the same structure within multiple closures.
    • Temporarily stores start and end characters until they can be added to the transaction during parsing.
  • Added Helper Functions symbol_id_from_name and struct_id_from_name; required for correct parsing of symbols and struct definitions.

Serialize & Typecheck Updates:

  • Minor adjustments to accommodate the new IR structure.
  • Operators (Ops) are now independent enumerations.

Parser Changes:

  • Implemented the entire parsing stage within parser.rs.
  • Test Suite Overhaul:
    • Added new tests for all updated files.
    • Removed obsolete files that no longer define structs.
    • Introduced new struct definitions where necessary.
    • Tests now parse and then reserialize.

@fpham0701
Copy link
Collaborator

For the function symbol_id_from_name and other getter functions that you made, isn't it possible to just index utilizing the symbol table itself? I.e. st[(name)]?

@fpham0701
Copy link
Collaborator

I saw one of the calyx_go_done tests still named calyx_go_down so I just changed it. woops!

@Nikil-Shyamsunder
Copy link
Collaborator Author

For the function symbol_id_from_name and other getter functions that you made, isn't it possible to just index utilizing the symbol table itself? I.e. st[(name)]?

the field by_name of SymbolTable is private, so I think this is the best way to do it.

@ekiwi
Copy link
Collaborator

ekiwi commented Feb 4, 2025

self.structs.keys().collect()
}
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This required changing the implementation of the indexing and fixing the test cases that use it accordingly. I then removed the helper function I was using and replaced it with this more simple indexing.

The only thing to consider as a downside is that it is harder to capture a parsing failure (e.g. someone attempts to assign to an undeclared variable, an expression refers to a non-existent symbol) and return an expressive error message now because this panics with "no entry found for key"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay, I've reverted for now after deciding that the panic issue causes problems for proper error handling in the parsing stage.

@fpham0701 fpham0701 merged commit 3226100 into main Feb 5, 2025
10 checks passed
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