Kniga-Online.club
» » » » UNIX — универсальная среда программирования - Керниган Брайан Уилсон

UNIX — универсальная среда программирования - Керниган Брайан Уилсон

Читать бесплатно UNIX — универсальная среда программирования - Керниган Брайан Уилсон. Жанр: Интернет год 2004. Так же читаем полные версии (весь текст) онлайн без регистрации и SMS на сайте kniga-online.club или прочесть краткое содержание, предисловие (аннотацию), описание и ознакомиться с отзывами (комментариями) о произведении.
Перейти на страницу:

lfCW n l.

fBTable 3:fP Built-in Constants

.sp .5

DEG   57.29577951308232087680 @180/ [email protected], degrees per radian

E     2.71828182845904523536  @[email protected], base of natural logarithms

GAMMA 0.57721566490153286060  @[email protected], Euler-Mascheroni constant

PHI   1.61803398874989484820  @( sqrt 5 +1)/[email protected], the golden ratio

PI    3.14159265358979323846  @[email protected], circular transcendental number

.ТЕ

.ix table~of [hoc] constants

.NH

Statements and Control Flow

.PP

.I Hoc

statements have the following grammar:

.DS

.I

stmt: expr

 | variable = expr

 | procedure ( arglist )

 | while ( expr ) stmt

 | if ( expr ) stmt

 | if ( expr ) stmt else stmt

 | { stmtlist }

 | print expr-list

 | return optional-expr

stmtlist: fR(nothing)fI

 | stmlist stmt

.R

.DE

An assignment is parsed by default as a statement rather than

an expression, so assignments typed interactively

do not print their value.

.PP

Note that semicolons are not special to

.ix [hoc] input~format

@[email protected]: statements are terminated by newlines.

This causes some peculiar behavior.

The following are legal

.IT if

statements:

.DS

.ft CW

if (x < 0) print(y) else print(z)

if (x < 0) {

 print(y)

} else {

 print(z)

}

.ft

.DE

In the second example, the braces are mandatory:

the newline after the

.I if

would terminate the statement and produce a syntax error were

the brace omitted.

.PP

The syntax and semantics of @[email protected]

control flow facilities are basically the same as in C.

The

.I while

and

.I if

statements are just as in C, except there are no @[email protected] or

@[email protected] statements.

.NH

Input and Output: @[email protected] and @[email protected]

.PP

.ix [hoc] [read]~statement

.ix [hoc] [print]~statement

The input function @[email protected], like the other built-ins,

takes a single argument. Unlike the built-ins, though, the argument

is not ал expression: it is the name of a variable.

The next number (as defined above) is read from the standard input

and assigned to the named variable.

The return value of @[email protected] is 1 (true) if a value was read, and 0 (false)

if @[email protected] encountered end of file or an error.

.PP

Output is generated with the ©print© statement.

The arguments to @[email protected] are a comma-separated list of expressions

and strings in double quotes, as in C.

Newlines must be supplied;

they are never provided automatically by @[email protected]

.PP

Note that @[email protected] is a special built-in function, and therefore takes

a single parenthesized argument, while @[email protected] is a statement that takes

a comma-separated, unparenthesized list:

.DS

.ft CW

while (read(x)) {

 print "value is ", x, "n"

}

.ft

.DE

.NH

Functions and Procedures

.PP

Functions and procedures are distinct in @[email protected],

although they are defined by the same mechanism.

This distinction is simply for run-time error checking:

it is an error for a procedure to return a value,

and for a function @[email protected] to return one.

.PP

The definition syntax is:

.ix [hoc] function~definition

.ix [hoc] procedure~definition

.DS

Перейти на страницу:

Керниган Брайан Уилсон читать все книги автора по порядку

Керниган Брайан Уилсон - все книги автора в одном месте читать по порядку полные версии на сайте онлайн библиотеки kniga-online.club.


UNIX — универсальная среда программирования отзывы

Отзывы читателей о книге UNIX — универсальная среда программирования, автор: Керниган Брайан Уилсон. Читайте комментарии и мнения людей о произведении.


Уважаемые читатели и просто посетители нашей библиотеки! Просим Вас придерживаться определенных правил при комментировании литературных произведений.

  • 1. Просьба отказаться от дискриминационных высказываний. Мы защищаем право наших читателей свободно выражать свою точку зрения. Вместе с тем мы не терпим агрессии. На сайте запрещено оставлять комментарий, который содержит унизительные высказывания или призывы к насилию по отношению к отдельным лицам или группам людей на основании их расы, этнического происхождения, вероисповедания, недееспособности, пола, возраста, статуса ветерана, касты или сексуальной ориентации.
  • 2. Просьба отказаться от оскорблений, угроз и запугиваний.
  • 3. Просьба отказаться от нецензурной лексики.
  • 4. Просьба вести себя максимально корректно как по отношению к авторам, так и по отношению к другим читателям и их комментариям.

Надеемся на Ваше понимание и благоразумие. С уважением, администратор kniga-online.


Прокомментировать
Подтвердите что вы не робот:*
Подтвердите что вы не робот:*