flex如何精确支持野牛定位? [英] How does flex support bison-location exactly?

查看:84
本文介绍了flex如何精确支持野牛定位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用flex和bison创建一个过滤器,因为我想从复杂的语言中获取某些语法元素.我的计划是使用flex + bison识别语法,并丢弃感兴趣的元素的位置. (然后使用脚本根据转储的位置获取文本.)

I'm trying to use flex and bison to create a filter, because I want get certain grammar elements from a complex language. My plan is to use flex + bison to recognise the grammar, and dump out the location of elements of interest. (Then use a script to grab text according the locations dumped.)

我发现flex可以支持称为bison-locations的bison功能,但是它的工作原理是完全正确的.我在flex文档中尝试了该示例,看来yylloc不是由flex自动设置的,我总是得到(1,0)-(1,0). flex可以自动计算每个令牌的位置吗?如果没有,我定义了什么接口函数来实现?有例子吗?

I found flex can support a bison feature called bison-locations, but how it works in exactly. I tried the example in flex document, it seems the yylloc is not set automatically by flex, I always get (1,0)-(1,0). Could flex calculate each token's location automatically? If not, what interface function is defined for me to implement? Is there any example?

关于工具的任何更好的解决方案?

Any better solution regarding to tools?

最好的问候, 凯文

现在yylex的界面变为:

Now the interface for yylex turn to:

int yylex(YYSTYPE * yylval_param,YYLTYPE * yylloc_param );

bison手册未指定词法分析器应如何实施以正确设置yylloc_param.对我而言,很难手动跟踪每个令牌的列号.

bison manual does not specify how lexer should implement to correctly set yylloc_param. For me it is hard to manually trace column number of each token.

推荐答案

看看

Take a look at section 3.6 of the Bison manual - that seems to cover locations in some detail. Combined with what you found in the Flex manual, that may be sufficient.

这篇关于flex如何精确支持野牛定位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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