<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Balafon &#187; parsing expression grammar</title>
	<atom:link href="http://balafon.net/archives/tag/parsing-expression-grammar/feed" rel="self" type="application/rss+xml" />
	<link>http://balafon.net</link>
	<description>Shouting Into the Void</description>
	<lastBuildDate>Mon, 30 Aug 2010 19:10:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Parsing Expression Grammars and Left Recursion</title>
		<link>http://balafon.net/archives/660</link>
		<comments>http://balafon.net/archives/660#comments</comments>
		<pubDate>Fri, 25 Jul 2008 16:41:20 +0000</pubDate>
		<dc:creator>Gordon</dc:creator>
				<category><![CDATA[Journal]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[parsing expression grammar]]></category>

		<guid isPermaLink="false">http://balafon.net/?p=660</guid>
		<description><![CDATA[Parsing Expression Grammars are a form of context-free grammars with ordered choice. This reduces ambiguity in the grammar and makes writing simple recursive-descent parsers (and parser generators) quite easy. With memoization, you can parse in linear time. The resulting parser is called a Packrat Parser. The only problem is handling left-recursion. If you have grammar [...]]]></description>
			<content:encoded><![CDATA[<p>Parsing Expression Grammars are a form of context-free grammars with ordered choice.  This reduces ambiguity in the grammar and makes writing simple recursive-descent parsers (and parser generators) quite easy.  With memoization, you can parse in linear time.  The resulting parser is called a <a href="http://pdos.csail.mit.edu/~baford/packrat/">Packrat Parser</a>.</p>
<p>The only problem is handling left-recursion.  If you have grammar rules like this:</p>
<p><code>Expression = Expression "+" Term<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| Term<br />
</code></p>
<p>your recursive-descent parser will recurse until it runs out of stack.</p>
<p>I just noticed a paper on detecting and handling left-recursion: <a href="http://www.vpri.org/pdf/packrat_TR-2007-002.pdf">Packrat Parsers can Handle Left Recursion</a>.  It&#8217;s a nifty technique, but it somewhat reduces the simplicity of the resulting program.</p>
<p>For a finger exercise a while ago I wrote a pretty basic packrat parser generator and used it to implement a C preprocessor.  Source is <a href="https://narwhal.svn.sourceforge.net/svnroot/narwhal/branches/old_c_work">here</a>.  When my supply of circular tuits increases I&#8217;ll have to look at implementing the stuff from the paper.</p>
]]></content:encoded>
			<wfw:commentRss>http://balafon.net/archives/660/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
