The MiniJava Scanner
October 6/7, 2003
[152 Home]     [Symbol Table]     [Syntax of MiniJava]     [What to do in lab?]     [Resources]

Symbol Table

  1. Definition:
    A symbol Table is a data structure containing a record for each identifier, with fields for the attributes of the id. It allows us to find the record for each identifier quickly and to store or retrieve data from that record quickly.

  2. What Attributes?
    • position in the input stream (start position, line number, ...);
    • type (const, variable, type, procedure...);
    • scope (program, procedure, ...);
    • ...

  3. When to insert an entry?
    When an id in the source program is detected by the scanner, it is inserted into the symbol table.

  4. When to fill in the attributes?
    At various times. The attributes cannot normally be determined during lexical analysis, and are filled in as the information becomes available.

  5. Who needs which attributes?
    • Semantic analysis and intermediate code generation need to know the types of identifiers so that they can generate the proper operations on them;
    • Code generator needs to know the storage assigned to identifiers so that it can generate the proper code to store and access it;
    • ...

  6. What operations?
    • insert(s, t): create a new entry for string s, return index of the new entry t
    • lookup(s): search for string s, return index in the symbol table

Syntax of MiniJava
  1. Valid tokens:
    • Basic Components: e.g. digit, letter
    • Complex Components: e.g. id, INTEGER_LITERAL
    • Keywords (bold words in grammar): e.g. class, System.out.println
    • Operators: e.g. "&&", "<"
    • Misc. Characters: e.g. ",", "["
  2. Valid but "useless" tokens: characters used to separate tokens, e.g. comments, tabs
  3. Invalid tokens: anything else not defined in MiniJava, e.g."#"

What to do in lab?
  1. Get familiar with the MiniJava specification
    • Categorize tokens
    • Figure out the regular expressions related with each token
  2. Try to get your scanner working - have it print out all of the tokens for Factorial.java

Resources
  1. The MiniJava Project
  2. man flex
  3. Textbook: SEC. 2.7 (pp. 60 - 62), SEC. 7.6 (pp. 429 - 440)