Seed7 Manual: Expressions (original) (raw)

There are two types of expressions. On one side there so called simple expressions, which are constructed using fixed predefined syntax rules. On the other side there are expressions which are constructed according to syntax rules. Syntax rules are defined with syntax declarations. How syntax declarations work is described in Chapter 3.2 (Syntax declarations) andchapter 9 (Structured syntax definition). The syntax declarations support the extensible syntax of Seed7. A simplified description of user defined expressions, which does not take priority levels into account, is:

expression ::=

prefix_expression | infix_expression | simple_expression .

prefix_expression ::=

identifier { identifier | expression } .

infix_expression ::=

expression identifier { identifier | expression } .

simple_expression ::=

dot_expression | call_expression .

The chapters below describe the predefined syntax rules of simple expressions.

11.1 Parentheses

Parentheses can be used to override any precedence rules of predefined and user defined syntax constructs. For example

2 * (3 + 4)

specifies that the + operator gets his parameters first.

Syntax:

parentheses_expression ::=

'(' expression ')' .

11.2 Call expressions

Call expressions can also be used to form a list. For example

writeln("hello world")

forms a list expression with the elements

"hello world"

writeln

The type of this list is specified with the system-declaration "system expr", which is defined in the include file "syntax.s7i" included from "seed7_05.s7i" as

$ system "expr" is expr;

A call expression with two parameters as

pos("Scotty! Beam me up.", "am")

forms a list expression with the elements

"Scotty! Beam me up."

"am"

pos

Syntax:

call_expression ::=

primary_expression [ '(' parameter_list ')' ] .

primary_expression ::=

parentheses_expression | token .

parameter_list ::=

expression { ',' expression } .

11.3 Dot expressions

Dot expressions start with a dot and have dots as separator between the elements of the list. For example

.not.TRUE

and

.OKAY.and.GO_ON

form list expressions with the elements

not

TRUE

and

OKAY

and

GO_ON

The type of this list is specified with the system-declaration "system expr", which is defined in the include file "syntax.s7i" included from "seed7_05.s7i" as

$ system "expr" is expr;

Dot expressions override the priority of the elements. Dot expressions are used in syntax-declarations.

Syntax:

dot_expression ::=

'.' dot_subexpression { '.' dot_subexpression } .

dot_subexpression ::=

empty_parentheses | parentheses_expression | call_expression .

empty_parentheses ::=

'(' ')' .