-
Notifications
You must be signed in to change notification settings - Fork 1
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
Symbol tables #31
Comments
@mingodad, any thoughts on this topic? |
Note that since symbol tables can be initialized, they can be used as a 'dictionary' as well, for keyword lists, etc.; use anywhere where you want to match a list of literals more efficiently than listing them out as choices: init: |
I need some time to digest it but at first it seems that it'll cover a lot of use cases. |
It seems that now there is only one literal keyword in the proposed grammar |
A full working grammar with good error recovering like in lpeglabel will end up awful but at the end somehow to use the grammar we'll need that functionality, with a tool to extract |
And just playing around I add a terminator (
Then Primary:
|
Here is the proposed grammar with definition terminator and
And here the sample usage:
|
It's not clear to me the |
Another common construction like |
Lexical scopes, the same idea as in SCOPES in https://github.com/Lercher/CocoR#scoped-symbols I like the ideas there but not sure I like how everything is defined in their syntax. They have this on a rule:
And then another area where they initialize and set if a table is strict or not (which I suppose could be added on to chpeg's TableInit.) Why is that part on the table init/definition, but USEONCE and USEALL are on the rule definition? STRICT to me seems like something similar to those two concepts; why would it be global for a table but USEONCE and USEALL are local to a rule? I figured I would add this kind of stuff later but perhaps the concepts and syntax should be ironed out first. |
I wish PEG had a terminator in the first place... I'd rather not break PEG compatibility like this though. Another thought I had was to put every pre-
Which would simplify that Identifier check to something like:
Somehow, it has to differentiate the rule Options in |
Not sure I follow completely, and I get a bit lost looking at LPEG syntax (not really familiar with it). Those are other extensions to consider, but I think the main syntax focus/issue here is related to extended rule-level options on the left of |
And that's why I gave an example of replacing
|
A new lexical scope would: create an empty symbol table for that scope; on set it would set the value in the nearest scope. On lookup it would search the nearest scope and then search outer scopes, nearest first. At least this is how I understand it, and how I implemented the similar concept of reference scopes ( To further expand on this, symbol tables will not be destroyed, except on backtracking in a way that 'undoes' them. This is the nature of PEG and doing semantic/context-sensitive things-mid processing (vs waiting until parse complete). I believe that 'destroyed' explanation applies to their LL(k) implementation. Like ref-scopes (which store the back-reference values), I plan to place the symbol table storage inside the parse-tree nodes to solve many issues and make it packrat compatible, issues I've discussed previously in a few places. Packrat will probably make sense to not undo/repeat a bunch of symbol table work on backtracking, but this really depends on grammar. It seems like the grammars like C that would use such symbol table features do a lot of backtracking. |
I just thought of something else related to backtracking: are symbol table related errors like parse errors, i.e. not actually errors until backtracking tries all options? I'm thinking it is probably possible to cause a symbol table error (e.g. "'foo' not defined") that is actually backtracked and discarded. Sometimes PEG is maddening. |
As you've said the important thing here is to find a proper way to describe then in the grammar but it would be interesting to play with some initial implementation to test with a few grammars and see how it feel/work. |
Proposed syntax for symbol table extension
Usage example:
The text was updated successfully, but these errors were encountered: