CSC 330 Lecture Notes Week 3, Part 2
A CUP-Built Parser for Pascal



  1. Pascal as a language.
    1. Pascal is a real language that is still in use today, though not very much commercially.
    2. In its heyday, it was used primarily as an instructional language.
    3. Today it is used as a good example to illustrate basic programming language concepts, and compare similar concepts in other languages.

  2. Comparing Pascal and EJay.
    1. In overall complexity and power, Pascal and EJay are quite comparable.
    2. Syntactically there are obvious differences.
      1. E.g., Pascal uses more verbose keywords, such as "begin" and "end" instead of "{" and "}".
      2. However, once we get beyond parsing, these differences are irrelevant.
    3. Semantically, Pascal and EJay are quite similar.
      1. Neither has any form of high-level modularization, such as classes or packages.
      2. They do have pretty similar scoping structures, such that the same symbol table design can be used for both of them.
      3. As we progress to writing an interpreter in coming weeks, we'll examine the semantics of simple languages like Pascal and EJay in detail.
    4. In the meantime, we'll use Pascal to present an example parser, to provide concrete guidance for your work on Assignment 3.

  3. A CUP parser for Pascal
    1. Included with these notes are source code listings for the Pascal CUP spec, plus files for the symbol table support classes.
    2. The Pascal parser also uses the same parse tree classes that are in Part 1 of this week's lecture notes.
    3. The attached listings are these:
      1. pascal.cup -- the CUP parser specification (tree building, but no symbol table yet)
      2. SymbolTable.java -- a symbol table data type for procedural languages such as Pascal and EJay
      3. SymbolTableEntry.java -- the definition of an entry in the symbol table
      4. VariableEntry.java -- an extension of SymbolTableEntry for variable and parameter entries
      5. FunctionEntry.java -- an extension of SymbolTableEntry for function (procedure, method) entries
    4. We will do an in-depth walk-through of these files in class.