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

Improving Lesson 1.3 by mentioning longest match while scanning tokens #3618

Merged
merged 3 commits into from
Sep 5, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions k-distribution/k-tutorial/1_basic/03_parsing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ interprets terms according to the grammar defined by the developer. It is
automatically converted into an AST of that term, and then the `colorOf`
function is evaluated using the function rules provided in the definition.

You can ask yourself: How does K match the strings between the double quotes?
The answer is that K uses Flex to generate a scanner for the grammar. Flex looks
for the longest possible match of a regular expression in the input. If there
are ambiguities between 2 or more regular expressions, it will pick the one with
the max precedence token. You can learn more about how Flex matching works
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"prec attribute", not "precedence token"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

[here](https://westes.github.io/flex/manual/Matching.html#Matching).

Bringing us back to the file `lesson-03-a.k`, we can see that this grammar
has given a simple BNF grammar for expressions over Booleans. We have defined
constructors corresponding to the Boolean values true and false, and functions
Expand Down