<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://safernicotine.wiki/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Parsing</id>
	<title>Parsing - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://safernicotine.wiki/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Parsing"/>
	<link rel="alternate" type="text/html" href="https://safernicotine.wiki/mediawiki/index.php?title=Parsing&amp;action=history"/>
	<updated>2026-05-10T01:41:36Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>https://safernicotine.wiki/mediawiki/index.php?title=Parsing&amp;diff=22541&amp;oldid=prev</id>
		<title>Richardpruen: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://safernicotine.wiki/mediawiki/index.php?title=Parsing&amp;diff=22541&amp;oldid=prev"/>
		<updated>2022-01-02T17:12:31Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en-GB&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 18:12, 2 January 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;4&quot; class=&quot;diff-notice&quot; lang=&quot;en-GB&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key uk_vapewiki:diff:1.41:old-22540:rev-22541 --&gt;
&lt;/table&gt;</summary>
		<author><name>Richardpruen</name></author>
	</entry>
	<entry>
		<id>https://safernicotine.wiki/mediawiki/index.php?title=Parsing&amp;diff=22540&amp;oldid=prev</id>
		<title>91.246.232.44: /* Parser */</title>
		<link rel="alternate" type="text/html" href="https://safernicotine.wiki/mediawiki/index.php?title=Parsing&amp;diff=22540&amp;oldid=prev"/>
		<updated>2021-12-29T16:45:27Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Parser&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{redirect|Parse}}&lt;br /&gt;
{{short description|Analysing a string of symbols, according to the rules of a formal grammar}}&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Parsing&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;syntax analysis&amp;#039;&amp;#039;&amp;#039;, or &amp;#039;&amp;#039;&amp;#039;syntactic analysis&amp;#039;&amp;#039;&amp;#039; is the process of analyzing a [[String (computer science)|string]] of [[Symbol (formal)|symbols]], either in [[natural language]], [[computer languages]] or [[data structure]]s, conforming to the rules of a [[formal grammar]].  The term &amp;#039;&amp;#039;parsing&amp;#039;&amp;#039; comes from Latin &amp;#039;&amp;#039;pars&amp;#039;&amp;#039; (&amp;#039;&amp;#039;orationis&amp;#039;&amp;#039;), meaning [[Part of speech|part (of speech)]].&amp;lt;ref name=&amp;quot;dictionary.com&amp;quot;&amp;gt;{{cite web |url=http://dictionary.reference.com/search?q=parse&amp;amp;x=0&amp;amp;y=0 |title=Parse|publisher=dictionary.reference.com |access-date=27 November 2010}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The term has slightly different meanings in different branches of [[linguistics]] and [[computer science]].  Traditional [[Sentence (linguistics)|sentence]] parsing is often performed as a method of understanding the exact meaning of a sentence or word, sometimes with the aid of devices such as [[sentence diagram]]s.  It usually emphasizes the importance of grammatical divisions such as [[subject (grammar)|subject]] and [[predicate (grammar)|predicate]].&lt;br /&gt;
&lt;br /&gt;
Within [[computational linguistics]] the term is used to refer to the formal analysis by a computer of a sentence or other string of words into its constituents, resulting in a [[parse tree]] showing their syntactic relation to each other, which may also contain [[Semantics|semantic]] and other information ([[p-values]]).{{citation needed|date=August 2019}} Some parsing algorithms may generate a &amp;#039;&amp;#039;parse forest&amp;#039;&amp;#039; or list of parse trees for a [[syntactically ambiguous]] input.&amp;lt;ref name=&amp;quot;Tomita2012&amp;quot;&amp;gt;{{cite book|author=Masaru Tomita|title=Generalized LR Parsing|url=https://books.google.com/books?id=VVDTBwAAQBAJ&amp;amp;q=%22parse+forest%22|date=6 December 2012|publisher=Springer Science &amp;amp; Business Media|isbn=978-1-4615-4034-2}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The term is also used in [[psycholinguistics]] when describing language comprehension.  In this context, parsing refers to the way that human beings analyze a sentence or phrase (in spoken language or text) &amp;quot;in terms of grammatical constituents, identifying the parts of speech, syntactic relations, etc.&amp;quot;&amp;lt;ref name=&amp;quot;dictionary.com&amp;quot; /&amp;gt;  This term is especially common when discussing what linguistic cues help speakers to interpret [[garden path sentence|garden-path sentences]].&lt;br /&gt;
&lt;br /&gt;
Within computer science, the term is used in the analysis of [[computer languages]], referring to the syntactic analysis of the input code into its component parts in order to facilitate the writing of [[compilers]] and [[interpreter (computing)|interpreters]]. The term may also be used to describe a split or separation.&lt;br /&gt;
&lt;br /&gt;
== Human languages ==&lt;br /&gt;
{{main category|Natural language parsing}}&lt;br /&gt;
&lt;br /&gt;
=== Traditional methods ===&lt;br /&gt;
The traditional grammatical exercise of parsing, sometimes known as &amp;#039;&amp;#039;clause analysis&amp;#039;&amp;#039;, involves breaking down a text into its component [[Part of speech|parts of speech]] with an explanation of the form, function, and syntactic relationship of each part.&amp;lt;ref&amp;gt;{{cite web | title=Grammar and Composition | url=http://grammar.about.com/od/pq/g/parsingterm.htm}}&amp;lt;/ref&amp;gt; This is determined in large part from study of the language&amp;#039;s [[conjugation (grammar)|conjugation]]s and [[declensions]], which can be quite intricate for heavily [[Inflection|inflected]] languages. To parse a phrase such as &amp;#039;man bites dog&amp;#039; involves noting that the [[Grammatical number|singular]] noun &amp;#039;man&amp;#039; is the [[Subject (grammar)|subject]] of the sentence, the verb &amp;#039;bites&amp;#039; is the [[Grammatical person|third person singular]] of the [[present tense]] of the verb &amp;#039;to bite&amp;#039;, and the singular noun &amp;#039;dog&amp;#039; is the [[Object (grammar)|object]] of the sentence.  Techniques such as [[sentence diagram]]s are sometimes used to indicate relation between elements in the sentence.&lt;br /&gt;
&lt;br /&gt;
Parsing was formerly central to the teaching of grammar throughout the English-speaking world, and widely regarded as basic to the use and understanding of written language.  However, the general teaching of such techniques is no longer current.{{Citation needed|date=August 2021}}&lt;br /&gt;
&lt;br /&gt;
=== Computational methods ===&lt;br /&gt;
{{main|Syntactic parsing (computational linguistics)}}&lt;br /&gt;
{{more citations needed section|date=February 2013}}&lt;br /&gt;
In some [[machine translation]] and [[natural language processing]] systems, written texts in human languages are parsed by computer programs.&amp;lt;ref name=&amp;quot;ManningManning1999&amp;quot;&amp;gt;{{cite book|author1=Christopher D.. Manning|author2=Christopher D. Manning|author3=Hinrich Schütze|title=Foundations of Statistical Natural Language Processing|url=https://books.google.com/books?id=YiFDxbEX3SUC&amp;amp;q=parsing|year=1999|publisher=MIT Press|isbn=978-0-262-13360-9}}&amp;lt;/ref&amp;gt; Human sentences are not easily parsed by programs, as there is substantial [[syntactic ambiguity|ambiguity]] in the structure of human language, whose usage is to convey meaning (or [[semantics]]) amongst a potentially unlimited range of possibilities but only some of which are germane to the particular case.&amp;lt;ref&amp;gt;{{Cite journal | doi=10.1207/s15516709cog2002_1|title = A Probabilistic Model of Lexical and Syntactic Access and Disambiguation| journal=Cognitive Science| volume=20| issue=2| pages=137–194|year = 1996|last1 = Jurafsky|first1 = Daniel| citeseerx=10.1.1.150.5711}}&amp;lt;/ref&amp;gt; So an utterance &amp;quot;Man bites dog&amp;quot; versus &amp;quot;Dog bites man&amp;quot; is definite on one detail but in another language might appear as &amp;quot;Man dog bites&amp;quot; with a reliance on the larger context to distinguish between those two possibilities, if indeed that difference was of concern. It is difficult to prepare formal rules to describe informal behaviour even though it is clear that some rules are being followed.{{citation needed|date=February 2018}}&lt;br /&gt;
&lt;br /&gt;
In order to parse natural language data, researchers must first agree on the [[grammar]] to be used. The choice of syntax is affected by both [[language|linguistic]] and computational concerns; for instance some parsing systems use [[lexical functional grammar]], but in general, parsing for grammars of this type is known to be [[NP-complete]]. [[Head-driven phrase structure grammar]] is another linguistic formalism which has been popular in the parsing community, but other research efforts have focused on less complex formalisms such as the one used in the Penn [[Treebank]]. [[Shallow parsing]] aims to find only the boundaries of major constituents such as noun phrases. Another popular strategy for avoiding linguistic controversy is [[dependency grammar]] parsing.&lt;br /&gt;
&lt;br /&gt;
Most modern parsers are at least partly [[statistical parsing|statistical]]; that is, they rely on a [[text corpus|corpus]] of training data which has already been annotated (parsed by hand). This approach allows the system to gather information about the frequency with which various constructions occur in specific contexts. &amp;#039;&amp;#039;(See [[machine learning]].)&amp;#039;&amp;#039; Approaches which have been used include straightforward [[PCFG]]s (probabilistic context-free grammars),&amp;lt;ref&amp;gt;Klein, Dan, and Christopher D. Manning. &amp;quot;[https://www.aclweb.org/anthology/P03-1054 Accurate unlexicalized parsing].&amp;quot; Proceedings of the 41st Annual Meeting on Association for Computational Linguistics-Volume 1. Association for Computational Linguistics, 2003.&amp;lt;/ref&amp;gt; [[maximum entropy classifier|maximum entropy]],&amp;lt;ref&amp;gt;Charniak, Eugene. &amp;quot;[https://aclanthology.info/pdf/A/A00/A00-2018.pdf A maximum-entropy-inspired parser].&amp;quot; Proceedings of the 1st North American chapter of the Association for Computational Linguistics conference. Association for Computational Linguistics, 2000.&amp;lt;/ref&amp;gt; and [[neural net]]s.&amp;lt;ref&amp;gt;Chen, Danqi, and Christopher Manning. &amp;quot;[http://www.aclweb.org/anthology/D14-1082 A fast and accurate dependency parser using neural networks].&amp;quot; Proceedings of the 2014 conference on empirical methods in natural language processing (EMNLP). 2014.&amp;lt;/ref&amp;gt; Most of the more successful systems use &amp;#039;&amp;#039;lexical&amp;#039;&amp;#039; statistics (that is, they consider the identities of the words involved, as well as their [[part of speech]]). However such systems are vulnerable to [[overfitting]] and require some kind of [[smoothing]] to be effective.{{Citation needed|date=May 2008}}&lt;br /&gt;
&lt;br /&gt;
Parsing algorithms for natural language cannot rely on the grammar having &amp;#039;nice&amp;#039; properties as with manually designed grammars for programming languages. As mentioned earlier some grammar formalisms are very difficult to parse computationally; in general, even if the desired structure is not [[context-free]], some kind of context-free approximation to the grammar is used to perform a first pass. Algorithms which use context-free grammars often rely on some variant of the [[CYK algorithm]], usually with some [[heuristic (computer science)|heuristic]] to prune away unlikely analyses to save time. &amp;#039;&amp;#039;(See [[chart parsing]].)&amp;#039;&amp;#039; However some systems trade speed for accuracy using, e.g., linear-time versions of the [[Shift-reduce parsing|shift-reduce]] algorithm. A somewhat recent development has been [[parse reranking]] in which the parser proposes some large number of analyses, and a more complex system selects the best option.{{citation needed|date=January 2019}} [[Semantic parsing|Semantic parser]]s convert texts into representations of their meanings.&amp;lt;ref name=&amp;quot;:0&amp;quot;&amp;gt;{{cite arxiv|last1=Jia|first1=Robin|last2=Liang|first2=Percy|date=2016-06-11|title=Data Recombination for Neural Semantic Parsing|eprint=1606.03622 |class=cs.CL}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Psycholinguistics ===&lt;br /&gt;
In [[psycholinguistics]], parsing involves not just the assignment of words to categories (formation of ontological insights), but the evaluation of the meaning of a sentence according to the rules of syntax drawn by inferences made from each word in the sentence (known as [[connotation]]). This normally occurs as words are being heard or read. Consequently, psycholinguistic models of parsing are of necessity &amp;#039;&amp;#039;incremental&amp;#039;&amp;#039;, meaning that they build up an interpretation as the sentence is being processed, which is normally expressed in terms of a partial syntactic structure. Creation of initially wrong structures occurs when interpreting [[garden-path sentence]]s.&lt;br /&gt;
&lt;br /&gt;
=== Discourse analysis ===&lt;br /&gt;
[[Discourse analysis]] examines ways to analyze language use and semiotic events. Persuasive language may be called [[rhetoric]].&lt;br /&gt;
&lt;br /&gt;
== Computer languages ==&lt;br /&gt;
{{unreferenced section|date=February 2013}}&lt;br /&gt;
&lt;br /&gt;
=== Parser ===&lt;br /&gt;
A &amp;#039;&amp;#039;&amp;#039;parser&amp;#039;&amp;#039;&amp;#039; is a software component that takes input data (frequently text) and builds a [[data structure]] – often some kind of [[parse tree]], [[abstract syntax tree]] or other hierarchical structure, giving a structural representation of the input while checking for correct syntax. The parsing may be preceded or followed by other steps, or these may be combined into a single step. The parser is often preceded by a separate [[Lexical analysis|lexical analyser]], which creates tokens from the sequence of input characters; alternatively, these can be combined in [[scannerless parsing]]. Parsers may be programmed by hand or may be automatically or semi-automatically generated by a [[parser generator]]. Parsing is complementary to [[templating language|templating]], which produces formatted &amp;#039;&amp;#039;output.&amp;#039;&amp;#039; These may be applied to different domains, but often appear together, such as the [[scanf]]/[[printf]] pair, or the input (front end parsing) and output (back end code generation) stages of a compiler.&lt;br /&gt;
&lt;br /&gt;
The input to a parser is often text in some [[computer language]], but may also be text in a natural language or less structured textual data, in which case generally only certain parts of the text are extracted, rather than a parse tree being constructed. Parsers range from very simple functions such as [[scanf]], to complex programs such as the frontend of a [[C++ compiler]] or the [[HTML]] parser of a [[web browser]]. An important class of simple parsing is done using [[regular expression]]s, in which a group of regular expressions defines a [[regular language]] and a regular expression engine automatically generating a parser for that language, allowing [[pattern matching]] and extraction of text. In other contexts regular expressions are instead used prior to parsing, as the lexing step whose output is then used by the parser.&lt;br /&gt;
&lt;br /&gt;
The use of parsers varies by input. In the case of data languages, a parser is often found as the file reading facility of a program, such as reading in HTML or [[XML]] text; these examples are [[markup language]]s. In the case of [[programming language]]s, a parser is a component of a [[compiler]] or [[Interpreter (computing)|interpreter]], which parses the [[source code]] of a [[computer programming language]] to create some form of internal representation; the parser is a key step in the [[compiler frontend]]. Programming languages tend to be specified in terms of a [[deterministic context-free grammar]] because fast and efficient parsers can be written for them. For compilers, the parsing itself can be done in one pass or multiple passes – see [[one-pass compiler]] and [[multi-pass compiler]].&lt;br /&gt;
&lt;br /&gt;
The implied disadvantages of a one-pass compiler can largely be overcome by adding [[Relocation (computing)|fix-ups]], where provision is made for code relocation during the forward pass, and the fix-ups are applied backwards when the current program segment has been recognized as having been completed. An example where such a fix-up mechanism would be useful would be a forward GOTO statement, where the target of the GOTO is unknown until the program segment is completed. In this case, the application of the fix-up would be delayed until the target of the GOTO was recognized. Conversely, a backward GOTO does not require a fix-up, as the location will already be known.&lt;br /&gt;
&lt;br /&gt;
Context-free grammars are limited in the extent to which they can express all of the requirements of a language. Informally, the reason is that the memory of such a language is limited. The grammar cannot remember the presence of a construct over an arbitrarily long input; this is necessary for a language in which, for example, a name must be declared before it may be referenced. More powerful grammars that can express this constraint, however, cannot be parsed efficiently. Thus, it is a common strategy to create a relaxed parser for a context-free grammar which accepts a superset of the desired language constructs (that is, it accepts some invalid constructs); later, the unwanted constructs can be filtered out at the [[Semantic analysis (compilers)|semantic analysis]] (contextual analysis) step.&lt;br /&gt;
&lt;br /&gt;
For example, in [[Python (programming language)|Python]] the following is syntactically valid code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
x = 1&lt;br /&gt;
print(x)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The following code, however, is syntactically valid in terms of the context-free grammar, yielding a syntax tree with the same structure as the previous, but violates the semantic  rule requiring variables to be initialized before use:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
x = 1&lt;br /&gt;
print(y)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Overview of process ===&lt;br /&gt;
[[File:Parser Flowո.gif|right|Flow of data in a typical parser]]&lt;br /&gt;
The following example demonstrates the common case of parsing a computer language with two levels of grammar: lexical and syntactic.&lt;br /&gt;
&lt;br /&gt;
The first stage is the token generation, or [[lexical analysis]], by which the input character stream is split into meaningful symbols defined by a grammar of [[regular expression]]s. For example, a calculator program would look at an input such as &amp;quot;&amp;lt;code&amp;gt;12 * (3 + 4)^2&amp;lt;/code&amp;gt;&amp;quot; and split it into the tokens &amp;lt;code&amp;gt;12&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;(&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;+&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;)&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;^&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt;, each of which is a meaningful symbol in the context of an arithmetic expression. The lexer would contain rules to tell it that the characters &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;+&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;^&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;(&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;)&amp;lt;/code&amp;gt; mark the start of a new token, so meaningless tokens like &amp;quot;&amp;lt;code&amp;gt;12*&amp;lt;/code&amp;gt;&amp;quot; or &amp;quot;&amp;lt;code&amp;gt;(3&amp;lt;/code&amp;gt;&amp;quot; will not be generated.&lt;br /&gt;
&lt;br /&gt;
The next stage is parsing or syntactic analysis, which is checking that the tokens form an allowable expression. This is usually done with reference to a [[context-free grammar]] which recursively defines components that can make up an expression and the order in which they must appear. However, not all rules defining programming languages can be expressed by context-free grammars alone, for example type validity and proper declaration of identifiers. These rules can be formally expressed with [[attribute grammar]]s.&lt;br /&gt;
&lt;br /&gt;
The final phase is [[Semantic analysis (computer science)|semantic parsing]] or analysis, which is working out the implications of the expression just validated and taking the appropriate action.&amp;lt;ref&amp;gt;Berant, Jonathan, and Percy Liang. &amp;quot;[https://www.aclweb.org/anthology/P14-1133.pdf Semantic parsing via paraphrasing].&amp;quot; Proceedings of the 52nd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers). 2014.&amp;lt;/ref&amp;gt; In the case of a calculator or interpreter, the action is to evaluate the expression or program; a compiler, on the other hand, would generate some kind of code. Attribute grammars can also be used to define these actions.&lt;br /&gt;
&lt;br /&gt;
== Types of parsers ==&lt;br /&gt;
The &amp;#039;&amp;#039;task&amp;#039;&amp;#039; of the parser is essentially to determine if and how the input can be derived from the start symbol of the grammar. This can be done in essentially two ways:&lt;br /&gt;
*[[Top-down parsing]] - Top-down parsing can be viewed as an attempt to find left-most derivations of an input-stream by searching for [[parse tree]]s using a top-down expansion of the given [[formal grammar]] rules. Tokens are consumed from left to right. Inclusive choice is used to accommodate [[ambiguity]] by expanding all alternative right-hand-sides of grammar rules.&amp;lt;ref name=&amp;quot; AhoSethiUllman 1986&amp;quot;&amp;gt;Aho, A.V., Sethi, R. and Ullman, J.D.  (1986) &amp;quot; Compilers: principles, techniques, and tools.&amp;quot; &amp;#039;&amp;#039; [[Addison-Wesley Longman]] Publishing Co., Inc. Boston, MA, USA. &amp;#039;&amp;#039;&amp;lt;/ref&amp;gt; This is known as the primordial soup approach. Very similar to sentence diagramming, primordial soup breaks down the constituencies of sentences.&amp;lt;ref&amp;gt;{{Cite book|title=Parsing schemata : a framework for specification and analysis of parsing algorithms|last=Sikkel, Klaas, 1954-|date=1997|publisher=Springer|isbn=9783642605413|location=Berlin|oclc=606012644}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[[Bottom-up parsing]] - A parser can start with the input and attempt to rewrite it to the start symbol. Intuitively, the parser attempts to locate the most basic elements, then the elements containing these, and so on. [[LR parser]]s are examples of bottom-up parsers. Another term used for this type of parser is [[Shift-reduce parser|Shift-Reduce]] parsing.&lt;br /&gt;
&lt;br /&gt;
[[LL parser]]s and [[recursive-descent parser]]  are examples of top-down parsers which cannot accommodate [[left recursion|left recursive]] [[Formal grammar#The syntax of grammars|production rules]]. Although it has been believed that simple implementations of top-down parsing cannot accommodate direct and indirect left-recursion and may require exponential time and space complexity while parsing [[ambiguous grammar|ambiguous context-free grammars]], more sophisticated algorithms for top-down parsing have been created by Frost, Hafiz, and Callaghan&amp;lt;ref name=&amp;quot;FrostHafizCallaghan 2007&amp;quot;&amp;gt;Frost, R., Hafiz, R. and Callaghan, P. (2007) &amp;quot; [https://aclanthology.info/pdf/W/W07/W07-2215.pdf Modular and Efficient Top-Down Parsing for Ambiguous Left-Recursive Grammars] .&amp;quot; &amp;#039;&amp;#039;10th International Workshop on Parsing Technologies (IWPT), ACL-SIGPARSE &amp;#039;&amp;#039;, Pages: 109 - 120, June 2007, Prague.&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;FrostHafizCallaghan 2008&amp;quot;&amp;gt;Frost, R., Hafiz, R. and Callaghan, P. (2008) &amp;quot; [http://scholar.uwindsor.ca/cgi/viewcontent.cgi?article=1411&amp;amp;context=etd#page=61 Parser Combinators for Ambiguous Left-Recursive Grammars].&amp;quot; &amp;#039;&amp;#039; 10th International Symposium on Practical Aspects of Declarative Languages (PADL), ACM-SIGPLAN &amp;#039;&amp;#039;, Volume 4902/2008, Pages: 167 - 181, January 2008, San Francisco.&amp;lt;/ref&amp;gt; which accommodate [[ambiguity]] and [[left recursion]] in polynomial time and which generate polynomial-size representations of the potentially exponential number of parse trees. Their algorithm is able to produce both left-most and right-most derivations of an input with regard to a given [[context-free grammar]].&lt;br /&gt;
&lt;br /&gt;
An important distinction with regard to parsers is whether a parser generates a &amp;#039;&amp;#039;leftmost derivation&amp;#039;&amp;#039; or a &amp;#039;&amp;#039;rightmost derivation&amp;#039;&amp;#039; (see [[context-free grammar]]). LL parsers will generate a leftmost [[Parse tree|derivation]] and LR parsers will generate a rightmost derivation (although usually in reverse).&amp;lt;ref name=&amp;quot; AhoSethiUllman 1986&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some &amp;#039;&amp;#039;{{visible anchor|graphical parsing}}&amp;#039;&amp;#039; algorithms have been designed for [[visual programming languages]].&amp;lt;ref&amp;gt;Rekers, Jan, and Andy Schürr. &amp;quot;[https://scholar.google.com/scholar?hl=en&amp;amp;as_sdt=0%2C47&amp;amp;q=%22graphical+parsing%22&amp;amp;btnG= Defining and parsing visual languages with layered graph grammars].&amp;quot; Journal of Visual Languages &amp;amp; Computing 8.1 (1997): 27-55.&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;Rekers, Jan, and A. Schurr. &amp;quot;[https://www.researchgate.net/profile/Andy_Schuerr/publication/3660769_A_graph_grammar_approach_to_graphical_parsing/links/55e4419708aecb1a7cc9fc62.pdf A graph grammar approach to graphical parsing].&amp;quot; Visual Languages, Proceedings., 11th IEEE International Symposium on. IEEE, 1995.&amp;lt;/ref&amp;gt; Parsers for visual languages are sometimes based on [[graph grammar]]s.&amp;lt;ref&amp;gt;Zhang, Da-Qian, Kang Zhang, and Jiannong Cao. &amp;quot;[https://web.archive.org/web/20180323220143/https://pdfs.semanticscholar.org/5d3d/217d73e0f6bbeefa3749c16fbc7b2e00ec0b.pdf A context-sensitive graph grammar formalism for the specification of visual languages].&amp;quot; The Computer Journal 44.3 (2001): 186-200.&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Adaptive parsing]] algorithms have been used to construct &amp;quot;self-extending&amp;quot; [[natural language user interface]]s.&amp;lt;ref name=&amp;quot;Lehman2012&amp;quot;&amp;gt;{{cite book|author=Jill Fain Lehman|title=Adaptive Parsing: Self-Extending Natural Language Interfaces|url=https://books.google.com/books?id=tU_tBwAAQBAJ&amp;amp;q=%22language+acquisition%22|date=6 December 2012|publisher=Springer Science &amp;amp; Business Media|isbn=978-1-4615-3622-2}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Parser development software ==&lt;br /&gt;
{{prose|date=January 2017}}&lt;br /&gt;
{{see also|Comparison of parser generators}}&lt;br /&gt;
Some of the well known parser development tools include the following:&lt;br /&gt;
{{div col|colwidth=20em}}&lt;br /&gt;
* [[ANTLR]]&lt;br /&gt;
* [[GNU Bison|Bison]]&lt;br /&gt;
* [[Coco/R]]&lt;br /&gt;
* [[Definite clause grammar]]&lt;br /&gt;
* [[GOLD (parser)|GOLD]]&lt;br /&gt;
* [[JavaCC]]&lt;br /&gt;
* [[Lemon (parser generator)|Lemon]]&lt;br /&gt;
* [[lex (software)|Lex]]&lt;br /&gt;
* LuZc&lt;br /&gt;
* [[Parboiled (Java)|Parboiled]]&lt;br /&gt;
* [[Parsec (parser)|Parsec]]&lt;br /&gt;
* [[Ragel]]&lt;br /&gt;
* [[Spirit Parser Framework]]&lt;br /&gt;
* [[Syntax Definition Formalism]]&lt;br /&gt;
* [[SYNTAX]]&lt;br /&gt;
* [[XPL]]&lt;br /&gt;
* [[Yacc]]&lt;br /&gt;
* [[PackCC]]&lt;br /&gt;
{{div col end}}&lt;br /&gt;
&lt;br /&gt;
== Lookahead ==&lt;br /&gt;
{{unreferenced section|date=April 2012}}&lt;br /&gt;
[[File:Parsing a C program that needs 2 token lookahead.svg|thumb|300px|[[C (programming language)|C]] program that cannot be parsed with less than 2 token lookahead. &amp;#039;&amp;#039;Top:&amp;#039;&amp;#039; C grammar excerpt.&amp;lt;ref&amp;gt;taken from {{cite book | isbn=0131103628 | author=Brian W. Kernighan and Dennis M. Ritchie | title=The C Programming Language | edition=2nd | location=Englewood Cliffs/NJ | publisher=Prentice Hall | series=Prentice Hall Software Series | date=Apr 1988 | url-access=registration | url=https://archive.org/details/cprogramminglang00bria }} (Appendix A.13 &amp;quot;Grammar&amp;quot;, p.193 ff)&amp;lt;/ref&amp;gt; &amp;#039;&amp;#039;Bottom:&amp;#039;&amp;#039; a parser has digested the tokens &amp;quot;&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot; inline&amp;gt;int v;main(){&amp;lt;/syntaxhighlight&amp;gt;&amp;quot; and is about choose a rule to derive &amp;#039;&amp;#039;Stmt&amp;#039;&amp;#039;. Looking only at the first lookahead token &amp;quot;&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot; inline&amp;gt;v&amp;lt;/syntaxhighlight&amp;gt;&amp;quot;, it cannot decide which of both alternatives for &amp;#039;&amp;#039;Stmt&amp;#039;&amp;#039; to choose; the latter requires peeking at the second token.]]&lt;br /&gt;
Lookahead establishes the maximum incoming tokens that a parser can use to decide which rule it should use. Lookahead is especially relevant to [[LL parser|LL]], [[LR parser|LR]], and [[LALR parser]]s, where it is often explicitly indicated by affixing the lookahead to the algorithm name in parentheses, such as LALR(1).&lt;br /&gt;
&lt;br /&gt;
Most [[programming language]]s, the primary target of parsers, are carefully defined in such a way that a parser with limited lookahead, typically one, can parse them, because parsers with limited lookahead are often more efficient. One important change{{Citation needed|date=December 2008}} to this trend came in 1990 when [[Terence Parr]] created [[ANTLR]] for his Ph.D. thesis, a [[parser generator]] for efficient LL(&amp;#039;&amp;#039;k&amp;#039;&amp;#039;) parsers, where &amp;#039;&amp;#039;k&amp;#039;&amp;#039; is any fixed value.&lt;br /&gt;
&lt;br /&gt;
LR parsers typically have only a few actions after seeing each token. They are shift (add this token to the stack for later reduction), reduce (pop tokens from the stack and form a syntactic construct), end, error (no known rule applies) or conflict (does not know whether to shift or reduce).&lt;br /&gt;
&lt;br /&gt;
Lookahead has two advantages.{{clarify|reason=This paragraph still seems to apply only to LR parsers.|date=April 2019}}&lt;br /&gt;
* It helps the parser take the correct action in case of conflicts. For example, parsing the if statement in the case of an else clause.&lt;br /&gt;
* It eliminates many duplicate states and eases the burden of an extra stack. A C language non-lookahead parser will have around 10,000 states. A lookahead parser will have around 300 states.&lt;br /&gt;
&lt;br /&gt;
Example: Parsing the Expression  {{nowrap|1 + 2 * 3}}&lt;br /&gt;
{{dubious|date=April 2019}}&lt;br /&gt;
{| class=&amp;quot;toccolours&amp;quot;&lt;br /&gt;
| colspan=3 | Set of expression parsing rules (called grammar) is as follows,&lt;br /&gt;
|-&lt;br /&gt;
| Rule1: || E → E + E  || style=&amp;quot;padding-left:1em&amp;quot; | Expression is the sum of two expressions.&lt;br /&gt;
|-&lt;br /&gt;
| Rule2: || E → E * E  || style=&amp;quot;padding-left:1em&amp;quot; |Expression is the product of two expressions.&lt;br /&gt;
|-&lt;br /&gt;
| Rule3: || E → number || style=&amp;quot;padding-left:1em&amp;quot; |Expression is a simple number&lt;br /&gt;
|-&lt;br /&gt;
| Rule4: || colspan=2 | + has less precedence than *&lt;br /&gt;
|}&lt;br /&gt;
Most programming languages (except for a few such as APL and Smalltalk) and algebraic formulas give higher precedence to multiplication than addition, in which case the correct interpretation of the example above is {{nowrap|1 + (2 * 3)}}.&lt;br /&gt;
Note that Rule4 above is a semantic rule. It is possible to rewrite the grammar to incorporate this into the syntax. However, not all such rules can be translated into syntax.&lt;br /&gt;
&lt;br /&gt;
; Simple non-lookahead parser actions&lt;br /&gt;
Initially Input = [1, +, 2, *, 3]&lt;br /&gt;
# Shift &amp;quot;1&amp;quot; onto stack from input (in anticipation of rule3). Input = [+, 2, *, 3] Stack = [1]&lt;br /&gt;
# Reduces &amp;quot;1&amp;quot; to expression &amp;quot;E&amp;quot; based on rule3. Stack = [E]&lt;br /&gt;
# Shift &amp;quot;+&amp;quot; onto stack from input (in anticipation of rule1). Input = [2, *, 3] Stack = [E, +]&lt;br /&gt;
# Shift &amp;quot;2&amp;quot; onto stack from input (in anticipation of rule3). Input = [*, 3] Stack = [E, +, 2]&lt;br /&gt;
# Reduce stack element &amp;quot;2&amp;quot; to Expression &amp;quot;E&amp;quot; based on rule3. Stack = [E, +, E]&lt;br /&gt;
# Reduce stack items [E, +, E] and new input &amp;quot;E&amp;quot; to &amp;quot;E&amp;quot; based on rule1. Stack = [E]&lt;br /&gt;
# Shift &amp;quot;*&amp;quot; onto stack from input (in anticipation of rule2). Input = [3] Stack = [E,*]&lt;br /&gt;
# Shift &amp;quot;3&amp;quot; onto stack from input (in anticipation of rule3). Input = [] (empty) Stack = [E, *, 3]&lt;br /&gt;
# Reduce stack element &amp;quot;3&amp;quot; to expression &amp;quot;E&amp;quot; based on rule3. Stack = [E, *, E]&lt;br /&gt;
# Reduce stack items [E, *, E] and new input &amp;quot;E&amp;quot; to &amp;quot;E&amp;quot; based on rule2. Stack = [E]&lt;br /&gt;
&lt;br /&gt;
The parse tree and resulting code from it is not correct according to language semantics.&lt;br /&gt;
&lt;br /&gt;
To correctly parse without lookahead, there are three solutions:&lt;br /&gt;
* The user has to enclose expressions within parentheses. This often is not a viable solution.&lt;br /&gt;
* The parser needs to have more logic to backtrack and retry whenever a rule is violated or not complete. The similar method is followed in LL parsers.&lt;br /&gt;
* Alternatively, the parser or grammar needs to have extra logic to delay reduction and reduce only when it is absolutely sure which rule to reduce first. This method is used in LR parsers. This correctly parses the expression but with many more states and increased stack depth.&lt;br /&gt;
&lt;br /&gt;
; Lookahead parser actions{{clarify|reason=While the previous text is highly dubious, the following paragraph could possibly turned into a sensible explanation about how an LR parser uses lookahead. To this end, a parser table excerpt (implementing the precedence) should be shown, the parsing mechnism should be sketched (when to shift, when to reduce, etc.), and the exaple run should be given in more tabular form, and without magic (&amp;#039;anticipation&amp;#039;).|date=April 2019}}&lt;br /&gt;
# Shift 1 onto stack on input 1 in anticipation of rule3. It does not reduce immediately.&lt;br /&gt;
# Reduce stack item 1 to simple Expression on input + based on rule3. The lookahead is +, so we are on path to E +, so we can reduce the stack to E.&lt;br /&gt;
# Shift + onto stack on input + in anticipation of rule1.&lt;br /&gt;
# Shift 2 onto stack on input 2 in anticipation of rule3.&lt;br /&gt;
# Reduce stack item 2 to Expression on input * based on rule3. The lookahead * expects only E before it.&lt;br /&gt;
# Now stack has E + E and still the input is *. It has two choices now, either to shift based on rule2 or reduction based on rule1. Since * has higher precedence than + based on rule4, we shift * onto stack in anticipation of rule2.&lt;br /&gt;
# Shift 3 onto stack on input 3 in anticipation of rule3.&lt;br /&gt;
# Reduce stack item 3 to Expression after seeing end of input based on rule3.&lt;br /&gt;
# Reduce stack items E * E to E based on rule2.&lt;br /&gt;
# Reduce stack items E + E to E based on rule1.&lt;br /&gt;
The parse tree generated is correct and simply {{clarify span|more efficient|reason=A parse tree and a parser cannot be compared w.r.t. efficiency. Even comparing two parse trees dosn&amp;#039;t make sense here; expression efficiency isn&amp;#039;t a matter of parsing, but of optimization.|date=April 2019}}{{Citation needed|date=April 2011}} than non-lookahead parsers. This is the strategy followed in [[LALR parser]]s.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
{{div col|colwidth=22em}}&lt;br /&gt;
* [[Backtracking]]&lt;br /&gt;
* [[Chart parser]]&lt;br /&gt;
* [[Compiler-compiler]]&lt;br /&gt;
* [[Deterministic parsing]]&lt;br /&gt;
* [[Generating strings]]&lt;br /&gt;
* [[Grammar checker]]&lt;br /&gt;
* [[LALR parser]]&lt;br /&gt;
* [[Lexical analysis]]&lt;br /&gt;
* [[Pratt parser]]&lt;br /&gt;
* [[Shallow parsing]]&lt;br /&gt;
* [[Left corner parser]]&lt;br /&gt;
* [[Parsing expression grammar]]&lt;br /&gt;
* [[DMS Software Reengineering Toolkit]]&lt;br /&gt;
* [[Program transformation]]&lt;br /&gt;
* [[Source code generation]]&lt;br /&gt;
{{div col end}}&amp;lt;!--&lt;br /&gt;
We don&amp;#039;t need a list of every piece of software that parses something.&lt;br /&gt;
If you&amp;#039;d like to make a SHORT list of NOTABLE applications, feel free.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
{{reflist}}21. Free Parse HTML Codes [https://www.sitedayexe.com/p/parse-html-codes.html]&lt;br /&gt;
&lt;br /&gt;
== Further reading ==&lt;br /&gt;
{{refbegin}}&lt;br /&gt;
* Chapman, Nigel P., [https://books.google.com/books?id=nEA9AAAAIAAJ&amp;amp;printsec=frontcover &amp;#039;&amp;#039;LR Parsing: Theory and Practice&amp;#039;&amp;#039;], [[Cambridge University Press]], 1987. {{ISBN|0-521-30413-X}}&lt;br /&gt;
* Grune, Dick; Jacobs, Ceriel J.H., [http://dickgrune.com/Books/PTAPG_1st_Edition/ &amp;#039;&amp;#039;Parsing Techniques - A Practical Guide&amp;#039;&amp;#039;], [[Vrije Universiteit Amsterdam]], Amsterdam, The Netherlands. Originally published by Ellis Horwood, Chichester, England, 1990; {{ISBN|0-13-651431-6}}&lt;br /&gt;
{{refend}}&lt;br /&gt;
&lt;br /&gt;
==External links==&lt;br /&gt;
{{wiktionary|parse|parsing}}&lt;br /&gt;
&lt;br /&gt;
* [http://www.hwaci.com/sw/lemon/ The Lemon LALR Parser Generator]&lt;br /&gt;
* [http://nlp.stanford.edu/software/lex-parser.shtml Stanford Parser] The Stanford Parser&lt;br /&gt;
* [http://www.tule.di.unito.it/ Turin University Parser] Natural language parser for the Italian, open source, developed in Common Lisp by Leonardo Lesmo, University of Torino, Italy.&lt;br /&gt;
* [http://blogs.perl.org/users/jeffrey_kegler/2014/09/parsing-a-timeline.html Short history of parser construction]&lt;br /&gt;
&lt;br /&gt;
{{Parsers}}&lt;br /&gt;
{{Strings}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Parsing| ]]&lt;br /&gt;
[[Category:Algorithms on strings]]&lt;br /&gt;
[[Category:Compiler construction]]&lt;/div&gt;</summary>
		<author><name>91.246.232.44</name></author>
	</entry>
</feed>