I created a class in 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
And I have expression function as:
function expression(compiler)
%Compile(Parse and Generate Babbage code)one line of MATLAB code
term(compiler);
end
and the term
function as:
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
When I tried to run Compiler('3+1')
, the output is empty. I tried to debug it step by step and I found that when the term
function finished and jumped back to the expression function, the compiler.out
changed from a 2 x 1
cell arrays to empty.
I am confused about that. I have implemented other classes similar to this and all of their properties could be changed by my class's private function.