\n", "

### Quiz

\n", "

\n", "

Which of these strings cannot be produced from the above `<start>` symbol?
\n", "

\n", "

\n", "

\n", " \n", " \n", "
\n", " \n", " \n", "
\n", " \n", " \n", "
\n", " \n", " \n", "
\n", " \n", "
\n", "

\n", " \n", " \n", "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "quiz(\"Which of these strings cannot be produced \"\n", " \"from the above `` symbol?\",\n", " [\n", " \"`007`\",\n", " \"`-42`\",\n", " \"`++1`\",\n", " \"`3.14`\"\n", " ], \"[27 ** (1/3), 256 ** (1/4)]\")" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "source": [ "### Arithmetic Expressions\n", "\n", "Let us expand our grammar to cover full *arithmetic expressions* – a poster child example for a grammar. We see that an expression (``) is either a sum, or a difference, or a term; a term is either a product or a division, or a factor; and a factor is either a number or a parenthesized expression. Almost all rules can have recursion, and thus allow arbitrary complex expressions such as `(1 + 2) * (3.4 / 5.6 - 789)`.\n", "\n", "```\n", " ::= \n", " ::= + | - | \n", " ::= * | / | \n", " ::= + | - | () | | .\n", " ::= | \n", " ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9\n", "```\n", "\n", "In such a grammar, if we start with `` and then expand one symbol after another, randomly choosing alternatives, we can quickly produce one valid arithmetic expression after another. Such *grammar fuzzing* is highly effective as it comes to produce complex inputs, and this is what we will implement in this chapter." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2022-05-17T17:03:18.396285Z", "iopub.status.busy": "2022-05-17T17:03:18.395776Z", "iopub.status.idle": "2022-05-17T17:03:18.397690Z", "shell.execute_reply": "2022-05-17T17:03:18.397917Z" }, "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", "
\n", "

### Quiz

\n", "

\n", "

Which of these strings cannot be produced from the above `<start>` symbol?
\n", "

\n", "

\n", "

\n", " \n", " \n", "
\n", " \n", " \n", "
\n", " \n", " \n", "
\n", " \n", " \n", "
\n", " \n", "
\n", "

\n", " \n", " \n", "
\n", "

### Quiz

\n", "

\n", "

What drawbacks does `simple_grammar_fuzzer()` have?
\n", "

\n", "

\n", "

\n", " \n", " \n", "
\n", " \n", " \n", "
\n", " \n", " \n", "
\n", " \n", " \n", "
\n", " \n", "
\n", "

\n", " \n", " \n", "