<?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>A Concurrent Affair &#187; Mint</title>
	<atom:link href="http://www.concurrentaffair.org/category/research/mint/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.concurrentaffair.org</link>
	<description>a blog about Mathias&#039; work and play.</description>
	<lastBuildDate>Tue, 07 Feb 2012 07:11:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Automatic Generation of Optimized Domain-Specific Operations, by Jason Eckhardt</title>
		<link>http://www.concurrentaffair.org/2010/11/22/automatic-generation-of-optimized-domain-specific-operations/</link>
		<comments>http://www.concurrentaffair.org/2010/11/22/automatic-generation-of-optimized-domain-specific-operations/#comments</comments>
		<pubDate>Mon, 22 Nov 2010 19:09:04 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[Mint]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2396</guid>
		<description><![CDATA[Jason Eckhardt, a student of Keith Cooper, had an interesting COMP 600 talk about StencilDSL and simplifying writing certain stencil-based array operations: Automatic Generation of Optimized Domain-Specific Operations In previous work, we introduced a compiler-based algorithm for eliminating inter-iteration redundancies &#8230; <a href="http://www.concurrentaffair.org/2010/11/22/automatic-generation-of-optimized-domain-specific-operations/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Jason Eckhardt, a student of Keith Cooper, had an interesting <a href="http://www.clear.rice.edu/comp600/">COMP 600</a> talk about StencilDSL and simplifying writing certain stencil-based array operations:</p>

<blockquote>Automatic Generation of Optimized Domain-Specific Operations

<br/><br/>
In previous work, we introduced a compiler-based algorithm for eliminating inter-iteration redundancies in array-based loop computations.  This algorithm detects and transforms loops from ordinary programs using sophisticated analysis techniques.  From that work we discovered that many of the codes amenable to our technique were concentrated in a few application-specific domains such as PDE solvers and image processing.  Moreover, the loops in these particular codes exhibit a regularity or simplicity which can simplify the task of analyzing and optimizing them.  We also discovered that these computations are often specified in the domain literature not as elaborate loop nests, but rather with simple matrices or other compact forms.  In this talk, we discuss a prototype automatic program generation tool which allows the domain expert to specify computations in a simple and familiar way, while letting the tool generate the actual source code.  By utilizing domain knowledge encoded in the specification, the tool generates optimized code by suppressing as many inter-iteration redundancies as possible.  The result is a highly efficient program with little effort from the domain expert, and with no need for a programming or computer architecture expert to optimize the code.</blockquote>

<p><br/></p>

<p>I wonder how this would fit into <a href="http://www.cs.rice.edu/~mgricken/research/mint/">Mint</a>, especially since we used one of those stencil-based operations, a simple <a href="http://www.concurrentaffair.org/2010/10/05/gaussian-blur-implemented-in-our-dsl/">Gaussian blur</a>, as benchmark example. Using <a href="http://portal.acm.org/citation.cfm?id=236114.236119">eta-expansion as &#8220;the trick&#8221;</a>, the staged generator might look exactly like the unstaged program.</p>

<p>But I definitely don&#8217;t have time to look at this right now.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/11/22/automatic-generation-of-optimized-domain-specific-operations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Mint Release: r15952</title>
		<link>http://www.concurrentaffair.org/2010/10/20/new-mint-release-r15952/</link>
		<comments>http://www.concurrentaffair.org/2010/10/20/new-mint-release-r15952/#comments</comments>
		<pubDate>Wed, 20 Oct 2010 22:05:29 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[Mint]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2357</guid>
		<description><![CDATA[I made a new release of Mint and DrJava with Mint yesterday: October 19, 2010 (r15952). The latest release is, as always, available from the Mint implementation page: JavaMint-r15952.tar.gzJavaMint-r15952-binaries.zipdrjava-r5403-mint-r15952.jar There were several bug fixes regarding assignment to variables declared as &#8230; <a href="http://www.concurrentaffair.org/2010/10/20/new-mint-release-r15952/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I made a new release of <a href="http://www.javamint.org/">Mint</a> and <a href="http://www.cs.rice.edu/%7Emgricken/research/mint/index.shtml">DrJava with Mint</a> yesterday: October 19, 2010 (r15952). The latest release is, as always, available from the <a href="http://plresearch.org/do/view/ProgrammingLanguages/JavaMint">Mint implementation</a> page:</p>

<ul><li><a href="http://plresearch.org/twiki/pub/ProgrammingLanguages/JavaMint/JavaMint-r15952.tar.gz">JavaMint-r15952.tar.gz</a></li><li><a href="http://plresearch.org/twiki/pub/ProgrammingLanguages/JavaMint/JavaMint-r15952-binaries.zip">JavaMint-r15952-binaries.zip</a></li><li><a href="http://www.cs.rice.edu/%7Emgricken/research/mint/download/drjava-r5403-mint-r15952.jar">drjava-r5403-mint-r15952.jar</a></li></ul>

<p>There were several bug fixes regarding assignment to variables declared as <tt>CodeFree</tt>, the places where <tt>SafeCode</tt> is required, treatment of type variables with bounds in escapes, and array types, which were erroneously printed as &#8216;[Lfoo/bar;&#8217; or &#8216;[B&#8217;.</p>

<p>The version of DrJava with Mint is based on the current trunk (and therefore is newer than the updated stable release of DrJava that was recently made available).</p>

<p>(Re-posted from <a href="http://www.javamint.org/2010/10/new-mint-release-r15952.html">The Java Mint Blog</a>.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/10/20/new-mint-release-r15952/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Back from GPCE 2010</title>
		<link>http://www.concurrentaffair.org/2010/10/17/back-from-gpce-2010/</link>
		<comments>http://www.concurrentaffair.org/2010/10/17/back-from-gpce-2010/#comments</comments>
		<pubDate>Sun, 17 Oct 2010 14:43:10 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[Mint]]></category>
		<category><![CDATA[Pictures]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2326</guid>
		<description><![CDATA[After a rather long return journey and more than enough time at the Amsterdam-Schiphol airport, I&#8217;m back from my trip to GPCE 2010 in Eindhoven. It was fun. Eddy and I presented a tutorial on DSL implementation in Mint. Of &#8230; <a href="http://www.concurrentaffair.org/2010/10/17/back-from-gpce-2010/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>After a rather long return journey and more than enough time at the Amsterdam-Schiphol airport, I&#8217;m back from my trip to <a href="http://program-transformation.org/GPCE10/ConferenceProgram">GPCE 2010 in Eindhoven</a>. It was fun.</p>

<p>Eddy and I presented a <a href="http://program-transformation.org/GPCE10/Tutorial4AgileEfficientDSLs">tutorial on DSL implementation in Mint</a>. Of course, I don&#8217;t have a picture of that, but Eelco might. But here&#8217;s Sukyoung Ryu presenting her <a href="http://program-transformation.org/GPCE10/Tutorial1ProjectFortress">tutorial on Fortress</a>.</p>

<div id="attachment_2327" class="wp-caption aligncenter" style="width: 650px"><a href="http://www.concurrentaffair.org/wp-content/uploads/2010/10/IMG00026.jpg"><img src="http://www.concurrentaffair.org/wp-content/uploads/2010/10/IMG00026-1024x768.jpg" alt="Sukyoung Ryu&#039;s GPCE 2010 Tutorial on Fortress" title="IMG00026" width="640" height="480" class="size-large wp-image-2327" /></a><p class="wp-caption-text">Sukyoung Ryu's GPCE 2010 Tutorial on Fortress</p></div>

<p>The auditorium for GPCE was nice, but it didn&#8217;t have power outlets. After 10 years in Texas, I guess that&#8217;s how I generally feel about Europe: quaint, a bit cramped and underpowered ;-)</p>

<div id="attachment_2335" class="wp-caption aligncenter" style="width: 650px"><a href="http://www.concurrentaffair.org/wp-content/uploads/2010/10/IMG00027.jpg"><img src="http://www.concurrentaffair.org/wp-content/uploads/2010/10/IMG00027-1024x768.jpg" alt="GPCE Auditorium in Eindhoven" title="IMG00027" width="640" height="480" class="size-large wp-image-2335" /></a><p class="wp-caption-text">GPCE Auditorium in Eindhoven</p></div>

<p>Also very European: Train, bike, landscape with canals.</p>

<div id="attachment_2337" class="wp-caption aligncenter" style="width: 650px"><a href="http://www.concurrentaffair.org/wp-content/uploads/2010/10/IMG00032.jpg"><img src="http://www.concurrentaffair.org/wp-content/uploads/2010/10/IMG00032-1024x768.jpg" alt="Train, bike, landscape with canals" title="IMG00032" width="640" height="480" class="size-large wp-image-2337" /></a><p class="wp-caption-text">Train, bike, landscape with canals</p></div>

<p>Some more pictures from the trip:</p>

<div id="attachment_2336" class="wp-caption aligncenter" style="width: 650px"><a href="http://www.concurrentaffair.org/wp-content/uploads/2010/10/IMG00030.jpg"><img src="http://www.concurrentaffair.org/wp-content/uploads/2010/10/IMG00030-1024x768.jpg" alt="Eindhoven train station, for a quick escape" title="IMG00030" width="640" height="480" class="size-large wp-image-2336" /></a><p class="wp-caption-text">Eindhoven train station, for a quick escape</p></div>

<div id="attachment_2330" class="wp-caption aligncenter" style="width: 650px"><a href="http://www.concurrentaffair.org/wp-content/uploads/2010/10/IMG00036.jpg"><img src="http://www.concurrentaffair.org/wp-content/uploads/2010/10/IMG00036-1024x768.jpg" alt="Landscape from the train" title="IMG00036" width="640" height="480" class="size-large wp-image-2330" /></a><p class="wp-caption-text">Landscape from the train</p></div>

<div id="attachment_2331" class="wp-caption aligncenter" style="width: 650px"><a href="http://www.concurrentaffair.org/wp-content/uploads/2010/10/IMG00049.jpg"><img src="http://www.concurrentaffair.org/wp-content/uploads/2010/10/IMG00049-1024x768.jpg" alt="Ready to leave Amsterdam-Schiphol airport" title="IMG00049" width="640" height="480" class="size-large wp-image-2331" /></a><p class="wp-caption-text">Ready to leave Amsterdam-Schiphol airport</p></div>

<p>And here are some more <a href="http://www.flickr.com/photos/tsfb/sets/72157625176718002/with/5086663281/">pictures that Eddy took</a>. Proof that I exist!</p>

<div id="attachment_2345" class="wp-caption aligncenter" style="width: 650px"><a href="http://www.flickr.com/photos/tsfb/5087240688/in/set-72157625176718002/"><img src="http://www.concurrentaffair.org/wp-content/uploads/2010/10/5087240688_9a5900030b_b.jpg" alt="At the Amsterdam-Schiphol airport train station" title="5087240688_9a5900030b_b" width="640" height="853" class="size-full wp-image-2345" /></a><p class="wp-caption-text">At the Amsterdam-Schiphol airport train station</p></div>

<div id="attachment_2346" class="wp-caption aligncenter" style="width: 650px"><a href="http://www.flickr.com/photos/tsfb/5086663281/in/set-72157625176718002/"><img src="http://www.concurrentaffair.org/wp-content/uploads/2010/10/5086663281_31dc1e4d2b_b.jpg" alt="&quot;Looking very European&quot; with my scarf" title="5086663281_31dc1e4d2b_b" width="640" height="853" class="size-full wp-image-2346" /></a><p class="wp-caption-text">&quot;Looking very European&quot; with my scarf</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/10/17/back-from-gpce-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Benoît Mandelbrot Died at Age 85</title>
		<link>http://www.concurrentaffair.org/2010/10/16/benoit-mandelbrot-died-at-age-85/</link>
		<comments>http://www.concurrentaffair.org/2010/10/16/benoit-mandelbrot-died-at-age-85/#comments</comments>
		<pubDate>Sun, 17 Oct 2010 01:46:44 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[Mint]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2324</guid>
		<description><![CDATA[Just after Eddy and I used the Mandelbrot set as benchmark in our DSL tutorial, Benoît Mandelbrot died. The Franco-American mathematician, who is most well-known for popularizing fractal geometry, died at the age of 85. Thank you for giving us &#8230; <a href="http://www.concurrentaffair.org/2010/10/16/benoit-mandelbrot-died-at-age-85/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Just after Eddy and I used the <a href="http://www.concurrentaffair.org/2010/10/10/another-image-processing-example-in-our-staged-dsl/">Mandelbrot set as benchmark</a> in our DSL tutorial, Benoît Mandelbrot died. The Franco-American mathematician, who is most well-known for popularizing fractal geometry, died at the age of 85.</p>

<p>Thank you for giving us such a visually appealing way of demonstrating our optimization for embarrassingly parallel loops.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/10/16/benoit-mandelbrot-died-at-age-85/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Another Image Processing Example in Our Staged DSL</title>
		<link>http://www.concurrentaffair.org/2010/10/10/another-image-processing-example-in-our-staged-dsl/</link>
		<comments>http://www.concurrentaffair.org/2010/10/10/another-image-processing-example-in-our-staged-dsl/#comments</comments>
		<pubDate>Sun, 10 Oct 2010 12:56:49 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[Mint]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2319</guid>
		<description><![CDATA[Last night, we implemented a Mandelbrot example in the image processing DSL that we created for our GPCE tutorial. Here&#8217;s a screenshot.]]></description>
			<content:encoded><![CDATA[<p>Last night, we implemented a Mandelbrot example in the image processing DSL that we created for our <a href="http://www.concurrentaffair.org/2010/10/10/gpce10-tutorial-slides/">GPCE tutorial</a>. Here&#8217;s a screenshot.</p>

<div id="attachment_2320" class="wp-caption aligncenter" style="width: 650px"><a href="http://www.concurrentaffair.org/wp-content/uploads/2010/10/screen-capture-mint-dsl-mandelbrot.jpg"><img src="http://www.concurrentaffair.org/wp-content/uploads/2010/10/screen-capture-mint-dsl-mandelbrot-1024x640.jpg" alt="Screen Capture of Mandelbrot in our Staged DSL" title="screen-capture-mint-dsl-mandelbrot" width="640" height="400" class="size-large wp-image-2320" /></a><p class="wp-caption-text">Screen Capture of Mandelbrot in our Staged DSL</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/10/10/another-image-processing-example-in-our-staged-dsl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>GPCE&#8217;10 Tutorial Slides</title>
		<link>http://www.concurrentaffair.org/2010/10/10/gpce10-tutorial-slides/</link>
		<comments>http://www.concurrentaffair.org/2010/10/10/gpce10-tutorial-slides/#comments</comments>
		<pubDate>Sun, 10 Oct 2010 12:44:55 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[Mint]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2317</guid>
		<description><![CDATA[The slides for our GPCE 2010 tutorial presentation &#8220;Agile and Efficient Domain-Specific Languages using Multi-Stage Programming in Java Mint&#8221; are available now as PowerPoint and PDF file. The zip file with the source code for our GPCE 2010 tutorial is &#8230; <a href="http://www.concurrentaffair.org/2010/10/10/gpce10-tutorial-slides/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The slides for our GPCE 2010 tutorial presentation &#8220;Agile and Efficient Domain-Specific Languages using Multi-Stage Programming in Java Mint&#8221; are available now as <a href="http://www.cs.rice.edu/~mgricken/research/mint/download/Mint-GPCE-tutorial-presentation-20101010.ppt">PowerPoint</a> and <a href="http://www.cs.rice.edu/~mgricken/research/mint/download/Mint-GPCE-tutorial-presentation-20101010.pdf">PDF</a> file.</p>

<p>The zip file with the <a href="http://www.cs.rice.edu/~mgricken/research/mint/download/mint-gpce2010-tutorial-source.zip">source code</a> for our GPCE 2010 tutorial is available too.</p>

<p>The simplest way to <a href="http://plresearch.org/do/view/ProgrammingLanguages/JavaMint">experiment with Mint</a> is to download the latest version of <a href="http://www.cs.rice.edu/~mgricken/research/mint/download/drjava-r5401-mint-r15903.jar">DrJava with Mint</a>.</p>

<p>(Re-posted from <a href="http://www.javamint.org/2010/10/gpce10-tutorial-slides.html">The Java Mint Blog</a>.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/10/10/gpce10-tutorial-slides/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>GPCE&#8217;10 Tutorial Source</title>
		<link>http://www.concurrentaffair.org/2010/10/10/gpce10-tutorial-source/</link>
		<comments>http://www.concurrentaffair.org/2010/10/10/gpce10-tutorial-source/#comments</comments>
		<pubDate>Sun, 10 Oct 2010 10:06:03 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[Mint]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2315</guid>
		<description><![CDATA[Here is a zip file with the source code for our GPCE 2010 tutorial. The simplest way to experiment with Mint is to download the latest version of DrJava with Mint. (Re-posted from The Java Mint Blog.)]]></description>
			<content:encoded><![CDATA[<p>Here is a zip file with the <a href="http://www.cs.rice.edu/~mgricken/research/mint/download/mint-gpce2010-tutorial-source.zip">source code</a> for our <a href="http://www.concurrentaffair.org/2010/08/16/gpce10-tutorial-lecture-agile-and-efficient-domain-specific-languages-using-multi-stage-programming-in-java-mint/">GPCE 2010 tutorial</a>.</p>

<p>The simplest way to <a href="http://plresearch.org/do/view/ProgrammingLanguages/JavaMint">experiment with Mint</a> is to download the latest version of <a href="http://www.cs.rice.edu/~mgricken/research/mint/download/drjava-r5401-mint-r15903.jar">DrJava with Mint</a>.</p>

<p>(Re-posted from <a href="http://www.javamint.org/2010/10/gpce10-tutorial-source.html">The Java Mint Blog</a>.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/10/10/gpce10-tutorial-source/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gaussian Blur Implemented in Our DSL</title>
		<link>http://www.concurrentaffair.org/2010/10/05/gaussian-blur-implemented-in-our-dsl/</link>
		<comments>http://www.concurrentaffair.org/2010/10/05/gaussian-blur-implemented-in-our-dsl/#comments</comments>
		<pubDate>Tue, 05 Oct 2010 21:28:04 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[Mint]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2292</guid>
		<description><![CDATA[Sexy! A screenshot showing an original image of random grayscale values, and a blurred version of the image, with the source code in our example DSL for the GPCE tutorial in the background.]]></description>
			<content:encoded><![CDATA[<p>Sexy!</p>

<div id="attachment_2295" class="wp-caption aligncenter" style="width: 650px"><a href="http://www.concurrentaffair.org/wp-content/uploads/2010/10/Screenshot.jpg"><img src="http://www.concurrentaffair.org/wp-content/uploads/2010/10/Screenshot-1024x768.jpg" alt="Gaussian Blur in DSL Screenshot" title="Gaussian Blur in DSL Screenshot" width="640" height="480" class="size-large wp-image-2295" /></a><p class="wp-caption-text">Gaussian Blur in DSL Screenshot</p></div>

<p>A screenshot showing an original image of random grayscale values, and a blurred version of the image, with the source code in our example DSL for the <a href="http://program-transformation.org/GPCE10/Tutorial4AgileEfficientDSLs">GPCE tutorial</a> in the background.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/10/05/gaussian-blur-implemented-in-our-dsl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Power_Let Was Wrong</title>
		<link>http://www.concurrentaffair.org/2010/10/04/power_let-was-wrong/</link>
		<comments>http://www.concurrentaffair.org/2010/10/04/power_let-was-wrong/#comments</comments>
		<pubDate>Mon, 04 Oct 2010 19:44:00 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[Mint]]></category>
		<category><![CDATA[Ramblings]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2283</guid>
		<description><![CDATA[I just did some experiments with Mint, because we ran into some problems with using HJ inside DrJava, and I wanted to make sure we didn&#8217;t have those problems. That&#8217;s when I noticed that our Power_Let example had been wrong. &#8230; <a href="http://www.concurrentaffair.org/2010/10/04/power_let-was-wrong/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I just did some experiments with Mint, because we ran into some problems with using HJ inside DrJava, and I wanted to make sure we didn&#8217;t have those problems. That&#8217;s when I noticed that our <a href="https://www.svn.rice.edu/filedetails.php?repname=rap&#038;path=%2Fproject%2Fjava-mint%2Ftrunk%2Flangtools%2FmintTest%2FPower_Let.java&#038;rev=13221">Power_Let</a> example had been wrong. One of our undergrads had written it as <img src='http://www.superscalar.org/blog/wp-content/latexrenderer/pictures/39eeab93961555c40f6dc5f7e5471052.gif' title='x^0 = x' alt='x^0 = x' align=absmiddle>, and no one had noticed&#8230;</p>

<p>Embarrassing&#8230; But at least the unstaged code was equally wrong, so the benchmark is valid ;)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/10/04/power_let-was-wrong/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Demo of DrJava/HJ</title>
		<link>http://www.concurrentaffair.org/2010/10/04/demo-of-drjavahj/</link>
		<comments>http://www.concurrentaffair.org/2010/10/04/demo-of-drjavahj/#comments</comments>
		<pubDate>Mon, 04 Oct 2010 19:29:48 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[DrJava]]></category>
		<category><![CDATA[Mint]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2276</guid>
		<description><![CDATA[In today&#8217;s DrJava/Habanero meeting, Vincent, Jarred and I presented a demo of DrJava/HJ to Jack Dennis of MIT. Generally, we were quite pleased how we could just re-build Habanero Java and DrJava, and get a working version with the newest &#8230; <a href="http://www.concurrentaffair.org/2010/10/04/demo-of-drjavahj/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In today&#8217;s DrJava/Habanero meeting, Vincent, Jarred and I presented a demo of <a href="http://www.concurrentaffair.org/2010/09/01/drjavahj-born/">DrJava/HJ</a> to Jack Dennis of MIT. Generally, we were quite pleased how we could just re-build Habanero Java and DrJava, and get a working version with the newest features from both packages.</p>

<p>We also noticed a few problems, of course. Perhaps most critically, when using the HJ compiler from within DrJava, the <a href="https://sourceforge.net/tracker/index.php?func=detail&#038;aid=3081009&#038;group_id=44253&#038;atid=438935">compiler uses the wrong directories when it generates class files for classes not in the default package</a>.</p>

<p>I fixed part of that bug. The compiler adapter was ignoring the destination directory passed to the HJ compiler adapter. Now, if you create a project and set a build directory, the class files will end up in the right place. I have committed this fix into the DrJava trunk and also into the drjava-hj branch.</p>

<p>I didn&#8217;t fix the problem (a) if there is no build directory set, or (b) if we are not in project mode. This is something that I think should be fixed in the HJ compiler, because it doesn&#8217;t behave the same way javac behaves: If you invoke javac and don&#8217;t give it a destination directory, it will generate the class files in the same directory where the source files are. The HJ compiler generates the class files in the current directory.</p>

<p>Example:</p>

<p><code class="codecolorer text mac-classic"><span class="text">javac src/HelloWorld.java</span></code> generates the class file <tt>src/HelloWorld.class</tt>.
<code class="codecolorer text mac-classic"><span class="text">hjc src/HelloWorld.hj</span></code> generates the class files <tt>HelloWorld.class</tt>, <tt>HelloWorld$0.class</tt>, and <tt>HelloWorld$Main.class</tt>. in the current directory, not in <tt>src</tt>.</p>

<p>I hope the HJ team will agree this is a change that should be made in the HJ compiler.</p>

<p>Furthermore, we noticed again that <a href="https://sourceforge.net/tracker/?func=detail&#038;atid=438935&#038;aid=3081079&#038;group_id=44253">compiler error messages aren&#8217;t displayed in DrJava&#8217;s Compiler Output pane</a>. We also noted that we <a href="https://sourceforge.net/tracker/?func=detail&#038;atid=438935&#038;aid=3081085&#038;group_id=44253">cannot call methods directly from the Interactions pane</a>: We have to use the <code class="codecolorer text mac-classic"><span class="text">hj</span></code> or <code class="codecolorer text mac-classic"><span class="text">run</span></code> commands, otherwise the class loader isn&#8217;t properly set up. We should at least come up with a better error message than throwing an exception:</p>

<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Welcome to DrJava. &nbsp;Working directory is /Users/mgricken/bin/hj.release/examples<br />
&gt; new FibFuture().fib(10)<br />
java.lang.NullPointerException<br />
&nbsp; &nbsp; at hj.lang.Runtime.here(Runtime.java:317)<br />
&nbsp; &nbsp; at hj.lang.Object.&lt;init&gt;(Object.java:44)<br />
&nbsp; &nbsp; at FibFuture.&lt;init&gt;(FibFuture.hj)</div></div>

<p>Interestingly, we can call Mint methods from the Interactions pane, we just cannot use the new syntax elements in Mint, brackets and escape.</p>

<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Welcome to DrJava. &nbsp;Working directory is /Users/mgricken/Documents/Research/Mint/java-mint/trunk/langtools/mintTest<br />
&gt; import edu.rice.cs.mint.runtime.*<br />
&gt; Code&lt;Integer&gt; c = DrJavaInteractions.makeCodeInt(5)<br />
&gt; c<br />
&lt;| ((5)) |&gt;<br />
&gt; Code&lt;Integer&gt; cTo10 = DrJavaInteractions.spower(c, 10)<br />
&gt; cTo10<br />
&lt;| (((5)) * (((5)) * (((5)) * (((5)) * (((5)) * (((5)) * (((5)) * (((5)) * (((5)) * (((5)) * (1))))))))))) |&gt;<br />
&gt; cTo10.run()<br />
9765625</div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/10/04/demo-of-drjavahj/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Mint Release: r15858</title>
		<link>http://www.concurrentaffair.org/2010/09/30/new-mint-release-r15858/</link>
		<comments>http://www.concurrentaffair.org/2010/09/30/new-mint-release-r15858/#comments</comments>
		<pubDate>Fri, 01 Oct 2010 04:37:06 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[Mint]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2271</guid>
		<description><![CDATA[I made a new release of Mint and DrJava with Mint yesterday: September 29, 2010 (r15858). The latest release is, as always, available from the Mint implementation page: JavaMint-r15858.tar.gzJavaMint-r15858-binaries.zipdrjava-r5398-mint-r15858.jar We have added the edu.rice.cs.mint.runtime.CodeFree interface and the edu.rice.cs.mint.runtime.CheckedExceptionInCode exception class. &#8230; <a href="http://www.concurrentaffair.org/2010/09/30/new-mint-release-r15858/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I made a new release of <a href="http://www.javamint.org/">Mint</a> and <a href="http://www.cs.rice.edu/%7Emgricken/research/mint/index.shtml">DrJava with Mint</a> yesterday: September 29, 2010 (r15858). The latest release is, as always, available from the <a href="http://plresearch.org/do/view/ProgrammingLanguages/JavaMint">Mint implementation</a> page:</p>

<ul><li><a href="http://plresearch.org/twiki/pub/ProgrammingLanguages/JavaMint/JavaMint-r15858.tar.gz">JavaMint-r15858.tar.gz</a></li><li><a href="http://plresearch.org/twiki/pub/ProgrammingLanguages/JavaMint/JavaMint-r15858-binaries.zip">JavaMint-r15858-binaries.zip</a></li><li><a href="http://www.cs.rice.edu/%7Emgricken/research/mint/download/drjava-r5398-mint-r15858.jar">drjava-r5398-mint-r15858.jar</a></li></ul>

<p>We have added the <code class="codecolorer java mac-classic"><span class="java">edu.<span style="color: #006633;">rice</span>.<span style="color: #006633;">cs</span>.<span style="color: #006633;">mint</span>.<span style="color: #006633;">runtime</span>.<span style="color: #006633;">CodeFree</span></span></code> interface and the <code class="codecolorer java mac-classic"><span class="java">edu.<span style="color: #006633;">rice</span>.<span style="color: #006633;">cs</span>.<span style="color: #006633;">mint</span>.<span style="color: #006633;">runtime</span>.<span style="color: #006633;">CheckedExceptionInCode</span></span></code> exception class.</p>

<p>The <code class="codecolorer java mac-classic"><span class="java">CodeFree</span></code> interface provides a different, more transparent way of specifying separable classes that can be used for non-local assignments and CSP. When a class is declared to implement the <code class="codecolorer java mac-classic"><span class="java">CodeFree</span></code> interface, the class is guaranteed to be code-free, provided a number of static checks are passed:</p>

<ol><li>All field types and method return types are code-free, either using the old definition that required the types to be <code class="codecolorer java mac-classic"><span class="java"><span style="color: #000000; font-weight: bold;">final</span></span></code>, or by themselves implementing the <code class="codecolorer java mac-classic"><span class="java">CodeFree</span></code> interface.</li><li>The same applies to all subtypes of types implementing  the <code class="codecolorer java mac-classic"><span class="java">CodeFree</span></code> interface. It is an error to extend a class declared to be code-free using the <code class="codecolorer java mac-classic"><span class="java">CodeFree</span></code> interface and then to add a field containing or a method returning code.</li></ol>

<p>This new rule makes it simpler to work with non-primitive types since the classes do not have to be <code class="codecolorer java mac-classic"><span class="java"><span style="color: #000000; font-weight: bold;">final</span></span></code> anymore. In the past, lifting had to be done instead of using CSP; that is not necessary anymore. Consider the old code with the required <code class="codecolorer java mac-classic"><span class="java">lift</span></code> method and its application instead of straight-forward CSP:</p>

<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> Value <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> separable <span style="color: #000066; font-weight: bold;">int</span> intValue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> WrongTypeException<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> separable <span style="color: #000066; font-weight: bold;">boolean</span> booleanValue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> WrongTypeException<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> separable <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000066; font-weight: bold;">boolean</span> valueEq<span style="color: #009900;">&#40;</span>Value other<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> separable <span style="color: #000000; font-weight: bold;">abstract</span> Code<span style="color: #339933;">&lt;</span>Value<span style="color: #339933;">&gt;</span> lift<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> IntValue <span style="color: #000000; font-weight: bold;">extends</span> Value <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> _data<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// ...</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> separable Code<span style="color: #339933;">&lt;</span>Value<span style="color: #339933;">&gt;</span> lift<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> lfData <span style="color: #339933;">=</span> _data<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// hack to help the Mint compiler</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #339933;">&lt;|</span> <span style="color: #009900;">&#40;</span>Value<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">new</span> IntValue<span style="color: #009900;">&#40;</span>lfData<span style="color: #009900;">&#41;</span> <span style="color: #339933;">|&gt;;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BooleanValue <span style="color: #000000; font-weight: bold;">extends</span> Value <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> _data<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// ...</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> separable Code<span style="color: #339933;">&lt;</span>Value<span style="color: #339933;">&gt;</span> lift<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">boolean</span> lfData <span style="color: #339933;">=</span> _data<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// hack to help the Mint compiler</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #339933;">&lt;|</span> <span style="color: #009900;">&#40;</span>Value<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">new</span> BooleanValue<span style="color: #009900;">&#40;</span>lfData<span style="color: #009900;">&#41;</span> <span style="color: #339933;">|&gt;;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// ...</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Val <span style="color: #000000; font-weight: bold;">implements</span> Exp <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> Code<span style="color: #339933;">&lt;</span>Value<span style="color: #339933;">&gt;</span> _value<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> Val<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Value value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; _value <span style="color: #339933;">=</span> value.<span style="color: #006633;">lift</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// lifting here</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// ...</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>

<p>and the new code that doesn&#8217;t require the <code class="codecolorer java mac-classic"><span class="java">lift</span></code> method anymore:</p>

<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> Value <span style="color: #000000; font-weight: bold;">implements</span> CodeFree, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aserializable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Serializable</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> separable <span style="color: #000066; font-weight: bold;">int</span> intValue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> WrongTypeException<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> separable <span style="color: #000066; font-weight: bold;">boolean</span> booleanValue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> WrongTypeException<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> separable <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000066; font-weight: bold;">boolean</span> valueEq<span style="color: #009900;">&#40;</span>Value other<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> IntValue <span style="color: #000000; font-weight: bold;">extends</span> Value <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> _data<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// ...</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BooleanValue <span style="color: #000000; font-weight: bold;">extends</span> Value <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> _data<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// ...</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// ...</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Val <span style="color: #000000; font-weight: bold;">implements</span> Exp <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> Code<span style="color: #339933;">&lt;</span>Value<span style="color: #339933;">&gt;</span> _value<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> Val<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Value value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; _value <span style="color: #339933;">=</span> <span style="color: #339933;">&lt;|</span> value <span style="color: #339933;">|&gt;;</span> <span style="color: #666666; font-style: italic;">// straight-forward CSP</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// ...</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>

<p>Please note that a class used in CSP still needs to be serializable if the code object it is used in is to be saved using <code class="codecolorer java mac-classic"><span class="java">MintSerializer.<span style="color: #006633;">save</span></span></code>. That means that whenever you implement <code class="codecolorer java mac-classic"><span class="java">CodeFree</span></code>, you should consider also implementing the <code class="codecolorer java mac-classic"><span class="java">java.<span style="color: #006633;">io</span>.<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aserializable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Serializable</span></a></span></code> interface.</p>

<p>The second change involves the way checked exceptions are thrown inside a code object. In the past, checked exceptions were not allowed, because the <code class="codecolorer java mac-classic"><span class="java">Code.<span style="color: #006633;">run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> method did not have a <code class="codecolorer java mac-classic"><span class="java"><span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athrowable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Throwable</span></a></span></code> clause.</p>

<p>We still didn&#8217;t add such a clause, because it would essentially require a try-catch construct around every call to <code class="codecolorer java mac-classic"><span class="java">Code.<span style="color: #006633;">run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code>. Instead, checked exceptions are caught and rethrown wrapped in a <code class="codecolorer java mac-classic"><span class="java">edu.<span style="color: #006633;">rice</span>.<span style="color: #006633;">cs</span>.<span style="color: #006633;">mint</span>.<span style="color: #006633;">runtime</span>.<span style="color: #006633;">CheckedExceptionInCode</span></span></code> unchecked exception. Here is an example:</p>

<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> separable <span style="color: #000066; font-weight: bold;">void</span> m<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aioexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">IOException</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/this/is/a/bad/path&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">createNewFile</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// throws IOException</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// ...</span><br />
<br />
SafeCode<span style="color: #339933;">&lt;</span>Void<span style="color: #339933;">&gt;</span> c <span style="color: #339933;">=</span> <span style="color: #339933;">&lt;|</span> <span style="color: #009900;">&#123;</span> m<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #339933;">|&gt;;</span><br />
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; c.<span style="color: #006633;">run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>CheckedExceptionInCode ce<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athrowable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Throwable</span></a> cause <span style="color: #339933;">=</span> ce.<span style="color: #006633;">getCause</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// ...</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>

<p>We also improved error checking for calls to separable methods and fixed a bug that required <code class="codecolorer java mac-classic"><span class="java">SafeCode<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span></span></code> in too many places.</p>

<p>The version of DrJava with Mint is based on the current trunk (and therefore is newer than the updated stable release of DrJava that was recently made available).</p>

<p>(Re-posted from <a href="http://www.javamint.org/2010/09/new-mint-release-r15858.html">The Java Mint Blog</a>.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/09/30/new-mint-release-r15858/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Mint Release: r15772</title>
		<link>http://www.concurrentaffair.org/2010/09/16/new-mint-release-r15772/</link>
		<comments>http://www.concurrentaffair.org/2010/09/16/new-mint-release-r15772/#comments</comments>
		<pubDate>Thu, 16 Sep 2010 21:00:24 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[Mint]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2242</guid>
		<description><![CDATA[We have just made a new release of Mint and DrJava with Mint: September 16, 2010 (r15772). The latest release is, as always, available from the Mint implementation page: JavaMint-r15772.tar.gzJavaMint-r15772-binaries.zipdrjava-r5385-mint-r15772.jar We have added the edu.rice.cs.mint.runtime.MintSerializer class to it that can &#8230; <a href="http://www.concurrentaffair.org/2010/09/16/new-mint-release-r15772/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We have just made a new release of <a href="http://www.javamint.org/">Mint</a> and <a href="http://www.cs.rice.edu/%7Emgricken/research/mint/index.shtml">DrJava with Mint</a>: September 16, 2010 (r15772). The latest release is, as always, available from the <a href="http://plresearch.org/do/view/ProgrammingLanguages/JavaMint">Mint implementation</a> page:</p>

<ul><li><a href="http://plresearch.org/twiki/pub/ProgrammingLanguages/JavaMint/JavaMint-r15772.tar.gz">JavaMint-r15772.tar.gz</a></li><li><a href="http://plresearch.org/twiki/pub/ProgrammingLanguages/JavaMint/JavaMint-r15772-binaries.zip">JavaMint-r15772-binaries.zip</a></li><li><a href="http://www.cs.rice.edu/%7Emgricken/research/mint/download/drjava-r5385-mint-r15772.jar" class="broken_link">drjava-r5385-mint-r15772.jar</a></li></ul>

<p>We have added the <code class="codecolorer java mac-classic"><span class="java">edu.<span style="color: #006633;">rice</span>.<span style="color: #006633;">cs</span>.<span style="color: #006633;">mint</span>.<span style="color: #006633;">runtime</span>.<span style="color: #006633;">MintSerializer</span></span></code> class to it that can write code object, including CSP data, to a jar file (or whatever stream you like), and then restore it again. Here is a very simple example:</p>

<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Code<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span> c <span style="color: #339933;">=</span> <span style="color: #339933;">&lt;|</span><span style="color: #cc66cc;">123</span><span style="color: #339933;">|&gt;;</span><br />
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a> f <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a><span style="color: #009900;">&#40;</span>dir, <span style="color: #0000ff;">&quot;IntegerCode1.jar&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
MintSerializer.<span style="color: #006633;">save</span><span style="color: #009900;">&#40;</span>c, <span style="color: #0000ff;">&quot;IntegerCode1&quot;</span>, f<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Integer</span></a> s <span style="color: #339933;">=</span> MintSerializer.<span style="color: #006633;">load</span><span style="color: #009900;">&#40;</span>f<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>

<p>The version of DrJava with Mint is based on the current trunk (and not on updated stable release of DrJava that was made available this week).</p>

<p>(Re-posted from <a href="http://www.javamint.org/2010/09/new-mint-release-r15772.html">The Java Mint Blog</a>.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/09/16/new-mint-release-r15772/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mint on the Mac</title>
		<link>http://www.concurrentaffair.org/2010/09/01/mint-on-the-mac/</link>
		<comments>http://www.concurrentaffair.org/2010/09/01/mint-on-the-mac/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 18:16:11 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[Mint]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2199</guid>
		<description><![CDATA[I guess I&#8217;m a bit behind the technology curve. The MacBook that I&#8217;m using as one of my development machines is one of the original white Intel MacBooks with a Core Duo CPU (not Core 2 Duo). It&#8217;s a 32-bit &#8230; <a href="http://www.concurrentaffair.org/2010/09/01/mint-on-the-mac/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I guess I&#8217;m a bit behind the technology curve. The MacBook that I&#8217;m using as one of my development machines is one of the original white Intel MacBooks with a Core Duo CPU (not Core 2 Duo). It&#8217;s a 32-bit machine, and Apple doesn&#8217;t offer Java 6 for 32-bit computers.</p>

<p>Mint, however, requires a version of Java 6, which is why we recommended using <a href="http://landonf.bikemonkey.org/static/soylatte/">SoyLatte</a> to run Mint. That comes with all kinds of inconveniences because SoyLatte uses X11 for its GUIs, which means DrJava needs to run under X11.</p>

<p>Yesterday I tested Mint and DrJava with Mint using Apple&#8217;s Java SE 6.0 Release 1 Developer Preview 6 (file name: <a href="http://www.google.com/search?q=download++javase6release1dp6.dmg"><tt>javase6release1dp6.dmg</tt></a>), which I still had floating around and which is the last version of Apple&#8217;s Java 6 that still runs on 32-bit Macs. It works! SoyLatte is only required if you don&#8217;t have a version of Java 6 (either Apple&#8217;s official version on 64-bit Macs, or Apple&#8217;s Java SE 6.0 Release 1 Developer Preview 6 on 32-bit Macs) on your Mac.</p>

<p>I have updated the instructions on how to <a href="http://www.concurrentaffair.org/2009/09/04/installing-javamint-on-macos/">install Java Mint on the Mac</a> and how to <a href="http://www.concurrentaffair.org/2009/09/29/drjava-with-mint-released/">run DrJava with Mint</a> accordingly.</p>

<p>(Re-posted from <a href="http://www.javamint.org/2010/09/mint-on-mac.html">The Java Mint Blog</a>.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/09/01/mint-on-the-mac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reflection-Based S-Expression Parser</title>
		<link>http://www.concurrentaffair.org/2010/09/01/reflection-based-s-expression-parser/</link>
		<comments>http://www.concurrentaffair.org/2010/09/01/reflection-based-s-expression-parser/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 05:43:54 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[Mint]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2191</guid>
		<description><![CDATA[I&#8217;m really quite proud of this little reflection-based S-expression parser that I wrote for our GPCE Mint tutorial. We wanted to have a parser so we don&#8217;t have to construct our ASTs using Java code. The problem was that we&#8217;ll &#8230; <a href="http://www.concurrentaffair.org/2010/09/01/reflection-based-s-expression-parser/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m really quite proud of this little reflection-based S-expression parser that I wrote for our <a href="http://www.concurrentaffair.org/2010/08/16/gpce10-tutorial-lecture-agile-and-efficient-domain-specific-languages-using-multi-stage-programming-in-java-mint/">GPCE Mint tutorial</a>.</p>

<p>We wanted to have a parser so we don&#8217;t have to construct our ASTs using Java code. The problem was that we&#8217;ll probably have ten different mini-languages, and we didn&#8217;t want to write a parser for each language. Reflection was the answer, of course.</p>

<p>For this parser to work, you need to define the base class of the class hierarchy (e.g. <code class="codecolorer java mac-classic"><span class="java">Exp</span></code>) and the subclasses as static nested classes inside the same outer class (e.g. all inside <code class="codecolorer java mac-classic"><span class="java">UnstagedLint</span></code>).</p>

<p>You then simply specify the base class, and the parser will search for the subclasses. The names of the S-expressions are the simple names of the subclasses (e.g. <tt>Add</tt> and <tt>Int</tt> if there are <code class="codecolorer java mac-classic"><span class="java">Add</span></code> and <code class="codecolorer java mac-classic"><span class="java">Int</span></code> subclasses).</p>

<p>When encountering an S-expression, the parser will try all of the constructors of the corresponding class. As arguments for a constructor, the parser can process all primitive types, the boxed types, strings, recursive occurrences of the base class (e.g. <code class="codecolorer java mac-classic"><span class="java">Add</span></code> containing two <code class="codecolorer java mac-classic"><span class="java">Exp</span></code> instances), as well as other class hierarchies, which are parsed using subparsers.</p>

<p>These subparsers work the same way the main parser works. For example, if a <code class="codecolorer java mac-classic"><span class="java">Val</span></code> constructor needs a <code class="codecolorer java mac-classic"><span class="java">Value</span></code> argument, and there is a subparser registered for the <code class="codecolorer java mac-classic"><span class="java">Val</span></code> hierarchy, the main parser will delegate to that subparser. Here&#8217;s an example:</p>

<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">DataTypes.<span style="color: #006633;">Exp</span> e <span style="color: #339933;">=</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> LintParser<span style="color: #339933;">&lt;</span>DataTypes.<span style="color: #006633;">Exp</span><span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>DataTypes.<span style="color: #006633;">Exp</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; .<span style="color: #006633;">addSubParser</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> LintParser<span style="color: #339933;">&lt;</span>DataTypes.<span style="color: #006633;">Value</span><span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>DataTypes.<span style="color: #006633;">Value</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; .<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;(Add (Val (IntValue 1)) (Val (IntValue 2)))&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>

<p>This creates a parser for expressions of class <code class="codecolorer java mac-classic"><span class="java">DataTypes.<span style="color: #006633;">Exp</span></span></code>, and it registers a subparser for expressions of class <code class="codecolorer java mac-classic"><span class="java">DataTypes.<span style="color: #006633;">Value</span></span></code>. Then it parses the string <code class="codecolorer text mac-classic"><span class="text">(Add (Val (IntValue 1)) (Val (IntValue 2)))</span></code>. The <code class="codecolorer text mac-classic"><span class="text">(IntValue 1)</span></code> and <code class="codecolorer text mac-classic"><span class="text">(IntValue 2)</span></code> substrings are parsed using the subparser.</p>

<p>It&#8217;s really quite elegant. Especially the ease of integrating the subparsers surprised me. Here&#8217;s the parser in full.</p>

<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br />207<br />208<br />209<br />210<br />211<br />212<br />213<br />214<br />215<br />216<br />217<br />218<br />219<br />220<br />221<br />222<br />223<br />224<br />225<br />226<br />227<br />228<br />229<br />230<br />231<br />232<br />233<br />234<br />235<br />236<br />237<br />238<br />239<br />240<br />241<br />242<br />243<br />244<br />245<br />246<br />247<br />248<br />249<br />250<br />251<br />252<br />253<br />254<br />255<br />256<br />257<br />258<br />259<br />260<br />261<br />262<br />263<br />264<br />265<br />266<br />267<br />268<br />269<br />270<br />271<br />272<br />273<br />274<br />275<br />276<br />277<br />278<br />279<br />280<br />281<br />282<br />283<br />284<br />285<br />286<br />287<br />288<br />289<br />290<br />291<br />292<br />293<br />294<br />295<br />296<br />297<br />298<br />299<br />300<br />301<br />302<br />303<br />304<br />305<br />306<br />307<br />308<br />309<br />310<br />311<br />312<br />313<br />314<br />315<br />316<br />317<br />318<br />319<br />320<br />321<br />322<br />323<br />324<br />325<br />326<br />327<br />328<br />329<br />330<br />331<br />332<br />333<br />334<br />335<br />336<br />337<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">parser</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.lang.reflect.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.*</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp;* A reflection-based S-expression parser returning an expression of type E.<br />
&nbsp;* Written by Mathias Ricken and Edwin Westbrook.<br />
&nbsp;*/</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LintParser<span style="color: #339933;">&lt;</span>E<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/** Convenience method to parse string s into an expression of class c,<br />
&nbsp; &nbsp; &nbsp; * using the specified subparsers as help, if the parser encounters non-primitive,<br />
&nbsp; &nbsp; &nbsp; * non-string arguments to S-expressions not within the class hierarcy under class c.<br />
&nbsp; &nbsp; &nbsp; * @param c class of the expression<br />
&nbsp; &nbsp; &nbsp; * @param s string to parse<br />
&nbsp; &nbsp; &nbsp; * @param subParsers subparsers for non-primitive, no-string values<br />
&nbsp; &nbsp; &nbsp; * @return expression of class c */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> T parse<span style="color: #009900;">&#40;</span>Class<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> c, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> s, LintParser<span style="color: #339933;">&lt;?&gt;</span>... <span style="color: #006633;">subParsers</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; LintParser<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> p <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LintParser<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>LintParser<span style="color: #339933;">&lt;?&gt;</span> sp<span style="color: #339933;">:</span> subParsers<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p.<span style="color: #006633;">addSubParser</span><span style="color: #009900;">&#40;</span>sp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> p.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/** Exception being thrown if the string cannot be parsed. */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aparseexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ParseException</span></a> <span style="color: #000000; font-weight: bold;">extends</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aruntimeexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">RuntimeException</span></a> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/** The class of the expression (e.g. lint1_arithmetic.UnstagedLint.Exp). */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Class<span style="color: #339933;">&lt;</span>E<span style="color: #339933;">&gt;</span> _expClass<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/** The class enclosing the expression classes (e.g. lint1_arithmetic.UnstagedLint). */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Class<span style="color: #339933;">&lt;?&gt;</span> _enclosingClass<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/** A map from S-expression names to classes (e.g. Int -&gt; lint1_arithmetic.UnstagedLint.Int). */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> HashMap<span style="color: #339933;">&lt;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a>,Class<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> E<span style="color: #339933;">&gt;&gt;</span> _classes <span style="color: #339933;">=</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a>,Class<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> E<span style="color: #339933;">&gt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/** A map from classes for which subparsers have been registered to the subparsers. */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> HashMap<span style="color: #339933;">&lt;</span>Class<span style="color: #339933;">&lt;?&gt;</span>,LintParser<span style="color: #339933;">&lt;?&gt;&gt;</span> _subParsers <span style="color: #339933;">=</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>Class<span style="color: #339933;">&lt;?&gt;</span>,LintParser<span style="color: #339933;">&lt;?&gt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/** Create a new parser for expressions of class expClass.<br />
&nbsp; &nbsp; &nbsp; * @param expClass the class of the expressions to be parsed */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> LintParser<span style="color: #009900;">&#40;</span>Class<span style="color: #339933;">&lt;</span>E<span style="color: #339933;">&gt;</span> expClass<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _expClass <span style="color: #339933;">=</span> expClass<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _enclosingClass <span style="color: #339933;">=</span> _expClass.<span style="color: #006633;">getEnclosingClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// find all concrete, static subclasses of expClass contained in the same enclosing class</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>Class<span style="color: #339933;">&lt;?&gt;</span> c<span style="color: #339933;">:</span> _enclosingClass.<span style="color: #006633;">getDeclaredClasses</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>c.<span style="color: #006633;">getModifiers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amodifier+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Modifier</span></a>.<span style="color: #000000; font-weight: bold;">ABSTRACT</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>c.<span style="color: #006633;">getModifiers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amodifier+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Modifier</span></a>.<span style="color: #000000; font-weight: bold;">STATIC</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Class<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> E<span style="color: #339933;">&gt;</span> contained <span style="color: #339933;">=</span> c.<span style="color: #006633;">asSubclass</span><span style="color: #009900;">&#40;</span>_expClass<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _classes.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>contained.<span style="color: #006633;">getSimpleName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #009900;">&#40;</span>Class<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> E<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#41;</span>contained<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span>contained.<span style="color: #006633;">getSimpleName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aclasscastexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ClassCastException</span></a> cce<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">/* skip */</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/** Add a subparser for expressions of type S. Return this parser (not the subparser!)<br />
&nbsp; &nbsp; &nbsp; * for method chaining.<br />
&nbsp; &nbsp; &nbsp; * @param p subparser for expressions of type S<br />
&nbsp; &nbsp; &nbsp; * @return this parser (for expressions of type E) */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #339933;">&lt;</span>S<span style="color: #339933;">&gt;</span> LintParser<span style="color: #339933;">&lt;</span>E<span style="color: #339933;">&gt;</span> addSubParser<span style="color: #009900;">&#40;</span>LintParser<span style="color: #339933;">&lt;</span>S<span style="color: #339933;">&gt;</span> p<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _subParsers.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>p._expClass, p<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> &nbsp; &nbsp;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/** Parse the string.<br />
&nbsp; &nbsp; &nbsp; * @param s the string to be parsed<br />
&nbsp; &nbsp; &nbsp; * @return the expression of type E */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> E parse<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> s<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;parse '&quot;</span><span style="color: #339933;">+</span>s<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; RestoreStringTokenizer st <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RestoreStringTokenizer<span style="color: #009900;">&#40;</span>s.<span style="color: #006633;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> parse<span style="color: #009900;">&#40;</span>st<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/** Parse the tokens in the tokenizer.<br />
&nbsp; &nbsp; &nbsp; * @param s the tokenizer with the tokens<br />
&nbsp; &nbsp; &nbsp; * @return the expression of type E */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> E parse<span style="color: #009900;">&#40;</span>RestoreStringTokenizer s<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// position to restore everything</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> sPos <span style="color: #339933;">=</span> s.<span style="color: #006633;">getPosition</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// read (</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; parseWhitespace<span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> word <span style="color: #339933;">=</span> s.<span style="color: #006633;">nextToken</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;word: '&quot;</span><span style="color: #339933;">+</span>word<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>word.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;(&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s.<span style="color: #006633;">restorePosition</span><span style="color: #009900;">&#40;</span>sPos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aparseexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ParseException</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// read S-expression name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; parseWhitespace<span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; word <span style="color: #339933;">=</span> s.<span style="color: #006633;">nextToken</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;word: '&quot;</span><span style="color: #339933;">+</span>word<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>_classes.<span style="color: #006633;">containsKey</span><span style="color: #009900;">&#40;</span>word<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// don't know what that is, restore</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s.<span style="color: #006633;">restorePosition</span><span style="color: #009900;">&#40;</span>sPos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aparseexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ParseException</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// known subclass of E</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Class<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> E<span style="color: #339933;">&gt;</span> c <span style="color: #339933;">=</span> _classes.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>word<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Class: &quot;</span><span style="color: #339933;">+</span>c.<span style="color: #006633;">getSimpleName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; parseWhitespace<span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// position to restore after trying out a constructor</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> sTryCtorPos <span style="color: #339933;">=</span> s.<span style="color: #006633;">getPosition</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; Constructor<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> E<span style="color: #339933;">&gt;</span> ctor<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>Constructor<span style="color: #339933;">&lt;?&gt;</span> ctor2<span style="color: #339933;">:</span> c.<span style="color: #006633;">getDeclaredConstructors</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>trying ctor &quot;</span><span style="color: #339933;">+</span>ctor2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// this is necessary since c.getDeclaredConstructors() returns Constructor&lt;?&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// but we want Constructor&lt;? extends E&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span> ctor <span style="color: #339933;">=</span> c.<span style="color: #006633;">getConstructor</span><span style="color: #009900;">&#40;</span>ctor2.<span style="color: #006633;">getParameterTypes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Anosuchmethodexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">NoSuchMethodException</span></a> nsme<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> AssertionError<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Should never happen.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// try to parse the arguments for this constructor</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a><span style="color: #009900;">&#91;</span>ctor.<span style="color: #006633;">getParameterTypes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">length</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> argIndex <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>Class<span style="color: #339933;">&lt;?&gt;</span> paramC<span style="color: #339933;">:</span> ctor.<span style="color: #006633;">getParameterTypes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// primitive types and their boxed types</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>paramC<span style="color: #339933;">==</span><span style="color: #000066; font-weight: bold;">int</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>paramC<span style="color: #339933;">==</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Integer</span></a>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; args<span style="color: #009900;">&#91;</span>argIndex<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> parseLeaf<span style="color: #009900;">&#40;</span>s,<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Integer</span></a>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>paramC<span style="color: #339933;">==</span><span style="color: #000066; font-weight: bold;">boolean</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>paramC<span style="color: #339933;">==</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aboolean+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Boolean</span></a>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; args<span style="color: #009900;">&#91;</span>argIndex<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> parseLeaf<span style="color: #009900;">&#40;</span>s,<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aboolean+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Boolean</span></a>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>paramC<span style="color: #339933;">==</span><span style="color: #000066; font-weight: bold;">long</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>paramC<span style="color: #339933;">==</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Along+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Long</span></a>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; args<span style="color: #009900;">&#91;</span>argIndex<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> parseLeaf<span style="color: #009900;">&#40;</span>s,<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Along+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Long</span></a>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>paramC<span style="color: #339933;">==</span><span style="color: #000066; font-weight: bold;">double</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>paramC<span style="color: #339933;">==</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adouble+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Double</span></a>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; args<span style="color: #009900;">&#91;</span>argIndex<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> parseLeaf<span style="color: #009900;">&#40;</span>s,<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adouble+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Double</span></a>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>paramC<span style="color: #339933;">==</span><span style="color: #000066; font-weight: bold;">float</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>paramC<span style="color: #339933;">==</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afloat+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Float</span></a>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; args<span style="color: #009900;">&#91;</span>argIndex<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> parseLeaf<span style="color: #009900;">&#40;</span>s,<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afloat+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Float</span></a>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>paramC<span style="color: #339933;">==</span><span style="color: #000066; font-weight: bold;">byte</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>paramC<span style="color: #339933;">==</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abyte+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Byte</span></a>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; args<span style="color: #009900;">&#91;</span>argIndex<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> parseLeaf<span style="color: #009900;">&#40;</span>s,<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abyte+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Byte</span></a>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>paramC<span style="color: #339933;">==</span><span style="color: #000066; font-weight: bold;">short</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>paramC<span style="color: #339933;">==</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ashort+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Short</span></a>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; args<span style="color: #009900;">&#91;</span>argIndex<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> parseLeaf<span style="color: #009900;">&#40;</span>s,<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ashort+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Short</span></a>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// char or Character</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>paramC<span style="color: #339933;">==</span><span style="color: #000066; font-weight: bold;">char</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>paramC<span style="color: #339933;">==</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Acharacter+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Character</span></a>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// parse as string</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a> temp <span style="color: #339933;">=</span> parseLeaf<span style="color: #009900;">&#40;</span>s,<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// must be exactly one character</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>temp.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aparseexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ParseException</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; args<span style="color: #009900;">&#91;</span>argIndex<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Acharacter+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Character</span></a><span style="color: #009900;">&#40;</span>temp.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// strings</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>paramC<span style="color: #339933;">==</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; args<span style="color: #009900;">&#91;</span>argIndex<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> parseLeaf<span style="color: #009900;">&#40;</span>s,<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// recursively parse expressions of type E</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>_expClass.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>paramC<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; args<span style="color: #009900;">&#91;</span>argIndex<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> parse<span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// try to use a subparser</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>_subParsers.<span style="color: #006633;">containsKey</span><span style="color: #009900;">&#40;</span>paramC<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// try one of the subparsers</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; args<span style="color: #009900;">&#91;</span>argIndex<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> _subParsers.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>paramC<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// don't know what that is</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// restore happens below</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aparseexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ParseException</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">++</span>argIndex<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aparseexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ParseException</span></a> pe<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// this constructor didn't work out, we need to restore and try another constructor</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s.<span style="color: #006633;">restorePosition</span><span style="color: #009900;">&#40;</span>sTryCtorPos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// continue with next constructor</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">continue</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// we read all values required for this constructor</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// make sure that the next token is )</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parseWhitespace<span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; word <span style="color: #339933;">=</span> s.<span style="color: #006633;">nextToken</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;word: '&quot;</span><span style="color: #339933;">+</span>word<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>word.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// it wasn't ), we need to restore and try another constructor</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s.<span style="color: #006633;">restorePosition</span><span style="color: #009900;">&#40;</span>sTryCtorPos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// continue with next constructor</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">continue</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parseWhitespace<span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// successfully used this constructor</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;new &quot;</span><span style="color: #339933;">+</span>ctor.<span style="color: #006633;">getDeclaringClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getSimpleName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; java.<span style="color: #006633;">util</span>.<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aarrays+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Arrays</span></a>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; E e <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>E<span style="color: #009900;">&#41;</span>ctor.<span style="color: #006633;">newInstance</span><span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> e<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// something went wrong using this constructor, we need to restore and try another</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s.<span style="color: #006633;">restorePosition</span><span style="color: #009900;">&#40;</span>sTryCtorPos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// continue with next constructor</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">continue</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; s.<span style="color: #006633;">restorePosition</span><span style="color: #009900;">&#40;</span>sPos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aparseexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ParseException</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/** Parse a leaf of class c, which must have a unary constructor taking a String, from<br />
&nbsp; &nbsp; &nbsp; * the tokenizer s.<br />
&nbsp; &nbsp; &nbsp; * @param s tokenizer from which to parse<br />
&nbsp; &nbsp; &nbsp; * @param c the class, which has a unary constructor taking a String, for that we want to create a value<br />
&nbsp; &nbsp; &nbsp; * @return parsed value of class c */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a> parseLeaf<span style="color: #009900;">&#40;</span>RestoreStringTokenizer s, Class<span style="color: #339933;">&lt;?&gt;</span> c<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// position so we can undo this attempt to parse</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> sPos <span style="color: #339933;">=</span> s.<span style="color: #006633;">getPosition</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> word <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// get the unary constructor taking String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aconstructor+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Constructor</span></a> ctor <span style="color: #339933;">=</span> c.<span style="color: #006633;">getDeclaredConstructor</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// skip whitespace, get the string, skip whitespace</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parseWhitespace<span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; word <span style="color: #339933;">=</span> s.<span style="color: #006633;">nextToken</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;word: '&quot;</span><span style="color: #339933;">+</span>word<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a> o <span style="color: #339933;">=</span> ctor.<span style="color: #006633;">newInstance</span><span style="color: #009900;">&#40;</span>word<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parseWhitespace<span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> o<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Anosuchmethodexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">NoSuchMethodException</span></a> nsme<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// something went wrong, restore and abort</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s.<span style="color: #006633;">restorePosition</span><span style="color: #009900;">&#40;</span>sPos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aparseexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ParseException</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainstantiationexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InstantiationException</span></a> ie<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// something went wrong, restore and abort</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s.<span style="color: #006633;">restorePosition</span><span style="color: #009900;">&#40;</span>sPos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aparseexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ParseException</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aillegalaccessexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">IllegalAccessException</span></a> iae<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// something went wrong, restore and abort</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s.<span style="color: #006633;">restorePosition</span><span style="color: #009900;">&#40;</span>sPos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aparseexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ParseException</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainvocationtargetexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InvocationTargetException</span></a> ite<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// something went wrong, restore and abort</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s.<span style="color: #006633;">restorePosition</span><span style="color: #009900;">&#40;</span>sPos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aparseexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ParseException</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/** Parse whitespace. Stop before the next non-whitespace token, or when there are no<br />
&nbsp; &nbsp; &nbsp; * more tokens.<br />
&nbsp; &nbsp; &nbsp; * @param s tokenizer from which to parse whitespace */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> parseWhitespace<span style="color: #009900;">&#40;</span>RestoreStringTokenizer s<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> word<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> sPrevPos<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>s.<span style="color: #006633;">hasMoreTokens</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sPrevPos <span style="color: #339933;">=</span> s.<span style="color: #006633;">getPosition</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; word <span style="color: #339933;">=</span> s.<span style="color: #006633;">nextToken</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>word.<span style="color: #006633;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s.<span style="color: #006633;">restorePosition</span><span style="color: #009900;">&#40;</span>sPrevPos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/** Debug method to print, comment System.out.println call out to disable debug printing */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> println<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a> o<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// System.out.println(o.toString());</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/** This tokenizer stores all read tokens in a stack so they can easily be<br />
&nbsp; &nbsp; &nbsp; * restored. This isn't as memory as it could be, but it's good enough for<br />
&nbsp; &nbsp; &nbsp; * small examples. */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> RestoreStringTokenizer <span style="color: #000000; font-weight: bold;">extends</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astringtokenizer+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">StringTokenizer</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/** Stack of read tokens. */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Stack<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> _read <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Stack<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/** Stack of restored tokens. */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Stack<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> _restored <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Stack<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/** Create a new string tokenizer that can restore positions. */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> RestoreStringTokenizer<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> s<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>s,<span style="color: #0000ff;">&quot; ()&quot;</span>,<span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/** Return the current position. */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getPosition<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> _read.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/** Rewind to a previous position. This only goes backward, not forward. */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> restorePosition<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> pos<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>_read.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;</span>pos<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _restored.<span style="color: #006633;">push</span><span style="color: #009900;">&#40;</span>_read.<span style="color: #006633;">pop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// overridden methods from StringTokenizer</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> countTokens<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> _restored.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">countTokens</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> hasMoreTokens<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>_restored.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">hasMoreTokens</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> hasMoreElements<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> hasMoreTokens<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> nextToken<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> token <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>_restored.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> _restored.<span style="color: #006633;">pop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">nextToken</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _read.<span style="color: #006633;">push</span><span style="color: #009900;">&#40;</span>token<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> token<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a> nextElement<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> nextToken<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> nextToken<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> delim<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>_restored.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span> _restored.<span style="color: #006633;">pop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">nextToken</span><span style="color: #009900;">&#40;</span>delim<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; lint2_cond.<span style="color: #006633;">UnstagedLint</span>.<span style="color: #006633;">Exp</span> e <span style="color: #339933;">=</span> parse<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#40;</span>lint2_cond.<span style="color: #006633;">UnstagedLint</span>.<span style="color: #006633;">Exp</span>.<span style="color: #000000; font-weight: bold;">class</span>,<span style="color: #0000ff;">&quot;(Ifz (Int 1) (Int 10) (Mul(Int 3)(Add(Int 5)(Int 10))))&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> lint2_cond.<span style="color: #006633;">UnstagedLint</span>.<span style="color: #006633;">Program</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">peval</span><span style="color: #009900;">&#40;</span>lint2_cond.<span style="color: #006633;">UnstagedLint</span>.<span style="color: #006633;">env0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; lint.<span style="color: #006633;">DataTypes</span>.<span style="color: #006633;">Value</span> v <span style="color: #339933;">=</span> parse<span style="color: #009900;">&#40;</span>lint.<span style="color: #006633;">DataTypes</span>.<span style="color: #006633;">Value</span>.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #0000ff;">&quot;(IntValue 1)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>v<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; lint.<span style="color: #006633;">DataTypes</span>.<span style="color: #006633;">Exp</span> e2 <span style="color: #339933;">=</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> LintParser<span style="color: #339933;">&lt;</span>lint.<span style="color: #006633;">DataTypes</span>.<span style="color: #006633;">Exp</span><span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>lint.<span style="color: #006633;">DataTypes</span>.<span style="color: #006633;">Exp</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .<span style="color: #006633;">addSubParser</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> LintParser<span style="color: #339933;">&lt;</span>lint.<span style="color: #006633;">DataTypes</span>.<span style="color: #006633;">Value</span><span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>lint.<span style="color: #006633;">DataTypes</span>.<span style="color: #006633;">Value</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;(Add (Val (IntValue 1)) (Val (IntValue 2)))&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> lint.<span style="color: #006633;">DataTypes</span>.<span style="color: #006633;">Program</span><span style="color: #009900;">&#40;</span>e2<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">peval</span><span style="color: #009900;">&#40;</span>lint.<span style="color: #006633;">DataTypes</span>.<span style="color: #006633;">env0</span>, lint.<span style="color: #006633;">DataTypes</span>.<span style="color: #006633;">fenv0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; lint.<span style="color: #006633;">DataTypes</span>.<span style="color: #006633;">Exp</span> e3 <span style="color: #339933;">=</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LintParser.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span>lint.<span style="color: #006633;">DataTypes</span>.<span style="color: #006633;">Exp</span>.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #0000ff;">&quot;(Add (Val (IntValue 1)) (Val (IntValue 2)))&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">new</span> LintParser<span style="color: #339933;">&lt;</span>lint.<span style="color: #006633;">DataTypes</span>.<span style="color: #006633;">Value</span><span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>lint.<span style="color: #006633;">DataTypes</span>.<span style="color: #006633;">Value</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> lint.<span style="color: #006633;">DataTypes</span>.<span style="color: #006633;">Program</span><span style="color: #009900;">&#40;</span>e3<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">peval</span><span style="color: #009900;">&#40;</span>lint.<span style="color: #006633;">DataTypes</span>.<span style="color: #006633;">env0</span>, lint.<span style="color: #006633;">DataTypes</span>.<span style="color: #006633;">fenv0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>

<p>Here is the definition of a simple language for arithmetic expressions that uses the parser:</p>

<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">lint1_arithmetic</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> UnstagedLint <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/*<br />
&nbsp; &nbsp; &nbsp;type exp = Int of int<br />
&nbsp; &nbsp; &nbsp;| Var of string<br />
&nbsp; &nbsp; &nbsp;| Add of exp * exp<br />
&nbsp; &nbsp; &nbsp;| Sub of exp * exp<br />
&nbsp; &nbsp; &nbsp;| Mul of exp * exp<br />
&nbsp; &nbsp; &nbsp;| Div of exp * exp<br />
&nbsp; &nbsp; &nbsp;type def = Definition of string * int<br />
&nbsp; &nbsp; &nbsp;type prog = Program of def list * exp<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">interface</span> Exp <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> eval<span style="color: #009900;">&#40;</span>Env e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> Int <span style="color: #000000; font-weight: bold;">implements</span> Exp <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> _value<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> Int<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _value <span style="color: #339933;">=</span> value<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> eval<span style="color: #009900;">&#40;</span>Env e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> _value<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> Var <span style="color: #000000; font-weight: bold;">implements</span> Exp <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> _s<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> Var<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> s<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _s <span style="color: #339933;">=</span> s<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> eval<span style="color: #009900;">&#40;</span>Env e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> e.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>_s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> BinOp <span style="color: #000000; font-weight: bold;">implements</span> Exp <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> Exp _left, _right<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> BinOp<span style="color: #009900;">&#40;</span>Exp left, Exp right<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _left <span style="color: #339933;">=</span> left<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _right <span style="color: #339933;">=</span> right<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> Add <span style="color: #000000; font-weight: bold;">extends</span> BinOp <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> Add<span style="color: #009900;">&#40;</span>Exp left, Exp right<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>left, right<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> eval<span style="color: #009900;">&#40;</span>Env e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> _left.<span style="color: #006633;">eval</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> _right.<span style="color: #006633;">eval</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> Sub <span style="color: #000000; font-weight: bold;">extends</span> BinOp <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> Sub<span style="color: #009900;">&#40;</span>Exp left, Exp right<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>left, right<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> eval<span style="color: #009900;">&#40;</span>Env e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> _left.<span style="color: #006633;">eval</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> _right.<span style="color: #006633;">eval</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> Mul <span style="color: #000000; font-weight: bold;">extends</span> BinOp <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> Mul<span style="color: #009900;">&#40;</span>Exp left, Exp right<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>left, right<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> eval<span style="color: #009900;">&#40;</span>Env e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> _left.<span style="color: #006633;">eval</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> _right.<span style="color: #006633;">eval</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> Div <span style="color: #000000; font-weight: bold;">extends</span> BinOp <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> Div<span style="color: #009900;">&#40;</span>Exp left, Exp right<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>left, right<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> eval<span style="color: #009900;">&#40;</span>Env e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> _left.<span style="color: #006633;">eval</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> _right.<span style="color: #006633;">eval</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/*<br />
&nbsp; &nbsp; &nbsp;exception EnvironmentException<br />
&nbsp; &nbsp; &nbsp;let env0 = fun x -&gt; raise EnvironmentException<br />
&nbsp; &nbsp; &nbsp;let fenv0 = env0<br />
&nbsp; &nbsp; &nbsp;let ext env x v = fun y -&gt; if x=y then v else env y <br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> EnvironmentException <span style="color: #000000; font-weight: bold;">extends</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aruntimeexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">RuntimeException</span></a> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// environment; implemented as a function object from String to Exp</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">interface</span> Env <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> get<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> y<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> Env env0 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Env<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> get<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> s<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> EnvironmentException<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> Env ext<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Env env, <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> x, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> v<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Env<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> get<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> y<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>x.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>y<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span> v<span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">return</span> env.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>y<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> Definition <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> _name<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> _v<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> Definition<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> name, <span style="color: #000066; font-weight: bold;">int</span> v<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _name <span style="color: #339933;">=</span> name<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _v <span style="color: #339933;">=</span> v<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> name<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> _name<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> value<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> _v<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> Program <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> Definition<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> _defs<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> Exp _body<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> Program<span style="color: #009900;">&#40;</span>Exp body, Definition... <span style="color: #006633;">defs</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _defs <span style="color: #339933;">=</span> defs<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _body <span style="color: #339933;">=</span> body<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> peval<span style="color: #009900;">&#40;</span>Env env<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> peval<span style="color: #009900;">&#40;</span>env,<span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> peval<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Env env, <span style="color: #000066; font-weight: bold;">int</span> defIndex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// match p with</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>_defs.<span style="color: #006633;">length</span><span style="color: #339933;">&lt;=</span>defIndex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// &nbsp; &nbsp; Program ([],e) -&gt; eval e env</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> _body.<span style="color: #006633;">eval</span><span style="color: #009900;">&#40;</span>env<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// &nbsp; &nbsp;|Program (Definition (n,v)::tl,e) -&gt; peval (Program(tl,e)) (ext env n v)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">final</span> Definition d <span style="color: #339933;">=</span> _defs<span style="color: #009900;">&#91;</span>defIndex<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> peval<span style="color: #009900;">&#40;</span>ext<span style="color: #009900;">&#40;</span>env, d.<span style="color: #006633;">name</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, d.<span style="color: #006633;">value</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>,defIndex<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/*<br />
&nbsp; &nbsp; &nbsp;let rec eval e env fenv =<br />
&nbsp; &nbsp; &nbsp;match e with<br />
&nbsp; &nbsp; &nbsp;Int i -&gt; i<br />
&nbsp; &nbsp; &nbsp;| Var s -&gt; env s<br />
&nbsp; &nbsp; &nbsp;| Add (e1,e2) -&gt; (eval e1 env fenv)+(eval e2 env fenv)<br />
&nbsp; &nbsp; &nbsp;| Sub (e1,e2) -&gt; (eval e1 env fenv)-(eval e2 env fenv)<br />
&nbsp; &nbsp; &nbsp;| Mul (e1,e2) -&gt; (eval e1 env fenv)*(eval e2 env fenv)<br />
&nbsp; &nbsp; &nbsp;| Div (e1,e2) -&gt; (eval e1 env fenv)/(eval e2 env fenv)<br />
&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp;let rec peval p env =<br />
&nbsp; &nbsp; &nbsp;match p with<br />
&nbsp; &nbsp; &nbsp;Program ([],e) -&gt; eval e env<br />
&nbsp; &nbsp; &nbsp;|Program (Definition (s1,i1)::tl,e) -&gt; peval (Program(tl,e)) (ext env s1 i1)<br />
&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> Program term10times20plus30 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Program<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Add<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Mul<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Var<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;x&quot;</span><span style="color: #009900;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> Var<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;y&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> Int<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">new</span> Definition<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;x&quot;</span>, <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">new</span> Definition<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;y&quot;</span>, <span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> Program parsedTerm10times20plus30 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Program<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#40;</span>parser.<span style="color: #006633;">LintParser</span>.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span>Exp.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #0000ff;">&quot;(Add (Mul (Var x) (Var y)) (Int 30))&quot;</span><span style="color: #009900;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">new</span> Definition<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;x&quot;</span>, <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">new</span> Definition<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;y&quot;</span>, <span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> Program termWhatX <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Program<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Var<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;x&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> Program parsedTermWhatX <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Program<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#40;</span>parser.<span style="color: #006633;">LintParser</span>.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span>Exp.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #0000ff;">&quot;(Var x)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> term10times20plus30.<span style="color: #006633;">peval</span><span style="color: #009900;">&#40;</span>env0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;term10times20plus30 = &quot;</span><span style="color: #339933;">+</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; i <span style="color: #339933;">=</span> parsedTerm10times20plus30.<span style="color: #006633;">peval</span><span style="color: #009900;">&#40;</span>env0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;parsedTerm10times20plus30 = &quot;</span><span style="color: #339933;">+</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i <span style="color: #339933;">=</span> termWhatX.<span style="color: #006633;">peval</span><span style="color: #009900;">&#40;</span>env0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;termWhatX = &quot;</span><span style="color: #339933;">+</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> AssertionError<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;This should throw an EnvironmentException&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>EnvironmentException ee<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;termWhatX threw &quot;</span><span style="color: #339933;">+</span>ee<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/* expected */</span> <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i <span style="color: #339933;">=</span> parsedTermWhatX.<span style="color: #006633;">peval</span><span style="color: #009900;">&#40;</span>env0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;parsedTermWhatX = &quot;</span><span style="color: #339933;">+</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> AssertionError<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;This should throw an EnvironmentException&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>EnvironmentException ee<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;parsedTermWhatX threw &quot;</span><span style="color: #339933;">+</span>ee<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/* expected */</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/09/01/reflection-based-s-expression-parser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>String Pool Interning Saves the Weakly Separable Day</title>
		<link>http://www.concurrentaffair.org/2010/08/31/string-pool-interning-saves-the-weakly-separable-day/</link>
		<comments>http://www.concurrentaffair.org/2010/08/31/string-pool-interning-saves-the-weakly-separable-day/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 06:03:52 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[Mint]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2179</guid>
		<description><![CDATA[I just took a swim in the string pool. Who would have thought that interning strings would be so useful for weak separability in Mint? I knew before that we had some problems calling String.equals in a separable method, like &#8230; <a href="http://www.concurrentaffair.org/2010/08/31/string-pool-interning-saves-the-weakly-separable-day/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I just took a swim in the string pool. Who would have thought that interning strings would be so useful for weak separability in <a href="http://www.cs.rice.edu/~mgricken/research/mint/">Mint</a>?</p>

<p>I knew before that we had some problems calling <code class="codecolorer java mac-classic"><span class="java"><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a>.<span style="color: #006633;">equals</span></span></code> in a separable method, like the <code class="codecolorer java mac-classic"><span class="java">Env.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> y<span style="color: #009900;">&#41;</span></span></code> method that does an environment look-up, because <code class="codecolorer java mac-classic"><span class="java"><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a>.<span style="color: #006633;">equals</span></span></code> wasn&#8217;t declared separable itself. That&#8217;s why I used the <code class="codecolorer java mac-classic"><span class="java"><span style="color: #339933;">==</span></span></code> operator in the initial Lint interpreter I wrote for the <a href="http://www.concurrentaffair.org/2010/01/31/paper-mint-java-multi-stage-programming-using-weak-separability/">PLDI 2010 paper</a>:</p>

<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> separable Env ext<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Env env,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> x,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">final</span> Code<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span> v<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Env<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> separable Code<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span> get<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> y<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// error: if (x.equals(y))</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>x<span style="color: #339933;">==</span>y<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> v<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> env.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>y<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>

<p>This wasn&#8217;t a problem because we didn&#8217;t have a parser and were creating our ASTs using hand-written Java code. The variable names are string constants, which are always interned:</p>

<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> Program term10times20plus30 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Program<br />
&nbsp; &nbsp; <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Add<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Mul<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Var<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;x&quot;</span><span style="color: #009900;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> Var<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;y&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> Int<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">new</span> Definition<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;x&quot;</span>, <span style="color: #339933;">&lt;|</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">|&gt;</span><span style="color: #009900;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">new</span> Definition<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;y&quot;</span>, <span style="color: #339933;">&lt;|</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">|&gt;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>

<p>Tonight, I wrote a reflection-based S-expression parser, and now the variable names are substrings of a longer string:</p>

<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> Program parsedTerm10times20plus30 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Program<br />
&nbsp; &nbsp; <span style="color: #009900;">&#40;</span>parser.<span style="color: #006633;">LintParser</span>.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span>Exp.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #0000ff;">&quot;(Add (Mul (Var x) (Var y)) (Int 30))&quot;</span><span style="color: #009900;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">new</span> Definition<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;x&quot;</span>, <span style="color: #339933;">&lt;|</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">|&gt;</span><span style="color: #009900;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">new</span> Definition<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;y&quot;</span>, <span style="color: #339933;">&lt;|</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">|&gt;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>

<p>Substrings aren&#8217;t interned automatically, and the comparison using <code class="codecolorer java mac-classic"><span class="java"><span style="color: #339933;">==</span></span></code> fails. Fortunately, I can simply intern the strings when I create the <code class="codecolorer java mac-classic"><span class="java">Var</span></code> AST nodes and the <code class="codecolorer java mac-classic"><span class="java">Definition</span></code> variable bindings:</p>

<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> Var <span style="color: #000000; font-weight: bold;">implements</span> Exp <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> _s<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> Var<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> s<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _s <span style="color: #339933;">=</span> s.<span style="color: #006633;">intern</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// must intern here, so we can use == in the ext method below</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> separable Code<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span> eval<span style="color: #009900;">&#40;</span>Env e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> e.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>_s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> Definition <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> _name<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Code<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span> _v<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> Definition<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> name, Code<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span> v<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _name <span style="color: #339933;">=</span> name.<span style="color: #006633;">intern</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// must intern here, so we can use == in the ext method above</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _v <span style="color: #339933;">=</span> v<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> separable <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> name<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> _name<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> separable Code<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span> value<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> _v<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>

<p>This was a whole lot simpler and cleaner than making some kind of exception for <code class="codecolorer java mac-classic"><span class="java"><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a>.<span style="color: #006633;">equals</span></span></code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/08/31/string-pool-interning-saves-the-weakly-separable-day/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Mint Release: r15716</title>
		<link>http://www.concurrentaffair.org/2010/08/30/new-mint-release-r15716/</link>
		<comments>http://www.concurrentaffair.org/2010/08/30/new-mint-release-r15716/#comments</comments>
		<pubDate>Mon, 30 Aug 2010 18:17:24 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[Mint]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2175</guid>
		<description><![CDATA[As mentioned before, Eddy and I discovered a problem with type variables in code generated by the Mint compiler. We have now fixed this problem in the new release of Mint and DrJava with Mint: August 30, 2010 (r15716). The &#8230; <a href="http://www.concurrentaffair.org/2010/08/30/new-mint-release-r15716/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As mentioned before, Eddy and I discovered a problem with type variables in code generated by the Mint compiler. We have now fixed this problem in the new release of <a href="http://www.javamint.org/">Mint</a> and <a href="http://www.cs.rice.edu/%7Emgricken/research/mint/index.shtml">DrJava with Mint</a>: August 30, 2010 (r15716). The latest release is, as always, available    from the <a href="http://plresearch.org/do/view/ProgrammingLanguages/JavaMint">Mint  implementation</a> page:</p>

<ul><li><a href="http://plresearch.org/twiki/pub/ProgrammingLanguages/JavaMint/JavaMint-r15716.tar.gz">JavaMint-r15716.tar.gz</a></li><li><a href="http://plresearch.org/twiki/pub/ProgrammingLanguages/JavaMint/JavaMint-r15716-binaries.zip">JavaMint-r15716-binaries.zip</a></li><li><a href="http://www.cs.rice.edu/%7Emgricken/research/mint/download/drjava-r5380-mint-r15716.jar" class="broken_link">drjava-r5380-mint-r15716.jar</a></li></ul>

<p>The problem occurred when the programmer used a type variable inside a bracket. An example of this would be a generic method like this:</p>

<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> separable <span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span> Code<span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span> fun<span style="color: #009900;">&#40;</span>Code<span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span> c1, Code<span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span> c2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #339933;">&lt;|</span> <span style="color: #009900;">&#40;</span> `<span style="color: #009900;">&#40;</span>lfTest.<span style="color: #006633;">eval</span><span style="color: #009900;">&#40;</span>e,f<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">booleanCodeValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; `c2 <span style="color: #339933;">:</span> `c1 <span style="color: #009900;">&#41;</span> &nbsp;<span style="color: #339933;">|&gt;;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>

<p>This caused Mint to generate 2nd stage code that contained the type variable <code class="codecolorer java mac-classic"><span class="java">X</span></code> unbound. Unfortunately, the types are erased, and there is no way to find out what type <code class="codecolorer java mac-classic"><span class="java">X</span></code> actually refers to at runtime, e.g. by writing something like <code class="codecolorer java mac-classic"><span class="java">X.<span style="color: #000000; font-weight: bold;">class</span></span></code> (this generates the Java compiler error &#8220;cannot select from a type variable&#8221;).</p>

<p>To get around this problem, we now require a final instance of type <code class="codecolorer java mac-classic"><span class="java">Class<span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span></span></code> to be in scope for every type variable <code class="codecolorer java mac-classic"><span class="java">X</span></code>. For example, in the generic method above, there is a type variable <code class="codecolorer java mac-classic"><span class="java">X</span></code> that is being used in the bracket. Therefore, we now have to have a final instance of <code class="codecolorer java mac-classic"><span class="java">Class<span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span></span></code> somewhere in scope, for example as a method parameter.</p>

<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> separable <span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span> Code<span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span> fun<span style="color: #009900;">&#40;</span>Code<span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span> c1, Code<span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span> c2,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">final</span> Class<span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span> xc<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #339933;">&lt;|</span> <span style="color: #009900;">&#40;</span> `<span style="color: #009900;">&#40;</span>lfTest.<span style="color: #006633;">eval</span><span style="color: #009900;">&#40;</span>e,f<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">booleanCodeValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; `c2 <span style="color: #339933;">:</span> `c1 <span style="color: #009900;">&#41;</span> &nbsp;<span style="color: #339933;">|&gt;;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>

<p>That&#8217;s all that is necessary. The variable <code class="codecolorer java mac-classic"><span class="java">xc</span></code> is not actually used in the code, it just needs to be in scope.</p>

<p>(Re-posted from <a href="http://www.javamint.org/2010/08/new-mint-release-r15716.html">The Java Mint Blog</a>.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/08/30/new-mint-release-r15716/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Passing a Class&lt;T&gt; for Every Type Variable T</title>
		<link>http://www.concurrentaffair.org/2010/08/30/passing-a-classt-for-every-type-variable-t/</link>
		<comments>http://www.concurrentaffair.org/2010/08/30/passing-a-classt-for-every-type-variable-t/#comments</comments>
		<pubDate>Mon, 30 Aug 2010 18:12:54 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[Mint]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2170</guid>
		<description><![CDATA[When working on our GPCE Mint tutorial, Eddy and I realized that there is a problem when programmers use type variables inside brackets. A method like 1234public separable &#60;X&#62; Code&#60;X&#62; fun&#40;Code&#60;X&#62; c1, Code&#60;X&#62; c2&#41; &#123; return &#60;&#124; &#40; `&#40;lfTest.eval&#40;e,f&#41;.booleanCodeValue&#40;&#41;&#41; ? &#8230; <a href="http://www.concurrentaffair.org/2010/08/30/passing-a-classt-for-every-type-variable-t/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When working on our <a href="http://www.concurrentaffair.org/2010/08/16/gpce10-tutorial-lecture-agile-and-efficient-domain-specific-languages-using-multi-stage-programming-in-java-mint/">GPCE Mint tutorial</a>, Eddy and I realized that there is a problem when programmers use type variables inside brackets. A method like</p>

<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> separable <span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span> Code<span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span> fun<span style="color: #009900;">&#40;</span>Code<span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span> c1, Code<span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span> c2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #339933;">&lt;|</span> <span style="color: #009900;">&#40;</span> `<span style="color: #009900;">&#40;</span>lfTest.<span style="color: #006633;">eval</span><span style="color: #009900;">&#40;</span>e,f<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">booleanCodeValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; `c2 <span style="color: #339933;">:</span> `c1 <span style="color: #009900;">&#41;</span> &nbsp;<span style="color: #339933;">|&gt;;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>

<p>causes Mint to generate code containing the free type variable <code class="codecolorer java mac-classic"><span class="java">X</span></code>. There is no way to get any type information from a type variable at runtime, e.g. by doing <code class="codecolorer java mac-classic"><span class="java">X.<span style="color: #000000; font-weight: bold;">class</span></span></code>, so instead we decided to require the user to have a final instance of <code class="codecolorer java mac-classic"><span class="java">Class<span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span></span></code> in scope somewhere.</p>

<p>This was a pragmatic solution that seems to work pretty well. The method above can be rewritten as</p>

<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> separable <span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span> Code<span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span> fun<span style="color: #009900;">&#40;</span>Code<span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span> c1, Code<span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span> c2,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">final</span> Class<span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span> xc<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #339933;">&lt;|</span> <span style="color: #009900;">&#40;</span> `<span style="color: #009900;">&#40;</span>lfTest.<span style="color: #006633;">eval</span><span style="color: #009900;">&#40;</span>e,f<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">booleanCodeValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; `c2 <span style="color: #339933;">:</span> `c1 <span style="color: #009900;">&#41;</span> &nbsp;<span style="color: #339933;">|&gt;;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>

<p>To implement this, we had to find all variables of type <code class="codecolorer java mac-classic"><span class="java">Class<span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span></span></code> that were in scope at the time a bracket was generated. This was surprisingly confusing to do with the javac environment and scope classes. In the end, I decided to adapt the <code class="codecolorer java mac-classic"><span class="java"><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aresolver+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Resolver</span></a>.<span style="color: #006633;">findVar</span></span></code> and <code class="codecolorer java mac-classic"><span class="java"><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aresolver+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Resolver</span></a>.<span style="color: #006633;">findField</span></span></code> methods.</p>

<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/** This method returns a list of all VarSymbols of type Class&lt;X&gt; in scope where X is a type variable. */</span><br />
&nbsp; &nbsp; List<span style="color: #339933;">&lt;</span>VarSymbol<span style="color: #339933;">&gt;</span> getClassVarsInScope<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// System.out.println(&quot;env = &quot;+env);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; List<span style="color: #339933;">&lt;</span>VarSymbol<span style="color: #339933;">&gt;</span> ret <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Alist+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">List</span></a>.<span style="color: #006633;">nil</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Scope current <span style="color: #339933;">=</span> env.<span style="color: #006633;">info</span>.<span style="color: #006633;">scope</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// System.out.println(&quot;Scope: &quot;+current);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>current <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// also go into the outer (enclosing) scopes</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// for(Symbol s: current.elems) {</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>Scope.<span style="color: #006633;">Entry</span> e <span style="color: #339933;">=</span> current.<span style="color: #006633;">elems</span><span style="color: #339933;">;</span> e <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span> e <span style="color: #339933;">=</span> e.<span style="color: #006633;">sibling</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ret <span style="color: #339933;">=</span> processPotentialClassVarInScope<span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">sym</span>, ret<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; current <span style="color: #339933;">=</span> current.<span style="color: #006633;">next</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// System.out.println(&quot;Asking for vars in &quot;+env.enclClass.sym);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ret <span style="color: #339933;">=</span> _getClassVarsInScope<span style="color: #009900;">&#40;</span>env, ret<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> ret.<span style="color: #006633;">reverse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; List<span style="color: #339933;">&lt;</span>VarSymbol<span style="color: #339933;">&gt;</span> processPotentialClassVarInScope<span style="color: #009900;">&#40;</span>Symbol s, List<span style="color: #339933;">&lt;</span>VarSymbol<span style="color: #339933;">&gt;</span> ret<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// System.out.println(&quot;in scope: &quot;+s+&quot; : &quot;+s.getClass().getSimpleName());</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>s <span style="color: #000000; font-weight: bold;">instanceof</span> VarSymbol<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VarSymbol vs <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>VarSymbol<span style="color: #009900;">&#41;</span>s<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>vs.<span style="color: #006633;">type</span>.<span style="color: #006633;">tsym</span> <span style="color: #339933;">==</span> syms.<span style="color: #006633;">classType</span>.<span style="color: #006633;">tsym</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>vs.<span style="color: #006633;">flags</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> <span style="color: #000000; font-weight: bold;">FINAL</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#40;</span>vs.<span style="color: #006633;">type</span>.<span style="color: #006633;">getTypeArguments</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">nonEmpty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#40;</span>vs.<span style="color: #006633;">type</span>.<span style="color: #006633;">getTypeArguments</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">head</span> <span style="color: #000000; font-weight: bold;">instanceof</span> TypeVar<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// vs is of type Class&lt;X&gt; where X is a type variable</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ret <span style="color: #339933;">=</span> ret.<span style="color: #006633;">prepend</span><span style="color: #009900;">&#40;</span>vs<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> ret<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; List<span style="color: #339933;">&lt;</span>VarSymbol<span style="color: #339933;">&gt;</span> _getClassVarsInScope<span style="color: #009900;">&#40;</span>Env<span style="color: #339933;">&lt;</span>AttrContext<span style="color: #339933;">&gt;</span> env, List<span style="color: #339933;">&lt;</span>VarSymbol<span style="color: #339933;">&gt;</span> ret<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Env<span style="color: #339933;">&lt;</span>AttrContext<span style="color: #339933;">&gt;</span> env1 <span style="color: #339933;">=</span> env<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">boolean</span> staticOnly <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>env1.<span style="color: #006633;">outer</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>rs.<span style="color: #006633;">isStatic</span><span style="color: #009900;">&#40;</span>env1<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> staticOnly <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Scope.<span style="color: #006633;">Entry</span> e <span style="color: #339933;">=</span> env1.<span style="color: #006633;">info</span>.<span style="color: #006633;">scope</span>.<span style="color: #006633;">elems</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>e <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Symbol sym <span style="color: #339933;">=</span> e.<span style="color: #006633;">sym</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>staticOnly <span style="color: #339933;">&amp;&amp;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sym.<span style="color: #006633;">kind</span> <span style="color: #339933;">==</span> VAR <span style="color: #339933;">&amp;&amp;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sym.<span style="color: #006633;">owner</span>.<span style="color: #006633;">kind</span> <span style="color: #339933;">==</span> TYP <span style="color: #339933;">&amp;&amp;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#40;</span>sym.<span style="color: #006633;">flags</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> <span style="color: #000000; font-weight: bold;">STATIC</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ret <span style="color: #339933;">=</span> processPotentialClassVarInScope<span style="color: #009900;">&#40;</span>sym, ret<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ret <span style="color: #339933;">=</span> _getClassFieldsInScope<span style="color: #009900;">&#40;</span>env1, env1.<span style="color: #006633;">enclClass</span>.<span style="color: #006633;">sym</span>.<span style="color: #006633;">type</span>, env1.<span style="color: #006633;">enclClass</span>.<span style="color: #006633;">sym</span>, ret<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e <span style="color: #339933;">=</span> e.<span style="color: #006633;">sibling</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ret <span style="color: #339933;">=</span> _getClassFieldsInScope<span style="color: #009900;">&#40;</span>env1, env1.<span style="color: #006633;">enclClass</span>.<span style="color: #006633;">sym</span>.<span style="color: #006633;">type</span>, env1.<span style="color: #006633;">enclClass</span>.<span style="color: #006633;">sym</span>, ret<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>env1.<span style="color: #006633;">enclClass</span>.<span style="color: #006633;">sym</span>.<span style="color: #006633;">flags</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> <span style="color: #000000; font-weight: bold;">STATIC</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> staticOnly <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; env1 <span style="color: #339933;">=</span> env1.<span style="color: #006633;">outer</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ret <span style="color: #339933;">=</span> _getClassFieldsInScope<span style="color: #009900;">&#40;</span>env, syms.<span style="color: #006633;">predefClass</span>.<span style="color: #006633;">type</span>, syms.<span style="color: #006633;">predefClass</span>, ret<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> ret<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; List<span style="color: #339933;">&lt;</span>VarSymbol<span style="color: #339933;">&gt;</span> _getClassFieldsInScope<span style="color: #009900;">&#40;</span>Env<span style="color: #339933;">&lt;</span>AttrContext<span style="color: #339933;">&gt;</span> env,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Type site,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TypeSymbol c,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;List<span style="color: #339933;">&lt;</span>VarSymbol<span style="color: #339933;">&gt;</span> ret<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>c.<span style="color: #006633;">type</span>.<span style="color: #006633;">tag</span> <span style="color: #339933;">==</span> TYPEVAR<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c <span style="color: #339933;">=</span> c.<span style="color: #006633;">type</span>.<span style="color: #006633;">getUpperBound</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">tsym</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Scope.<span style="color: #006633;">Entry</span> e <span style="color: #339933;">=</span> c.<span style="color: #006633;">members</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">elems</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>e <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">sym</span>.<span style="color: #006633;">kind</span> <span style="color: #339933;">==</span> VAR <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">sym</span>.<span style="color: #006633;">flags_field</span> <span style="color: #339933;">&amp;</span> SYNTHETIC<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>rs.<span style="color: #006633;">isAccessible</span><span style="color: #009900;">&#40;</span>env, site, e.<span style="color: #006633;">sym</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ret <span style="color: #339933;">=</span> processPotentialClassVarInScope<span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">sym</span>, ret<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e <span style="color: #339933;">=</span> e.<span style="color: #006633;">sibling</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Type st <span style="color: #339933;">=</span> types.<span style="color: #006633;">supertype</span><span style="color: #009900;">&#40;</span>c.<span style="color: #006633;">type</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>st <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>st.<span style="color: #006633;">tag</span> <span style="color: #339933;">==</span> <span style="color: #000000; font-weight: bold;">CLASS</span> <span style="color: #339933;">||</span> st.<span style="color: #006633;">tag</span> <span style="color: #339933;">==</span> TYPEVAR<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ret <span style="color: #339933;">=</span> _getClassFieldsInScope<span style="color: #009900;">&#40;</span>env, site, st.<span style="color: #006633;">tsym</span>, ret<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>Type it<span style="color: #339933;">:</span> types.<span style="color: #006633;">interfaces</span><span style="color: #009900;">&#40;</span>c.<span style="color: #006633;">type</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ret <span style="color: #339933;">=</span> _getClassFieldsInScope<span style="color: #009900;">&#40;</span>env, site, it.<span style="color: #006633;">tsym</span>, ret<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> ret<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>

<p>A new <a href="http://www.javamint.org/">Mint</a> release can be expected shortly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/08/30/passing-a-classt-for-every-type-variable-t/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Mint Release: r15707</title>
		<link>http://www.concurrentaffair.org/2010/08/24/new-mint-release-r15707/</link>
		<comments>http://www.concurrentaffair.org/2010/08/24/new-mint-release-r15707/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 22:06:20 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[Mint]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2164</guid>
		<description><![CDATA[When working on our GPCE tutorial, Eddy and I discovered a small bug in the Mint compiler which I have now fixed in the new release of Mint and DrJava with Mint: August 24, 2010 (r15707). The latest release is, &#8230; <a href="http://www.concurrentaffair.org/2010/08/24/new-mint-release-r15707/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When working on our GPCE tutorial, Eddy and I discovered a small bug in the Mint compiler which I have now fixed in the new release of <a href="http://www.javamint.org/">Mint</a> and <a href="http://www.cs.rice.edu/%7Emgricken/research/mint/index.shtml">DrJava with Mint</a>: August 24, 2010 (r15707). The latest release is, as always, available    from the <a href="http://plresearch.org/do/view/ProgrammingLanguages/JavaMint">Mint  implementation</a> page:</p>

<ul><li><a href="http://plresearch.org/twiki/pub/ProgrammingLanguages/JavaMint/JavaMint-r15707.tar.gz">JavaMint-r15707.tar.gz</a></li><li><a href="http://plresearch.org/twiki/pub/ProgrammingLanguages/JavaMint/JavaMint-r15707-binaries.zip">JavaMint-r15707-binaries.zip</a></li><li><a href="http://www.cs.rice.edu/%7Emgricken/research/mint/download/drjava-r5373-mint-r15707.jar" class="broken_link">drjava-r5373-mint-r15707.jar</a></li></ul>

<p>The only change I made was to fix the <tt>let</tt> expression pretty printer when the expression contained more than one declaration.</p>

<p>The problem never came up before because we only had one declaration per <tt>let</tt> expression, and it was always possible to rewrite</p>

<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">let <span style="color: #000066; font-weight: bold;">int</span> x <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span>, y <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span> x<span style="color: #339933;">+</span>y</div></td></tr></tbody></table></div>

<p>as</p>

<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">let <span style="color: #000066; font-weight: bold;">int</span> x <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> let <span style="color: #000066; font-weight: bold;">int</span> y <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span> x<span style="color: #339933;">+</span>y</div></td></tr></tbody></table></div>

<p>We are pushing the Mint compiler more, and we have discovered another problem with generic methods. Currently, Mint generates a class extending <code class="codecolorer java mac-classic"><span class="java">Code<span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span></span></code> with <code class="codecolorer text mac-classic"><span class="text">X</span></code> occuring unbound when this method is called:</p>

<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> separable <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span> Code<span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span> fun<span style="color: #009900;">&#40;</span>Code<span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span> c1, Code<span style="color: #339933;">&lt;</span>X<span style="color: #339933;">&gt;</span> c2, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a>... <span style="color: #006633;">param</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>

<p>We are looking at making another bugfix soon.</p>

<p>(Re-posted from <a href="http://www.javamint.org/2010/08/new-mint-release-r15707.html">The Java Mint Blog</a>.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/08/24/new-mint-release-r15707/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Mint Release: r15700</title>
		<link>http://www.concurrentaffair.org/2010/08/21/new-mint-release-r15700/</link>
		<comments>http://www.concurrentaffair.org/2010/08/21/new-mint-release-r15700/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 05:32:28 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[Mint]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2151</guid>
		<description><![CDATA[On Friday, I created a new release of Mint and DrJava with Mint: August 20, 2010 (r15700). The latest release is, as always, available from the Mint implementation page: JavaMint-r15700.tar.gzJavaMint-r15700-binaries.zipdrjava-r5372-mint-r15700.jar The only changes that we made were a small change &#8230; <a href="http://www.concurrentaffair.org/2010/08/21/new-mint-release-r15700/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>On Friday, I created a new release of <a href="http://www.javamint.org/">Mint</a> and <a href="http://www.cs.rice.edu/%7Emgricken/research/mint/index.shtml">DrJava with Mint</a>: August 20, 2010 (r15700). The latest release is, as always, available    from the <a href="http://plresearch.org/do/view/ProgrammingLanguages/JavaMint">Mint  implementation</a> page:</p>

<ul><li><a href="http://plresearch.org/twiki/pub/ProgrammingLanguages/JavaMint/JavaMint-r15700.tar.gz">JavaMint-r15700.tar.gz</a></li><li><a href="http://plresearch.org/twiki/pub/ProgrammingLanguages/JavaMint/JavaMint-r15700-binaries.zip">JavaMint-r15700-binaries.zip</a></li><li><a href="http://www.cs.rice.edu/%7Emgricken/research/mint/download/drjava-r5372-mint-r15700.jar" class="broken_link">drjava-r5372-mint-r15700.jar</a></li></ul>

<p>The only changes that we made were a small change to the build process on Mac OS, and the addition of the <tt>Range</tt> and <tt>Lift</tt> utility classes.</p>

<p>The <tt>Lift</tt> class allows the user to manually lift primitive values and strings when the compiler did not do that already, for example when working with arrays.</p>

<p>The <tt>Range</tt> class provides methods that allow many <tt>for</tt> loops to be written as <tt>foreach</tt> loops with a <tt>final</tt> loop variable that can be used across bracket boundaries immediately. Consider this example of a staged sparse matrix multiplication:</p>

<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> separable<br />
Code<span style="color: #339933;">&lt;</span>Void<span style="color: #339933;">&gt;</span> smmult<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> a,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Code<span style="color: #339933;">&lt;</span><span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span> b,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Code<span style="color: #339933;">&lt;</span><span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span> output,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> l, <span style="color: #000066; font-weight: bold;">int</span> m, <span style="color: #000066; font-weight: bold;">int</span> n<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; Code<span style="color: #339933;">&lt;</span>Void<span style="color: #339933;">&gt;</span> stats <span style="color: #339933;">=</span> <span style="color: #339933;">&lt;|</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span> <span style="color: #339933;">|&gt;;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">:</span> range<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, l<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> j<span style="color: #339933;">:</span> range<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, m<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; Code<span style="color: #339933;">&lt;</span>Double<span style="color: #339933;">&gt;</span> c <span style="color: #339933;">=</span> <span style="color: #339933;">&lt;|</span> <span style="color: #cc66cc;">0.0</span> <span style="color: #339933;">|&gt;;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> k<span style="color: #339933;">:</span> range<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, n<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0.0</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">continue</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1.0</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c <span style="color: #339933;">=</span> <span style="color: #339933;">&lt;|</span> `c <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>`b<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span> <span style="color: #339933;">|&gt;;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c <span style="color: #339933;">=</span> <span style="color: #339933;">&lt;|</span> `c <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>`<span style="color: #009900;">&#40;</span>lift<span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span>`b<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|&gt;;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; stats <span style="color: #339933;">=</span> <span style="color: #339933;">&lt;|</span> <span style="color: #009900;">&#123;</span> `stats<span style="color: #339933;">;</span> <span style="color: #009900;">&#40;</span>`output<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> `c<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #339933;">|&gt;;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">return</span> stats<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>

<p>is a lot cleaner than</p>

<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> separable<br />
Code<span style="color: #339933;">&lt;</span>Void<span style="color: #339933;">&gt;</span> smmult<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> a,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Code<span style="color: #339933;">&lt;</span><span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span> b,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Code<span style="color: #339933;">&lt;</span><span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span> output,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> l, <span style="color: #000066; font-weight: bold;">int</span> m, <span style="color: #000066; font-weight: bold;">int</span> n<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; Code<span style="color: #339933;">&lt;</span>Void<span style="color: #339933;">&gt;</span> stats <span style="color: #339933;">=</span> <span style="color: #339933;">&lt;|</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span> <span style="color: #339933;">|&gt;;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> l<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> j <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> j <span style="color: #339933;">&lt;</span> m<span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> ii <span style="color: #339933;">=</span> i<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> jj <span style="color: #339933;">=</span> j<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; Code<span style="color: #339933;">&lt;</span>Double<span style="color: #339933;">&gt;</span> c <span style="color: #339933;">=</span> <span style="color: #339933;">&lt;|</span> <span style="color: #cc66cc;">0.0</span> <span style="color: #339933;">|&gt;;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> k <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> k <span style="color: #339933;">&lt;</span> n<span style="color: #339933;">;</span> k<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> kk <span style="color: #339933;">=</span> k<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0.0</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">continue</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1.0</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c <span style="color: #339933;">=</span> <span style="color: #339933;">&lt;|</span> `c <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>`b<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>kk<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>jj<span style="color: #009900;">&#93;</span> <span style="color: #339933;">|&gt;;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c <span style="color: #339933;">=</span> <span style="color: #339933;">&lt;|</span> `c <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>`<span style="color: #009900;">&#40;</span>lift<span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>ii<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>kk<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span>`b<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>kk<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>jj<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|&gt;;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; stats <span style="color: #339933;">=</span> <span style="color: #339933;">&lt;|</span> <span style="color: #009900;">&#123;</span> `stats<span style="color: #339933;">;</span> <span style="color: #009900;">&#40;</span>`output<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>ii<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>jj<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> `c<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #339933;">|&gt;;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">return</span> stats<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>

<p>The <tt>ii</tt>, <tt>jj</tt>, and <tt>kk</tt> variables aren&#8217;t necessary anymore.</p>

<p>(Re-posted from <a href="http://www.javamint.org/2010/08/new-mint-release-r15700.html">The Java Mint Blog</a>.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/08/21/new-mint-release-r15700/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GPCE&#8217;10 Tutorial Lecture: Agile and Efficient Domain-Specific Languages using Multi-stage Programming in Java Mint</title>
		<link>http://www.concurrentaffair.org/2010/08/16/gpce10-tutorial-lecture-agile-and-efficient-domain-specific-languages-using-multi-stage-programming-in-java-mint/</link>
		<comments>http://www.concurrentaffair.org/2010/08/16/gpce10-tutorial-lecture-agile-and-efficient-domain-specific-languages-using-multi-stage-programming-in-java-mint/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 19:50:14 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[Mint]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2132</guid>
		<description><![CDATA[Eddy, Walid, and I proposed a tutorial lecture for GPCE&#8217;10, and we&#8217;re delighted to report that it has been accepted for presentation on Sunday, October 10, 2010. Agile and Efficient Domain-Specific Languages using Multi-stage Programming in Java Mint Domain-specific languages &#8230; <a href="http://www.concurrentaffair.org/2010/08/16/gpce10-tutorial-lecture-agile-and-efficient-domain-specific-languages-using-multi-stage-programming-in-java-mint/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Eddy, Walid, and I proposed a tutorial lecture for <a href="http://program-transformation.org/GPCE10/">GPCE&#8217;10</a>, and we&#8217;re delighted to report that it has been accepted for presentation on Sunday, October 10, 2010.</p>

<p><span style="font-weight:bold;">Agile and Efficient Domain-Specific Languages using Multi-stage Programming in Java Mint</span></p>

<p>Domain-specific languages (DSLs) are a powerful productivity tool
because they allow domain experts, who are not necessarily programming
experts, to quickly develop programs. DSL implementations have unique
constraints for programming languages because they must be efficient,
in order to ensure high productivity, but they must also be agile, in
order to meet the rapidly changing demands of their domains. In this
tutorial we show how multi-stage programming (MSP) can be used to
build staged interpreters, which combine the agility of interpreters
with the efficiency of compilers. The tutorial is conducted in Java
Mint, an multi-stage Java based on recent work incorporating MSP into
imperative object-oriented languages. In the first half of
the tutorial, we introduce MSP by demonstrating how to write a staged
interpreter for a number of basic language constructs, such as
recursive functions, conditionals, and let expressions. In the second
half, we extend our staged interpreter to take advantage of several
well-known compiler optimizations, including type inference, constant
folding, and static parallel loop scheduling. We highlight the opportunities
afforded by using MSP with object-oriented design to quickly create
efficient DSL implementations.<br/></p>

<p><br/>Brief Outline of Tutorial</p>

<p>This tutorial uses Java Mint to introduce MSP in imperative,
object-oriented languages. We will progress as follows:</p>

<ol>
<li>Introduction to MSP, the three language constructs &#8220;bracket&#8221;,
&#8220;escape&#8221; and &#8220;run&#8221;, and their use in Java Mint.</li>
<li>Brief overview of MSP applications other than interpreters.</li>
<li>Development of a staged interpreter for a small DSL. We
incrementally add:
  <ol style="list-style-type:lower-alpha">
  <li>Arithmetic expressions</li>
  <li>Conditionals</li>
  <li>Recursive functions</li>
  <li>Let expressions</li>
  </ol>
</li>
<li>Application of compiler optimizations in the interpreter
for our DSL. We discuss:
  <ol style="list-style-type:lower-alpha">
  <li>Extending the interpreter with multiple data types</li>
  <li>Type inference</li>
  <li>Constant folding</li>
  <li>Static parallel loop scheduling</li>
  </ol>
</li>
</ol>

<p><br/>Biographies</p>

<p>Mathias Ricken is a doctoral candidate in the Programming Languages
Team at Rice University and one of the principal developers of the
DrJava integrated development environment. His research interests
include concurrent programming, extending the Java language, and
computer science education. He is the developer of the Concutest
concurrent unit testing framework and has created various experimental
extensions of Java to address, for instance, programming with
meta-data. Currently, Mathias is contributing to Java Mint, a
multi-stage extension of Java that allows safe and expressive
statically typed program generation and specialization in an
imperative language setting.</p>

<p>Edwin Westbrook is a post-doctoral researcher at Rice University. His
primary interests are in developing techniques for implementing and
verifying properties of domain-specific languages (DSLs). He has
worked on a number of projects in this area, including: Cinic, a type
theory for building machine-checked proofs of properties of DSLs using
a new approach to higher-order abstract syntax; Java Mint, a
multi-stage version of Java used for efficient implementations of
DSLs; and Acumen, a DSL for designing cyber-physical systems.</p>

<p>Walid Taha is an professor at Halmstad University. His current interest is in modeling and simulation of cyberphysical systems. He was the principal investigator on a number of research awards and contracts from the National Science Foundation (NSF), Semi-conductor Research Consortium (SRC), and Texas Advanced Technology Program (ATP). He received an NSF CAREER award to develop Java Mint. He is the principle designer Java Mint, Acumen, MetaOCaml, and the Verilog Preprocessor. He founded the ACM Conference on Generative Programming and Component Engineering (GPCE), the IFIP Working Group on Program Generation (WG 2.11), and the Middle Earth Programming Languages Seminar (MEPLS). In 2009, he chaired the IFIP Working Conference on Domain Specific Languages (DSLs).</p>

<p>(Re-posted from <a href="http://www.javamint.org/2010/08/gpce10-tutorial-lecture-agile-and.html">The Java Mint Blog</a>.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/08/16/gpce10-tutorial-lecture-agile-and-efficient-domain-specific-languages-using-multi-stage-programming-in-java-mint/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

