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 lex: Lexical Analyzer Generator<br />

Specifying Alternation and Grouping<br />

The vertical bar (I) operator indicates alternation. For example,<br />

(ab I cd)<br />

ma<strong>tc</strong>hes either ab or cd. Note that parentheses are used for grouping, although they are<br />

not necessary at the outside level. For example<br />

ab l cd<br />

would have sufficed in the preceding example. Parentheses should be used for more<br />

complex expressions, such as<br />

(ab I cd + )?(ef) *<br />

which ma<strong>tc</strong>hes such strings as abefef, efefef, cdef, and cddd, but not abc, abed, or<br />

abcdef.<br />

Specifying Context Sensitivity<br />

lex recognizes a small amount of surrounding context. The two simplest operators for<br />

this are the caret (") and the dollar sign ($). If the first character of an expression is a<br />

caret, then the expression is only ma<strong>tc</strong>hed at the beginning of a line (after a newline<br />

character or at the beginning of the input stream). This can never conflict with the<br />

other meaning of the caret, complem entation of character classes, since<br />

complementation applies only within brackets. If the very last character is dollar sign,<br />

the expression is only ma<strong>tc</strong>hed at the end of a line (when immediately followed by a<br />

newline). The latter operator is a special case of the slash (/) operator, which indicates<br />

trailing context. The expression<br />

ab/cd<br />

ma<strong>tc</strong>hes the string ab, but only if followed by cd. Thus<br />

ab$<br />

is the same as<br />

ab/ \n<br />

Left context is handled in lex by specifying start conditions as explained in the section<br />

"Specifying Left Context Sensitivity." If a rule is only to be executed when the lex<br />

automaton interpreter is in start condition x, the rule should be enclosed in angle<br />

brackets:<br />

<br />

9-7

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

Saved successfully!

Ooh no, something went wrong!