//?<tron>;

<compile>
	::sys<args #x>
	::sys<nth #inputfile #x 1>
	::sys<suffix #outputfile #inputfile c>
	<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;">
					<setVar exline 1>
		<vO> <EOF>	<print "exit(0);">
					<print "}">
		;

<vO>				<x <exline #l>
						<errormsg #l "\G[">>
		{[<s> { ";" <s>}] (<Rg> | <CR>)}
		;


<s>				<SKIPSPACE>
					<setVar exline ::sys <line #l>>
		(<if> | <while> | <print> | <times> | <>)
		;


<if>          "if"	 		<x <errormsg "ifɃG[">>
					<printf "if (">
		<>		<printf ") {" <\_n>>
		<vO> 
		[ 
			"else"	  	<x <errormsg "elseɃG[">>
			 		<printf "} else {" <\_n>>
			<vO> 
		] 
		"end"			<printf "}" <\_n>>
		;

<while>       "while"  		<x <errormsg "whileɃG[">>
			 		<printf "while (">
		<> 		<printf ") {" <\_n>>
		<vO> 
		"end"			<printf "}" <\_n>>
		;

<times>       (<NUM #n> | <ϐ #n>)
		"." "times"	 	<x <errormsg "timesɃG[">>
			 		<printf "{int ct; for (ct=0; ct<">
					<printf #n>
					<printf "; ct++) {" <\_n>>
		"do"
		<vO> 
		"end"			<printf "}}" <\_n>>
		;

<print>
	       "print"	  	 	<x <errormsg "printɃG[">>
		<\> {","  <\>}
		;

<\>
		  <STRINGS #s>		<printf 'printf("%s", "' #s '");' <\_n>>
		| <NUM #n>		<printf 'printf("%d ", ' #n ');' <\_n>>
		| <ϐ #v>		<printf 'printf("%d ", ' #v ');' <\_n>>
		;

<>        <ϐ #v>
		"="  	 		<x <errormsg "ɃG[">>
					<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>
		;

<> 		  	 	<x <errormsg "ɃG[">>
		<> 
		(">=" | ">" | "==" | "!=" | "<=" | "<") 
					<GETTOKEN #op>
					<printf #op>
		<>
		;

<ϐ #x> 
		<RANGE #x a z>
		;

<Rg>	"#" <SKIPCR>
		;

<errormsg #x>
		::sys <line #n>
		<warn "error : " #n ":" #x>
		<exit>
		;
<errormsg #n #x>
		<warn "error : " #n ":" #x>
		<exit>
		;

?<compile>;

