是否可以让几个词法分析器共享相同的ident定义? [英] Is it possible to let several lexers share same ident definitions?

查看:86
本文介绍了是否可以让几个词法分析器共享相同的ident定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个词法分析器:lexer_1.mlllexer_2.mll,...

I have several lexers: lexer_1.mll, lexer_2.mll, ...

ident(let ident = regexp)的某些定义是常见的,并且在这些文件中重复.例如,INTEGERFLOAT,...

Some definitions of ident (let ident = regexp) are common and repeated in these files. For instance, the definition of INTEGER, FLOAT, ...

有人知道是否有可能在某个地方为它们一次定义一次,然后让.mll文件调用吗?

Does anyone know if it is possible to define them the once for all somewhere, and let the .mll files call it?

推荐答案

恐怕没有解决方案,因为ident似乎已被ocamllex系统内联.您仍然可以将regexp定义放在文件中,并在需要的地方使用cpp(或任何其他C预处理程序)将其#include用作它.当然,这是对cpp的滥用,因为您没有将其与.c文件一起使用,但是您将不是第一个这样做的人.

I'm afraid there's no "pure OCaml" solution, as ident seems to be systematically inlined by ocamllex. You can still put your regexp definition in a file, and use cpp (or any other C pre-processor) to #include it wherever needed though. This is of course an abuse of cpp, as you're not feeding it with .c file, but you wouldn't be the first one to do that.

事实上,我碰到了 cppo ,这是一种类似于cpp的实用程序您可能会发现有用的OCaml程序.

As a matter of fact, I've just come across cppo, a cpp-like utility targetting OCaml programs, that you might find useful.

这篇关于是否可以让几个词法分析器共享相同的ident定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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