HPlogo HP C/HP-UX Reference Manual: Workstations and Servers > Chapter 2 Lexical Elements

Operators

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

An operator specifies an operation to be performed on one or more operands.

Syntax

operator ::= One selected from the set
[ ] ( ) . ->
++ -- & * + - ~ ! sizeof
/ % << >> < > <= >= !=
^ | && || ? : = == *=
/= %= += -= <<= >>= &= ^= |=
, # ##

Description

Operator representations may require one, two, or three characters. The compiler matches the longest sequence to find tokens. For example,

  a+++++b

is parsed as if it had been written

  a++ ++ + b

which results in a syntax error. An alternate parse

  a++ + ++b

is not chosen because it does not follow the longest first rule, even though it results in a syntactically correct expression. As a result, white space is often important in writing expressions that use complex operators. The precedence of operators is discussed in more detail in Chapter 5 “Expressions ”. The obsolete form of the assignment operators (=* instead of *=) is not supported. If this form is used, the compiler parses it as two tokens (= and *).

The operators [ ], ?:, and ( ) (function call operator) occur only in pairs, possibly separated by expressions. You can use some operators as either binary operators or unary operators. Often the meaning of the binary operator is much different from the meaning of the unary operator. For example, binary multiply and unary indirection:

  a * b  versus  *p