<p>Err, ummm, ...<br>
Are you perhaps trying to reinvent Resolver 1 -- a spreadsheet written in Python? Maybe I misunderstand what you are trying to do, but you may want to look at it, unless you cannot use a commercial product.</p>
<div class="gmail_quote">On Mar 1, 2012 7:58 PM, &quot;Curt Hagenlocher&quot; &lt;<a href="mailto:curt@hagenlocher.org">curt@hagenlocher.org</a>&gt; wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>I would argue that this is a bad idea. How Python-compatible do you want this simple Excel-like language to be? If it&#39;s really just a small subset of the full Python language, you may be better off writing a simple parser that emits Python text as its back end and prevents the users from doing anything more complicated. This should not be significantly more complex than what you propose to do. If you really want to offer the full power of the Python language, then you should consider whether you are doing your users a disservice by teaching them a language that&#39;s almost the same as Python, but different in just one minor and hard-to-debug respect.<br>

<br></div><div class="gmail_quote">On Thu, Mar 1, 2012 at 12:31 PM, Tuomas Utrecht <span dir="ltr">&lt;<a href="mailto:tuomas.utrecht@gmail.com" target="_blank">tuomas.utrecht@gmail.com</a>&gt;</span> wrote:<br><blockquote style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid" class="gmail_quote">

Hello,<br><br>I apologize if this has been answered elsewhere, but I am unable to find anything up to date, or that covers my question in particular.<br><br>The short version is: Can I modify the AST of a parsed file before compiling/executing in an embedded context? I want to allow simple, Excel-like statements to be executed from a .NET application. One major hitch is that Excel uses ^ for power whereas Python uses **. Ideally, I would be able to catch calls to ^ and replace with ** at compile time.<br>


<br>If this is just not possible without rebuilding IronPython, do let me know.<br><br>I have gotten as far as the below, although the BinaryExpression node&#39;s Operator is only gettable. I also am unsure how to take an AST and compile it, or if that is even public/allowed.<br>


<br>    var engine = Python.CreateEngine();<br>    var s = HostingHelpers.GetSourceUnit(engine.CreateScriptSourceFromString(&quot;3^4&quot;));<br>    var cc = new CompilerContext(s, new PythonCompilerOptions(), ErrorSink.Default);<br>


    var p = Parser.CreateParser(cc, new PythonOptions());<br>    PythonAst ast = p.ParseFile(false);<br><br>    // I originally tried this with a PythonWalker, but this is more succinct for the purpose of this example<br>


    SuiteStatement body = (SuiteStatement)ast.Body;<br>    ExpressionStatement st = (ExpressionStatement)body.Statements[0];<br>    BinaryExpression exp = (BinaryExpression) st.Expression;<br>    //exp.Operator = PythonOperator.Power; // Were it only so easy...<br>


<br><br>Thanks for reading!<br>
<br>_______________________________________________<br>
Ironpython-users mailing list<br>
<a href="mailto:Ironpython-users@python.org" target="_blank">Ironpython-users@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/ironpython-users" target="_blank">http://mail.python.org/mailman/listinfo/ironpython-users</a><br>
<br></blockquote></div><br>
<br>_______________________________________________<br>
Ironpython-users mailing list<br>
<a href="mailto:Ironpython-users@python.org">Ironpython-users@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/ironpython-users" target="_blank">http://mail.python.org/mailman/listinfo/ironpython-users</a><br>
<br></blockquote></div>