Skip to content

Commit

Permalink
feat: update AST to reflect new grammar
Browse files Browse the repository at this point in the history
Previously, our implementation of the context-free grammar did not properly take into account operator precendence (for example, NOT was applying incorrectly over the expressions when building the AST). We updated the grammar and relevant components of the plugin to account for these fixes.

Co-authored-by: sanjanamandadi <sanjanamandadi@gmail.com>
Co-authored-by: timoslater <tsla0307@gmail.com>
Co-authored-by: Nytro1O1 <35637473+Nytro1O1@users.noreply.github.com>
Co-authored-by: micah-0w0 <tinyviolin1@gmail.com>
  • Loading branch information
5 people committed Jul 20, 2024
1 parent b88d1ba commit 52ddb53
Show file tree
Hide file tree
Showing 10 changed files with 689 additions and 360 deletions.
31 changes: 21 additions & 10 deletions parser/README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
### Extended Backus-Naur Form (EBNF) Grammar
An EBNF context-free grammar (CFG) representing a formal language for boolean expressions.

```
Expr ::= Var Expr'
| ! Expr
| ( Expr )
Expr' ::= & Expr
| \| Expr
Expr ::= Term Expr'
Expr' ::= | Expr'
| & Expr'
| ^ Expr'
| ε
Term ::= ( Expr )
| ! Term
| Var
Var ::= [A-Z]+
| t
| f
```

### LL(1) Parsing Table
### LL(1) Parse Table
The parse table applying all of the above production rules in the EBNF grammar showing that it is LL(1).

TODO: Update this table.

| | [A-Z] | ( | ) | ! | & | \| | $ |
|-------|:-----------------:|:-------------:|:-:|:---------------:|:----------------:|:---------------:|:---------:|
| Expr | Expr → Var Expr' | Expr → (Expr) | | Expr → ! Expr | | | |
| Expr' | | | | | Expr' → & Expr | Expr' → \| Expr | Expr' → ϵ |
| Var | Var → [A-Z]+ | | | | | | |

Var = Variable \
Expr = Expression

### First and Follow Function Table
A table showing the FIRST and FOLLOW sets of each non-terminal in the EBNF grammar along with if the non-terminal is NULLABLE.

TODO: Update this table.

| | FIRST | FOLLOW | NULLABLE |
|-------|:------------:|:------:| :-------: |
| Expr | [A-Z]+, !, ( | $, ) | |
Expand Down
Loading

0 comments on commit 52ddb53

Please sign in to comment.