09.06.2013 Views

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>XENIX</strong> Programming yacc: Compiler-Compiler<br />

describes the precedence and associativity of the four arithmetic operators. Plus and<br />

minus are left associative, and have lower precedence than star and slash, which are<br />

also left associative. The keyword %right . is used to describe right associative<br />

operators, and the keyword 96nonassoc is used to describe operators, like the operator<br />

.LT. in FORTRAN, that may not associate with themselves; thus<br />

A .LT. B . LT . C<br />

is illegal in FORTRAN, and such an operator would be described with the keyword<br />

96nonassoc in yacc. As an example of the behavior of these declarations, the description<br />

%right I I<br />

=<br />

%left I +<br />

I l_l<br />

%left 1 * 1 1 1 1<br />

%%<br />

expr : expr<br />

I expr<br />

I expr<br />

I expr<br />

I expr<br />

j NAME<br />

I I<br />

=<br />

I + I<br />

I I<br />

-<br />

I * I<br />

I<br />

I I<br />

expr<br />

expr<br />

expr<br />

expr<br />

expr<br />

might be used to structure the input<br />

as follows:<br />

a = b = c*d - e-f*g<br />

a = ( b = ( ((c*d)-e) - (f*g) ) )<br />

When this mechanism is used, unary operators must, in general, be given a precedence.<br />

Sometimes a unary operator and a binary operator have the same symbolic<br />

representation, but different precedences. An example is unary and binary '-'; unary<br />

minus may be given the same strength as multiplication, or even higher, while binary<br />

minus has a lower strength than multiplication. The keyword 96prec changes the<br />

precedence level associated with a particular gram mar rule. The 96prec keyword<br />

appears immediately after the body of the grammar rule, before the action or closing<br />

semicolon, and is followed by a token name or literal. It causes the precedence of the<br />

grammar rule to become that of the following token name or literal. For example, to<br />

make unary minus have the same precedence as multiplication the rules might resemble:<br />

10-19

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!