You can read a set of pointers (i.e. suitable types of tokens) from the LR (k) grammar, but such grammars tend to be huge. Various forms of grammar compression (of which LALR (1) are probably still the most common) make it less clear (it will always contain valid types of tokens, but it may also contain invalid ones). Invalid types of tokens in the lookahead set can also be introduced by compressing tables and by deliberately enabling error generation (to improve error messages).
Reading a control set from a recursive descent parser can be more complicated, in part because such parsers are usually open source, and not depending on jump tables. However, in theory, at least the LL (k) grammar also has the ability to compute a control set, although it may also be inaccurate.
The most interesting autocomplete, however, is not punctuation, but symbols. Grammar is not enough to tell you which names are in scope at a given point, although it can tell you which types of names would be feasible. You will need to connect to the character table to get accurate autocomplete information. In languages ββwhere identifiers can be used before they are declared, this can be even more complex, although it is likely that the parser does maintain a list of unresolved names.
Another difficulty with using parsers to generate autocomplete information is that parsers are typically optimized for syntactically correct programs and may not work at all after detecting a syntax error. For an IDE user, this can be really annoying; minor punctuation errors turn off autocomplete until the error is tracked and fixed. (Personally, I found that such systems are too distracting from the code, I would rather focus on what I'm writing at the moment than on the missing brackets in other parts of the code.)
IM (H) O, it would be better to use something vaguely similar to parsing packages to highlight enough context at the input point to get a reasonable idea of ββwhat might follow. If you have access to the complete correct data type declarations, use them, but there is always backing up something to text that looks like a character in a set for viewing (although this can also be annoying).
In any case, good luck.
rici source share