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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

In each of these cases, the first rule will be reduced for the first item only, and the<br />

second rule will be reduced for the second and all succeeding items.<br />

With right recursive rules, such as<br />

seq item<br />

I item seq<br />

the parser would be a bit bigger, and the items would be seen, and reduced, from right<br />

to left. More seriously, an internal stack in the parser would be in danger of<br />

overflowing if a very long sequence were read. Thus, the user should use left recursion<br />

wherever reasonable.<br />

Consider whether a sequence with zero elements has any meaning, and if so, consider<br />

writing the sequence specification with an empty rule:<br />

seq /* empty *I<br />

I seq item<br />

Once again, the first rule would always be reduced exactly once, before the first item<br />

was read, and then the second rule would be reduced once for each item read.<br />

Permitting empty sequences often leads to increased generality. However, conflicts<br />

might arise if yacc is asked to decide which empty sequence it has seen, when it hasn't<br />

seen enough to know.<br />

lexica l Tie-ins<br />

Some lexical decisions depend on context. For example, the lexical analyzer might want<br />

to delete blanks normally, but not within quoted strings. Or names might be entered<br />

into a symbol table in declarations, but not in expressions.<br />

One way of handling this situation is to create a global flag that is examined by the<br />

lexical analyzer and set by actions. For example, suppose a program consists of 0 or<br />

more declarations, followed by 0 or more statem ents.<br />

10-25

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

Saved successfully!

Ooh no, something went wrong!