SMC(The State Machine Compiler)を試す その3

テキストで書いた状態遷移マップから
Cのコードを生成し、実行、出力コードの解析までできました。

今回は他の言語も試してみます。

各言語のサンプルEX1はC版と同じで0*1*をチェックする
状態遷移機械です。

C++

%cd examples/C++/EX1
%make
java -jar ../../../bin/Smc.jar -c++ -g     AppClass.sm
c++ -g -Wall -Wextra -I../../../lib/C++ -o checkstring AppClass_sm.cpp AppClass.cpp Main.cpp

% ./checkstring.exe 001
The string "001" is acceptable.

% ./checkstring.exe 001119 0
The string "010" is not acceptable.

% ./checkstring.exe 01010190000
The string "100" is not acceptable.

GNU c++コンパイルしましたが問題なく動作しました。
C++版サンプルは、VC++でもビルドできるように
プロジェクトワークスペースを用意してくれてあります(ex1.dsw)。

Perl

%cd examples/Perl/EX1
%make
java -jar ../../../bin/Smc.jar -perl -g  AppClass.sm

% perl -I ../../../lib/Perl/lib checkstring.pl 
Can't locate DFA/Statemap.pm in @INC (@INC contains: ...

Statemap.pmが見つからないようです。ふむ。

% perl -I ../../../lib/Perl/lib checkstring.pl
Can't locate DFA/Statemap.pm in @INC (@INC contains: ...

ライブラリをmake installするとDFAというフォルダに
コピーするようです。
とりあえずは以下のようにごまかしました。

% diff -u AppClass_sm.pm.org AppClass_sm.pm
--- AppClass_sm.pm.org  2012-03-27 21:35:26.640625000 +0900
+++ AppClass_sm.pm      2012-03-27 21:35:58.859375000 +0900
@@ -6,7 +6,7 @@
 use strict;
 use warnings;

-use DFA::Statemap;
+use Statemap;

 package AppClassState;
     use base qw(DFA::Statemap::State);


% perl -I ../../../lib/Perl checkstring.pl 0010101
The string "0001" is acceptable.
% perl -I ../../../lib/Perl checkstring.pl 000110
The string "0010" is not acceptable.
% perl -I ../../../lib/Perl checkstring.pl 001001101
The string "0011" is acceptable.

動きました。

Ruby

% make
java -jar ../../../bin/Smc.jar -ruby -g  AppClass.sm
% cp ../../../lib/Ruby/statemap.rb .

% ruby checkstring.rb 001
The string "001" is acceptable.
% ruby checkstring.rb 001 
The string "00" is acceptable.
% ruby checkstring.rb 0010
The string "010" is not acceptable.


動きました。

Python

% make
java -jar ../../../bin/Smc.jar -python -g  AppClass.sm
bash-3.2$ cp ../../li  ../lib/Python/
Makefile     README.txt   setup.py     statemap.py  
% cp ../../../lib/Python/statemap.py .
% python checkstring.py 
No string to check.

% python checkstring.py 010
The string "010" is not acceptable.

% python checkstring.py 010   000
The string "000" is acceptable.

動きました。

C++PerlRubyPythonでサンプルが正しく動きました。

では次回はRubyのサンプルをもう少し見ていこうと思います。