简单的解析器问题...... [英] Simple parser question...

查看:124
本文介绍了简单的解析器问题......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何制作一个解析字符串的简单解析器

ex。

" string1 string2 string3"

并存储在一个矢量中?


如何使用BOOST.Spirit完成?


---

leaf

How do i make a simple parser that parse strings
ex.
"string1 string2 string3"
and store in a vector?

how can it be done using BOOST.Spirit?

---
leaf

推荐答案

需要BOOST.Spirit?只需使用strtok

修改MSDN简单

char string1 [] =" string1 string2 string3" ;;

char seps [] =" " ;;

char * token;

vector< string>(temp)

void main(void)

{

printf("%s\\\
\\\
Tokens:\ n",string1);

/ *建立字符串并获取第一个令牌: * /

token = strtok(string1,seps);

while(token!= NULL)

{

/ *虽然string1中有令牌,但* /

printf("%s \ n",令牌);

temp.push_back(令牌);

/ *获取下一个标记:* /

token = strtok(NULL,seps);

}

}

need BOOST.Spirit?just using strtok
modify the MSDN simple
char string1[] = "string1 string2 string3";
char seps[] = " ";
char *token;
vector<string >(temp)
void main( void )
{
printf( "%s\n\nTokens:\n", string1 );
/* Establish string and get the first token: */
token = strtok( string1, seps );
while( token != NULL )
{
/* While there are tokens in "string1" */
printf( " %s\n", token );
temp.push_back(token);
/* Get next token: */
token = strtok( NULL, seps );
}
}


尝试了它并且它有效。


但我的实际实现类似于解析:

" public:__ thishisallall unsigned int FunctionName(类型,类型,类型......)"


---

leaf

tried it and it worked.

but my actual implementation is something like parsing:
"public: __thiscall unsigned int FunctionName( type, type, type ... )"

---
leaf


数组seps来分隔字符串可以stro几个字符。所以你好

字符串也可以解析。

the array seps to separate the string can stroe a few characters .so ur
string can aslo be parsing.


这篇关于简单的解析器问题......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆