how to check syntax error in state flow chart

Hello All,
I would like to check syntax errors in state flow state chart. As you see below, I have called state which is State_name, Inside this state I have different actions. If you see state_action2 = 0 missed by following semi colon(;) and state_action3 is not within state area.
How can I check state actions line by line and syntax errors by using m-script/commands?
Any help would be appreciated..

 採用された回答

Anthony Poulin
Anthony Poulin 2015 年 5 月 28 日

0 投票

I give you a small code (not optimize and without check...). The code give the "txt" variable which is the text from a stateflow state and then I put each line in a cell of the cell array "Line".
nlChar = findstr(txt, 10);
Line{1,1} = txt(1:nlChar(1));
for i = 2:length(nlChar)
Line{i,1} = txt(nlChar(i-1)+1:nlChar(i));
end
Line{i+1,1} = txt(nlChar(i):end);
Then, when you have this cell aray, you just have to make your check on each cells.

9 件のコメント

N/A
N/A 2015 年 5 月 28 日
Thank you very much.. . Do you have any idea to check whether state actions within chart or not?
Anthony Poulin
Anthony Poulin 2015 年 5 月 28 日
I am not sure to understand your question...
If it is : "how to know if a line is for an action?"
You can exlude the first line (=> it is always the name of the state), and you can search the character ":" => the line must contain "en:", "du:", "ex:", or "entry:", "during:", "exit:" so there is not an action on this line.
Or you can search the "=" character, I think (but I am not sure) that a line containing an action has always a "=".
N/A
N/A 2015 年 5 月 28 日
sorry for lack of clarification.. I should check two issues in state flow chart:
First One:
I have to check whether each action ended with semicolon or not.
In this, Yes. You are right.Normally, actions contains "=" and ends with ; . If I find "=" then its action other wise its not proper action or it may be en/ex/du. but sometimes people can also write like en: action = 1; in one line then in next other actions. how can I check that?
Second :
I have check whether each action within in state chart or not.
Anthony Poulin
Anthony Poulin 2015 年 5 月 28 日
So for the first one, just check if there is a "=" on the line and if yes check if the last character of the line is ";"
For the second, I don't understand "each action within in state chart or not"...
N/A
N/A 2015 年 5 月 28 日
In below figure, go_only_forward = 1; is state action and it is not fitted inside the state(action is not within the area of state chart). I need to check those issues in state flow.
Hope you understood the problem.
Anthony Poulin
Anthony Poulin 2015 年 5 月 28 日
Now, I understand but for the moment I have not any idea to check this...
N/A
N/A 2015 年 5 月 29 日
編集済み: N/A 2015 年 5 月 29 日
Hello Anthony,
Thank you very much. I was able to find "=" in cell elements and then I have to check last char ; or not.
but as of now I can able to find whether it has ; or not.
could you please help me to find last position character is ; or not?
nlCharEqualArray = {};
nlCharColonArray = {};
nlChar = findstr(txt, 10);
Line{1,1} = txt(1:nlChar(1));
for i = 2:length(nlChar)
Line{i,1} = txt(nlChar(i-1)+1:nlChar(i));
end
Line{i+1,1} = txt(nlChar(i):end);
for k=2 : length(Line)
nlCharEqual = findstr(Line{k}, '=');
if (~isempty(nlCharEqual))
nlCharEqualArray = [nlCharEqualArray Line{k}];
end
end
for inx = 1 : length(nlCharEqualArray)
nlCharColon = findstr(nlCharEqualArray{inx}, ';');
if (~isempty(nlCharColon))
nlCharColonArray = [nlCharColonArray nlCharEqualArray{inx}];
end
end
Anthony Poulin
Anthony Poulin 2015 年 5 月 29 日
Hello,
First I use the function "findstr" and it is a mistake because this function will be removed so prefer "strfind" function.
Then what I suggest is to make a cell array (1 cell per text line) containing a boolean. For each line containing "=", if the last (=> last line) or penultimate character (=> other lines, because the last char must be char(10))is a ";", then you have 1 oterwise 0?
nlCharEqualArray = {};
nlChar = strfind(txt, 10);
Line{1,1} = txt(1:nlChar(1));
for i = 2:length(nlChar)
Line{i,1} = txt(nlChar(i-1)+1:nlChar(i));
end
Line{i+1,1} = txt(nlChar(i):end);
for k=2 : length(Line)
nlCharEqual = strfind(Line{k}, '=');
if (~isempty(nlCharEqual))
nlCharEqualArray{k,1} = ~isempty(strfind(Line{k}(end-1:end), ';'));
%I test on the 2 last characters, if you want to test on the 5 (for exemple), just do: Line{k}(end-5:end)
end
end
Is it clear?
N/A
N/A 2015 年 6 月 9 日
編集済み: N/A 2015 年 6 月 9 日
Thank you very much...You helped me a lot...

サインインしてコメントする。

その他の回答 (2 件)

Anthony Poulin
Anthony Poulin 2015 年 5 月 27 日

0 投票

Hello,
I can give you some command line which help you to access to the content of the stateflow chart.
% to catch the root of the stateflow chart, that yoy have selected by clicking on it
SfPath = gcb;
% to catch the stateflow object
SfObj = get_param(SfPath,'Object');
% to catch the chart object
ChartObj = SfObj.find('-isa','Stateflow.Chart');
% to catch all the StatesObj of the chart
StatesObj= ChartObj.find('-isa','Stateflow.State');
% To get the string in the FIRST chart (=> StatesObj(1))
StringInChart = get(StatesObj(1),'LabelString');
I hope it can help you.
(When I needed to access to stateflow data I found a lot of information in: Help > Stateflow > User's Guide > Using the API)

1 件のコメント

N/A
N/A 2015 年 5 月 27 日
Hello Anthony,
Thanks for reply.. I have tried that and here is my code:
m=sfroot;
chartArray = m.find('-isa','Stateflow.Chart');
for i = 1:length(chartArray)
current_chart = chartArray(i);
stateArray = chartArray.find('-isa','Stateflow.State');
for j = 1 : length(stateArray)
current_state = stateArray(j);
state_actions = get(current_state(1),'LabelString');
end
end
Here problem is, state_actions returns all statements as single char. please have look on image.
but I want to read actions statements separately. so that I can check each action statement last char whether it ended with semi colon (;) or not and also I can find the length of each action statement.
so please let me know any idea on that?

サインインしてコメントする。

Anthony Poulin
Anthony Poulin 2015 年 5 月 27 日

0 投票

Yes, you catch a char containing all the text.
Then you have to treat this char, to separate the line you can find the character "char(10)" (= new line) or "char(13)" (= carriage return).
Is it ok for you, or do you want a short example?

カテゴリ

ヘルプ センター および File ExchangeDecision Logic についてさらに検索

質問済み:

N/A
2015 年 5 月 26 日

編集済み:

N/A
2015 年 6 月 9 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by