C/C++交互式口译员
C/C++ interactive interpreter
我想知道是否有一个等效的 C/C++ python 解释器:
$ python
Python 2.7.3 (default, Mar 13 2014, 11:03:55)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> " testnn ".strip()
'test'
>>> import re
>>> re.search('([d.]*).tgz', 'package-2.1.5.tgz').group(1)
'2.1.5'
到目前为止,我一直为此目的使用虚拟 bash 脚本。它不是交互式的,但它可以防止使用 main 等创建 C++ 文件来检查单个或某些命令的结果。
我很确定我们可以以某种方式在 gdb 或 eclipse 中做到这一点,或者它存在于隐藏在包中的其他地方,所以如果你知道围绕这个问题的有趣东西,我将不胜感激。谢谢,祝你有美好的一天。
$ cat cInterpreter.sh
#!/bin/bash
function usage {
cat <<EOF
USAGE:
$0 '<semi-colon separated includes>' '<semi-colon separated commands>'
EXAMPLE:
$0 'arpa/inet.h' 'printf("%04xn", htons(5294));'
EOF
}
if [ $# -ne 2 ] || [ "$1" = "--help" ]; then
usage
exit 0
fi
includes=$1
commands=$2
g++ -Wall -x c++ - -o /tmp/cInterpreter.bin <<EOF &&
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
$(tr ';' 'n' <<< $includes | xargs -I{} echo "#include <{}>")
int main() {
$commands;
return 0;
}
EOF
/tmp/cInterpreter.bin
$ cInterpreter.sh 'arpa/inet.h' 'printf("%04xn", htons(5294));'
ae14
你有坚持,它并不完美,但它是一个 c++ repl
http://blog.coldflake.com/posts/On-the-fly-C++/
git clone http://root.cern.ch/git/llvm.git src
cd src
git checkout cling-patches
cd tools
git clone http://root.cern.ch/git/cling.git
git clone http://root.cern.ch/git/clang.git
cd clang
git checkout cling-patches
cd ../..
./configure --enable-cxx11
make
sudo make install
$ cling -Wc++11-extensions -std=c++11
****************** CLING ******************
* Type C++ code and press enter to run it *
* Type .q to exit *
*******************************************
[cling]$ #include <arpa/inet.h>
[cling]$ htons(5294)
(uint16_t) 44564
[cling]$ printf("%04xn", htons(5294))
input_line_5:2:2: error: use of undeclared identifier 'printf'
printf("%04xn", htons(5294))
^
[cling]$ #include <stdio.h>
[cling]$ printf("%04xn", htons(5294))
ae14
Tiny C Compiler (http://bellard.org/tcc) 支持解释器模式。虽然它只是C。
RCRL(read-compile-run-loop)是坚持C++的替代方法。
相关文章:
- 与 stdio 同步是否使程序 I/O 非交互式?
- 外壳包装器句柄/执行交互式命令管道C++ UNIX
- 如何在gedit中使用外部工具运行交互式C++程序
- 与 Python 中子进程中的另一个应用程序的交互式会话
- C++交互式命令行提示符,无需等待换行符
- 使用QProcess将EndOfText(Ctrl-C)发送到交互式shell
- 如何用C++编写LUA中具有对话和菜单的交互式NPC脚本
- 如何制作交互式命令行界面
- 从动态库交互式调用函数,无需等待返回(python,ctypes)
- 使用 OpenGL 创建交互式对话框
- 在C++中创建交互式提示
- 适用于交互式移动地图的语言/框架
- MAC c++ 控制交互式命令行工具
- C/C++交互式口译员
- 是否有任何交互式控制台 B 树实现
- 设计像交互式shell一样的python
- 开发一个交互式shell
- 将交互式控制台附加到嵌入式python脚本
- 如何知道所有交互式用户何时已注销
- 是否有Qt对话框或小部件可以交互式地对字符串列表进行排序