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

Generate return-style code instead of default branches #10

Closed
sulir opened this issue May 19, 2012 · 5 comments
Closed

Generate return-style code instead of default branches #10

sulir opened this issue May 19, 2012 · 5 comments
Labels

Comments

@sulir
Copy link
Collaborator

sulir commented May 19, 2012

There exists an another possible style of generated decoder code, which uses the return statement after a variant is successfully recognized and throws an exception at the end of each rule. The default branches are not used at all.

This style should allow less strict ambiguity detection and the performance could be improved. However, it would bring some new issues which must be concerned, e.g. the instruction length recognition would be more difficult.

@ghost ghost assigned sulir May 19, 2012
@vbmacher
Copy link
Collaborator

vbmacher commented Jul 9, 2021

@sulir if you remember this ticket, what did you mean by "this style should allow less strict ambiguity detection"? Thanks

@sulir
Copy link
Collaborator Author

sulir commented Jul 9, 2021

I cannot remember exactly, but probably it is related to cases such as this one:

rule = "a": 0000 |
       "b": 00 subrule(2);

The recognition would be performed in the order defined in the file, so if some variant matches, the generated return statement is executed and the rest of the variants is not tested.

But the approach may have some shortcomings, and maybe I am confounding this with some other idea, it was a long time ago.

@vbmacher
Copy link
Collaborator

Hm, this actually reminds me the problem I explained in #34 . E.g., the following example:

instruction =  "JMP": line(5)     ignore8(8) 000 ignore16(16) |
               "JPR": line(5)     ignore8(8) 100 ignore16(16) |
               "DATA": data(32);

will fail with ambiguity detected, even if I want not to fail. My expectation (and the feature proposal in #34) is that it would try the instructions and only if those are not matched, then the last "branch" - "DATA" will be matched.

One solution as explained in #34 is to support multiple root rules, which will allow kind-of mixing the current style with "return-style" of the root rules:

root instruction, data;

instruction =  "JMP": line(5)     ignore8(8) 000 ignore16(16) |
               "JPR": line(5)     ignore8(8) 100 ignore16(16);

data = "DATA": data(32);

but on the other hand it is a grammar change. I actually like that the current style detects the ambiguity because I think in most of the cases it's the mistake of a programmer (I've run into many such issues and it was always my error). So I think it would be shame if we lost this capability by expanding the return-style in general.

I guess the proposal in #34 solves this best as far as I can see.

@vbmacher
Copy link
Collaborator

Therefore I propose to close this ticket...

@sulir
Copy link
Collaborator Author

sulir commented Jul 12, 2021

OK.

@sulir sulir closed this as completed Jul 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants