Context-free language reachabilityContext-free language reachability is an algorithmic problem with applications in static program analysis. Given a graph with edge labels from some alphabet and a context-free grammar over that alphabet, the problem is to determine whether there exists a path through the graph such that the concatenation of the labels along the path is a string accepted by the grammar. VariationsIn addition to the decision problem formulation given above, there are several related function problem formulations of CFL-reachability. For brevity, define an L-path to be a path with edge labels in the language of the grammar. Then:[1]
AlgorithmsThere is a relatively simple dynamic programming algorithm for solving all-pairs CFL-reachability. The algorithm requires a normalized grammar, where each production has at most two symbols (terminals or nonterminals) on the right-hand side. The runtime of this algorithm , where is the number of terminals and nonterminals in the normalized grammar (which is linear with respect to the original grammar), and is the number of nodes in the graph.[2] The algorithm works by repeatedly adding summary edges to the graph: given a production , if there exists an edge between some nodes x and y labeled with B and an edge between y and z labeled C, then the algorithm adds a new edge labeled A between x and z. This process is repeated until saturation, i.e., until no more summary edges may be added.[citation needed] Applications to program analysisSeveral problems in program analysis can be formulated as CFL-reachability problems, including:[3]
Alias analysisConsider an imperative language with pointers, like a simplified C. The program expression graph (PEG) for a program in such a language has a node for each expression in the program, and two kinds of edges:[citation needed]
For each The CFL-reachability problem over the PEG and the following grammar encodes the may-alias problem:[6] M ::= ~d V d
V ::= ~F M? F
F ::= (a M?)*
~F ::= (M? ~a)*
The nonterminal The following grammar is equivalent:[citation needed] M ::= ~d V d
V ::= (M? ~a)* M? (a M?)*
Related problemsEvery CFL-reachability problem can be encoded as a Datalog program.[7] References
|
Portal di Ensiklopedia Dunia