问题标签 [camlp4]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
ocaml - 如何显示来自解析器的位置信息?
Stream.Error
当解析器内部发生 a 时,如何显示位置信息?例如:
如何获取流中的位置?有没有办法Stream.count
不用手动计算换行符?
ocaml - Camlp4 解析器函数:表达式具有 int 类型,但表达式应为 float 类型
我正在编写一个简单的解析器函数,它需要一个流中的项目,并返回一个 int,但由于某种原因,编译器出于我无法理解的原因一直期待一个浮点数;特别是考虑到代码实际上是来自 llvm ocaml 教程的示例代码。
我已经尝试将这两个变量类型转换为整数,并且通常只是摆弄语法,但是该函数非常简单,我无法弄清楚实际出了什么问题。我知道对于普通函数,可以指定类型, let: type->type
但我不知道这将如何与解析器函数一起使用。
这是功能:
这是在也是问题一部分的情况下使用它的更大背景(尽管我不认为它是):
我目前只是获得标准
类型错误。
有谁知道为什么这期待浮动?如何使函数期望一个 int?
编辑:
我现在意识到我现在措辞很糟糕,但是我意识到程序的上下文决定了函数的类型,我在问程序中的什么让它假设函数返回一个 int。似乎它超出了我发布的范围,因此我正在使用与显示的所有内容相关的代码更新我的帖子。
这是相关代码的完整集。很抱歉一开始就没有包括这个。
令牌.ml:
解析器.ml
astml
installation - In Ocaml Camlp5 is not installing (and it is necessary to use Quotations)
In Ocaml 4, I have to use the Quotation
module, on its Quotation.add
and Quotation.ExStr
functions. It seems I have to install the Camlp5
library (seems to be a preprocessor) to do so. Found lots of info about Camlp, like:
- Camlp5: https://camlp5.readthedocs.io/en/latest/intro.html
- Camlp5: https://camlp5.github.io/doc/html/index.html
- Camlp4: https://caml.inria.fr/pub/docs/tutorial-camlp4/tutorial004.html
But no installation guides, so I tried: opam install camlp5
with the result:
So some dependencies seem not to be there, and I have tried: opam depext --install camlp5
with the result:
So does not seem to work.
The error diagnosis is the same for both commands:
I have been trying similars and alternatives for some hours, and cannot achieve it. Any help?
PS1: I am working in MAC.
PS2: If someone wants, my context for this problem is that I want to use the functions of one directory -which is a black box for me-, and all the examples are written with the parser, like <<y+2=5>>
so I do not know the grammar and have to achieve to make the parser run.
EDIT 1 (The solution proposed by Ivg)
After trying both commands of the proposed solution by Ivg (answering local::lib
in one of the questions and yes
on the others), the second of the errors seem to be corrected, when doing opam install camlp5
:
Where the whole terminal has been:
EDIT 2 (Solved, repeating)
Suddenly it worked. I wrote once again sudo cpan IPC::System::Simple
(there was no questions now) and after that, opam install conf-perl-ipc-system-simple
.
Anyway, the Quoation
module is not opening for me.