Changes between Version 33 and Version 34 of IR2


Ignore:
Timestamp:
04/28/21 15:04:24 (5 years ago)
Author:
siegel
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • IR2

    v33 v34  
    77=== Questions ===
    88
    9 1. **Do variables have initial values?**
    10   * No, a declared variable must be initialized before it is used.
     91. **Do variables have default initial values?**
     10  * No, a declared variable must be initialized before it is used.   Otherwise, the behavior is undefined.
    11111. **How do you initialize a variable?**
    12   * By assigning a value to it.   For example `n=$new($int);` will assign `n` an arbitrary integer, while `n=0;` will assign the integer `0` to `n.
     12  * By assigning a value to it.   For example `n=$new($int);` will assign `n` an arbitrary integer, while `n=0;` will assign the integer `0` to `n`.
    13131. **How is an array allocated?**
    1414  * An array variable `a` is declared with a decl such as `T a[];`, and then a statement such as `a=$new(T[n]);` will assign to `a` a new arbitrary array value for an array of length `n` of elements of type `T`.    For heap-allocation, a pointer is declared with a decl such as `T * p;`, and a heap variable is also declared somewhere with a decl such as `$heap heap;` and then a statement such as `p = $alloc(&heap, n, T);` will add a new object to the heap and return a pointer to the first element.  An `$alloc`-ed object can be deallocated with `$free(p);`.
     151. **Is there an "array-pointer pun", as in C?**
     16  * No, if you want a pointer to element 0 of an array, you have to explicitly say something like `&a[0]`.
    15171. **How to you translate between sequences and arrays?**
    16181. Can you make types values? (reification)
     
    98100direct-declarator:
    99101    ID  /* variable being declared */
    100   | direct-declarator '[' ']'  /* array of ... */
     102  | direct-declarator '[' expr? ']'  /* array of ... */
    101103  | direct-declarator  '(' type-list? ')'  /* function consuming ... and returning ... */
    102104  | '(' declarator ')'
     
    104106type-name: ... /* same as declarator but without the ID */
    105107type-list: type-name (',' type-name)* ;
    106 complete-type-name: ... /* same as declarator except '[' expr ']' */
    107108
    108109}}}