UNIX: A History and Memoir by Brian W Kernighan

UNIX: A History and Memoir by Brian W Kernighan

Author:Brian W Kernighan
Language: eng
Format: epub
Published: 2019-12-10T16:00:00+00:00


5.2 Yacc, Lex, Make

We use language to communicate, and better languages help us to communicate more effectively. This is especially true of the artificial languages that we use to communicate with computers. A good language lowers the barrier between what we want to say (“just do it”) and what we have to say to get some job done. A great deal of research in computing is concerned with how to create expressive languages.

Seventh edition Unix offered a diversity of language-based tools, some rather unconventional. I think it’s fair to say that the majority of those languages would not exist had it not been for tools, especially Yacc, that made it easy for non-experts to create new languages. This section describes the language-building tools. The overall message is that Unix tools facilitated the creation of new languages and thus led to better ways to communicate with computers. You can safely skip the details, but the message is important.

Computer languages are characterized by two main aspects, syntax and semantics. Syntax describes the grammar: what the language looks like, what’s grammatically legal and what’s not. The syntax defines the rules for how statements and functions are written, what the arithmetic and logical operators are, how they are combined into expressions, what names are legal, what words are reserved, how literal strings and numbers are expressed, how programs are formatted, and so on.

Semantics is the meaning that is ascribed to legal syntax: what does a legal construction mean or do. For the area computation program in Chapter 2, which is repeated here:

void main() {

float length, width, area; scanf("%f %f", ^length, &width); area = length * width; printf("area = %f\n", area);

}

the semantics say that when the function main is called, it will call the function scanf to read two data values from the standard input, compute the area, and call printf to print area =, the area and a newline character (\n).

A compiler is a program that translates something written in one language into something semantically equivalent in another language. For example, compilers for high-level languages like C and Fortran might translate into assembly language for a particular kind of computer; some compilers translate from other languages, such as Ratfor into Fortran.

The first part of the compilation process is to parse the program, that is, to determine its syntactic structure by recognizing names, constants, function definitions, control flow, expressions, and the like, so that subsequent processing can attach suitable semantics.

Today, writing a parser for a programming language is well-understood technology, but in the early 1970s it was an active research area, focused on creating programs that would convert the grammar rules of a language into an efficient parser for programs written in that language. Such parser-generator programs were also known as “compiler-compilers,” since they made it possible to generate the parser for a compiler mechanically. Typically they created a parser and also provided a way to execute code when particular grammar constructs were encountered during parsing.

Yacc

In 1973, Steve Johnson (Figure 5.1), with language-theory help from A1 Aho, created a compiler-compiler that he called YACC (henceforth Yacc).



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.