yacc のメイン関数でパーサーに渡した文字列を解析したい。これを使用して実行できることyy_scan_string
は知っていますが、使用方法がわかりません。Web と man ページを検索しましたが、まだ明確ではありません。私を助けてください。
14667 次
6 に答える
19
再入可能なレクサーのサンプルが必要な場合:
int main(void)
{
yyscan_t scanner;
YY_BUFFER_STATE buf;
yylex_init(&scanner);
buf = yy_scan_string("replace me with the string youd like to scan", scanner);
yylex(scanner);
yy_delete_buffer(buf, scanner);
yylex_destroy(scanner);
return 0;
}
于 2011-06-14T21:23:04.253 に答える
9
これは私にとってはうまくいきます。Bison ファイルのサブルーチン セクション (つまり、3 番目のセクション) に次のコードがあります。
struct eq_tree_node *parse_equation(char *str_input)
{
struct eq_tree_node *result;
yy_scan_string(str_input);
yyparse();
/* to avoid leakage */
yylex_destroy();
/* disregard this. it is the function that I defined to get
the result of the parsing. */
result = symtab_get_parse_result();
return result;
}
于 2010-09-01T13:50:19.017 に答える
4
これは私にとってはうまくいきました... yy_scan_string() を使用してください
int main(int argc, char **argv)
{
char Command[509];
int ReturnVal;
char input[40] = "This is my input string";
/*Copy string into new buffer and Switch buffers*/
yy_scan_string (input);
/*Analyze the string*/
yylex();
/*Delete the new buffer*/
yy_delete_buffer(YY_CURRENT_BUFFER);
}
于 2012-03-29T07:00:34.200 に答える
3
lex/yacc (または flex/bison) を学びたい人には、このページを常にお勧めします。
于 2009-12-15T14:37:56.683 に答える
-1
ここで自分自身に例を見つけました。あなたに役立つかもしれません:
于 2009-12-18T19:19:38.080 に答える