in reply to Re^15: printing unitialized value of the 'do BLOCK' (EXPRESSION vs TERM vs STATEMENT)
in thread printing unitialized value of the 'do BLOCK'
The Perldocs are a bit fuzzy about the definitions of statement, expression, term
A file is a sequence of statements. A block is a sequence of statements in curlies. A statement can be a flow control statement (if, while, etc), a simple statement (an expression used for its side-effects), as well as other things.
An expression defines the syntax of code required to evaluate to one or more values. For example, an if statement's condition must be an expression.
No one used the word "term". It's a parser rule that usually encompasses variables, literals and sub-expressions in parens. Not a very useful word.
A TERM is a sub-expression inside a statement
No. For example, 1+2 is not a term. An expression inside a statement is an expression (which contains terms).
perlsyn explicitly calls statements "expressions"
No, it doesn't. "The only kind of simple statement is an expression evaluated for its side-effects" is equivalent to "an expression evaluated for its side-effects is a simple statement." In other words, expressions are also statements. For example, print("x") is an expression (so you can do if (print("x")) { ... }), but it can also be used as a statement.
So I hope it's clearer now that the difference is mainly in how something is parsed into the syntax tree.
Both "statement" and "expression" are names of parser rules. As parser rules, there are two differences between them: The syntax they allow, and where they can be used.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^17: printing unitialized value of the 'do BLOCK' (EXPRESSION vs TERM vs STATEMENT)
by LanX (Saint) on Dec 27, 2019 at 17:20 UTC | |
by ikegami (Patriarch) on Dec 28, 2019 at 13:57 UTC | |
by LanX (Saint) on Dec 28, 2019 at 17:20 UTC | |
by ikegami (Patriarch) on Dec 28, 2019 at 17:33 UTC | |
by LanX (Saint) on Dec 28, 2019 at 17:53 UTC | |
|