In score = base + 6 * rate, what token kind does 6 have?
- A number token
- A name token
- A times token
In this front end, what is the lexer's job?
- Execute machine instructions and record their results
- Group characters into tokens with kinds and text
- Connect tokens into a tree under the grammar rules
Here * binds more tightly than +. The expression a + b * c groups as a + (b * c).
Circle one: True False
Use a binary-operator tree, where * binds more tightly than +. Which tree represents fee + hours * rate?
- Root * has left child + with children fee and hours, and right child rate
- Root + has left child fee and right child * with children hours and rate
- Root + has three direct leaf children fee, hours and rate, with no * node
Ignore spaces and keep names whole. How does the lexer split score = base + 6 * rate?
- score = base, +, 6 * rate: three tokens containing whole expression pieces
- s, c, o, r, e, =, b, a, s, e, +, 6, *, r, a, t, e: seventeen character tokens
- score, =, base, +, 6, *, rate: seven tokens with names kept whole
Subtraction is left associative. How does unparenthesised a - b - c group?
- It groups as a - (b - c)
- It has no grouping until runtime
- It groups as (a - b) - c
Here term has no unparenthesised subtraction and | separates alternatives. Which rule makes subtraction left associative?
- expr = expr - term | term
- expr = term - expr | term
- expr = term - term | term
Subtraction is left associative. A parser groups 9 - 4 - 1 as 9 - (4 - 1), giving 6. Which diagnosis fits?
- The parser used right grouping; the required left grouping gives 4
- The lexer must delete the final minus; deletion preserves the required grouping
- Subtraction is commutative here; changing operand order always preserves its value