-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[golang] Fix for #4469: Add symbol table. #4488
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
base: master
Are you sure you want to change the base?
Conversation
Results of parsing goroot runtime: 2835 success out of 3058 total .go files.
Annoyingly, Antlr does not parse correctly when predicates are placed after a decision point. This occurs when there are two deriviations that lead to the same thing, as with input
and
There are two derivations for
If we place the predicate at the end of The second choice is the correct one because the string Parr et al recommend hoisting the predicate into the calling rule, but this is quite unnatural because we don't have the parse tree for the input at the point where the choice needs to be made. In fact, all we have is a stream of tokens. There are a number of different hacks to fix this. One hack is to perform the parse at the beginning of |
It turns out that we should have both the ambiguous grammar from spec without symbol table and one with symbol table. Using the strategy I outline above to implement disambiguation predicates, the original grammar without predicates is important in identifying the source of the ambiguity. We need to understand where the ambiguity is actually coming from so we can add in the "syntactic predicate" hack at the correct pinch points. |
This is a fix for #4488.
This PR fixes all ambiguity in the grammar with the addition of explicit actions and predicates. This is likely the first grammar in grammars-v4 with a full-scale symbol table.
The reason for the symbol table is that the Go language is not context-free. The EBNF grammar from the Go Language Specification is ambiguous. The semantics to disambiguate the EBNF grammar is given in the Spec, but it is not in the EBNF itself. This PR adds that part of the semantics explicitly into the grammar using actions and predicates in target-agnostic format.
In addition, some parts of the grammar were just incorrect, somehow erroneously copied from the Spec.
This PR is being tested against the Go runtime.
Current status of testing of the Go runtime: 2835 success out of 3058 total .go files.
This is the test suite.
goroot-src.tar.gz