Assignment 3, due June 23

Includes Machine Problem 2, due June 25

Part of the homework for 22C:50, Summer 2003
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

 

Machine Problem 2

Ground rules: See Machine Problem 1!

Part 1 of the assignment: The EAL assembler distributed to the class lacks many features! One of these is the ability to test expressions to see if they are already defined. Consider using the following notation to set x to one if the expression a+b has a defined value and to zero otherwise (for more discussion, see Figure 6.2 of the text):

	x = DEF( a + b )

Clearly, this is a modification to the expression syntax, handled by parse_operand in our assembler. To handle this, we begin by modifying the BNF grammar for operands:

	 := ... |  (  )

This opens the door to a host of built-in functions in EAL, but we are only interested in one of them, the specific identifier DEF. Implement this extension to the assembler's expression evaluator! While you're at it, fix the comments at the head of parse_operand to reflect the grammar it actually handles -- there is a significant error there!

Part 2 of the assignment: Add support for conditional assembly to the EAL assembler, using the conditional notation illustrated in Figure 6.3.

Homework 3

  1. Correct the BNF given in the header comments for parse_operand

  2. Hand assemble this EAL code -- you can verify your work using the real EAL assembler, but you should do it by hand first in order to improve your understanding of the assembly process:
    	; The following code just illustrates some features of EAL
    	A = .
    	. = B
              W A
            . = A
              W B
            B = .
    

  3. Using the two-pass model of assembly, hand assemble this bit of EAL code that uses conditional assembly:
    	IF UND(A)
    	  . = 1
    	ENDIF
    	  W A
    	A:
    	  W A
    

  4. The previous example includes what is called a phase error, where a label gets a different definition on pass 1 than it had on pass 2. Suggest a way to detect and report phase errors. Does your solution also detect and report multiple label definitions (where the same identifier is used as a label in two or more places in the program).

  5. There are two ways of supporting multi-character operators such as <<. The lexical analyzer can handle these as two-character punctuation marks, reporting < and << as different lexemes, or the parser can use look-ahead to distinguish between < when it is followed by < and < when it is followed by anything else.

    Propose an experiment you could do, as a programmer, to find out whether << is a distinct lexeme or whether it is two lexemes that are collapsed into one operator at the syntactic level. Do this experiment for some C or C++ compiler and report the result.