Week 4

JOOS


    1. Explain for the following fragment of joos.l what each of the rules does, by stating what input character(s) each rule would accept and what output it would attach to the generated token. (Hint: Be reminded of "escaping".)
      '\\n'                  { yylval.charconst = '\n';
      return tCHARCONST; }
      '\\\"' { yylval.charconst = '\"';
      return tCHARCONST; }
      '\\'' { yylval.charconst = '\'';
      return tCHARCONST; }
      '\\\\' { yylval.charconst = '\\';
      return tCHARCONST; }
      '\\[0-7][0-7][0-7]' { yylval.charconst = 64*yytext[1]+8*yytext[2]+yytext[3]-73*'0';
      return tCHARCONST; }
      ''' return tERROR;
      '\\' return tERROR;
      '.' { yylval.charconst = yytext[1];
      return tCHARCONST; }
    2. How can you see in the lexer that JOOS will not accept string constants that contain a "  ? (For instance, JOOS will not accept an assignment s = "\""; .)
    3. Explain why the JOOS compiler constructs lists backwards (e.g. for arguments), see page 31 here. (Hint: Parse stack) What effect would a size limit for the call stack have during the pretty-printing (page 32)?
    4. Explain what the implementation of typeImplementationSTATEMENT does and how it works.

Maintained by Eric Bodden. [HOME]