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

[build] Add testing for grammar ambiguity. #4276

Merged
merged 1 commit into from
Oct 5, 2024

Conversation

kaby76
Copy link
Contributor

@kaby76 kaby76 commented Oct 5, 2024

I'm really excited about this one!!

This change adds testing for grammar ambiguity using trperf. The tool essentially runs the parser with the ProfilingATNSimulator. (It does not test the grammar using Z3/SMT. I am still working on that.)

  • A CSharp parser is first generated for the grammar.
  • The CSharp parser is built.
  • The parser is run via trperf on all input files. trperf collects data on the ambiguity and rule name. This output is filtered using grep for non-zero ambiguity, then the list of rule names sorted and made unique. It's all done via the command line, using simple Bash piping.

The output is a little hard to read, but you can see the list of symbols that are ambiguous after all parses.

  • abb: dataList
  • aql: collect, expr, filter, for_in, let_list, limit, sort
  • arden: exprBefore, exprFunction, exprSort
  • asl: compound_logical_condition, event_generation, if_statement, logical_condition, operation_invocation, simple_logical_condition, struct_value
  • ...
  • bcpl: e0, e2, e3, e4, e5, e6, e7, e8, ...
  • bnf: xalt, xelem, xlhs, xrhs
  • c: blockItem, castExpression, ......
  • ...

The entire list of grammars and ambiguity at this point are here:
ambig.txt

Note, the actual ambiguous parse trees can be obtained using trparse --ambig, but that can take a lot of time, so it is not done.

@kaby76 kaby76 marked this pull request as ready for review October 5, 2024 08:24
@teverett
Copy link
Member

teverett commented Oct 5, 2024

@kaby76 thanks. This is great.

@teverett teverett merged commit b363027 into antlr:master Oct 5, 2024
7 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.

2 participants