<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Nuo Yan : 5. Programming</title><link>http://msmvps.com/blogs/nuoyan/archive/tags/5.+Programming/default.aspx</link><description>Tags: 5. Programming</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>Class instance variable for ruby modules</title><link>http://msmvps.com/blogs/nuoyan/archive/2009/08/20/class-instance-variable-for-ruby-modules.aspx</link><pubDate>Fri, 21 Aug 2009 05:54:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1717034</guid><dc:creator>Nuo Yan</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/nuoyan/rsscomments.aspx?PostID=1717034</wfw:commentRss><comments>http://msmvps.com/blogs/nuoyan/archive/2009/08/20/class-instance-variable-for-ruby-modules.aspx#comments</comments><description>&lt;p&gt;Sorry if the title is a bit misleading, but this post talks about the scenario such that I have several classes, all extending the same module, and I need to avoid using shared or class variables (@@) in the module because the classes extending the module may change the shared or class variable at the same time and cause problem.&lt;/p&gt;
&lt;p&gt;So basically we have:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;class Test&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;extend TestModule&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;end&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;class TestTwo&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;extend TestModule&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;end&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;module TestModule&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;@@val&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;def somemethod&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; #do something with @@val&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;end&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;end&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And the goal is the replace the @@val class variable with a class instance variable so that if the Test.somemethod and TestTwo.somemethod happens at the same time, there won&amp;#39;t be any problem.&lt;/p&gt;
&lt;p&gt;The easiest way (I can think of) of doing this is to set the variable within the class, instead of setting it in the module. For example:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;class Test&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;@val = &amp;quot;abc&amp;quot;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;class &amp;lt;&amp;lt; self; attr_accessor :val; end&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;extend TestModule&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;end&amp;nbsp;&lt;/p&gt;
&lt;p&gt;But the problem of doing this is that everybody else using TestModule will need to update their code after this update, which is unacceptable.&lt;/p&gt;
&lt;p&gt;Is there a way to move the variable definition and accessor to the module and has exactly the same effect as defining them in the class? Yes. define the self.extended(base) method.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;module TestModule&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;def self.extended(base)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;class &amp;lt;&amp;lt; base; attr_accessor :val; end&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;base.val = &amp;quot;abc&amp;quot;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;end&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;def somemethod&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; #do something with self.val&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;end&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;end&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;class Test&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;extend TestModule&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;end&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here base refers to the class extending this module. self. extended is called when the module is initialized, and the accessors for the base class is then created (&lt;i&gt;class &amp;lt;&amp;lt; base; attr_accessor :val; end&lt;/i&gt;), &lt;i&gt;base.val = abc&lt;/i&gt; sets the default value.&lt;/p&gt;
&lt;p&gt;By doing it this way, the module works exactly the same as before, and multiple classes can extend it and call the same method without affecting each other.&lt;/p&gt;
&lt;p&gt;Hope this helps.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1717034" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/nuoyan/archive/tags/5.+Programming/default.aspx">5. Programming</category></item><item><title>Don't forget the port number when replicating CouchDB</title><link>http://msmvps.com/blogs/nuoyan/archive/2009/07/16/don-t-forget-the-port-number-when-replicating-couchdb.aspx</link><pubDate>Fri, 17 Jul 2009 02:52:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1702470</guid><dc:creator>Nuo Yan</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/nuoyan/rsscomments.aspx?PostID=1702470</wfw:commentRss><comments>http://msmvps.com/blogs/nuoyan/archive/2009/07/16/don-t-forget-the-port-number-when-replicating-couchdb.aspx#comments</comments><description>&lt;p&gt;In the afternoon I needed to replicate a database &amp;nbsp;from my co-worker&amp;#39;s CoudhDB using CouchDBX. In the replicator, I entered my co-worker&amp;#39;s database&amp;#39;s path like the following:&lt;/p&gt;
&lt;p&gt;http://10.0.0.3/TestDatabase&lt;/p&gt;
&lt;p&gt;And I selected to replicate to one of my existing databases. &amp;nbsp;Everything seemed to be right (I could ping and telnet my co-worker&amp;#39;s IP and CouchDB port 5984 without problem), but CouchDBX returned error 500, could not connect to remote database.&lt;/p&gt;
&lt;p&gt;After a series of diagnostics, we finally realized, we forgot to put the port number in the path of remote database. When we changed the database path to&amp;nbsp;http://10.0.0.3:5984/TestDatabase, &amp;nbsp;everything just worked very well.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m sharing this since I bet many people may encounter the same problem. Hope this is helpful.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1702470" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/nuoyan/archive/tags/5.+Programming/default.aspx">5. Programming</category></item><item><title>Creating a Merb Rack middleware for running in Merb applications</title><link>http://msmvps.com/blogs/nuoyan/archive/2009/07/13/creating-a-merb-rack-middleware-for-running-in-merb-applications.aspx</link><pubDate>Tue, 14 Jul 2009 03:54:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1700726</guid><dc:creator>Nuo Yan</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/nuoyan/rsscomments.aspx?PostID=1700726</wfw:commentRss><comments>http://msmvps.com/blogs/nuoyan/archive/2009/07/13/creating-a-merb-rack-middleware-for-running-in-merb-applications.aspx#comments</comments><description>&lt;p&gt;There are a lot of resources on the Internet showing how to write and run a standalone rack application or middleware, but few showing how to write one to run in other Merb applications. This is actually very easy, so I&amp;#39;m going to share how I did it. Hopefully to be helpful to people in such need.&lt;/p&gt;
&lt;p&gt;The goal is to have a rack middleware in a merb application, which can be installed as gem, and then can be ued in other merb applications.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;First&lt;/b&gt;, create the merb application:&lt;/p&gt;
&lt;pre&gt;$ merb-gen app  application_name &lt;/pre&gt;
&lt;p&gt;where application_name is your proposed application name.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Second&lt;/b&gt;, create your code folder and ruby file. I created a &amp;quot;lib&amp;quot; folder to be the container of my middlewares.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Third&lt;/b&gt;, open the ruby file and write your middleware. (In this example, let&amp;#39;s name&amp;nbsp; it samplemiddleware.rb within the &amp;quot;lib/test&amp;quot; folder)&lt;/p&gt;
&lt;p&gt;The class could inherit Merb::Rack::Middleware if you want. Below is an example.&lt;/p&gt;
&lt;p&gt;module Test&lt;br /&gt;&amp;nbsp; class SampleMiddleware &amp;lt; Merb::Rack::Middleware&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def initialize(app)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @app = app&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def deferred?(env)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @app.deferred?(env) if @app.respond_to?(:deferred?)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def call(env)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; puts &amp;quot;do something here&amp;quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @app.call(env)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp; end&lt;br /&gt;end&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Fourth&lt;/b&gt;, write your rake file, so the rack middleware merb application can be installed as a gem.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Fifth&lt;/b&gt;, install the gem.&lt;/p&gt;
&lt;p&gt;So far we finished the middleware, now we go to the other merb application which we want the middleware to run within. Assuming the merb application has a rack configuration file (rack.rb) under the &amp;quot;config&amp;quot; folder. Open this file. &lt;/p&gt;
&lt;p&gt;We need to require our middleware, in this case:&lt;/p&gt;
&lt;pre&gt;require &amp;#39;test/samplemiddleware.rb&amp;#39;&amp;#39;&lt;/pre&gt;
&lt;p&gt;And then use the middleware in the same file:&lt;/p&gt;
&lt;pre&gt;use Test::SampleMiddleware&lt;/pre&gt;
&lt;p&gt;Finally remember to have a line to run the Merb::Rack application (should already have it):&lt;/p&gt;
&lt;pre&gt;run Merb::Rack::Application.new&lt;/pre&gt;
&lt;p&gt;Now when the merb application runs, the rack middleware you wrote and installed will run as well. It&amp;#39;s handy to use the middleware to process requests in your Merb applications before Merb handles the requests.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1700726" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/nuoyan/archive/tags/5.+Programming/default.aspx">5. Programming</category></item><item><title>Modify bind address for couchdb 0.9.0</title><link>http://msmvps.com/blogs/nuoyan/archive/2009/05/28/modify-bind-address-for-couchdb-0-9-0.aspx</link><pubDate>Thu, 28 May 2009 23:21:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1693353</guid><dc:creator>Nuo Yan</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/nuoyan/rsscomments.aspx?PostID=1693353</wfw:commentRss><comments>http://msmvps.com/blogs/nuoyan/archive/2009/05/28/modify-bind-address-for-couchdb-0-9-0.aspx#comments</comments><description>&lt;p&gt;By default couchdb only binds to 127.0.0.1 so it&amp;#39;s not accepting requests from other IP addresses. The bind address setting can be modified in the configuration file. For 0.9.0, by default, the default configuration file is located at /usr/local/etc/couchdb/default.ini, and the local configuration file is located at /usr/local/etc/couchdb/local.ini. Settings in the local configuration file will override those in the default one.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Bind address is in the [httpd] section&lt;/p&gt;
&lt;p&gt;
&lt;p&gt;[httpd]&lt;/p&gt;
&lt;p&gt;port = 5984&lt;/p&gt;
&lt;p&gt;bind_address = 127.0.0.1&lt;/p&gt;
&lt;p&gt;Note that in the local configuration file, this may be commented out with a leading &amp;quot;;&amp;quot;, if you want to set it in the local configuration file, you need to uncomment the bind_address line and modify 127.0.0.1 to some other IP address.&lt;/p&gt;
&lt;p&gt;If you modify the bind address to 0.0.0.0, it will bind all interfaces.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1693353" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/nuoyan/archive/tags/8.+Other+_2800_Technical_2900_/default.aspx">8. Other (Technical)</category><category domain="http://msmvps.com/blogs/nuoyan/archive/tags/5.+Programming/default.aspx">5. Programming</category></item><item><title>Making an executable standalone Merb Slice gem</title><link>http://msmvps.com/blogs/nuoyan/archive/2009/05/21/making-a-executable-standalone-merb-slice-gem.aspx</link><pubDate>Thu, 21 May 2009 07:31:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1692836</guid><dc:creator>Nuo Yan</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/nuoyan/rsscomments.aspx?PostID=1692836</wfw:commentRss><comments>http://msmvps.com/blogs/nuoyan/archive/2009/05/21/making-a-executable-standalone-merb-slice-gem.aspx#comments</comments><description>&lt;p&gt;I have a standalone Merb Slice which can be started by running the &amp;quot;slice&amp;quot; command in its top directory. Today I needed to make a gem file for this Slice so that people can install the gem and start it directly by running the Slice&amp;#39;s name, for example, &amp;quot;foo&amp;quot;. &lt;/p&gt;
&lt;p&gt;So I created the Rakefile, in which I specified the executable file in the following way:&lt;/p&gt;
&lt;p&gt;&lt;b&gt;--- Code: Rakefile ---&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;spec = Gem::Specification.new do |s|&lt;br /&gt;&amp;nbsp; s.rubyforge_project = &amp;#39;merb&amp;#39;&lt;br /&gt;&amp;nbsp; s.name = GEM_NAME&lt;br /&gt;&amp;nbsp; s.version = GEM_VERSION&lt;br /&gt;&amp;nbsp; s.platform = Gem::Platform::RUBY&lt;br /&gt;&amp;nbsp; s.has_rdoc = false&lt;br /&gt;&amp;nbsp; s.summary = SUMMARY&lt;br /&gt;&amp;nbsp; s.description = s.summary&lt;br /&gt;&amp;nbsp; s.author = AUTHOR&lt;br /&gt;&amp;nbsp; s.email = EMAIL&lt;br /&gt;&amp;nbsp; s.homepage = HOMEPAGE&lt;br /&gt;&lt;b&gt;&amp;nbsp; s.executables = &amp;quot;foo&amp;quot;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; s.require_path = &amp;#39;lib&amp;#39;&lt;br /&gt;&amp;nbsp; s.autorequire = GEM_NAME&lt;br /&gt;&amp;nbsp; s.files = %w(Rakefile TODO) + Dir.glob(&amp;quot;{config,lib,spec,app,data,public}/**/*&amp;quot;)&lt;br /&gt;end&lt;/p&gt;
&lt;p&gt;Then I created a &lt;b&gt;bin&lt;/b&gt; folder within the Slice&amp;#39;s top directory, and created a file named &amp;quot;&lt;b&gt;foo&lt;/b&gt;&amp;quot; within the &lt;b&gt;bin&lt;/b&gt; folder I put Merb.start in the file &amp;quot;foo&amp;quot;, and I tried to make a gem and installed it. But the Slice &lt;span style="text-decoration:underline;"&gt;did not start correctly this way.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Then I spent a while trying different possibilities, and with somebody&amp;#39;s help, I finally got the right way of doing it.&lt;/p&gt;
&lt;p&gt;1. look up the location of merb-slices. This can be done by executing &lt;i&gt;gem list - d | grep merb-slices&lt;/i&gt;.&lt;/p&gt;
&lt;p&gt;2. locate a file named &amp;quot;&lt;b&gt;slice&lt;/b&gt;&amp;quot; under the &lt;b&gt;bin&lt;/b&gt; folder of merb-slices.&lt;/p&gt;
&lt;p&gt;3. copy the contents of this file to the file you have in your Slice&amp;#39;s bin folder, and amend from that (you may want to remove or change the Merb::Config.use block since your own Slice may have that set somewhere else, for example, in init.rb).&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Depending on how you amend the slice binary file, you may encouter a situation that your executable is only able to run within the source folder. For example, if you run &amp;quot;foo&amp;quot; in your Slice&amp;#39;s source folder, it becomes equivalent as running &amp;quot;slice&amp;quot;, but if you run it anywhere else, it fails with the error &amp;quot;No slice found&amp;quot;. If this happens, what you need to do is change the following things in your &amp;quot;foo&amp;quot; binary file:&lt;/p&gt;
&lt;p&gt;1. Change __DIR__ (originally assigned to current directory):&lt;/p&gt;
&lt;p&gt;Dir.chdir File.join(File.dirname(__FILE__),&amp;quot;..&amp;quot;)&lt;br /&gt;__DIR__ = Dir.getwd&lt;/p&gt;
&lt;p&gt;2. Update slice_name:&lt;/p&gt;
&lt;p&gt;slice_name = &amp;quot;foo&amp;quot;&lt;/p&gt;
&lt;p&gt;3. Add a line before &lt;i&gt;Merb.start&lt;/i&gt; to specify the right init file to load:&lt;/p&gt;
&lt;p&gt;ARGV.push *[ &amp;quot;-I&amp;quot;, File.join(File.dirname(__FILE__), &amp;quot;..&amp;quot;, &amp;quot;config&amp;quot;, &amp;quot;init.rb&amp;quot;) ]&lt;/p&gt;
&lt;p&gt;&lt;i&gt;Note: &lt;/i&gt;This assumes init.rb is under config folder of your Slice project.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1692836" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/nuoyan/archive/tags/5.+Programming/default.aspx">5. Programming</category></item><item><title>Testing exceptions with RSpec</title><link>http://msmvps.com/blogs/nuoyan/archive/2009/04/20/testing-exceptions-with-rspec.aspx</link><pubDate>Mon, 20 Apr 2009 22:54:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1689087</guid><dc:creator>Nuo Yan</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/nuoyan/rsscomments.aspx?PostID=1689087</wfw:commentRss><comments>http://msmvps.com/blogs/nuoyan/archive/2009/04/20/testing-exceptions-with-rspec.aspx#comments</comments><description>&lt;p&gt;I&amp;#39;m new to ruby and rspec. I wrote a ruby function and wanted to check whether it throws an exception or not in a certain situation with rspec, but I realized should_raise function no longer worked in the rspec version I was&amp;nbsp;using (1.2.2). I tried to find information on the Internet and I found that I should use raise_error.&lt;/p&gt;
&lt;p&gt;However, when I wrote something like:&lt;/p&gt;
&lt;p&gt;it &amp;quot;description&amp;quot; do&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ObjectName.new(&amp;quot;parameterName&amp;quot;).should raise_error &lt;br /&gt;end&lt;/p&gt;
&lt;p&gt;It did not work. Finally I learned the correct way - using lambda:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;it &lt;/strong&gt;&amp;quot;description&amp;quot; &lt;strong&gt;do&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lambda{&lt;/strong&gt;ObjectName.new(&amp;quot;parameterName&amp;quot;)&lt;strong&gt;}.should raise_error &lt;br /&gt;end&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Wanted to post this here and hope it can be helpful for people in the similar need.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1689087" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/nuoyan/archive/tags/5.+Programming/default.aspx">5. Programming</category></item><item><title>Using Eclipse to add/update files to CVS</title><link>http://msmvps.com/blogs/nuoyan/archive/2009/02/10/using-eclipse-to-add-update-files-to-cvs.aspx</link><pubDate>Wed, 11 Feb 2009 01:31:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1671301</guid><dc:creator>Nuo Yan</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/nuoyan/rsscomments.aspx?PostID=1671301</wfw:commentRss><comments>http://msmvps.com/blogs/nuoyan/archive/2009/02/10/using-eclipse-to-add-update-files-to-cvs.aspx#comments</comments><description>&lt;p style="MARGIN:0in 0in 10pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;The command-line based CVS tool is hard to use for first time users; many GUI-based CVS tools are not really well designed to be easy to use either. I&amp;rsquo;m not against the point that developers and testers should learn how to use a technical tool in no time even though the tool is hard to use, but developers and testers have their schedules and need to be efficient. Having an efficient way to add and update files to CVS is very necessary.&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 10pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;Eclipse is the tool I use to deal with CVS file operations. It works really well not only with source code, but any other file type. &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 10pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;For example, if you want to upload a Microsoft Word document (docx) to a remote CVS repository, simply follow the following steps:&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 0pt 0.5in;TEXT-INDENT:-0.25in;mso-list:l0 level1 lfo1;" class="MsoListParagraphCxSpFirst"&gt;&lt;span style="mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-theme-font:minor-latin;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;1.&lt;/span&gt;&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;In Eclipse, import the remote CVS repository by using the Import wizard:&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 0pt 1in;TEXT-INDENT:-0.25in;mso-list:l0 level2 lfo1;mso-add-space:auto;" class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-theme-font:minor-latin;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;a.&lt;/span&gt;&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;Click File-&amp;gt;Import&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 0pt 1in;TEXT-INDENT:-0.25in;mso-list:l0 level2 lfo1;mso-add-space:auto;" class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-theme-font:minor-latin;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;b.&lt;/span&gt;&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;Choose &amp;ldquo;Projects from CVS&amp;rdquo; and click Next&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 0pt 1in;TEXT-INDENT:-0.25in;mso-list:l0 level2 lfo1;mso-add-space:auto;" class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-theme-font:minor-latin;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;c.&lt;/span&gt;&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;Depends on real situation, either select &amp;ldquo;Create a new repository location&amp;rdquo; or &amp;ldquo;Use an existing repository location&amp;rdquo;. In this example, we use an existing repository location because we want to add the Microsoft Word document to an existing CVS repository. Click Next.&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 10pt 1in;TEXT-INDENT:-0.25in;mso-list:l0 level2 lfo1;mso-add-space:auto;" class="MsoListParagraphCxSpLast"&gt;&lt;span style="mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-theme-font:minor-latin;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;d.&lt;/span&gt;&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:small;"&gt;&lt;span style="font-family:Calibri;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/span&gt;Select &amp;ldquo;Use an existing module&amp;rdquo;, and navigate the tree list to find the repository you want to add the file to. Click Next.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 10pt 1in;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;em&gt; If you need to upload different files to different subfolders (repositories) within a folder (repository), it&amp;rsquo;s often useful to select the parent folder in this step so you don&amp;rsquo;t need to run this wizard every time for each of the subfolders.&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 0pt 1in;TEXT-INDENT:-0.25in;mso-list:l0 level2 lfo1;mso-add-space:auto;" class="MsoListParagraphCxSpFirst"&gt;&lt;span style="mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-theme-font:minor-latin;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;e.&lt;/span&gt;&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:small;"&gt;&lt;span style="font-family:Calibri;"&gt;Follow the remaining steps in the wizard to finish the import process. Selecting &amp;ldquo;Check out as a project in the workspace&amp;rdquo; is the easiest way to import the repository to a new project. If you want to import it into your existing project, select &amp;ldquo;Check out into existing project.&amp;rdquo; &lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 0pt 1in;mso-add-space:auto;" class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="DISPLAY:none;MARGIN:0in 0in 0pt 0.5in;TEXT-INDENT:-0.25in;mso-list:l1 level1 lfo2;" class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="DISPLAY:none;mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-theme-font:minor-latin;mso-hide:all;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 0pt 0.5in;TEXT-INDENT:-0.25in;mso-list:l1 level1 lfo2;" class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-theme-font:minor-latin;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;2.&lt;/span&gt;&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;Import the file(s) you want to add/update to the CVS repository to the appropriate folders:&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 0pt 1in;TEXT-INDENT:-0.25in;mso-list:l1 level2 lfo2;mso-add-space:auto;" class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-theme-font:minor-latin;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;a.&lt;/span&gt;&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;In the Project Explorer, expand the folder you just checked out from CVS, right click the folder you want to add the new file to, and click &amp;ldquo;Import&amp;rdquo; from the context menu.&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 0pt 1in;TEXT-INDENT:-0.25in;mso-list:l1 level2 lfo2;mso-add-space:auto;" class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-theme-font:minor-latin;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;b.&lt;/span&gt;&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;Select &amp;ldquo;File System&amp;rdquo; and click Next.&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 0pt 1in;TEXT-INDENT:-0.25in;mso-list:l1 level2 lfo2;mso-add-space:auto;" class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-theme-font:minor-latin;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;c.&lt;/span&gt;&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;Click &amp;ldquo;Browse&amp;hellip;&amp;rdquo; to browse the folder containing the file you want to add or update to CVS. &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 0pt 1in;TEXT-INDENT:-0.25in;mso-list:l1 level2 lfo2;mso-add-space:auto;" class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-theme-font:minor-latin;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;d.&lt;/span&gt;&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;Select the files, and click &amp;ldquo;Finish&amp;rdquo;.&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 0pt 1in;TEXT-INDENT:-0.25in;mso-list:l1 level2 lfo2;mso-add-space:auto;" class="MsoListParagraphCxSpMiddle"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 0pt 1in;TEXT-INDENT:-0.25in;mso-list:l1 level2 lfo2;mso-add-space:auto;" class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 10pt 0.5in;TEXT-INDENT:-0.25in;mso-list:l1 level1 lfo2;" class="MsoListParagraphCxSpLast"&gt;&lt;span style="mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-theme-font:minor-latin;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;3.&lt;/span&gt;&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;Now the file(s) you want to add or update to CVS are in the appropriate folders. Right click each file, and click Team-&amp;gt; Commit to commit the file to the corresponding remote CVS repository. &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 10pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;Hope this helps.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1671301" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/nuoyan/archive/tags/8.+Other+_2800_Technical_2900_/default.aspx">8. Other (Technical)</category><category domain="http://msmvps.com/blogs/nuoyan/archive/tags/5.+Programming/default.aspx">5. Programming</category></item><item><title>Book Recommendation</title><link>http://msmvps.com/blogs/nuoyan/archive/2007/05/29/book-recommendation.aspx</link><pubDate>Wed, 30 May 2007 06:04:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:933440</guid><dc:creator>Nuo Yan</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/nuoyan/rsscomments.aspx?PostID=933440</wfw:commentRss><comments>http://msmvps.com/blogs/nuoyan/archive/2007/05/29/book-recommendation.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=1556155514%26tag=nuoyanslife-20%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/1556155514%253FSubscriptionId=1KDHEGDEXZNBKYAEECR2"&gt;&lt;font color="#669966"&gt;Writing Solid Code: Microsoft&amp;#39;s Techniques for Developing Bug-Free C Programs (Microsoft Programming Series)&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Yes it&amp;#39;s an old book which was published in 1993, but it&amp;#39;s really awesome! I first got this book&amp;nbsp;in last&amp;nbsp;Saturday night, then I spent several hours finished reading it. I just couldn&amp;#39;t stop until I finished!&lt;/p&gt;
&lt;p&gt;I recommend every C programmer to read it, if you haven&amp;#39;t done so yet.&lt;/p&gt;
&lt;p&gt;Nuo&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=933440" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/nuoyan/archive/tags/5.+Programming/default.aspx">5. Programming</category></item><item><title>Calculating Required Storage In a Direct-Mapped Cache</title><link>http://msmvps.com/blogs/nuoyan/archive/2007/05/03/calculating-required-storage-in-a-direct-mapped-cache.aspx</link><pubDate>Fri, 04 May 2007 04:58:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:889813</guid><dc:creator>Nuo Yan</dc:creator><slash:comments>13</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/nuoyan/rsscomments.aspx?PostID=889813</wfw:commentRss><comments>http://msmvps.com/blogs/nuoyan/archive/2007/05/03/calculating-required-storage-in-a-direct-mapped-cache.aspx#comments</comments><description>&lt;p&gt;Suppose a 1-level direct-mapped cache need to have 64 KB&amp;#39;s data, each block is 16-byte, and the memory address is 32-bit. &lt;/p&gt;
&lt;p&gt;To&amp;nbsp; calculate the total bits needed for the cache, we could go through &amp;nbsp;the following steps:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;We need to have 64 KB&amp;#39;s data (2^16 bytes) in the cache, and each block is sized as 16 bytes (2^4), so we totally need 2^12 blocks for the data, let&amp;#39;s call the &amp;quot;12&amp;quot; as &amp;quot;&lt;b&gt;a&lt;/b&gt;.&amp;quot; This means &lt;em&gt;a&lt;/em&gt; bits are used for the index.&lt;/li&gt;
&lt;li&gt;Each word has 4 bytes, then in this case each block has 2^2 words, let&amp;#39;s call the exponent 2 as &amp;quot;&lt;b&gt;b&lt;/b&gt;.&amp;quot; This means &lt;em&gt;b&lt;/em&gt; bits are used for word in each block.&lt;/li&gt;
&lt;li&gt;The size of the tag is determined by the equation &amp;quot;&lt;b&gt;&lt;i&gt;length of address - (a+b+2)&lt;/i&gt;&lt;/b&gt;,&amp;quot; the 2 bits here are the byte offset of the address. So, in this case, it&amp;#39;s &amp;quot;32 - (12+2+2) = 16.&amp;quot;&lt;/li&gt;
&lt;li&gt;Each block has 16 bytes, each byte has 8 bits, so the amount of data for each block is 16 * 8 + tag + valid bit = 128 + 16 + 1 = 145 bits.&lt;/li&gt;
&lt;li&gt;Times the amount of data for each block (145) to the number of blocks (2^12). Then we get 593920 Bits. Convert to KB, it is 72.5 KB.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;So 72.5 KB&amp;#39;s of data is required to make a 64KB 1-level direct-mapped cache .&lt;/p&gt;
&lt;p&gt;In general, the idea is very simple: &lt;b&gt;&lt;i&gt;total bits required = number of blocks * bits required for each block&lt;/i&gt;&lt;/b&gt;. Mistakes can usually be made during the process of calculating the size of the tag. Sometimes it&amp;#39;s also easy to forget to add the valid bit. But if doing it carefully, we could realize that the way of calculating it is quite simple.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=889813" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/nuoyan/archive/tags/5.+Programming/default.aspx">5. Programming</category></item><item><title>Notes on Compiler Constructions</title><link>http://msmvps.com/blogs/nuoyan/archive/2007/01/29/notes-on-compiler-constructions-cse-class-compiler-project-report.aspx</link><pubDate>Tue, 30 Jan 2007 01:13:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:527655</guid><dc:creator>Nuo Yan</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/nuoyan/rsscomments.aspx?PostID=527655</wfw:commentRss><comments>http://msmvps.com/blogs/nuoyan/archive/2007/01/29/notes-on-compiler-constructions-cse-class-compiler-project-report.aspx#comments</comments><description>&lt;H2 style="MARGIN:13pt 0in;"&gt;&lt;FONT face=Calibri size=3&gt;&lt;SPAN style="FONT-SIZE:12pt;LINE-HEIGHT:173%;"&gt;&lt;FONT face=Cambria&gt;Table of Contents:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/H2&gt;
&lt;P class=MsoListParagraph style="MARGIN:0in 0in 0pt 0.25in;TEXT-INDENT:-0.25in;mso-char-indent-count:0;mso-list:l0 level1 lfo1;"&gt;&lt;SPAN style="mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;1.&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;Introduction&lt;/P&gt;
&lt;P class=MsoListParagraph style="MARGIN:0in 0in 0pt 0.25in;TEXT-INDENT:-0.25in;mso-char-indent-count:0;mso-list:l0 level1 lfo1;"&gt;&lt;SPAN style="mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;2.&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;Overview of Compilers&lt;/P&gt;
&lt;P class=MsoListParagraph style="MARGIN:0in 0in 0pt 0.25in;TEXT-INDENT:-0.25in;mso-char-indent-count:0;mso-list:l0 level1 lfo1;"&gt;&lt;SPAN style="mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;3.&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;Scanner&lt;/P&gt;
&lt;P class=MsoListParagraph style="MARGIN:0in 0in 0pt 0.25in;TEXT-INDENT:-0.25in;mso-char-indent-count:0;mso-list:l0 level1 lfo1;"&gt;&lt;SPAN style="mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;4.&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;Parser and Code Generation&lt;/P&gt;
&lt;P class=MsoListParagraph style="MARGIN:0in 0in 0pt 0.25in;TEXT-INDENT:-0.25in;mso-char-indent-count:0;mso-list:l0 level1 lfo1;"&gt;&lt;SPAN style="mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;5.&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;Conclusions&lt;/P&gt;
&lt;P class=MsoListParagraph style="MARGIN:0in 0in 0pt 0.25in;TEXT-INDENT:0in;mso-char-indent-count:0;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;H2 style="MARGIN:13pt 0in;"&gt;&lt;SPAN style="FONT-SIZE:12pt;LINE-HEIGHT:173%;"&gt;&lt;FONT face=Cambria&gt;Introduction:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;This document briefly introduces the concepts and construction of programming language compilers. The document uses a simple programming language we named “D” for the purposes of this project, then goes through the process of constructing a full compiler for the “D” programming language. “D” only represents the name of the sample programming language used in this project, and has no relationship with any popular existing programming language. Code samples will be included in this document; however, since this document will be published on the Internet, to prevent future computer science students with similar assignments from plagiarizing any part of this paper, the full source code for the compiler project will not be included in this document. All source codes for the compiler in this document are written in C, and compiled using &lt;B style="mso-bidi-font-weight:normal;"&gt;gcc&lt;/B&gt; in Unix/Linux. The source code has also been tested for compilation under Windows NT (including 2000, XP, and Vista) using Visual C++ (including 6.0, 2003, and 2005). The X86 assembly language code presented in this documents uses the Microsoft/ Intel standard, which is different from the GNU/AT&amp;amp;T standard in some respects. This document is neither a course requirement, nor an assignment. All contents represent the author’s personal interests and the author provides no warranty.&lt;/P&gt;&lt;/FONT&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face=Calibri size=3&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face=Calibri size=3&gt;&lt;STRONG&gt;To view the full document, either:&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;
&lt;DIV class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face=Calibri size=3&gt;Download the attachment of this post, which is in *.zip format.&lt;/FONT&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face=Calibri size=3&gt;Click on the following link: &lt;/FONT&gt;&lt;FONT face=Calibri size=3&gt;&lt;A href="http://students.washington.edu/~nuoyan/compiler.pdf"&gt;http://students.washington.edu/~nuoyan/compiler.pdf&lt;/A&gt;.&lt;/FONT&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face=Calibri size=3&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face=Calibri size=3&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=527655" width="1" height="1"&gt;</description><enclosure url="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Components.PostAttachments/00.00.52.76.55/Revised_5F00_Final_5F00_Notes-on-Compiler-Constructions.zip" length="417628" type="application/x-zip-compressed" /><category domain="http://msmvps.com/blogs/nuoyan/archive/tags/7.+Writing+and+Project+Samples/default.aspx">7. Writing and Project Samples</category><category domain="http://msmvps.com/blogs/nuoyan/archive/tags/5.+Programming/default.aspx">5. Programming</category></item></channel></rss>