1/5
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What are the nonterminal symbols in a grammar?
A name on the left of a rewrite rule

What are the terminal symbols in a grammar?
Example: Non-terminals expr, term, digit-seq
The actual characters that end up in your program, can’t be rewritten further, and terminate the rewriting process: +, -, *, 0-9, (, )

Draw the derivation tree 4+6×2
Why is 6 a term and 2 a factor?
Same logic as #1, just one level down. The rule used for 6*2 was:
term → term mult-op factorThis has three slots again. * fills mult-op, so:
Everything left of * fills the term slot → 6
Everything right of * fills the factor slot → 2
![<p>Why is <code>6</code> a term and <code>2</code> a factor? </p><p class="font-claude-response-body break-words whitespace-normal leading-[1.7]">Same logic as #1, just one level down. The rule used for <code>6*2</code> was:</p><pre><code>term → term mult-op factor</code></pre><p class="font-claude-response-body break-words whitespace-normal leading-[1.7]">This has three slots again. <code>*</code> fills <code>mult-op</code>, so:</p><ul><li><p>Everything left of <code>*</code> fills the <code>term</code> slot → <code>6</code></p></li><li><p>Everything right of <code>*</code> fills the <code>factor</code> slot → <code>2</code></p></li></ul><p></p>](https://assets.knowt.com/user-attachments/9cf9546a-52a6-4af0-9c90-395041fe02fb.png)

What are the nonterminal & terminal symbols in this CFG?
nonterminals: expr, term, factor, add-op, mult-op, digit-seq, digit
terminals:
+ | -
* | DIV | REM
0 | 1 | 2… | 9
When is a string invalid according to the grammar?
A symbol appears that no rule can produce (e.g. % isn't in any rule)
The structure doesn't match any rule (e.g. two operators in a row 4++2)
It's incomplete — you can't finish rewriting all non-terminals (e.g. just +)
If you get stuck — meaning no rule can produce what you need — the string is invalid.
What is the standard precedence latter and what does low/high precedence mean?
Low precedence = sits at the top of the tree
High precedence = sits deeper in the tree
The standard precedence ladder (you just have to memorize this)
+ and - → lowest precedence (top of tree)
* and / → highest precedence