Skip to content

d_initial is not used by the parser, so no point generating it #12212

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

Merged
merged 1 commit into from
Mar 9, 2019

Conversation

tyomitch
Copy link
Contributor

@tyomitch tyomitch commented Mar 7, 2019

No description provided.

Copy link
Member

@pablogsal pablogsal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think is better to pass the index of the start symbol into the list of dfas down to the grammar and use that when generating the parser input files.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@tyomitch
Copy link
Contributor Author

tyomitch commented Mar 7, 2019

I think is better to pass the index of the start symbol into the list of dfas down to the grammar and use that when generating the parser input files.

Could you please clarify?

@pablogsal
Copy link
Member

pablogsal commented Mar 7, 2019

Could you please clarify?

Yup, make pgen generate it from the position of the initial symbol. The initial dfa symbol is placed in the grammar in:

https://github.com/python/cpython/blob/e12f56075edc5704c9cfbf69d268474328642fa3/Parser/pgen/pgen.py#L53

The value has to be the position of that symbol in the list of dfas. It will be 0 as single_input is always the first DFA in the list of dfas, but doing programmatically will protect in case the position changes in the future. Basically something on the lines of (for illustrative purposes):

change:

"0, {n_states}, states_{dfa_index},\n".format(

to

start_index = list(self.dfas.keys()).index(self.start)
"{start}, {n_states}, states_{dfa_index},\n".format(start=start_index

@tyomitch
Copy link
Contributor Author

tyomitch commented Mar 8, 2019

Now I see what you mean, but d_initial is not about the initial DFA of the grammar, it's about the initial state of a DFA: each DFA has its own d_initial, and they're all zeroes.

@pablogsal
Copy link
Member

Now I see what you mean, but d_initial is not about the initial DFA of the grammar, it's about the initial state of a DFA: each DFA has its own d_initial, and they're all zeroes.

Oh, right! Sorry, I have mistaken this with the start rule in the old pgen:

g = newgrammar(gr->gr_nfa[0]->nf_type);

But as you indicate, d_initial has been initialized always to 0:

d->d_initial = 0;

@pablogsal
Copy link
Member

@tyomitch Can you rebase to regenerate the graminit.c file.

@tyomitch
Copy link
Contributor Author

tyomitch commented Mar 9, 2019

@tyomitch Can you rebase to regenerate the graminit.c file.

Done!

@pablogsal pablogsal merged commit 1b304f9 into python:master Mar 9, 2019
@pablogsal
Copy link
Member

Thanks @tyomitch for the contribution! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants