Return to asir2string.pl CVS log | Up to [local] / OpenXM / misc |
File: [local] / OpenXM / misc / asir2string.pl (download)
Revision 1.1, Wed Sep 3 06:28:48 2008 UTC (15 years, 10 months ago) by ohara
A converter from asir program to string. The string can be accepted at eval_str and ox_executeString. Note that the converter has restrictions. See the source for detail. |
#!/usr/bin/perl # $OpenXM: OpenXM/misc/asir2string.pl,v 1.1 2008/09/03 06:28:48 ohara Exp $ ## asir のプログラムを(できるだけ短い)文字列形式に書き換える. ## usage: asir2string.pl example.rr example.txt ## Bugs: (1) 文字列リテラルの内部も改変されてしまう. ## (2) トークンの境界を無視する. 例えば ## 「A = B + +C」 が 「A=B++C」となる. sub main { ($_) = @_; s#/\*.*?\*/##gs ; s#\\#\\\\#gs ; s#\s+# #gs ; s#end[\$;].*$##gs ; s#"#\\"#gs ; s#\s?([,=;<>\[\]\(\){}\+\-\*/%])\s?#\1#gs ; s#^\s?#"#gs ; s#\s?$#"#gs ; return $_; } local $/; open(STDIN, $ARGV[0]) if @ARGV > 0 ; open(STDOUT, '>' . $ARGV[1]) if @ARGV > 1; my $buffer; $buffer = <STDIN>; $buffer = main $buffer; print $buffer;