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

allows a typedefed named to immediately follow its typedef #26

Merged
merged 1 commit into from
May 13, 2021

Conversation

ivg
Copy link
Member

@ivg ivg commented May 13, 2021

In the following example

typedef int T; T foo(void);

i.e., when the next token after a typedef is the typedefed name, the T
token is already looked ahead, so it is recognized as IDENT not as
NAMED_TYPE, e.g., here is the trace,

Lookahead token is now IDENT (15-16) <-- 'T'
Reducing production typedef -> TYPEDEF typedef_type typedef_defs SEMICOLON
adding T <-- debug output from the lexer, indicating that T was added

The solution is to factor out the typedef non-terminal and move the
semicolon to globals so that we have it reduced earlier, when the next
token is SEMICOLON:

Reducing production typedef -> TYPEDEF typedef_type typedef_defs
adding T <-- typedef reduces before semicolon
State 542:
Shifting (SEMICOLON) to state 543
State 543:
Lookahead token is now NAMED_TYPE (15-16) <-- it is now recognized as type name

Fixes #23

In the following example
```
typedef int T; T foo(void);
```

i.e., when the next token after a typedef is the typedefed name, the T
token is already looked ahead, so it is recognized as IDENT not as
NAMED_TYPE, e.g., here is the trace,
```
Lookahead token is now IDENT (15-16) <-- 'T'
Reducing production typedef -> TYPEDEF typedef_type typedef_defs SEMICOLON
adding T <-- debug output from the lexer, indicating that T was added
```

The solution is to factor out the typedef non-terminal and move the
semicolon to globals so that we have it reduced earlier, when the next
token is SEMICOLON:

```
Reducing production typedef -> TYPEDEF typedef_type typedef_defs
adding T <-- typedef reduces before semicolon
State 542:
Shifting (SEMICOLON) to state 543
State 543:
Lookahead token is now NAMED_TYPE (15-16) <-- it is now recognized as type name
```

Fixes #23
@ivg ivg force-pushed the fixes-typedef-following-by-decl branch from d7ba59b to c8a9b03 Compare May 13, 2021 19:59
@ivg ivg merged commit fd12c40 into master May 13, 2021
@ivg ivg deleted the fixes-typedef-following-by-decl branch May 13, 2021 20:05
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.

Fail parsing named type right after it is defined
1 participant