Skip to content

Commit

Permalink
Add a bit more code to 38/Readme.md.
Browse files Browse the repository at this point in the history
  • Loading branch information
Warren Toomey committed Nov 21, 2019
1 parent 8fff879 commit 3d96b60
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions 38_Dangling_Else/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,24 @@ All of these are, at present, calling `compound_statement(0)`, but this
enforces the parsing of a closing '}', and we won't have one of these for a single statement.

The answer is to get the IF, WHILE and FOR parsing code to call
`single_statement()` to parse one statement.
Thus, I've also made these changes:
`single_statement()` to parse one statement. And, get `single_statement()`
to call `compound_statement()` if it see an opening curly bracket.

Thus, I've also made these changes in `stmt.c`:

```
// Parse a single statement and return its AST.
static struct ASTnode *single_statement(void) {
...
switch (Token.token) {
case T_LBRACE:
// We have a '{', so this is a compound statement
lbrace();
stmt = compound_statement(0);
rbrace();
return(stmt);
}
...
static struct ASTnode *if_statement(void) {
...
// Get the AST for the statement
Expand Down

0 comments on commit 3d96b60

Please sign in to comment.