加载中,请稍候
期末考试
答题进度: 0/31 交卷

第六、七、八章节

  1. 1.

    When inheriting a previously computed synthesized attribute during LR parsing, it is suitable to treat the computed synthesized attribute as ________.

    单选题 (2 分)
  2. 2.

    The concept  ________ is not related with automatic management of the heap.

    单选题 (2 分)
  3. 3.

    Which of the following is commonly found in an activation record?  

    单选题 (2 分)
  4. 4.

    In the following, ________ must be done by the caller.

    单选题 (2 分)
  5. 5.

    The suitable structure of the symbol table with large amount of symbols is ________.

    单选题 (2 分)
  6. 6.

    Given the following declarations:   

      t1 = array [10] of int;

      t2 = array [10] of int;

    if t1 and t2 is equivalent, it follows ________ equivalence.

    单选题 (2 分)
  7. 7.

    The space for bookkeeping information will not contain________.

    单选题 (2 分)
  8. 8.

    The idea of delayed evaluation is used in  ________ parameter passing mechanism.

    单选题 (2 分)
  9. 9.

    The output of the semantic analysis phase is _____________.

    单选题 (2 分)
  10. 10.

    Which of the following is used to retrieve nonlocal data declared within another procedure?

    单选题 (2 分)
  11. 11.

    The access link will be used in ________.

    单选题 (2 分)
  12. 12.

    A Yacc-generated parser implements the semantic values by keeping a ________ parallel to the parsing stack.

    单选题 (2 分)
  13. 13.

    Which of the following is true ?

    单选题 (2 分)
  14. 14.

    When computing the attributes of a language, a traverse order of the dependency graph must be _____.

    单选题 (2 分)
  15. 15.

    The runtime environment dependents only on the architecture of the target machine.

    判断题 (1.5 分)
  16. 16.

    The space for local temporaries is generally not allocated in the procedure activation record.

    判断题 (1.5 分)
  17. 17.

    Intermediate code can be very high level, or it can closely resemble target code.

    判断题 (1.5 分)
  18. 18.

    Semantic analysis is an independent phase that its computations always occur prior to code generation and after parsing.

    判断题 (1.5 分)
  19. 19.

    All inherited attributes can be changed into synthesized attributes by suitable modification of the grammar, without changing the language of the grammar.

    判断题 (1.5 分)
  20. 20.

    All the S-attribute grammars belong to L-attribute grammars.

    判断题 (1.5 分)
  21. 21.

    The general organization of runtime storage will contain the code area, the global/static area, a stack, a free space as well as a heap.

    判断题 (1.5 分)
  22. 22.

    Yacc can not use ambiguous grammars.

    判断题 (1.5 分)
  23. 23.

    An inherited attribute can be calculated by a postorder traversal of the parse tree.

    判断题 (1.5 分)
  24. 24.

    When a procedure is called, an activation record P is generated on stack. There may be activation records on stack corresponding to sibling children nodes of P in the activation tree.

    判断题 (1.5 分)
  25. 25.

    Three-address code has three fields.

    判断题 (1.5 分)
  26. 26.

    The activation record kept in the stack is always directly pointed by frame pointer (fp).

    判断题 (1.5 分)
  27. 27.

    Translate the following statements into a quadruple sequence:

    while (a<b and c>d) do

       if (e<f) then

               x := y + z;

    else

              x := y - z;

    简答题 (10 分)
    附件 上传 最多可上传6张图片
  28. 28.

    Given the following program: 

      #include <stdio.h>

      Int i=0;

      Void swap(int x, int y)

      { x= x+y;

       y=x-y;

       x=x-y;

      }

      main()

      { int a[3]= {2, 0, 1};

       swap(i, a[i]);

       printf(“%d %d %d %d \n”,i ,a[0], a[1], a[2]);

       return 0;

      }

    Please show the output of the above program using four parameter passing methods (pass by value, pass by reference, pass by value-result, pass by name) respectively.

    简答题 (8 分)
    附件 上传 最多可上传6张图片
  29. 29.

    The IR code generation can be performed during a parse.  Please complete the C program of the action1、action2、action3、action4、action5、action6  in the YACC file of the following grammar.  

    Grammar: 

    stmt while-stmt | break | other

    while-stmt → while ( exp stmt

    exp true | false

    the IR codes as following :                      the three-address codes as following: 

     label L1                                                      read x             (rd,x _,_ )

    <code to evaluate exp to t1>                    if_false,t1,L1   ( if_f, t1,L1,_)

    if_false t1 goto L2                                      label L1           (lab,L1,_,_)

    <code for stmt>                                        goto L1            (go,L1,_,_)

    goto L1                                                       x=t3                (asn,t3, x ,_ )

    label L2 



    YACC:

      while-stmt { action1 }  while  ( exp { action2 }  stmt

                  {action3 } 

    exp true   { action4 } 

    | false  { action5 }


      stmt:  while-stmt 

    | break  {  action6  } 

    | other

    简答题 (12 分)
    附件 上传 最多可上传6张图片
  30. 30.

    Consider the CFG of number with a one-character suffix o (for octal) or d (for decimal).

    based-num → num basechar 

    basechar → o | d

    num → num digit | digit

    digit → 0|1|2|3|4|5|6|7|8|9

    In this case, we need two attributes, base (for indicating octal or decimal) and val (for value of the number).

    (1) Rewrite the grammar so that the computation of the attribute base does not depend on parent nodes.

    (2) Given the number “789o”, show the dependency of attribute computation on its parsing tree of the above modified CFG.

    简答题 (14 分)
    附件 上传 最多可上传6张图片
  31. 31.

    Given a program as follow: 

      int x=3;

      void g(int);

      void f(int n)

      {  

          static int x =1;

          g(n);

          x--;

      }

      void g(int m)

      { 

         int y = m-1;

         If (y > 0)

         { f(y);

           x--;

           g(y);

          }

      }

      main()

      { 

          g(x);

          return 0;

      }

    Please draw the runtime environment of the above program at the point just before the second call to g.

    简答题 (10 分)
    附件 上传 最多可上传6张图片