
<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 <TinyPython>>>
	;


<TinyPython>				<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>
		{
					<SKIPSPACE>
		  			<INDENT 0>
		  <vO> 
		}
					<SKIPSPACE>
					<x <errormsg "indent error">>
		  			<INDENT 0>
		<EOF>			<print "exit(0);">
					<print "}">
		;

<vO>
		  <䕶>
		| 
		  <vO>
		;

<vO>
		[<s> { ";" <s>}] [<Rg>] <CR>;

<ubN>
		":"			<INDENT #n0>
					<SKIPSPACE>
					<INDENT #n>
					<print "{">
		{
					<SKIPSPACE>
					<INDENT #n>
		  <vO>
		}
					<SKIPSPACE>
					<INDENT #n0>
					<x <errormsg "indent error">>
					<print "}">
		;

<䕶>	( <if> | <while> | <for> )
					<setVar exline 
						<_ = ::sys <line #l>+1>>;

<s>	( <print> | <>)
					<setVar exline 
						<_ = ::sys <line #l>+1>>;


<if>          "if"	 		<x <errormsg "ifɃG[">>
					<printf "if (">
		<>		<printf ") ">
		<ubN> 
		[ 
			"else"   	<x <errormsg "elseɃG[">>
			 		<printf "else " <\_n>>
			<ubN> 
		] 
		;

<while>       "while"  		<x <errormsg "whileɃG[">>
			 		<printf "while (">
		<> 		<printf ") " <\_n>>
		<ubN> 
		;

<for>       "for"
				 	<x <errormsg "forɃG[">>
		<ϐ #i>
		"in" "range" "("
		       (<NUM #n> | <ϐ #n>)
		")"
			 		<printf "{"  <\_n>>
					<printf "int " #i ";" <\_n>> 
					<printf "for (" #i "=0; " #i " < ">
					<printf #n>
					<printf "; " #i "++) " <\_n>>
		<ubN> 
					<printf "}" <\_n>>
		;

<print>
	       "print"	  	 	<x <errormsg "printɃG[">>
		<\> 
			{","  		<printf 'printf(" ");' <\_n>>
			  <\>}
					<printf 'printf("\n");' <\_n>>
		;

<\>				<printf 'printf('>
		(
		   <STRINGS #s>		<printf '"%s","' #s '"'>
		 | 
					<printf '"%d", '>
		   <>
		)
					<printf ');' <\_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> 
		<SKIPSPACE>
		<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>;

