public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* [Bug translator/11038] New: Trailing semicolon as null-statement confusing
@ 2009-12-01 10:21 mjw at redhat dot com
  2009-12-01 10:23 ` [Bug translator/11038] " mjw at redhat dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: mjw at redhat dot com @ 2009-12-01 10:21 UTC (permalink / raw)
  To: systemtap

semicolons (;) are optional, the parser really uses whitespace as separator of
statements. This is slightly confusing since semicolons are treated as
null-statements. This causes some confusion when writing code like:

probe begin {if (1 > 0) log("foo"); else log ("bar");}'

There will be an error for the else saying:
parse error: expected statement
	saw: keyword at <input>:1:37
     source: probe begin {if (1 > 0) log("foo"); else log ("bar");}

After encountering this a couple of time it dawns that one either has to put
braces around the then part or remove the semicolon. It would (imho) be better
if the null-statement following another statement expression was really silent
and optional.

-- 
           Summary: Trailing semicolon as null-statement confusing
           Product: systemtap
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: translator
        AssignedTo: systemtap at sources dot redhat dot com
        ReportedBy: mjw at redhat dot com


http://sourceware.org/bugzilla/show_bug.cgi?id=11038

------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug translator/11038] Trailing semicolon as null-statement confusing
  2009-12-01 10:21 [Bug translator/11038] New: Trailing semicolon as null-statement confusing mjw at redhat dot com
@ 2009-12-01 10:23 ` mjw at redhat dot com
  2009-12-01 17:11 ` jistone at redhat dot com
  2009-12-21 21:40 ` mjw at redhat dot com
  2 siblings, 0 replies; 4+ messages in thread
From: mjw at redhat dot com @ 2009-12-01 10:23 UTC (permalink / raw)
  To: systemtap


------- Additional Comments From mjw at redhat dot com  2009-12-01 10:23 -------
Created an attachment (id=4433)
 --> (http://sourceware.org/bugzilla/attachment.cgi?id=4433&action=view)
Patch to make null-statement really silent

This patch makes sure that any null-statement following another statement
expression is considered totally optional making the example compile as
expected and without any regressions seen.

-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=11038

------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug translator/11038] Trailing semicolon as null-statement confusing
  2009-12-01 10:21 [Bug translator/11038] New: Trailing semicolon as null-statement confusing mjw at redhat dot com
  2009-12-01 10:23 ` [Bug translator/11038] " mjw at redhat dot com
@ 2009-12-01 17:11 ` jistone at redhat dot com
  2009-12-21 21:40 ` mjw at redhat dot com
  2 siblings, 0 replies; 4+ messages in thread
From: jistone at redhat dot com @ 2009-12-01 17:11 UTC (permalink / raw)
  To: systemtap


------- Additional Comments From jistone at redhat dot com  2009-12-01 17:11 -------
(In reply to comment #1)
> Created an attachment (id=4433)
 --> (http://sourceware.org/bugzilla/attachment.cgi?id=4433&action=view)
> Patch to make null-statement really silent

As far as I can see, this won't change the behavior of any previously valid
scripts; it will only make a difference in this if-else case that currently
gives an error.  So in that sense, your patch seems harmless.

However, I find it a little weird to squash the ';' on blocks and other
"compound" statements (if, for, foreach, while).  For blocks, I think we do want
to parse "{...};" as two statements, even though it shouldn't make much
difference.  For the others, a singleton body should already eat one semicolon,
so you're also eating a second.  That means you could do this:

  if (x) if (y) foo();; else bar()

and it will attach the 'else' to the outer 'if'.  Normally you can't do that
without using braces.  Perhaps that's an interesting feature, but I think
explaining the ';' rules involved would make it too weird to be very useful.

So, I think we shouldn't squash semicolons after blocks, if, for, foreach, and
while, and then the patch looks ok to me.

-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=11038

------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug translator/11038] Trailing semicolon as null-statement confusing
  2009-12-01 10:21 [Bug translator/11038] New: Trailing semicolon as null-statement confusing mjw at redhat dot com
  2009-12-01 10:23 ` [Bug translator/11038] " mjw at redhat dot com
  2009-12-01 17:11 ` jistone at redhat dot com
@ 2009-12-21 21:40 ` mjw at redhat dot com
  2 siblings, 0 replies; 4+ messages in thread
From: mjw at redhat dot com @ 2009-12-21 21:40 UTC (permalink / raw)
  To: systemtap


------- Additional Comments From mjw at redhat dot com  2009-12-21 21:40 -------
Thanks for the review. I made the changes you suggested and added a testcase.

commit 40b71c4777ca110d69d5d61563d032a5ba1355df
Author: Mark Wielaard <mjw@redhat.com>
Date:   Mon Dec 21 22:37:20 2009 +0100

    PR11038 Trailing semicolon as null-statement confusing.
    
    * parse.cxx (parser::parse_statement): Squash semicolon after non-block-like
      statements.
    * testsuite/buildok/semicolon.stp: New test.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


http://sourceware.org/bugzilla/show_bug.cgi?id=11038

------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-12-21 21:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-01 10:21 [Bug translator/11038] New: Trailing semicolon as null-statement confusing mjw at redhat dot com
2009-12-01 10:23 ` [Bug translator/11038] " mjw at redhat dot com
2009-12-01 17:11 ` jistone at redhat dot com
2009-12-21 21:40 ` mjw at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).