//?<tron>;

<compile>
	::sys<args #x>
	::sys<nth #inputfile #x 1>
	::sys<suffix #outputfile #inputfile c>
	<setVar inputfile #inputfile>
	<print inputfile #inputfile>
	<print outputfile #outputfile>
	::sys<openw #outputfile
		::sys<openr #inputfile <TinyRuby>>>
	;


<TinyRuby>				<print "#include <stdio.h>">
					<print "int main() {">
					<print "int a,b,c,d,e,f,g,h,i,j,k,l,m;">
					<print "int n,o,p,q,r,s,t,u,v,w,x,y,z;">
		<プログラム> <EOF>	<print "exit(0);">
					<print "}">
		;

<プログラム>    {[<実行文> { ";" <実行文>}] (<コメント> | <CR>)};


<実行文>        <if文> | <while文> | <print文> | <times文> | <代入文> ;


<if文>          "if" 			<x <errormsg "error if"><exit>>
					<printf "if (">
		<条件式>		<printf ") {" <¥_n>>
		<プログラム> 
		[ 
			"else" 		<printf "} else {" <¥_n>>
			<プログラム> 
		] 
		"end"			<printf "}" <¥_n>>
		;

<while文>       "while" 		<x <errormsg "error while"><exit>>
			 		<printf "while (">
		<条件式> 		<printf ") {" <¥_n>>
		<プログラム> 
		"end"			<printf "}" <¥_n>>
		;

<times文>       (<NUM #n> | <変数 #n>)
		"." "times"		<x <errormsg "error times"><exit>>
			 		<printf "{int ct; for (ct=0; ct<">
					<printf #n>
					<printf "; ct++) {" <¥_n>>
		"do"
		<プログラム> 
		"end"			<printf "}}" <¥_n>>
		;

<print文>       "print"			<x <errormsg "error print"><exit>>
		<表示項目> {","  <表示項目>};

<表示項目>	
		  <STRINGS #s>		<printf 'printf("%s", "' #s '");' <¥_n>>
		| <NUM #n>		<printf 'printf("%d ", ' #n ');' <¥_n>>
		| <変数 #v>		<printf 'printf("%d ", ' #v ');' <¥_n>>
		;

<代入文>        <変数 #v>
		"="  			<x <errormsg "error ="><exit>>
					<printf #v>
					<printf " = ">
		<数式>			<printf ";" <¥_n>>
		;

<数式>          <expradd>;

<expradd>       <exprmul> 
		{ "+" 			<printf "+">
			<exprmul> 
		| "-" 			<printf "-">
			<exprmul> 
		}
		;

<exprmul>       <exprID> 
		{ "*" 			<printf "*">
			<exprID> 
		| "/" 			<printf "/">
			<exprID> 
		}
		;

<exprID>        "+" <exprterm> 
		| "-" 			<printf "-">
			<exprterm> 
		| <exprterm>
		;

<exprterm>      "(" 			<printf "(">
			<数式> 
		")" 			<printf ")">
		| <NUM> 		<GETTOKEN #n>
					<printf #n>
		| <変数 #v>		<printf #v>
		;

<条件式>        <数式> 
		(">=" | ">" | "==" | "!=" | "<=" | "<") 
					<GETTOKEN #op>
					<printf #op>
		<数式>
		;

<変数 #x> 
		<RANGE #x a z>
		;

<コメント>	"#" <SKIPCR>
		;

<errormsg #x>
		<inputfile #i>
		::sys <line #n>
		<warn>
		<warn #i ":" #n ":" #x>
		<warn>
		;

?<compile>;

