1

MATLAB でクラスを作成しました。

classdef Compiler
%UNTITLED2 Summary of this class goes here
%   Detailed explanation goes here

properties(Access = public)
    in=''       %a line of string of MATLAB code
    out={}      %several lines of string(cell array) of Babbage Code
end

methods(Access = private)
    %compile(compiler);
    expression(compiler); 
    term(compiler);
end

methods(Access = public)
    function compiler = Compiler(str) 
        compiler.in = str;
        expression(compiler);
        compiler.out
    end
end

そして、私は次のような式関数を持っています:

function expression(compiler)
%Compile(Parse and Generate Babbage code)one line of MATLAB code

   term(compiler);         
end

およびterm関数は次のとおりです。

function term(compiler)
    % Read Number/Variable terms
    num = regexp(compiler.in, '[0-9]+','match');
    len = length(compiler.out);
    compiler.out(len+1,:) = {['Number ' num{1} ' in V0 in Store']}; 
    compiler.out(len+2,:) = {['Number ' num{2} ' in V1 in Store']};
end

を実行しようとするCompiler('3+1')と、出力が空です。段階的にデバッグしようとしたところ、term関数が終了して式関数に戻ると、セル配列から空にcompiler.out変わったことがわかりました。2 x 1

私はそれについて混乱しています。これに似た他のクラスを実装しましたが、それらのすべてのプロパティはクラスのプライベート関数によって変更できます。

4

1 に答える 1