Skip to content

Can backtracking be avoided? #281

Answered by skyrich62
0x8000-0000 asked this question in Q&A
Discussion options

You must be logged in to vote

A way to reasonably distinguish between identifiers and keywords

Using this technique, you can use a grammar rule to specify a keyword where it must be that keyword, and still allow it to be used as an identifier in other contexts.

Consider a grammar where "require" is sometimes a keyword, but can be used as an identifier in other places, for example:

require_clause <- REQUIRE identifier
decl_clause <- DECLARE identifier

Where "identifier" has the usual meaning, and REQUIRE and DECLARE, (capitalized here to show them as terminal symbols in the PEG), have been declared as keywords as show below:

This could allow:

require xyzzy      // "require" used as keyword
declare require   // "requi…

Replies: 6 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by 0x8000-0000
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@0x8000-0000
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants