C language lexical analysis of the greedy algorithm

C language lexical analysis of the greedy algorithm

When we write a---bwhen we should consider this statement of C language compiler is how to analyze this statement.

C language to solve the solution to this problem can be summarized in a very simple rule: each symbol should contain as many characters. That is, the method of the compiler program is decomposed into symbols: left to right, a character is read, the read character by character, if the character may be composed of one symbol, then the next character read into, determination whether the string has been read two characters may be part of a symbol; if possible, to continue to the next character is read, the determination is repeated, until a string of characters read may no longer have to form a symbolic meaning. The processing strategy sometimes called "greedy", or, more colloquial point, called the "mouth Law", Kernighan and Ritchie expression of this is as follows, "if the input stream (compiler) to a cutoff before characters have been decomposed into a symbol, then the next number will include a possible composition of a symbol from the character following the longest string. "

--- "C traps and pitfalls," the eighth page

Note that, in addition to the character string constants, the middle symbol is not embedded white space (spaces, tabs and line feed). For example, == is a single symbol, and = = is two symbols,

This case can be distinguished by a space, do not write complex code points. It can be a---bwritten in a-- -bthe middle of a space that brings on a certain degree of convenience and avoid the errors that may occur, where a---bthe a- --bmeaning is different.

Likewise, if I was the first character to determine the next symbol and read, and then I immediately *, then no matter what the context, these two characters will be treated as a symbol / * denotes a comment s begin.

The meaning of the code annotation, the following statement appears intended to be divided by a value of p points x, and then assign the quotient y

y = x/*p /* p指向除数*/

In fact, / * Compiler is understood as the beginning of a comment, the compiler will continue to read characters until * / appears. In other words, this statement directly to the value of x is assigned to y, p will not take into account that appears later. The above statement is rewritten as follows:
y = x / *p /* p指向除数*/;
Or more clearly, writing:
y=x/(*p) /*p指向除数*/;
this is the practical effect of the statement obtained by the intent expressed by the comment.

Guess you like

Origin www.cnblogs.com/cuianbing/p/11597436.html