[请益] 实作判断code中 { } 的配对 (有不成对的)

楼主: donkeychen (Bad_To_The_Bone)   2014-09-19 12:08:42
大家好
小弟在写一个程式 目的是parse
一份code的trace过程所丢出的log
我的方式如下
==================
如果原本code是
int func1()
{
do something;
return func2();
}
int func2()
{
return xxx;
}
将其改为
int func1()
{
cout << ">>>func1";
do something;
cout << "call func2()";
int a = func2();
cout << "<<<func1"
return a;
}
int func2()
{
cout << ">>>func2";
do something;
cout << "<<<func2";
return xxx;
}
其中cout的行数是拿来丢到log中
==================
得到log如下
>>>main()
call func1()
>>>func1
call func2()
>>>func2
<<<func2
<<<func1
<<<main()
==================
我以程式对log内容做tab缩排
psuedo code如下
int tabcount = 0;
read line to string Line;
if (Line.pos("<<<"))
tabcount

Links booklink

Contact Us: admin [ a t ] ucptt.com