Question 1.1. Errors in a computer program can be classified according to when they are detected and, if they are detected at compile time, what part of the compiler detects them. Using your favorite imperative language,

Click here to order similar paper @Essaybay.net. 100% Original.Written from scratch by professional writers.


Click here to order similar paper @Essaybay.net. 100% Original.Written from scratch by professional writers.

 

 

Textbook Assignment 1 : Introduction

  1. Question 1.1. Errors in a computer program can be classified according to when they are detected and, if they are detected at compile time, what part of the compiler detects them. Using your favorite imperative language, give an example of each of the following.
    1. A lexical error, detected by the scanner
    2. A syntax error, detected by the parser
    3. A static semantic error, detected by semantic analysis
    4. A dynamic semantic error, detected by code generated by the compiler
    5. An error that the compiler can neither catch nor easily generate code to catch (this should be a violation of the language definition, not just a program bug)
  2. Question 1.8. The Unix make utility allows the programmer to specify dependences among the separately compiled pieces of a program. If file A depends on file B and file B is modified, make deduces that A must be recompiled, in case any of the changes to B would affect the code produced for A. How accurate is this sort of dependence management? Under what circumstances will it lead to unnecessary work? Under what circumstances will it fail to recompile something that needs to be recompiled?
  3. Question 2.1. Write regular expressions to capture the following.
    1. Strings in C. These are delimited by double quotes (“), and may not contain newline characters. They may contain double-quote or backslash characters if and only if those characters are “escaped” by a preceding backslash. You may find it helpful to introduce shorthand notation to represent any character that is not a member of a small specified set
    2. Comments in Pascal. These are delimited by (* and *) or by { and }. They are not permitted to nest.
    3. Numeric constants in C. These are octal, decimal, or hexadecimal integers, or decimal or hexadecimal floating-point values. An octal integer begins with 0, and may contain only the digits 0–7. A hexadecimal integer begins with 0x or 0X, and may contain the digits 0–9 and a/A– f/F. A decimal floating-point value has a fractional portion(beginning with a dot) or an exponent (beginning with E or e). Unlike a decimal integer, it is allowed to start with 0. A hexadecimal floating-point value has an optional fractional portion and a mandatory exponent (beginning with P or p). In either decimal or hexadecimal, there may be digits to the left of the dot, the right of the dot, or both, and the exponent itself is given in decimal, with an optional leading + or – sign. An integer may end with an optional U or u (indicating “unsigned”), and/or L or l (indicating “long”) or LL or ll (indicating “long long”). A floating point value may end with an optional F or f (indicating “float”—single precision) or L or l (indicating “long”—double precision).
    4. Floating-point constants in Ada. These match the definition of real in Example2.3,except that (1) a digit is required on both sides of the decimal point, (2) an underscore is permitted between digits, and (3) an alternative numeric base may be specified by surrounding the nonexponent part of the number with pound signs, preceded by a base in decimal (e.g., 16#6.a7#e+2). In this latter case, the letters a..f (both upper- and lowercase) are permitted as digits. Use of these letters in an inappropriate (e.g., decimal) number is an error, but need not be caught by the scanner.
    5. Inexact constants in Scheme. Scheme allows real numbers to be explicitly inexact (imprecise). A programmer who wants to express all constants using the same number of characters can use sharp signs (#) in place of any lower-significance digits whose values are not known. A base-10 constant without exponent consists of one or more digits followed by zero of more sharp signs. An optional decimal point can be placed at the beginning, the end, or anywhere in-between. (For the record, numbers in Scheme are actually a good bit more complicated than this. For the purposes of this exercise, please ignore anything you may know about sign, exponent, radix, exactness and length specifiers, and complex or rational values.)
    6. Financial quantities in American notation. These have a leading dollar sign ($), an optional string of asterisks (*—used on checks to discourage fraud), a string of decimal digits, and an optional fractional part consisting of a decimal point (.) and two decimal digits. The string of digits to the left of the decimal point may consist of a single zero (0). Otherwise it must not start with a zero. If there are more than three digits to the left of the decimal point, groups of three (counting from the right) must be separated by commas (,). Example: $**2,345.67. (Feel free to use “productions” to define abbreviations, so long as the language remains regular.)
  4. Question 2.13 (a, b). Consider the following grammar:

 

  1. Construct a parse tree for the input string foo(a, b)
  2. Give a canonical (right-most) derivation of this same string.

 

 

  1. Question 2.17. Extend the grammar of Figure 2.25 to include if statements and while loops, along the lines suggested by the following examples.

Your grammar should support the six standard comparison operations in conditions, with arbitrary expressions as operands. It should also allow an arbitrary number of statements in the body of an if or while statement.



Click here to order similar paper @Essaybay.net. 100% Original.Written from scratch by professional writers.

Leave a Reply

Your email address will not be published. Required fields are marked *