<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Formal Language Processing in Scala, Part 5</title>
	<atom:link href="http://szeiger.de/blog/2009/07/05/formal-language-processing-in-scala-part-5/feed/" rel="self" type="application/rss+xml" />
	<link>http://szeiger.de/blog/2009/07/05/formal-language-processing-in-scala-part-5/</link>
	<description>Stefan Zeiger's Software Development Weblog</description>
	<lastBuildDate>Mon, 26 Jul 2010 10:55:14 +0200</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Daniel Spiewak</title>
		<link>http://szeiger.de/blog/2009/07/05/formal-language-processing-in-scala-part-5/comment-page-1/#comment-51</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Mon, 06 Jul 2009 18:36:34 +0000</pubDate>
		<guid isPermaLink="false">http://szeiger.de/?p=28#comment-51</guid>
		<description>Not sure how I messed that one up, but my grammar was very wrong.  Correction: http://paste.pocoo.org/show/126951/</description>
		<content:encoded><![CDATA[<p>Not sure how I messed that one up, but my grammar was very wrong.  Correction: <a href="http://paste.pocoo.org/show/126951/" rel="nofollow">http://paste.pocoo.org/show/126951/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://szeiger.de/blog/2009/07/05/formal-language-processing-in-scala-part-5/comment-page-1/#comment-50</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Mon, 06 Jul 2009 18:01:03 +0000</pubDate>
		<guid isPermaLink="false">http://szeiger.de/?p=28#comment-50</guid>
		<description>Markup fail (correct if you can please).  In the meantime, here&#039;s a paste which is properly formatted and colored:  http://paste.pocoo.org/show/126941/</description>
		<content:encoded><![CDATA[<p>Markup fail (correct if you can please).  In the meantime, here&#8217;s a paste which is properly formatted and colored:  <a href="http://paste.pocoo.org/show/126941/" rel="nofollow">http://paste.pocoo.org/show/126941/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://szeiger.de/blog/2009/07/05/formal-language-processing-in-scala-part-5/comment-page-1/#comment-49</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Mon, 06 Jul 2009 17:59:54 +0000</pubDate>
		<guid isPermaLink="false">http://szeiger.de/?p=28#comment-49</guid>
		<description>Defined using my GLL combinators library (http://github.com/djspiewak/gll-combinators):

import edu.uwm.cs.gll.RegexParsers

object Fun1Parser extends RegexParsers {
  
  // %%
  
  lazy val program = seq
  
  lazy val seq = (expr + &quot;;&quot;) ^^ Sequence
  
  lazy val expr: Parser[Expression] = (
      expr ~ &quot;+&quot; ~ term                   ^^ { (e1, _, e2) =&gt; Add(e1, e2) }
    &#124; expr ~ &quot;-&quot; ~ term                   ^^ { (e1, _, e2) =&gt; Subtract(e1, e2) }
  )
  
  lazy val term: Parser[Expression] = (
      term ~ &quot;*&quot; ~ factor                 ^^ { (e1, _, e2) =&gt; Mult(e1, e2) }
    &#124; term ~ &quot;/&quot; ~ factor                 ^^ { (e1, _, e2) =&gt; Div(e1, e2) }
  )
  
  lazy val factor: Parser[Expression] = 
      factor ~ &quot;=&quot; ~ exprBase             ^^ { (e1, _, e2) =&gt; Equal(e1, e2) }
  
  lazy val exprBase = (
      &quot;\\&quot; ~&gt; (id + &quot;,&quot;) ~ &quot;-&gt;&quot; ~ expr    ^^ { (p, _, e) =&gt; Lambda(p, e) }
    &#124; &quot;let&quot; ~&gt; id ~ &quot;=&quot; ~ expr            ^^ { (id, _, e) =&gt; Let(id, e) }
    &#124; id ~ (&quot;(&quot; ~&gt; (expr + &quot;,&quot;)  expr ~ &quot;then&quot; ~ expr ~ &quot;else&quot; ~ expr    ^^ { (e1, _, e2, _, e3) =&gt; If(e1, e2, e3) }
    
    &#124; id                                  ^^ Var
    &#124; strLit                              ^^ Lit
    &#124; intLit                              ^^ Lit
  )
  
  val id = &quot;&quot;&quot;[a-zA-Z_][a-ZA-Z0-9_]*&quot;&quot;&quot;r
  
  val strLit = &quot;&quot;&quot;&quot;([^\\&quot;]&#124;\\.)*&quot;&quot;&quot;&quot;r
  
  val intLit = &quot;&quot;&quot;\d+&quot;&quot;&quot;.r    ^^ { _.toInt }
  
  // %%
}

For the record, I had to make-up/assume a lot of things in order to create this.  The definition of an identifier, operator precedence, string semantics, etc.  A rough E/BNF grammar would help.  :-)</description>
		<content:encoded><![CDATA[<p>Defined using my GLL combinators library (<a href="http://github.com/djspiewak/gll-combinators)" rel="nofollow">http://github.com/djspiewak/gll-combinators)</a>:</p>
<p>import edu.uwm.cs.gll.RegexParsers</p>
<p>object Fun1Parser extends RegexParsers {</p>
<p>  // %%</p>
<p>  lazy val program = seq</p>
<p>  lazy val seq = (expr + &#8220;;&#8221;) ^^ Sequence</p>
<p>  lazy val expr: Parser[Expression] = (<br />
      expr ~ &#8220;+&#8221; ~ term                   ^^ { (e1, _, e2) =&gt; Add(e1, e2) }<br />
    | expr ~ &#8220;-&#8221; ~ term                   ^^ { (e1, _, e2) =&gt; Subtract(e1, e2) }<br />
  )</p>
<p>  lazy val term: Parser[Expression] = (<br />
      term ~ &#8220;*&#8221; ~ factor                 ^^ { (e1, _, e2) =&gt; Mult(e1, e2) }<br />
    | term ~ &#8220;/&#8221; ~ factor                 ^^ { (e1, _, e2) =&gt; Div(e1, e2) }<br />
  )</p>
<p>  lazy val factor: Parser[Expression] =<br />
      factor ~ &#8220;=&#8221; ~ exprBase             ^^ { (e1, _, e2) =&gt; Equal(e1, e2) }</p>
<p>  lazy val exprBase = (<br />
      &#8220;\\&#8221; ~&gt; (id + &#8220;,&#8221;) ~ &#8220;-&gt;&#8221; ~ expr    ^^ { (p, _, e) =&gt; Lambda(p, e) }<br />
    | &#8220;let&#8221; ~&gt; id ~ &#8220;=&#8221; ~ expr            ^^ { (id, _, e) =&gt; Let(id, e) }<br />
    | id ~ (&#8221;(&#8221; ~&gt; (expr + &#8220;,&#8221;)  expr ~ &#8220;then&#8221; ~ expr ~ &#8220;else&#8221; ~ expr    ^^ { (e1, _, e2, _, e3) =&gt; If(e1, e2, e3) }</p>
<p>    | id                                  ^^ Var<br />
    | strLit                              ^^ Lit<br />
    | intLit                              ^^ Lit<br />
  )</p>
<p>  val id = &#8220;&#8221;"[a-zA-Z_][a-ZA-Z0-9_]*&#8221;"&#8221;r</p>
<p>  val strLit = &#8220;&#8221;"&#8221;([^\\"]|\\.)*&#8221;"&#8221;"r</p>
<p>  val intLit = &#8220;&#8221;"\d+&#8221;"&#8221;.r    ^^ { _.toInt }</p>
<p>  // %%<br />
}</p>
<p>For the record, I had to make-up/assume a lot of things in order to create this.  The definition of an identifier, operator precedence, string semantics, etc.  A rough E/BNF grammar would help.  <img src='http://szeiger.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>
