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!
=== Example execution of the algorithm === An example execution on the expression 2 + 3 * 4 + 5 == 19 is as follows. We give precedence 0 to equality expressions, 1 to additive expressions, 2 to multiplicative expressions. ''parse_expression_1'' (''lhs'' = 2, ''min_precedence'' = 0) * the lookahead token is +, with precedence 1. the outer while loop is entered. * ''op'' is + (precedence 1) and the input is advanced * ''rhs'' is 3 * the lookahead token is *, with precedence 2. the inner while loop is entered.<br>''parse_expression_1'' (''lhs'' = 3, ''min_precedence'' = 2) :* the lookahead token is *, with precedence 2. the outer while loop is entered. ::* ''op'' is * (precedence 2) and the input is advanced ::* ''rhs'' is 4 ::* the next token is +, with precedence 1. the inner while loop is not entered. ::* ''lhs'' is assigned 3*4 = 12 ::* the next token is +, with precedence 1. the outer while loop is left. :* 12 is returned. * the lookahead token is +, with precedence 1. the inner while loop is not entered. * ''lhs'' is assigned 2+12 = 14 * the lookahead token is +, with precedence 1. the outer while loop is not left. * ''op'' is + (precedence 1) and the input is advanced * ''rhs'' is 5 * the next token is ==, with precedence 0. the inner while loop is not entered. * ''lhs'' is assigned 14+5 = 19 * the next token is ==, with precedence 0. the outer while loop is not left. * ''op'' is == (precedence 0) and the input is advanced * ''rhs'' is 19 * the next token is ''end-of-line'', which is not an operator. the inner while loop is not entered. * ''lhs'' is assigned the result of evaluating 19 == 19, for example 1 (as in the C standard). * the next token is ''end-of-line'', which is not an operator. the outer while loop is left. 1 is returned.
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)