PREV INDEX NEXT

Author: Stan Eisenstat
Subject: Re: [Cs223] Comments in line splicing?
Date: Wednesday, 29 Jan 2020, 07:09:39


    > Message Posted By: Unknown
    >
    > Hello,
    >
    > The specification says:
    > "handle both /*...*/ and //... comments correctly (e.g., they do not nest
    > and are the equivalent of a single space character)"
    >
    > I am currently trying to understand why comments should be treated as a
    > single space character and how this makes sense given the output of the
    > solution executable.

Comments are treated as a single space character because
that is how the C language treats them.
=====

    > For example:
    > identif\//comment
    > ier;
    >
    > Produces:
    > identif:1
    > ier:2

Since line splices are removed before comments are
replaced, there is no line splice, and the input is
equivalent to

  identif\
  ier;

(where the space following the \ is invisible).
=====

    > While:
    > identif\
    > ier;
    >
    > Produces:
    > identifier:1
    >
    > To be clear, the second case has a single space after the backslash, i.e.:
    > identif\[space]
    > ier;

That is not the result when I run Hwk1/Cxref:

  % cat -vet z
  identif\ $
  ier;$
  % /c/cs223/Hwk1/Cxref < z
  identif:1
  ier:2

Note the use of the cat command with the -vet option to
make the space visible.

--Stan-
PREV INDEX NEXT