[BACK]Return to asir2string.pl CVS log [TXT][DIR] 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, 7 months ago) by ohara
Branch: MAIN
CVS Tags: R_1_3_1-2, RELEASE_1_3_1_13b, RELEASE_1_2_3_12, HEAD

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;