本文介绍了我如何生成的lex / yacc的不同yyparse功能在同一程序中使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要生成的lex / yacc的两个独立的分析功能。通常YACC给你一个函数yyparse()的时候,你需要做一些分析,你可以打电话,但我需要每一个不同的词法和语法相关的几个不同的yyparses。手册页似乎暗示了-p(preFIX)标志,但这并没有为我工作。我从GCC其中指出yylval是不正确被重新标记错误(即它声称几种不同的记号没有定义)。有谁知道一般rpocedure生成这些独立的功能?

I want to generate two separate parsing functions from lex/yacc. Normally yacc gives you a function yyparse() that you can call when you need to do some parsing, but I need to have several different yyparses each associated with different lexers and grammars. The man page seems to suggest the -p (prefix) flag, but this didn't work for me. I got errors from gcc that indicated that yylval was not properly being relabeled (i.e. it claims that several different tokens are not defined). Does anyone know the general rpocedure for generating these separate functions?

感谢

推荐答案

我前一段时间有一个同样的问题,我结束了写下面的头文件:

I had a same problem sometime ago and I ended up writing following header file:

#ifndef RENAME_FLEX_H
#define RENAME_FLEX_H

#define yy_create_buffer scan__create_buffer
#define yy_delete_buffer scan__delete_buffer
#define yy_init_buffer scan_init_buffer
#define yy_load_buffer_state scan_load_buffer_state
#define yy_switch_to_buffer scan_switch_to_buffer
#define yyin scan_in
#define yyleng scan_leng
#define yylex scan_lex
#define yyout scan_out
#define yyrestart scan_restart
#define yytext scan_text
#define yy_flex_debug scab_flex_debug
#define yywrap scan_wrap
#define yyrealloc scan_realloc
#define yyfree scan_free
#define yy_flush_buffer scan_flush_buffer
#define yypush_buffer_state scan_push_buffer_state
#define yypop_buffer_state scan_pop_buffer_state
#define yy_scan_buffer scan_scan_buffer
#define yy_scan_string scan_scan_string
#define yy_scan_bytes scan_scan_bytes
#define yyget_in scan_get_in
#define yyget_out scan_get_out
#define yyget_leng scan_get_leng
#define yyset_text scan_set_text
#define yyset_in scan_set_in
#define yyset_out scan_set_out
#define yyget_debug scan_get_debug
#define yyset_debug scan_set_debug
#define yylex_destroy scan_lex_destroy
#define yyalloc scan_alloc
#define yyget_text scan_get_text

#endif

和其包含到 .L ,所以从我的 .C 文件我可以使用扫描_ - prefixed为第二SCANER符号,而不是 YY - prefixed

and include it into .l, so from my .c file I can use scan_-prefixed symbols for second scaner, rather then yy-prefixed

这篇关于我如何生成的lex / yacc的不同yyparse功能在同一程序中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 03:52