Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

+ Compiles assignment, wraps output with a small driver script that P…

…review displays
  • Loading branch information...
commit 728a78705105198255c8035b906d0e87a9d89839 1 parent 2723ab3
@kschiess authored
Showing with 28 additions and 1 deletion.
  1. +20 −1 bin/wt
  2. +3 −0  lib/wt/ast.rb
  3. +5 −0 spec/wt/compiler_spec.rb
View
21 bin/wt
@@ -4,5 +4,24 @@ $:.unshift File.dirname(__FILE__) + "/../lib"
require 'wt'
compiler = Wt::Compiler.new()
-p compiler.compile(ARGV.join(' '))
+output = compiler.compile(ARGV.join(' '))
+
+puts %Q{
+ %!PS
+ /Courier % name the desired font
+ 20 selectfont % choose the size in points and establish
+ % the font as the current one
+ 72 500 moveto % position the current point at
+ % coordinates 72, 500 (the origin is at the
+ % lower-left corner of the page)
+
+ /nstr 7 string def
+ /prt-n % stack: n
+ { nstr cvs show } def
+
+ (the answer is ) show
+ #{output} prt-n
+
+ showpage % print all on the page
+}
View
3  lib/wt/ast.rb
@@ -21,5 +21,8 @@ def compile
end
class Assign < Struct.new(:ident, :exp)
+ def compile
+ "/#{ident} #{exp.compile} def #{ident}"
+ end
end
end
View
5 spec/wt/compiler_spec.rb
@@ -10,4 +10,9 @@
it { should == '1 2 add'}
end
+ context "assignment" do
+ let(:source) { 'a = 1' }
+
+ it { should == '/a 1 def a'}
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.