码迷,mamicode.com
首页 > 其他好文 > 详细

Flex + Bison: Scanning from memory buffer

时间:2015-08-07 01:45:10      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:

Found from StackOverflow:

=============================================================================================

The following routines are available for setting up input buffers for scanning in-memory strings instead of files (as yy_create_buffer does):

  • YY_BUFFER_STATE yy_scan_string(const char *str): scans a NUL-terminated string`
  • YY_BUFFER_STATE yy_scan_bytes(const char *bytes, int len): scans len bytes (including possibly NULs) starting at location bytes

Note that both of these functions create, return a corresponding YY_BUFFER_STATE handle (which you must delete with yy_delete_buffer() when done with it) so yylex() scan a copy of the string or bytes. This behavior may be desirable since yylex() modifies the contents of the buffer it is scanning).

If you want avoid the copy (and yy_delete_buffer) using:

  • YY_BUFFER_STATE yy_scan_buffer(char *base, yy_size_t size)

sample main:

int main() {
    yy_scan_buffer("a test string");
    yylex();
}

Flex + Bison: Scanning from memory buffer

标签:

原文地址:http://www.cnblogs.com/len3d/p/4709589.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!