【发布时间】:2015-06-29 14:57:59
【问题描述】:
我想知道是否有与 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.
>>> " test\n\n ".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("%04x\n", 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("%04x\n", htons(5294));'
ae14
【问题讨论】:
标签: c++ c batch-processing interactive