First steps walkthru of lab1

Here's a short example going through adding and testing some sample tokens and rules for the lab1 lex and yacc files.

I'm going to follow this sequence:
  1. Add a tokens for identifiers and the set keyword, and revising the statement rule so that it accepts either of them or the numtok, and test what we've got so far.
  2. Change the body rule so it accepts multiple statements (i.e. I can have multiple identifiers, set keywords, and numbers in my source code) then test it works.
  3. Change the statement rule so that it recognizes a more realistic kind of statement, specifically a (simplified) assignment statement: set identifier number, and test it works.


1. Adding and checking tokens for identifiers and the set keyword


2. Changing the body rule to accept multiple statements

Right now the body can only have a single statment between begin and end, let's change that to be one-or-more.

To do so we'll change the (yacc) body rule to accept a statementlist rather than a single statement, and add a new rule to say that a statementlist can be either a single statement or a statement followed by more statements.


3. Changing the statement rule to handle (simplified) assignment statments

All the actual statements in the language are more complex than just single tokens, so let's change our statement rule to represent a single more realistic one.

We'll start with just a simple assignment statement of the following form:
set IDENTTOK NUMTOK
(eventually we'll want the right-hand side of that to be an expression rather than just a number, but start small and expand incrementally!)
We'll scrap the old statement rule, replacing it with something like statement --> assignstmt and add an assignstmt rule: