This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Language Reference, updated


On Tuesday, December 12, 2006 11:03 AM, Mike Mason wrote:
> Section 6.0.15
> I'm not sure why you'd ever use a ';' by itself instead of a newline.
> Explain further why you'd want to do that if, in fact, it's valid. 

The semicolon is necessary because it's optional.  :-/

Said with less tongue-in-cheek: There are certain grammatical
ambiguities that are due to the fact that the language has no statement
separator.  Remember that statements may also span lines, so a newline
itself is not a separator.  The semicolon then becomes necessary to make
it clear what you intend.  For example:

  probe foo {
    a = b
    ++c
  }

The spacing indicates what I want to happen, but the actual parsing will
produce this:

  probe foo {
    (a) = ((b)++)
    c
  }

Surprise!  Possible fixes here are to add a semicolon after 'b', reorder
'++c' before the assignment, or change it to a postincrement, 'c++'.

You might conclude that it's best to always include a semicolon as a
statement separator, but even that can backfire.  Another example:

  probe foo {
    if (a)
      printf("a is true\n");
    else            
      printf("a is false\n");
  }

This will give you "parse error: expected statement", pointing to the
'else' as the problem.  This is because the semicolon gets treated as a
separate statement.  Thus with two statements after an 'if' with no
curly braces, the 'else' becomes invalid syntax.

The second example might actually be a bug, depending on the intentions
of the language designers.  Frank, care to comment?


Josh


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]