Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Operator-precedence parser
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Pseudocode === The pseudocode for the algorithm is as follows. The parser starts at function ''parse_expression''. Precedence levels are greater than or equal to 0. <u>parse_expression()</u> '''return''' parse_expression_1(parse_primary(), 0) <u>parse_expression_1(lhs, min_precedence)</u> ''lookahead'' := peek next token '''while''' ''lookahead'' is a binary operator whose precedence is >= ''min_precedence'' ''op'' := ''lookahead'' advance to next token ''rhs'' := ''parse_primary'' () ''lookahead'' := peek next token '''while''' ''lookahead'' is a binary operator whose precedence is greater than ''op''<nowiki>'</nowiki>s, or a right-associative operator whose precedence is equal to ''op'''s ''rhs'' := ''parse_expression_1'' (''rhs'', precedence of ''op'' + (1 if ''lookahead'' precedence is greater, else 0)) ''lookahead'' := peek next token ''lhs'' := the result of applying ''op'' with operands ''lhs'' and ''rhs'' '''return''' ''lhs'' Note that in the case of a production rule like this (where the operator can only appear once): <syntaxhighlight lang="abnf"> equality-expression ::= additive-expression ( '==' | '!=' ) additive-expression </syntaxhighlight> the algorithm must be modified to accept only binary operators whose precedence is > ''min_precedence''.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)