我正在执行一个单独的字符串,当看到分隔符时,我确实添加了一个情况,对于最后一个分隔符,它工作得很好。例如,我的字符串是"symbol control_line : std_logic:= '0' ; --example comment",当看到第一个分隔符时,输出是正确的:但是当它查看第二个:=时,它失败了。我不知道为什么会这样?这两个分隔符的代码应该都很好,为什么只知道第一个,而第二个却失败了?
这个prepareNextToken函数计算出第二个令牌的tokenLength是什么。我可以使用这个函数得到当前的令牌。
void Tokenizer::prepareNextToken()
{
string real=*str;
if(offset==real.size())
complete=true;
else
{
if(ifcomment==false)
{
size_t length=0;
size_t index=offset;
size_t smallest=find_first_delimilater(vhdl_char);
while(index<real.size() )
{
length++;
if(index==smallest && real[index+1]==' ')
{
cout<<real[smallest]<<" ";
break;
}
else if(index==smallest && real[index+1]!=' ')
{
length++;
break;
}
else if(index==real.find(' ',offset))
{
break;
}
else if(index==real.find("--",offset))
{
length++;
break;
}
index++;
}
tokenLength=length;
}
else if(ifcomment==true)
tokenLength=real.size()-offset;
}
//cout<<tokenLength<<endl;
}我的输出是
signal --which is correct
control_line --the current offset
: --which is right because I reach the first case in my
--prepareNextToken and ":" is first delimilator
std_logic:= --that is the wrong output because it should be std_logic
-- and in a separate line comes out ";=" which is another
--delimilator, and is a multiple delimilator no empty case
-- so that means I go to the second cases
-- -- which is also right which go to fourth case
sample comment -- which is right我的问题是,为什么":“在它自己的行中出现,但为什么":=”以std_logic结尾?
发布于 2015-10-25 17:26:22
substr的第二个参数是要提取的字符数,而不是结束位置(参见http://www.cplusplus.com/reference/string/string/substr/)。所以你的提取线应该是:
s=name.substr(offset,tokenLength);https://stackoverflow.com/questions/33332448
复制相似问题