Skip to content

Use a semantic actions commit-list during parsing / Partial parsing #44

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

Open
ptal opened this issue Feb 24, 2015 · 5 comments
Open

Use a semantic actions commit-list during parsing / Partial parsing #44

ptal opened this issue Feb 24, 2015 · 5 comments

Comments

@ptal
Copy link
Owner

ptal commented Feb 24, 2015

Currently, the semantic action are called whenever the sub-expression is parsed. It means that if the parsing fails upwards, the result of the semantic action will be dropped. This is terrible if the semantic action has side-effect. It also will avoid to copy arguments passed to rules (when it'll be implemented) and it'll probably optimize the whole parsing step since no semantic rule will be called for nothing.

@ptal
Copy link
Owner Author

ptal commented Jul 4, 2015

Probably the easiest technique to implement this is to parse a first time the input without calling semantic actions or constructing the AST and to register the "good path". And to reparse it in a second pass by effectively calling the actions.

@ptal ptal changed the title Use a semantic actions commit-list during parsing Use a semantic actions commit-list during parsing / Partial parsing Aug 10, 2015
@ptal
Copy link
Owner Author

ptal commented Aug 10, 2015

This "path" could also be used for recording a partial state where more of the input is needed to continue. It might be less efficient?

@ptal
Copy link
Owner Author

ptal commented Aug 18, 2015

A version that does not record path is already implemented by &rule rule, &rule try to parse the input and only construct the AST with rule in case of success.

@ptal
Copy link
Owner Author

ptal commented Jul 8, 2016

We need benchmarks for measuring how fast is the recognizing step vs. parsing step. If it is fast enough, I propose to record the path when recognizing. It is doable by compiling the choice as follow:

e1 / e2 --->

let idx = state.replay.pop().unwrap();
match idx {
  0 => [e1],
  1 => [e2]
}

During recognizing we record the corresponding index into a replay index vector. I'm not sure if it's wise to make this the default and to store replay inside the state.

@ptal
Copy link
Owner Author

ptal commented Jan 6, 2021

I suggest a simpler version, useful to avoid calling semantic action with side effects on a global environment, by englobing semantic actions in lambda functions.
For instance, e1 e2 > f will produce a function || -> f(arg1(), arg2()) where arg1, arg2 are also functions generated by e1 and e2. Later on, it is possible to pass an environment as parameter, connecting to #10.
It doesn't seem too hard to implement.

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

No branches or pull requests

1 participant