Time and Space Complexity of Top-down Parsing
When top-down parser tries to parse an ambiguous input with respect to an ambiguous CFG, it may need exponential number of steps (with respect to the length of the input) to try all alternatives of the CFG in order to produce all possible parse trees, which eventually would require exponential memory space. The problem of exponential time complexity in top-down parsers constructed as sets of mutually recursive functions has been solved by Norvig in 1991. His technique is similar to the use of dynamic programming and state-sets in Earley's algorithm (1970), and tables in the CYK algorithm of Cocke, Younger and Kasami.
The key idea is to store results of applying a parser p at position j in a memotable and to reuse results whenever the same situation arises. Frost, Hafiz and Callaghan also use memoization for refraining redundant computations to accommodate any form of CFG in polynomial time (Θ(n4) for left-recursive grammars and Θ(n3) for non left-recursive grammars). Their top-down parsing algorithm also requires polynomial space for potentially exponential ambiguous parse trees by 'compact representation' and 'local ambiguities grouping'. Their compact representation is comparable with Tomita’s compact representation of bottom-up parsing.
Using PEG's, another representation of grammars, packrat parsers provide an elegant and powerful parsing algorithm. See Parsing expression grammar.
Read more about this topic: Top-down Parsing
Famous quotes containing the words time and, time, space and/or complexity:
“They do not live in the world,
Are not in time and space.
From birth to death hurled
No word do they have, not one
To plant a foot upon,
Were never in any place.”
—Edwin Muir (18871959)
“The new American finds his challenge and his love in the traffic-choked streets, skies nested in smog, choking with the acids of industry, the screech of rubber and houses leashed in against one another while the townlets wither a time and die.”
—John Steinbeck (19021968)
“The secret ones around a stone
Their lips withdrawn in meet surprise
Lie still, being naught but bone
With naught but space within their eyes....”
—Allen Tate (18991979)
“In times like ours, where the growing complexity of life leaves us barely the time to read the newspapers, where the map of Europe has endured profound rearrangements and is perhaps on the brink of enduring yet others, where so many threatening and new problems appear everywhere, you will admit it may be demanded of a writer that he be more than a fine wit who makes us forget in idle and byzantine discussions on the merits of pure form ...”
—Marcel Proust (18711922)