Select this to skip to main content [CSUSB] >> [CNS] >> [Comp Sci Dept] >> [R J Botting] >> [CSci620] >> 07 [Source]
[Index] [Schedule] [Syllabi] [Text] [Labs] [Projects] [Resources] [Search] [Grading]
Mon Apr 26 07:58:40 PDT 2004


    CSCI620 Session 7


      [ 06.html ]


      Study Chapter 4 pages 87.. semantic interpretation. Prepare some notes and at least one question you need to ask on it.


        I've translated some of the Pascal code into C++ [ 07.cpp ] to give some idea for non-Pascal people.

      . . . . . . . . . ( end of section Notes) <<Contents | Index>>


        Does the interpreter on pages 93 to 98 work

        Yes. When transcribed correctly into C++, compiled and tested it worked well. It some extra stuff that could be commented out, and the identifier error was defined as a constant int with value 0. See the Laboratory.

        May I use a different definition of function and procedure?

        Only if you are willing to explain why. The standard computer science terminology is: Functions and procedures are two types of subprogram, functions return values, procedures don't.

        In some languages functions are supposed to have no side-effects. This is difficult to enforce, and makes it harder to write some things. For example the code in this chapter relies on boolean functions that read data, and also push and pop data onto a stack.

        In this class, do not use the C/C++/Java terminology of void function vs nonvoid function unless you say that you are using the C/C++/Java terminology.

        On page 88 figure 4.3 side bar has a pointer to the second part of the box!

        When we draw data structures it does not matter which edge of the box an arrow is attached! Even if it points at the end, it is actually the address of the first byte in the box.

        If the arrow ends inside a box then the pointer may be referring to part of the data. If it touches the edge, it refers to the whole.

        On page 91 Where is the second item pushed on the stack in t1.

        Function t1 calls function f (in an if) before it gets to popping 2 items off the stack. Function f pushes more data onto the stack as a side effect.

        On page 98 at the bottom is P" correct?

        Yes. Also near the top of page 78.

        What is the difference between a compiler and an interpreter?

        A compiler produces a complete program and stops. The program is stored in a file -- an executable. This file can be executed. It can be run many times without recompiling.

        An interpreter executes a program directly. Each statement in turn is lexed, parsed, and executed in turn. No new translation of the program is stored. In a single run of the program some statements are parsed many times!

        In a hybrid compiler/interpreter the source code is translated into an intermediate code (byte code for example) and a separate interpreter (a virtual machine) executes the code.

        Compilers tend to be slow in translating code, but produce fast running programs. Interpreters tend to execute slower than compiled code.

        Most languages have had both interpreters and compilers. Most languages are typically either interpreted or compiled. For example C was compiled, but there was a CTERP program shared by readers of a magazine. LISP is traditionally executed by an interpreter, and yet modern interpreters do a form of compilation when presented with function definitions.

        The difference between compiling and interpreting is practical and not theoretical. So there is no connection between them and types of machines (TM, PDA, FSA,...). However -- Turing constructed a single universal TM that interprets a programs stored on the TM's tape.

        What is a symbol table?

        A symbol table stores pairs: a symbol and a value. It has operations to add and remove pairs, and the ability to find the value associated with a given symbol.

        How does a symbol table work?

        There are many ways to make a symbol table work. Hash tables, tree structures, linear lists, can all be used.

        If you need one in a C++ program use the STL map and pair templates. In Java use a Dictionary.

        You will meet a simple symbol table future labs.

        In Pascal what does forward mean?

        The symbol forward is use in Pascal to stand in for the body of a subprogram that is completely defined later in the program. The C++ equivalent is a function header, and in C a prototype:
        function e:boolean; forward;bool e();
        procedure push(i:int); forward;void push(int);

      . . . . . . . . . ( end of section Questions) <<Contents | Index>>



      . . . . . . . . . ( end of section Exercises) <<Contents | Index>>


      Lexical and syntactic analysis: [ lab07.html ]


      Chapter 5 pp99-116: imperative, Von Neumann, FORTRAN,... Prepare some notes and at least one question you need to ask on it. [ 08.html ]

    . . . . . . . . . ( end of section CSCI620 Session 7) <<Contents | Index>>


  1. BNF::="Backus-Naur Form", for syntax and grammar, developed by Backus and Naur.
  2. EBNF::="Extended " BNF.
  3. HTML::= "HyperText Markup Language", used on the WWW.
  4. HTML_page::syntax= "<HTML>" head body.
  5. Java::="An " OO " Language from Sun".
  6. LISP::= "LISt Processing Language".
  7. LRM::="Language Reference Manual".
  8. OO::="Object-Oriented".
  9. Prolog::="Programming in Logic".
  10. TBA::="To Be Announced".
  11. UML::="Unified Modeling Language".
  12. URL::=Universal_Resource_Locator,
  13. Universal_Resource_Locator::syntax= protocol ":" location, where
    1. protocol::= "http" | "ftp" | "mailto" | ... ,
    2. location::= O( "//" host) O(pathname).

    (End of Net)
  14. WWW::= See, index to web site for this class.
  15. XBNF::="eXtreme" BNF, developed by the teacher from EBNF, designed to ASCII input of syntax, semantics, and other formal specifications.

Formulae and Definitions in Alphabetical Order