如何从源代码编译 picoProlog? [英] How to compile picoProlog from source code?

查看:61
本文介绍了如何从源代码编译 picoProlog?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是计算机科学专业的学生,​​正在学习使用 Prolog 进行逻辑编程.

I am a student in Computer Science, and I am learning about logic programming with Prolog.

我发现了一个有趣的 Prolog 解释器,picoProlog(http://spivey.oriel.ox.ac.uk/corner/Logic_Programming).

I have found an interesting Prolog interpreter, picoProlog (http://spivey.oriel.ox.ac.uk/corner/Logic_Programming).

为了更多地了解 Prolog,我试图编译他们的源代码,但我失败了.

To know more about Prolog, I am trying to compile their source code, but I failed.

在这个网页上,他们说:

In this web page, they said:

解释器源代码是用最小的 Pascal 方言编写的,避免了包括指针在内的许多功能,但使用宏来克服 Pascal 的一些限制,其风格受到 Kernighan 和 Plauger 的《Pascal 软件工具》一书的启发.它带有一个从 Pascal 方言到 C 的翻译器,可用于构建解释器和所需的宏处理器的源代码.

The interpreter source is written in a minimal dialect of Pascal, avoiding many features including pointers, but using macros to overcome some of Pascal's limitations, in a style inspired by Kernighan and Plauger's book Software tools in Pascal. It comes with a translator from the Pascal dialect into C that can be used to build the interpreter and also source for the macro processor that is needed.

要在 Linux 机器上构建解释器,只需提取 tar 文件并键入 make.构建分为几个阶段:

To build the interpreter on a Linux machine, just extract the tar file and type make. The building happens in several stages:

  1. 首先,Pascal-to-C 转换器 ptc 是从 C 源代码构建的,包括用 lex 和 yacc 编写的词法分析器和解析器.文件 README 提供了此翻译器接受的非常受限的 Pascal 子集的一些详细信息.
  2. 接下来,ptc 用于构建宏处理器 ppp.
  3. 最后,picoProlog 解释器是从文件 pprolog.x 中的源代码构建的,首先使用 ppp 扩展宏以获得文件 pprolog.p,然后使用 ptc 转换为 C,最后编译 C 代码.

文本和软件版权 © J. M. Spivey,1996、2002、2010.

Text and software copyright © J. M. Spivey, 1996, 2002, 2010.

他们说只能在Linux上编译,所以我不知道如何在Windows机器上编译这个源代码.我可以在 Windows XP 上用 Turbo Pascal 7.0(没有任何要求)编译它吗?您能否仅删除用于 Pascal 编译 的脚本的某些部分?

They said about compiling on Linux only, so I don't know how to compile this source code in Windows machine. Can I compile it with Turbo Pascal 7.0 (without any requirement) on Windows XP? Can you remove some part of script for Pascal compiling only?

推荐答案

为了避免在您可能只对解释器而不是它的 *nix 引导程序感兴趣时花费更多时间让 P2C/PTC 引导程序运行,我认为它更容易忘记 PTC 的东西并专注于让 pascal 部分编译/使用 FPC 2.6.x.(下面花了 10 分钟),生成了一个独立的 Windows EXE,其中添加了 10-20 行代码.

To avoid spending more time in getting the P2C/PTC bootstrapping to run while you are probably only interested in the interpreter and not its *nix bootstrapping, I think it is easier to forget the PTC stuff and focus getting the pascal parts to compile/work with FPC 2.6.x. (the below took 10 minutes), generating a standalone Windows EXE with 10-20 code line additions.

从 ppp 开始,嗯,开箱即用的编译(nand 工作!):<​​/p>

Start with ppp, hmm, that compiles (nand works!) out of the box:

D:\dls\prlg\pprolog>fpc ppp.p
Free Pascal Compiler version 2.6.2 [2013/02/12] for i386
Copyright (c) 1993-2012 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling ppp.p
Linking ppp.exe
394 lines compiled, 0.1 sec , 30352 bytes code, 1692 bytes data

代码确实看起来像是要输入管道.我们通过它 (ppp) 拖拽 pprolog.x,它 (pprolog.pp) 几乎可以编译.有四个问题,但都可以通过在顶部添加一些代码来解决,而不改变原始代码(标有MVDV:在源代码中)

The code does looks like it is meant to have its input piped in. We haul pprolog.x through it (ppp) and it (pprolog.pp) almost compiles. There are four problems, but all are fixable by adding some code to the top, and not changing original code (marked with MVDV: in the source)

  1. 一些范围检查错误,因为整数类型对于设置的 1MB 堆栈空间来说太小了.这禁止使用 Turbo Pascal,但我们可以通过将 integer 定义为 longint 来解决它.
  2. 似乎它假设前向函数不需要重复它们的参数,而在 FPC 中它们通常需要重复.
  3. 在 ("initialize") 的最后一个函数中,使用了一些非标准的 ptc 库函数,它们借鉴了 C (argv, argc) 而不是它们典型的 pascal 等效函数.固定.
  4. (原作者测试后报告) ParseFactor 有一个右手递归,由阅读代替结果.启用 TP 模式(使用行上方的 {$mode tp}),或添加 () 以消除歧义

在这些之后,pprolog.pp 用 FPC 编译:

After these, pprolog.pp compiles with FPC:

Free Pascal Compiler version 2.6.2 [2013/02/12] for i386
Copyright (c) 1993-2012 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling pprolog.pp
pprolog.pp(487,19) Warning: unreachable code
pprolog.pp(532,19) Note: Local variable "dummy" is assigned but never used
Linking pprolog.exe
2150 lines compiled, 0.1 sec , 84400 bytes code, 13932 bytes data
1 warning(s) issued
1 note(s) issued

一些注意事项:

  1. 未经测试
  2. 我不知道我的 argv/argc 范围是否完全正确.(0..argc-1 而 paramcount 基于 1 等)如有必要,请检查.
  3. string 系统早于 TP String 类型并且很复杂(可能是因为 PTC,请参阅 README),我不知道它是否有效.

我已将生成的编译源代码放在 http://www.stack.nl/~marcov/files/pprolog.pp

I've put the resulting, compiling source code at http://www.stack.nl/~marcov/files/pprolog.pp

祝你好运!

这篇关于如何从源代码编译 picoProlog?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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