That’s an Expression

You are probably familiar with the kinds of expressions that a calculator interprets. Look at the following arithmetic expression:

2 + 4

“Two plus four” consists of several constants or literal values and an operator. A calculator program must recognize, for instance, that “2” is a numeric constant and that the plus sign represents an operator, not to be interpreted as the “+” character.

An expression tells the computer how to produce a result. Although it is the result of “two plus four” that we really want, we don’t simply tell the computer to return a six. We instruct the computer to evaluate the expression and return a value.

An expression can be more complicated than “2 + 4”; in fact, it might consist of multiple simple expressions, such as the following:

2 + 3 * 4

A calculator normally evaluates an expression from left to right. However, certain operators have precedence over others: that is, they will be performed first. Thus, the above expression will evaluate to 14 and not 20 because multiplication takes precedence over addition. Precedence can be overridden by placing the simple expression in parentheses. Thus, “(2 + 3) * 4” or “the sum of two plus three times four” will evaluate to 20. The parentheses are symbols that instruct the calculator to change the order in which the expression is evaluated.

A regular expression, by contrast, describes a pattern or sequence of characters. Concatenation is the basic operation implied in every regular expression. ...

Get sed & awk, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.