Skip to content

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

Merged
pablogsal merged 1 commit into
python:masterfrom
tyomitch:d_initial
Mar 9, 2019
Merged

d_initial is not used by the parser, so no point generating it#12212
pablogsal merged 1 commit into
python:masterfrom
tyomitch:d_initial

Conversation

@tyomitch

@tyomitch tyomitch commented Mar 7, 2019

Copy link
Copy Markdown
Contributor

No description provided.

@pablogsal pablogsal left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown

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

tyomitch commented Mar 7, 2019

Copy link
Copy Markdown
Contributor Author

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

pablogsal commented Mar 7, 2019

Copy link
Copy Markdown
Member

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

tyomitch commented Mar 8, 2019

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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
Copy Markdown
Member

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

@tyomitch

tyomitch commented Mar 9, 2019

Copy link
Copy Markdown
Contributor Author

@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
Copy Markdown
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