Update BASIC.ipynb

This commit is contained in:
Peter Norvig
2024-04-17 18:03:33 -07:00
committed by GitHub
parent b7366db896
commit ec29440c14

View File

@@ -695,7 +695,7 @@
"source": [
"# Parsing: Grammar of Expressions\n",
"\n",
"Now for the single most complicated part of the grammar: the `expression`. The biggest complication is operator precedence: the string `\"A + B * X + C\"` should be parsed as if it were `\"A + (B * X) + C\"`, and not as `\"(A + B) * (X + C),\"` because multiplication binds more tightly than addition. There are [many schemes](https://en.wikipedia.org/wiki/Operator-precedence_parser) for parsing expressions, I'll use [an approach](https://groups.google.com/forum/#!topic/comp.compilers/ruJLlQTVJ8o) attributed to Keith Clarke.\n",
"Now for the single most complicated part of the grammar: the `expression`. The biggest complication is operator precedence: the string `\"A + B * X + C\"` should be parsed as if it were `\"A + (B * X) + C\"`, and not as `\"(A + B) * (X + C),\"` because multiplication binds more tightly than addition. There are [many schemes](https://en.wikipedia.org/wiki/Operator-precedence_parser) for parsing expressions, I'll use [an approach](https://groups.google.com/forum/#!topic/comp.compilers/ruJLlQTVJ8o) attributed to Keith Clarke called Compact Recursive-Descent Parsing.\n",
"\n",
"Like all our grammatical categories, calling `expression()` pops off some tokens and returns a data object. The first thing it does is parse one of five types of simple \"primary\" expressions: \n",
"a number like `1.23`; \n",