<?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</title>
	<atom:link href="http://www.concurrentaffair.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.concurrentaffair.org</link>
	<description>a blog about Mathias&#039; work and play.</description>
	<lastBuildDate>Thu, 02 Sep 2010 16:54:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>DrJava/HJ Born</title>
		<link>http://www.concurrentaffair.org/2010/09/01/drjavahj-born/</link>
		<comments>http://www.concurrentaffair.org/2010/09/01/drjavahj-born/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 23:49:44 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[DrJava]]></category>
		<category><![CDATA[Research]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2201</guid>
		<description><![CDATA[I have been able to merge Vincent&#8217;s and Jarred&#8217;s changes into the DrJava trunk to create a version of DrJava/HJ that can compile and run Habanero Java (HJ) programs. Most importantly, there is a version where both HJ and DrJava &#8230; <a href="http://www.concurrentaffair.org/2010/09/01/drjavahj-born/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have been able to <a href="http://drjava.svn.sourceforge.net/viewvc/drjava?view=revision&#038;revision=5383">merge Vincent&#8217;s and Jarred&#8217;s changes into the DrJava trunk</a> to create a version of DrJava/HJ that can compile and run <a href="http://habanero.rice.edu/">Habanero Java</a> (HJ) programs. Most importantly, there is a version where <a href="http://www.cs.rice.edu/~mgricken/research/drjava/download/drjava-hj-20100901.jar">both HJ and DrJava are in one 20 MB file</a>. Please try it out: <a href="http://www.cs.rice.edu/~mgricken/research/drjava/download/drjava-hj-20100901.jar"><tt>drjava-hj.jar</tt></a></p>

<p><img src="http://www.concurrentaffair.org/wp-content/uploads/2010/09/DrJavaHJ.png" alt="DrJava/HJ Logo" title="DrJavaHJ" width="360" height="60" class="size-full wp-image-2203" /></p>

<p>I have identified a change that needs to be made to the HJ Runtime in order to integrate it with DrJava. It is small and does not affect the performance or execution of HJ when it is run independently from DrJava.</p>

<p>The class loader that HJ uses to find classes it is running has to be changed. DrJava has a dynamic class path, depending on the files that are open, the configuration of the project, and the global preferences. If HJ is to find the classes that DrJava has compiled, HJ needs to use the class loader DrJava provides. DrJava passes this class loader to its runtimes as &#8220;thread context class loader&#8221;, which &#8220;provides a way to pass an &#8216;intended classloader parent&#8217; into a framework without explicitly needing to pass it.&#8221; [<a href="http://www.javaworld.com/javaworld/javaqa/2003-06/01-qa-0606-load.html">source</a>]</p>

<p>The thread context class loader can be queried using <code class="codecolorer java mac-classic"><span class="java"><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a>.<span style="color: #006633;">currentThread</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getContextClassLoader</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> and needs to be passed wherever a user class is loaded using <code class="codecolorer java mac-classic"><span class="java"><span style="color: #000000; font-weight: bold;">Class</span>.<span style="color: #006633;">forName</span></span></code>. I found four such calls to <code class="codecolorer java mac-classic"><span class="java"><span style="color: #000000; font-weight: bold;">Class</span>.<span style="color: #006633;">forName</span></span></code> in the HJ runtime. The nice thing about the thread context class loaders is that, unless they are set, they default to the system class loader. As a result, unless DrJava (or some other application using the HJ runtime) set the thread context class loader to tell HJ &#8220;use this class loader to find my classes&#8221;, everything is just as before.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/09/01/drjavahj-born/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>String,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>String,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>Bookmark Google Calendar Searches</title>
		<link>http://www.concurrentaffair.org/2010/08/31/bookmark-google-calendar-searches/</link>
		<comments>http://www.concurrentaffair.org/2010/08/31/bookmark-google-calendar-searches/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 19:38:31 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2184</guid>
		<description><![CDATA[I think I have finally figured out how how to bookmark Google Calendar searches. The problem was that the search parameters did not seem to be passed using URL &#8220;get&#8221; parameters. The Google Calendar URL was always just https://www.google.com/calendar/render and &#8230; <a href="http://www.concurrentaffair.org/2010/08/31/bookmark-google-calendar-searches/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I think I have finally figured out how how to bookmark Google Calendar searches. The problem was that the search parameters did not seem to be passed using URL &#8220;get&#8221; parameters. The Google Calendar URL was always just <pre>https://www.google.com/calendar/render</pre> and the search parameters never made it into a bookmark.</p>

<p>I just experimented a bit by passing <tt>q=blabla</tt> arguments, and doing that seems to work. I can specify to just search my calendar using <tt>src=username%40gmail.com</tt>. For example, this URL can be bookmarked to search my calendar for &#8220;opera OR symphony OR concert OR theater OR theatre&#8221;:</p>

<div class="codecolorer-container text 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="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">https://www.google.com/calendar/render?src=username%40gmail.com&amp;q=opera%20OR%20concert%20OR%20symphony%20OR%20theater%20OR%20theatre</div></td></tr></tbody></table></div>

<p>Replace <tt>username%40gmail.com</tt> with your GMail address. Use <tt>%40</tt> instead of the &#8220;at&#8221; sign (<tt>@</tt>) and <tt>%20</tt> instead of a space.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/08/31/bookmark-google-calendar-searches/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">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">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>Two Pieces of Fail</title>
		<link>http://www.concurrentaffair.org/2010/08/24/two-pieces-of-fail/</link>
		<comments>http://www.concurrentaffair.org/2010/08/24/two-pieces-of-fail/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 14:54:42 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[Pictures]]></category>
		<category><![CDATA[Ramblings]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2157</guid>
		<description><![CDATA[I encountered two pieces of fail today already. Fail number 1: Absolutely no place to park my bike. This has been pretty much the case ever since the undergrads have been back. Rice built two new colleges right next to &#8230; <a href="http://www.concurrentaffair.org/2010/08/24/two-pieces-of-fail/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I encountered two pieces of fail today already.</p>

<p>Fail number 1: Absolutely no place to park my bike. This has been pretty much the case ever since the undergrads have been back. Rice built two new colleges right next to the building I work in, but didn&#8217;t consider what an increased resident population would do to bike rack space: The undergrads, of course, store their bikes semi-permanently on the bike racks that we need to commute.</p>

<p>This is what the bike racks looked like shortly after 9 AM this morning:</p>

<div id="attachment_2158" class="wp-caption aligncenter" style="width: 650px"><a href="http://www.concurrentaffair.org/wp-content/uploads/2010/08/Photo_082410_001.jpg"><img src="http://www.concurrentaffair.org/wp-content/uploads/2010/08/Photo_082410_001-1024x819.jpg" alt="Overfull Duncan Hall Bike Rack, 9:15 AM" title="Photo_082410_001" width="640" height="511" class="size-large wp-image-2158" /></a><p class="wp-caption-text">Overfull Duncan Hall Bike Rack, 9:15 AM</p></div>

<p>I have been lobbying for more bike racks for over a year now, to no avail. I guess I&#8217;m going to be taking my bike up into my building from now on.</p>

<p>Fail number 2: I still don&#8217;t have my Texas drivers license, even though it has been 67 days since I renewed it. It&#8217;s even been over three weeks since I first contacted the DPS and was told the license would be remade and resent. Today I found out why it&#8217;s taking so long:</p>

<blockquote>
You will be mailed out a temporary permit today while you receive your license in the mail.  Apparently the license was not remade when the visitor status was updated.  I sincerely apologize for the inconvenience this has caused you.</blockquote>

<p><br/>In essence, they cut up my old drivers license, updated their internal database, and never mailed me a new license. Good job, Texas DPS. I&#8217;m glad I have an international drivers license as a backup.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/08/24/two-pieces-of-fail/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">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>double<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>double<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>double<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>double<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>Compiled &#8220;Run&#8221; Commands in DrJava</title>
		<link>http://www.concurrentaffair.org/2010/08/20/compiled-run-commands-in-drjava/</link>
		<comments>http://www.concurrentaffair.org/2010/08/20/compiled-run-commands-in-drjava/#comments</comments>
		<pubDate>Fri, 20 Aug 2010 22:27:23 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[DrJava]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2146</guid>
		<description><![CDATA[I had mentioned a while ago that the way we put together the commands that get interpreted when the user presses the &#8220;Run&#8221; button or types in java or applet or run in the Interactions Pane is very messy. I &#8230; <a href="http://www.concurrentaffair.org/2010/08/20/compiled-run-commands-in-drjava/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I had mentioned a while ago that <a href="http://www.concurrentaffair.org/2010/07/30/another-bugfix-for-smart-run/">the way we put together the commands that get interpreted when the user presses the &#8220;Run&#8221; button</a> or types in <tt>java</tt> or <tt>applet</tt> or <tt>run</tt> in the Interactions Pane is very messy.</p>

<p>I had told myself that I should try to rewrite this as Java code that doesn’t get interpreted in our Interactions Pane, but that actually gets statically compiled. I did that, and the code was a whole lot more maintainable. Compare this code to the <a href="http://www.concurrentaffair.org/2010/07/30/another-bugfix-for-smart-run/">previous code</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 />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 /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/** This method performs the &quot;smart run&quot;. Unfortunately, we don't get the right static error messages.<br />
&nbsp; &nbsp; * @param s full command line, i.e. &quot;run MyClass 1 2 3&quot;<br />
&nbsp; &nbsp; * @param c class to be run, i.e. MyClass.class<br />
&nbsp; &nbsp; */</span><br />
&nbsp; @SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;unchecked&quot;</span><span style="color: #009900;">&#41;</span><br />
&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> runCommand<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: #000000; font-weight: bold;">Class</span> c<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%3Athrowable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Throwable</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>s.<span style="color: #006633;">endsWith</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> &nbsp;s <span style="color: #339933;">=</span> _deleteSemiColon<span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> tokens <span style="color: #339933;">=</span> ArgumentTokenizer.<span style="color: #006633;">tokenize</span><span style="color: #009900;">&#40;</span>s, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&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> classNameWithQuotes <span style="color: #339933;">=</span> tokens.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// this is &quot;MyClass&quot;</span><br />
&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> className <span style="color: #339933;">=</span><br />
&nbsp; &nbsp; &nbsp; classNameWithQuotes.<span style="color: #006633;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span>, classNameWithQuotes.<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: #339933;">;</span> <span style="color: #666666; font-style: italic;">// removes quotes, becomes MyClass</span><br />
&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><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%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span>tokens.<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: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</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> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> tokens.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><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; &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> t <span style="color: #339933;">=</span> tokens.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; args<span style="color: #009900;">&#91;</span>i <span style="color: #339933;">-</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> t.<span style="color: #006633;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span>, t.<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: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">boolean</span> isProgram <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">boolean</span> isApplet <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">Class</span> oldC <span style="color: #339933;">=</span> c<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>c <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; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;acm.program.Program&quot;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>c.<span style="color: #006633;">getName</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; <span style="color: #0000ff;">&quot;acm.graphics.GTurtle&quot;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>c.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> isProgram <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; c <span style="color: #339933;">=</span> c.<span style="color: #006633;">getSuperclass</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; c <span style="color: #339933;">=</span> oldC<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>isProgram<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// if this doesn't throw, c is a subclass of Applet</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; c.<span style="color: #006633;">asSubclass</span><span style="color: #009900;">&#40;</span>java.<span style="color: #006633;">applet</span>.<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aapplet+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Applet</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; isApplet <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <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: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; java.<span style="color: #006633;">lang</span>.<span style="color: #006633;">reflect</span>.<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amethod+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Method</span></a> m <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isApplet<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; m <span style="color: #339933;">=</span> c.<span style="color: #006633;">getMethod</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;main&quot;</span>, java.<span style="color: #006633;">lang</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>.<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; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>m.<span style="color: #006633;">getReturnType</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: #000066; font-weight: bold;">void</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: #009900;">&#123;</span> m <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>java.<span style="color: #006633;">lang</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> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> m <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>m<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; java.<span style="color: #006633;">applet</span>.<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aapplet+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Applet</span></a> instance <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;">if</span> <span style="color: #009900;">&#40;</span>args.<span style="color: #006633;">length</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; <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;">// try default (nullary) constructor first</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;">getConstructor</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; instance <span style="color: #339933;">=</span> java.<span style="color: #006633;">applet</span>.<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aapplet+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Applet</span></a>.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">cast</span><span style="color: #009900;">&#40;</span>ctor.<span style="color: #006633;">newInstance</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; <span style="color: #009900;">&#125;</span><br />
&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> instance <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&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%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> instance <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&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%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> instance <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>java.<span style="color: #006633;">lang</span>.<span style="color: #006633;">reflect</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: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ite.<span style="color: #006633;">getCause</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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; &nbsp; <span style="color: #000000; font-weight: bold;">throw</span> ite.<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; &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; <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;">err</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error: Please turn off 'Smart Run' or use 'java' command instead of 'run'.&quot;</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; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>instance<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;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// try String[] constructor next</span><br />
&nbsp; &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;">getConstructor</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: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>.<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; instance <span style="color: #339933;">=</span> java.<span style="color: #006633;">applet</span>.<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aapplet+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Applet</span></a>.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">cast</span><span style="color: #009900;">&#40;</span>ctor.<span style="color: #006633;">newInstance</span><span style="color: #009900;">&#40;</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><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">new</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: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#125;</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; &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> instance <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</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%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> instance <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</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%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> instance <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</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>java.<span style="color: #006633;">lang</span>.<span style="color: #006633;">reflect</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; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ite.<span style="color: #006633;">getCause</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">throw</span> ite.<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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&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; <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;">err</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error: Please turn off 'Smart Run' or use 'java' command instead of 'run'.&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;">return</span><span style="color: #339933;">;</span><br />
&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; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>instance<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; <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;">err</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error: This applet does not have a default constructor or a constructor &quot;</span><span style="color: #339933;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">&quot;accepting String[].&quot;</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: #339933;">;</span><br />
&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;">else</span> <span style="color: #009900;">&#123;</span><br />
&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; <span style="color: #666666; font-style: italic;">// try String[] constructor</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;">getConstructor</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: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>.<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; instance <span style="color: #339933;">=</span> java.<span style="color: #006633;">applet</span>.<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aapplet+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Applet</span></a>.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">cast</span><span style="color: #009900;">&#40;</span>ctor.<span style="color: #006633;">newInstance</span><span style="color: #009900;">&#40;</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><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> args <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&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> instance <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&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%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> instance <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&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%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> instance <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>java.<span style="color: #006633;">lang</span>.<span style="color: #006633;">reflect</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: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ite.<span style="color: #006633;">getCause</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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; &nbsp; <span style="color: #000000; font-weight: bold;">throw</span> ite.<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; &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; <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;">err</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error: Please turn off 'Smart Run' or use 'java' command instead of 'run'.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</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; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>instance<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; <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;">err</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error: This applet does not have a constructor accepting String[].&quot;</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: #339933;">;</span><br />
&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; edu.<span style="color: #006633;">rice</span>.<span style="color: #006633;">cs</span>.<span style="color: #006633;">plt</span>.<span style="color: #006633;">swing</span>.<span style="color: #006633;">SwingUtil</span>.<span style="color: #006633;">showApplet</span><span style="color: #009900;">&#40;</span>instance, <span style="color: #cc66cc;">400</span>, <span style="color: #cc66cc;">300</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; m <span style="color: #339933;">=</span> c.<span style="color: #006633;">getMethod</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;main&quot;</span>, java.<span style="color: #006633;">lang</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>.<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; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>m.<span style="color: #006633;">getReturnType</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: #000066; font-weight: bold;">void</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: #009900;">&#123;</span><br />
&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;">err</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error: This class does not have a static void main method accepting String[].&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m <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: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>java.<span style="color: #006633;">lang</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> e<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%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">err</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error: This class does not have a static void main method accepting String[].&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; m <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>m <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; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isProgram<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><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> newArgs <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%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span>args.<span style="color: #006633;">length</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; newArgs<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;code=&quot;</span><span style="color: #339933;">+</span>c.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</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;">arraycopy</span><span style="color: #009900;">&#40;</span>args, <span style="color: #cc66cc;">0</span>, newArgs, <span style="color: #cc66cc;">1</span>, args.<span style="color: #006633;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; args <span style="color: #339933;">=</span> newArgs<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; m.<span style="color: #006633;">setAccessible</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; m.<span style="color: #006633;">invoke</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</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><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> args <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&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%3Asecurityexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">SecurityException</span></a> se<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%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">err</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error: Please turn off 'Smart Run' or use 'java' command instead of 'run'.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&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; <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;">err</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error: Please turn off 'Smart Run' or use 'java' command instead of 'run'.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>java.<span style="color: #006633;">lang</span>.<span style="color: #006633;">reflect</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; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ite.<span style="color: #006633;">getCause</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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; <span style="color: #000000; font-weight: bold;">throw</span> ite.<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; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&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; <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;">err</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error: Please turn off 'Smart Run' or use 'java' command instead of 'run'.&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; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>

<p>It&#8217;s actual Java code that is statically compiled, not a string that is concatenated at runtime and that might be erroneous.</p>

<p>Unfortunately, we don&#8217;t get the right static error messages. I can print something like &#8220;Static Error: Undefined class &#8216;Foo&#8217;&#8221; as output, but it doesn&#8217;t have the right font and doesn&#8217;t invoke the right listeners, so the &#8220;Auto-Import&#8221; dialog doesn&#8217;t show up, for example.</p>

<p>For now, I&#8217;m using the old string concatenation routine again.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/08/20/compiled-run-commands-in-drjava/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Versions on the Mac</title>
		<link>http://www.concurrentaffair.org/2010/08/17/java-versions-on-the-mac/</link>
		<comments>http://www.concurrentaffair.org/2010/08/17/java-versions-on-the-mac/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 21:47:12 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2139</guid>
		<description><![CDATA[Stephen had some questions about Java on the Mac. I tried to answer them. From the DrJava site, I see notes that a JDK is already installed on OS X machines—that explains why I can’t find downloads for it. There &#8230; <a href="http://www.concurrentaffair.org/2010/08/17/java-versions-on-the-mac/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Stephen had some questions about Java on the Mac. I tried to answer them.</p>

<blockquote>From the DrJava site, I see notes that a JDK is already installed on OS X machines—that explains why I can’t find downloads for it.
</blockquote>

<p><br/>There are some <a href="http://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wo/5.1.17.2.1.3.3.1.0.1.1.0.3.8.3.3.1">Java downloads from Apple</a>, but they&#8217;re hard to find and
meant for developers (Apple ID required).</p>

<blockquote>I have a couple of questions about it though:</blockquote>

<p><br/>Here are some answers from Apple: <a href="http://developer.apple.com/java/faq/">Mac OS X Java Frequently Asked Questions (FAQ) for developers</a>.</p>

<blockquote>a)  Is it a 32-bit or a 64-bit JDK?</blockquote>

<p><br/>As far as I know, Macs have both a 32-bit and a 64-bit JDK installed. If I understand <a href="http://developer.apple.com/java/javaleopard.html">this page</a> correctly, by default, the 32-bit JVM is running.</p>

<p>I don&#8217;t have a 64-bit Mac, though, so I don&#8217;t have any experience with 64-bit Mac JVMs.</p>

<blockquote>b) Does the Mac run some sort of auto-updating process on it &#8211; how do you know what version it is running and how do you get a newer version if needed?</blockquote>

<p><br/>This is what the FAQ says:</p>

<blockquote>Java updates usually stand alone, allowing you to choose when an update is appropriate. However, it is always recommended to check the description and release notes for all software updates to see which technologies are affected. Major upgrades such as Mac OS X Leopard typically update Java as well.</blockquote>

<p><br/>It&#8217;s been such a long time since I&#8217;ve had a Java update on my 10.4 32-bit MacBook, but I think new versions of Java appear in the &#8220;Software Update&#8221; list (see Apple menu).</p>

<blockquote>
The reason I ask is that for running Eclipse, one needs to know if you’re running a 32-bit or 64-bit version because not only are different plug-ins needed, but the install procedure can be different as well.   Also, we need to know what version of Java people are running on their Macs.</blockquote>

<p><br/>On the command line: <code class="codecolorer text mac-classic"><span class="text">java -version</span></code></p>

<p>The <tt>sun.arch.data.model</tt> property may also help, it should be <code class="codecolorer java mac-classic"><span class="java"><span style="color: #0000ff;">&quot;32&quot;</span></span></code>,
<code class="codecolorer java mac-classic"><span class="java"><span style="color: #0000ff;">&quot;64&quot;</span></span></code> or <code class="codecolorer java mac-classic"><span class="java"><span style="color: #0000ff;">&quot;unknown&quot;</span></span></code>. You can get the value by calling <code class="codecolorer java mac-classic"><span class="java"><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;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sun.arch.data.model&quot;</span><span style="color: #009900;">&#41;</span></span></code>, for example in the DrJava Interactions Pane (see <a href="http://www.oracle.com/technetwork/java/hotspotfaq-138619.html">Oracle FAQ entry</a>).</p>

<p>Here is some more <a href="http://developer.apple.com/mac/library/technotes/tn2002/tn2110.html">Apple-specific information about Java versions</a>.</p>

<p>Hope this helps.</p>

<p><strong>Update</strong></p>

<p>Corky said what I had written about &#8220;by default, the 32-bit JVM is running&#8221; had confused him. He wondered: &#8220;Is a 32 bit version of Java 6 now available on Leopard?&#8221;</p>

<p>No, there&#8217;s still no 32-bit Java 6 from Apple for Tiger (10.4).</p>

<p>It seems like the -d64 switch is a mode, like -server or -client, and that on the Mac both the 32-bit and the 64-bit JVMs are rolled into one. On Windows, Linux and Solaris, there are 32-bit and 64-bit JVMs that need to be installed separately.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/08/17/java-versions-on-the-mac/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 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 (DSLs) &#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 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>(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>2</slash:comments>
		</item>
		<item>
		<title>New Version of DrJava with Mint: drjava-r5366-mint-r15665</title>
		<link>http://www.concurrentaffair.org/2010/08/16/new-version-of-drjava-with-mint-drjava-r5366-mint-r15665/</link>
		<comments>http://www.concurrentaffair.org/2010/08/16/new-version-of-drjava-with-mint-drjava-r5366-mint-r15665/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 19:36:10 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[DrJava]]></category>
		<category><![CDATA[Mint]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2130</guid>
		<description><![CDATA[The DrJava team released a new stable version of DrJava today, drjava-stable-20100816-r5366. I therefore created a new release of DrJava with Mint: August 16, 2010 (drjava-r5366-mint-r15665.jar). The latest release is available from the Mint implementation page: JavaMint-r15665.tar.gzJavaMint-r15665-binaries.zipdrjava-r5366-mint-r15665.jar Nothing has changed &#8230; <a href="http://www.concurrentaffair.org/2010/08/16/new-version-of-drjava-with-mint-drjava-r5366-mint-r15665/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://drjava.org/">DrJava</a> team released a <a href="https://sourceforge.net/news/?group_id=44253&amp;id=290558">new stable version of DrJava</a> today, <a href="https://sourceforge.net/projects/drjava/files/1.%20DrJava%20Stable%20Releases/drjava-beta-20100711-r5314/">drjava-stable-20100816-r5366</a>.</p>

<p>I therefore created a new release of <a href="http://www.cs.rice.edu/%7Emgricken/research/mint/index.shtml">DrJava with Mint</a>: August 16, 2010 (drjava-r5366-mint-r15665.jar). The latest release is 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-r15665.tar.gz">JavaMint-r15665.tar.gz</a></li><li><a href="http://plresearch.org/twiki/pub/ProgrammingLanguages/JavaMint/JavaMint-r15665-binaries.zip">JavaMint-r15665-binaries.zip</a></li><li><a href="http://www.cs.rice.edu/%7Emgricken/research/mint/download/drjava-r5366-mint-r15665.jar">drjava-r5366-mint-r15665.jar</a></li></ul>

<p>Nothing has changed on the Mint language side.</p>

<p>(Re-posted from <a href="http://www.javamint.org/2010/08/new-version-of-drjava-with-mint-drjava.html">The Java Mint Blog</a>.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/08/16/new-version-of-drjava-with-mint-drjava-r5366-mint-r15665/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New DrJava Stable Release: drjava-stable-20100816-r5366</title>
		<link>http://www.concurrentaffair.org/2010/08/16/new-drjava-stable-release-drjava-stable-20100816-r5366/</link>
		<comments>http://www.concurrentaffair.org/2010/08/16/new-drjava-stable-release-drjava-stable-20100816-r5366/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 18:47:35 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[DrJava]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2127</guid>
		<description><![CDATA[We have just released a new stable release of DrJava: drjava-stable-20100816-r5366. You can download it from SourceForge or from the DrJava homepage. Available for download at http://drjava.org . DrJava is a lightweight programming environment for Java designed to foster test-driven &#8230; <a href="http://www.concurrentaffair.org/2010/08/16/new-drjava-stable-release-drjava-stable-20100816-r5366/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We have just released a new stable release of DrJava: drjava-stable-20100816-r5366. You can download it from <a href="http://sourceforge.net/projects/drjava/files/1.%20DrJava%20Stable%20Releases/drjava-stable-20100816-r5366/">SourceForge</a> or from the <a href="http://drjava.org/">DrJava</a> homepage.</p>

<p>Available for download at <a href="http://drjava.org/">http://drjava.org</a>  .</p>

<p>DrJava is a lightweight programming environment for Java designed to
foster test-driven software development. It includes an intelligent
program editor, an interactions pane for evaluating program text, a
source level debugger, and a unit testing tool.</p>

<p>In addition to bug fixes, this stable release includes a number of new
features introduced after the last beta release:</p>

<p>These features include improved keyboard shortcuts, improved undo/redo
functionality outside the Definitions Pane, as well as better menus
for detached windows on the Mac.</p>

<p>Note: Java 1.4 compatibility has been dropped. To use DrJava, you will
need Java 5 or newer.</p>

<p>New features since the last beta release:</p>

<ul>
    <li>Keyboard shortcuts for Project menu items.</li>
    <li>Menus for detached windows on Mac OS.</li>
    <li>Undo/Redo for Input Box and detached Interactions Pane.</li>
    <li>Keyboard shortcuts available in detached windows.</li>
    <li>Displaying compiz warning only for Java older than 1.6.0_20.</li>
    <li>Changing the default look-and-feel for non-Windows, non-Mac
   machines (=Linux) to the system default. This will probably
   be GTK instead of Metal, which is much prettier.</li>
</ul>

<p>Bug fixes since last beta release:</p>

<ul>
    <li>Properly disabled &#8216;Run Project&#8217;s Main Class&#8217; if main class not set.</li>
    <li>Bugfix for a problem relating to menu item availability, which
   caused the project menu to be disabled when it should be enabled.</li>
    <li>IllegalAccessException with Smart Run on non-Public class.</li>
    <li>Fixed NullPointerException when removing Find All matches.</li>
    <li>Fixed a bug that caused a NullPointerException when a Find All
   encountered a missing file.</li>
    <li>Fixed bug StringIndexOutOfBoundsException on non-Western systems
   that use characters longer than a byte.</li>
    <li>Fixed bug that caused Undo/Redo menu items to not be enabled
   properly.</li>
    <li>Fixed bug that caused pressing Ctrl-Z (Undo) to make the System.in
   box disappear.</li>
    <li>Fixed bug that caused { or } to be inserted on Linux when using
   &#8220;Go to Opening/Closing Brace&#8221; shortcuts.</li>
    <li>Fixed a bug that enabled Undo for the Interactions Pane on Macs
   even when there was nothing to undo.</li>
    <li>Fixed problem that prevented configuration of key bindings for
   actions with the same names, e.g. &#8220;New&#8221; (File) and &#8220;New&#8221; (Project).</li>
    <li>Fixed bug that caused changes to Key Bindings to not be canceled
   properly.</li>
</ul>

<p>New features since the last stable release:</p>

<ul>
    <li>The Eclipse Java Compiler is now integrated into DrJava. DrJava
   therefore does not require the JDK anymore to compile
   programs. Note that the JDK is still required to use the debugger
   or to create Javadoc.</li>

<li>DrJava supports the OpenJDK and JavaMint (multi-stage programming
   in Java; see <a href="http://www.javamint.org/">http://www.javamint.org/</a> ) compilers.</li>

<li>JUnit 4.7 support.</li>

<li>ConcJUnit support (for concurrent unit tests; see
   <a href="http://www.concutest.org/">http://www.concutest.org/</a> ).</li>

<li>Access control for private and package private members now enabled
   by default.</li>

<li>DynamicJava (Interpreter) error messages are much better,
   especially those involving method and constructor invocation.</li>

<li>Added support in DynamicJava for explicit type arguments in local
   function invocations (x = foo(23)).</li>

<li>The Breakpoint, Bookmarks, and Find Results tabbed panes now have
   Previous/Next buttons and associated keyboard shortcuts for simpler
   browsing.</li>

<li>The Interactions Pane working directory can now be specified even
   when not using projects.</li>

<li>If DrJava cannot start, for example because of bad memory settings
   in the Preferences, DrJava will suggest that you let it reset the
   Preferences.</li>

<li>The preferred compiler can now be set, and this setting will be
   restored when DrJava starts the next time.</li>

<li>Zoom for Print Preview.</li>

<li>New Class wizard.</li>

<li>Save Copy ability for Definitions documents, Interactions Pane and
   Console Pane contents.</li>

<li>The Java Language Level facility has been simplified. There now is
   only one language level called &#8220;Functional Java&#8221;, using the file
   extension .dj. It is comparable to the Intermediate level and
   can still compile .dj0 and .dj1 files. .dj2 files are compiled
   using the Full Java compiler. DrJava will suggest that you rename
   .dj0 and .dj1 files to .dj files, and .dj2 files to .java files.</li>

<li>DrJava can generate a custom .jar file of itself that includes
   additional files. There is a Tools/Advanced/Generate Custom
   drjava.jar menu item that takes the current DrJava executable file
   and a number of user-specified files to generate a new jar file.
<ul>
<li>The libraries included in the new jar file will then
      automatically be included in the classpath and be usable without
      adding them to a classpath somewhere.</li>

<li>There is no functionality to remove the libraries again from the
      modified jar file.</li>

<li>Generating a custom DrJava jar file disables the check for
      updated versions. Otherwise a user may download an updated
      version that doesnt have required libraries anymore.</li>
</ul></li>

<li>When DrJava encounters missing files during a &#8220;Find All&#8221; search,
   it will ask the user whether to continue or abort the search.</li>

<li>Improved &#8220;New Java Class&#8221; dialog with some auto-completion.</li>

<li>Better feedback when Java API data is loaded, which may involve
   some delay if it is retrieved from the internet.</li>
    <li>There is a new option in Preferences/Interactions Pane
   called &#8220;Smart Run (&#8216;java&#8217;) Command&#8221;. If enabled (default),
   the &#8220;Run&#8221; button and the &#8220;java&#8221; command in the Interactions
   Pane detects if the class (a) is an ACM Java Task Force
   program (subclass of acm.program.Program) or (b) an applet.
   If (a), then it runs the program&#8217;s main method, but inserts
   &#8220;code=MyClass&#8221; as argument 0. If (b), it starts the
   applet viewer. Otherwise, the &#8220;java&#8221; command behaves just
   as before.</li>

<li>Right margin line.</li>

<li>Improved Save As file naming.</li>

<li>Tools->Advanced->New DrJava Instance feature.</li>

<li>Appending .jar to file name when generating custom DrJava.</li>
</ul>

<p>Bug fixes since the last stable release:</p>

<ul>
    <li>Fixed some indentation bugs.</li>

<li>Fixed some GUI initialization problems that prevented DrJava from
   starting on some systems.</li>

<li>Fixed a bug that prevented DrJava from opening on MacOS 10.5 or
   10.6.</li>

<li>Fixed compiler error when closing curly brace missing.</li>

<li>Fixed NullPointerException in Jar Project dialog.</li>

<li>Fixed a bug that prevented users from editing External Processes.</li>

<li>Fixed a bug in un-commenting source code.</li>

<li>Fixed a bug in displaying the Auto-Import dialog in the
   Interactions Pane.</li>

<li>Improved suggestion to increase interactions JVM heap.</li>

<li>Improved responsiveness when selecting a compiler.</li>

<li>Fixed a bug that prevented users from generating Javadoc of
   Language Level files.</li>

<li>DynamicJava (Interpreter) bug fix allows the declaration of
   interfaces.</li>

<li>Miscellaneous small DynamicJava bug fixes make it much more robust
   and correct, including better handling of member lookup, inner
   classes, enums, interfaces, raw types, static imports, switch
   statements, casts, and final variables.</li>

<li>Bugfix for comparing 0.0 == -0.0 and NaNs.</li>

<li>Bugfix in DynamicJava: Supports annotation declarations</li>

<li>Bugfix in DynamicJava: Fixes parser bug for enums</li>

<li>Bugfix in DynamicJava: Fixes implicit accessibility of interface
   members</li>

<li>Bugfix in DynamicJava: Fixes checking of assignments from character
   literals</li>

<li>Bugfix in DynamicJava: Improves checking of casts</li>

<li>Bugfix in DynamicJava: getClass() is a special method with type
   Class for all classes</li>

<li>Bugfix in DynamicJava: Improves error messages for inner class
   references</li>

<li>Bugfix in DynamicJava: Preserves location in wildcards</li>

<li>Bugfix in DynamicJava: Catches errors that occur during static
   initialization of a class</li>

<li>Bugfix in DynamicJava: Short-circuiting during type checking</li>

<li>Bugfix in DynamicJava: += for strings</li>

<li>Bugfix in DynamicJava: Array initializer is assigned to a non-array
   type</li>

<li>Misc improvements to DynamicJava SoureChecker</li>

<li>Bugfix that prevented users from watching local variables in the
   Debugger.</li>

<li>Smaller Java Language Level fixes.</li>

    <li>StringIndexOutOfBoundsException During Next Word</li>

<li>Exception when double click on External process tab</li>

<li>This commit fixes some glitches in the new functional
   LL, effectively subsuming both the Elementary (.dj0)
   and Intermediate (.dj1) language levels.</li>

<li>Bugfix for throw null</li>

<li>Fixing a memory leak in DefinitionsPane.</li>

</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/08/16/new-drjava-stable-release-drjava-stable-20100816-r5366/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Improved DrC#?</title>
		<link>http://www.concurrentaffair.org/2010/08/16/improved-drc/</link>
		<comments>http://www.concurrentaffair.org/2010/08/16/improved-drc/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 13:37:23 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[DrJava]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2125</guid>
		<description><![CDATA[Recently, I was asked if there will ever be a new DrC# which is similar to DrJava. Unfortunately, I don&#8217;t expect an improved DrC# in the near future. We don&#8217;t have the funding and personnel to work on such a &#8230; <a href="http://www.concurrentaffair.org/2010/08/16/improved-drc/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recently, I was asked if there will ever be a new <a href="http://drcsharp.sourceforge.net/">DrC#</a> which is similar to <a href="http://drjava.org/">DrJava</a>.</p>

<p>Unfortunately, I don&#8217;t expect an improved <a href="http://drcsharp.sourceforge.net/">DrC#</a> in the near future. We don&#8217;t have the funding and personnel to work on such a project. We already have trouble maintaining the <a href="http://drjava.org/index.php?page=eclipse.shtml">DrJava Plug-in for Eclipse</a>.</p>

<p>It may be possible to integrate a C# command line compiler into DrJava, though, if there is interest. There are problems with this approach, though: The syntax highlighting wouldn&#8217;t be right, and the Interactions Pane wouldn&#8217;t be functional.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/08/16/improved-drc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I&#8217;m Going to Eindhoven</title>
		<link>http://www.concurrentaffair.org/2010/08/15/im-going-to-eindhoven/</link>
		<comments>http://www.concurrentaffair.org/2010/08/15/im-going-to-eindhoven/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 00:34:05 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[Mint]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2113</guid>
		<description><![CDATA[The Java Mint tutorial lecture called &#8220;Agile and Efficient Domain-Specific Languages using Multi-stage Programming in Java Mint&#8220;, which Eddy and I proposed, has been accepted at GPCE 2010. I&#8217;m looking forward to being in Eindhoven in October. Before that, on &#8230; <a href="http://www.concurrentaffair.org/2010/08/15/im-going-to-eindhoven/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.cs.rice.edu/~mgricken/research/mint/">Java Mint</a> tutorial lecture called &#8220;<a href="http://www.concurrentaffair.org/2010/08/15/tutorial-lecture-agile-and-efficient-domain-specific-languages-using-multi-stage-programming-in-java-mint/">Agile and Efficient Domain-Specific Languages using Multi-stage Programming in Java Mint</a>&#8220;, which Eddy and I proposed, has been accepted at <a href="http://program-transformation.org/GPCE10/Tutorial4AgileEfficientDSLs">GPCE 2010</a>.</p>

<p>I&#8217;m looking forward to being in <a href="http://goo.gl/maps/1quA">Eindhoven</a> in October. Before that, on September 20, Eddy and I will have an opportunity to practice the lecture in our <a href="http://www.clear.rice.edu/comp600/">COMP 600 Graduate Research Seminar.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/08/15/im-going-to-eindhoven/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tutorial Lecture: Agile and Efficient Domain-Specific Languages using Multi-stage Programming in Java Mint</title>
		<link>http://www.concurrentaffair.org/2010/08/15/tutorial-lecture-agile-and-efficient-domain-specific-languages-using-multi-stage-programming-in-java-mint/</link>
		<comments>http://www.concurrentaffair.org/2010/08/15/tutorial-lecture-agile-and-efficient-domain-specific-languages-using-multi-stage-programming-in-java-mint/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 00:29:52 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[Publications]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2115</guid>
		<description><![CDATA[Agile and Efficient Domain-Specific Languages using Multi-stage Programming in Java Mint (PDF, view embedded) Mathias Ricken and Edwin Westbrook A tutorial lecture to be presented at the Ninth International Conference on Generative Programming and Component Engineering (GPCE&#8217;10) October 10-13, 2010 &#8230; <a href="http://www.concurrentaffair.org/2010/08/15/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><a href="http://www.cs.rice.edu/~mgricken/research/mint/download/mint-gpce2010-tutorial.pdf">Agile and Efficient Domain-Specific Languages using Multi-stage Programming in Java Mint</a>
(PDF, <a href="http://www.cs.rice.edu/~mgricken/view-pdf.shtml?http://www.cs.rice.edu/~mgricken/research/mint/download/mint-gpce2010-tutorial.pdf">view embedded</a>)</p>

<p>Mathias Ricken and Edwin Westbrook</p>

<p>A tutorial lecture to be presented at the</p>

<p><a href="http://program-transformation.org/GPCE10/Tutorial4AgileEfficientDSLs">Ninth International Conference on
Generative Programming and Component Engineering (GPCE&#8217;10)</a></p>

<p>October 10-13, 2010<br />
Eindhoven, The Netherlands</p>

<p>Abstract</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.</p>

<p>Author 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>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/08/15/tutorial-lecture-agile-and-efficient-domain-specific-languages-using-multi-stage-programming-in-java-mint/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>drjava.org Temporarily Unavailable</title>
		<link>http://www.concurrentaffair.org/2010/08/14/drjava-org-temporarily-unavailable/</link>
		<comments>http://www.concurrentaffair.org/2010/08/14/drjava-org-temporarily-unavailable/#comments</comments>
		<pubDate>Sat, 14 Aug 2010 20:01:09 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[DrJava]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2109</guid>
		<description><![CDATA[Our DrJava website is currently not available under the usual address (http://drjava.org). We are working on fixing this problem as quickly as possible. If you need access to the DrJava website in the meantime, please use one of these two &#8230; <a href="http://www.concurrentaffair.org/2010/08/14/drjava-org-temporarily-unavailable/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Our <a href="http://drjava.org">DrJava website</a> is currently not available under <a href="http://drjava.org">the usual address</a> (<a href="http://drjava.org">http://drjava.org</a>). We are working on fixing this problem as quickly
as possible.</p>

<p>If you need access to the DrJava website in the meantime, please use one of these two URLs instead:</p>

<p><a href="http://drjava.sourceforge.net/">http://drjava.sourceforge.net/</a>
<a href="http://www.cs.rice.edu/~javaplt/drjava/">http://www.cs.rice.edu/~javaplt/drjava/</a></p>

<p>We apologize for the inconvenience. Thanks for using DrJava!</p>

<p><strong>Update</strong></p>

<p>At some point during the morning of August 15, the domain started working again. We are happy to report that our <a href="http://drjava.org">website</a> is available again under the usual address: <a href="http://drjava.org">http://drjava.org</a> .</p>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/08/14/drjava-org-temporarily-unavailable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rice University Virtual Tour</title>
		<link>http://www.concurrentaffair.org/2010/08/09/rice-university-virtual-tour/</link>
		<comments>http://www.concurrentaffair.org/2010/08/09/rice-university-virtual-tour/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 15:48:50 +0000</pubDate>
		<dc:creator>Mathias</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.concurrentaffair.org/?p=2101</guid>
		<description><![CDATA[These are really cool panorama pictures of my university: Experience Rice University&#8217;s 300-acre campus and its urban surroundings by taking our virtual tour http://bit.ly/a7Yt0I If you click on the fourth image from the left in the navigation bar at the &#8230; <a href="http://www.concurrentaffair.org/2010/08/09/rice-university-virtual-tour/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>These are really cool panorama pictures of my university:</p>

<blockquote>Experience Rice University&#8217;s 300-acre campus and its urban surroundings by taking our virtual tour <a href="http://bit.ly/a7Yt0I">http://bit.ly/a7Yt0I</a></blockquote>

<p><br/>
If you click on the fourth image from the left in the navigation bar at the bottom, you can see my office building, Duncan Hall.</p>

<div id="attachment_2105" class="wp-caption aligncenter" style="width: 510px"><a href="http://www.rice.edu/virtualtours/campus/tourfiles/flash/index_fs.html"><img src="http://www.concurrentaffair.org/wp-content/uploads/2010/08/duncan-e1281369260766.jpg" alt="Duncan Hall at Rice University" title="duncan" width="500" height="463" class="size-full wp-image-2105" /></a><p class="wp-caption-text">Duncan Hall at Rice University</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.concurrentaffair.org/2010/08/09/rice-university-virtual-tour/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
