oct2mat script based on parse tree
Muthiah Annamalai
muthuspost at gmail.com
Wed Jan 9 00:05:15 CST 2008
John W. Eaton wrote:
> On 8-Jan-2008, Muthiah Annamalai wrote:
>
> | I have a oct2mat like the one Paul Kienzle mentions in his
> | README file based on the AST walker. Utilizing Octave's
> | parse tree to do the conversion is very helpful and accurate
> | to a larger degree. Its still a work in progress (my disclaimer).
> |
> | Large parts of the code are directly derived from Octave
> | source written by JWE.
> |
> | This script is essentially to help deploy code to your colleagues
> | who want to use it on Matlab systems for whatever reason. Primary
> | development is still expected to be based on an Octave based
> | environment.
>
> Wouldn't it make more sense to modify the current tree_print_code
> class in src/pt-pr-code.cc to optionally print the output in a
> different format instead of mostly duplicating the code there? If you
> did that, then it might be possible to include this code in Octave
> itself.
>
I want to do that maybe eventually, but first I need to find out
what an oct2mat() script is supposed to do. So that is mostly
going to take a long time, during which I want this to be compiled
as a dynamic loadable function only. I believe bug-fixing is easier
that way, and reduces compile times.
> | 1. Can treat only function files or script files not both.
>
> There are some vague plans to make Octave parse entire script files at
> once and build a list of commands (see the unfinished ov_user_script
> class in src/ov-usr-fcn.h). If that work is completed, then handling
> scripts should be much simplified.
>
>
Thanks!
> | 2. Pollutes your command history, as it pipes out to octave_stdout.
>
> I don't see how that affects command history. If it does, then maybe
> there is a bug.
>
> | 3. Cannot handle a script file with function definitions
>
> | 4. Doesnot write to a separate directory or file, just all output on
> | stdout. So you need to create a driver program.
>
> Why not have your function accept a directory name?
>
Will do that, but its going to take a while.
> | 5. Not sure if it works correctly for all cases.
>
> You should probably issue a warning any time you encounter an
> unwind_protect block. Silently omitting the keywords for the unwind
> protect block is misleading. Although the code will appear to work
> correctly when it is executed with no errors or other exceptions
> occuring in the first block of code, it could really cause some
> confusing results or resource leaks if there is an error or exception.
>
>
I handled that piece of code wrongly. Paul Kienzle treats that
by converting unwind_protect piece of code into a try-catch
statement.
> | Copyright (C) 1992-2007 John W. Eaton
>
> Please don't abbreviate lists of years like this. See the guidelines
> here:
>
> http://www.gnu.org/prep/maintain/maintain.html#Copyright-Notices
>
>
OK. Will do.
> | void
> | tree_print_matlab_code::visit_simple_assignment (tree_simple_assignment& expr)
> | {
> | #ifdef O2M_DBG
> | os << "% visiting simple assignment \n";
> | #endif
> |
> | indent ();
> |
> | print_parens (expr, "(");
> |
> | tree_expression *lhs = expr.left_hand_side ();
> |
> | if (lhs)
> | lhs->accept (*this);
> |
> | // assignment is mostly OK. Just that we need to
> | // re-form the += , *= operators by transforming the
> | // parse tree.
> | os << " " << expr.oper () << " ";
> |
> | tree_expression *rhs = expr.right_hand_side ();
> |
> | if (rhs)
> | rhs->accept (*this);
> |
> | print_parens (expr, ")");
> | }
>
> I don't think you need to modify the parse tree here when you
> encounter something like "+=". You just need to emit the lhs, then
> the binary op corresponding to the OP= operator (you can get that with
> the octave_value::op_eq_to_binary_op method) and then emit the rhs.
>
> There will always be problems converting code that uses built-in
> functions in Octave that have no counterpart in Matlab, do you intend
> to try to warn about those?
>
> jwe
>
>
Actually that comment is misleading. I dont do any parse-tree
modifications, and I just mangle some strings to achieve the ends.
-Muthu
More information about the Octave-maintainers
mailing list