get human readable AST from c++ code

In order to get a better understanding of some of the details of the C++ language and grammer, I would love to be able to write a small C++ program, and see the AST that a compiler generates from that. It looks like clang had this feature in the past (-emit-asm), but it has removed. Is there an easy way to do this today? clang still has that functionality: The commands are -ast-dump and -

从c ++代码中获取可读的AST

为了更好地理解C ++语言和语法的一些细节,我希望能够编写一个小型的C ++程序,并查看编译器从中产生的AST。 看起来clang在过去有这个功能(-emit-asm),但它已被删除。 今天有这么简单的方法吗? 铿锵仍然有这样的功能: 这些命令是-ast-dump和-ast-dump-xml 注意: -ast-dump-xml仅在调试模式下构建clang时才有效。 http://clang.llvm.org/docs/IntroductionToTheClangAST.html 例如: ## cat test.cpp int ma

What do people mean when they say C++ has "undecidable grammar"?

What do people mean when they say this? What are the implications for programmers and compilers? This is related to the fact that C++'s template system is Turing complete. This means (theoretically) that you can compute anything at compile time with templates that you could using any other Turing complete language or system. This has the side effect that some apparently valid C++ progra

当人们说C ++有“不可判断的语法”时,人们意味着什么?

当他们这样说时,人们的意思是什么? 对程序员和编译器有什么影响? 这与C ++的模板系统是图灵完整的事实有关。 这意味着(理论上)您可以在编译时使用可以使用任何其他Turing完整语言或系统的模板来计算任何东西。 这有一些副作用,一些明显有效的C ++程序无法编译; 编译器将永远无法确定程序是否有效。 如果编译器能够决定所有程序的有效性,它就能够解决停机问题。 请注意,这与C ++语法的歧义无关。 编辑:Josh

c++

I'm confused about how context-sensitivity and ambiguity influence each other. What i think is correct is: Ambiguity: An ambiguous grammar leads to the construction of more than one parse-tree using either left or right derivation. A language where all possible grammars are ambiguous is an ambiguous language. For instance C++ is an ambiguous language because x * y always can mean two

C ++

我对于情境敏感性和模糊性如何相互影响感到困惑。 我认为是正确的是: 歧义: 模糊的语法导致使用左或右派生来构建多个分析树。 所有可能的语法都不明确的语言是一种模糊的语言。 例如C ++是一种模糊的语言,因为x * y总是可以表示两种不同的东西,如下所述:为什么C ++不能用LR(1)解析器分析? 上下文灵敏度: 上下文敏感语法的规则是,这些规则的左边可能包含除了不同类型语法的所有规则的lhs内所需的一个非终

Why can't C++ be parsed with a LR(1) parser?

I was reading about parsers and parser generators and found this statement in wikipedia's LR parsing -page: Many programming languages can be parsed using some variation of an LR parser. One notable exception is C++. Why is it so? What particular property of C++ causes it to be impossible to parse with LR parsers? Using google, I only found that C can be perfectly parsed with LR(1) bu

为什么不能用LR(1)解析器解析C ++?

我正在阅读关于解析器和解析器生成器,并在维基百科的LR解析页面中找到了这个语句: 许多编程语言可以使用LR解析器的一些变体来解析。 一个明显的例外是C ++。 为什么这样? C ++的特殊属性是不可能用LR解析器解析的? 使用谷歌,我只发现C可以用LR(1)完美解析,但C ++需要LR(∞)。 Lambda Ultimate上有一个有趣的线索,讨论了C ++的LALR语法。 它包含一个博士论文的链接,其中包括对C ++解析的讨论,其中指出:

Is D's grammar really context

I've posted this on the D newsgroup some months ago, but for some reason, the answer never really convinced me, so I thought I'd ask it here. The grammar of D is apparently context-free. The grammar of C++, however, isn't (even without macros). ( Please read this carefully! ) Now granted, I know nothing (officially) about compilers, lexers, and parsers. All I know is from what

D的语法真的是上下文吗?

几个月前,我在D新闻组上发布了这个消息,但由于某种原因,答案从来没有真正让我信服,所以我想我会在这里问。 D的语法显然没有上下文。 但是,C ++的语法不是(即使没有宏)。 ( 请仔细阅读! ) 现在被授予, 我对编译器,词法分析器和解析器一无所知 (正式)。 我所知道的仅仅是从我在网上学到的知识。 这就是我所了解的关于上下文的内容(我相信),用非技术性的术语来解释: 语言的语法是上下文无关的,当且

how to get linux command output string and output status in c++

I want to get a Linux command's output string as well as command output status in a C++ program. I am executing Linux commands in my application. for example: Command: rmdir abcd Command output string: rmdir: failed to remove `abcd': No such file or directory Command Status: 1 (Which means command has been failed) I tried using Linux function system() which gives the output

如何在c ++中获得linux命令的输出字符串和输出状态

我想在C ++程序中获得Linux命令的输出字符串以及命令输出状态。 我正在执行我的应用程序中的Linux命令。 例如:命令: rmdir abcd 命令输出字符串: rmdir:无法删除`abcd':没有这样的文件或目录 命令状态: 1(表示命令失败) 我尝试使用Linux函数system() ,它给出了输出状态,函数popen()给出了一个命令的输出字符串,但是这两个函数都没有给出Linux命令的输出字符串和输出状态。 输出字符串是标准输出

How to properly use system() to execute a command in C++?

I am new to C++ programming under Windows. I am trying to execute a command say cuobjdump in C++ code using the system() function: system("C:\program files\nvidia gpu computing...\cuobjdump.exe --dump-cubin C:\..\input.exe"); output: Usage : cuobjdump [options] <file> This followed by the list of the options for cuobjdump. When I execute this program I always get the cuobjdump help

如何正确使用system()在C ++中执行命令?

我是Windows下的C ++编程新手。 我试图执行一个命令说cuobjdump在C ++代码中使用system()函数: system("C:\program files\nvidia gpu computing...\cuobjdump.exe --dump-cubin C:\..\input.exe"); 输出: Usage : cuobjdump [options] <file> 随后是cuobjdump的选项列表。 当我执行这个程序时,我总是得到命令行中显示的cuobjdump帮助选项。 就好像系统调用不解析文件名一样。 我究竟做错了什么? 我在使用cr

Bash input/output in C++

I'm writing program in C++ (for XAMPP communication) and I want to execute command which I have in strings (I know that this is simply system("command")) but I want to get the output from bash to C++ to string. I've founded several threads about this, but no which solved Bash -> C++. You can call the FILE *popen(const char *command, const char *mode) function. Then, you c

Bash输入/输出在C ++中

我正在用C ++编写程序(用于XAMPP通信),我想执行我在字符串中的命令(我知道这只是系统(“命令”)),但我想从bash获取输出到C ++字符串。 我已经建立了几个线程,但没有解决Bash - > C ++。 你可以调用FILE *popen(const char *command, const char *mode)函数。 然后,您可以读取它返回的文件以获取您的呼叫输出。 这就像使用管道将您使用的命令的输出重定向到硬盘驱动器中的文件然后读取该文件,但是您无法在硬盘

Using a regex capture directly in expression in C++

I'm trying to use a captured group directly in the regex. However, when I try to do this the program hangs indefinitely. For example: string input = "<Tag>blahblah</Tag>"; regex r1("<([a-zA-Z]+)>[a-z]+</1>"); string result = regex_replace(result, regex, ""); If I add another slash to the capture "<([a-zA-Z]+)>[az]</\1>" , the program compiles

直接在C ++表达式中使用正则表达式捕获

我试图直接在正则表达式中使用捕获的组。 但是,当我尝试这样做时,程序无限期地挂起。 例如: string input = "<Tag>blahblah</Tag>"; regex r1("<([a-zA-Z]+)>[a-z]+</1>"); string result = regex_replace(result, regex, ""); 如果我添加另一个斜杠到捕获"<([a-zA-Z]+)>[az]</\1>" ,程序编译但会抛出一个“regex_error(regex_constants :: error_backref)”异常。 笔

Debug in VS C++ with dll, pdb files and source

A question about pdb file. Is pdb file for debugging in Visual Studio? If so, why do they also exist in my Release folder? It's normal that pdb files are in Debug folder, but why they are also in Release folder. So I have now a Release folder build by Integration team with all the pdb files. Now I can load all the corresponding source (in GIT) so I'm sure that the binaries correspon

在VS C ++中使用dll,pdb文件和源代码进行调试

关于pdb文件的问题。 是在Visual Studio中进行调试的pdb文件吗? 如果是这样,为什么他们也存在于我的Release文件夹中? pdb文件在Debug文件夹中是正常的,但为什么它们也在Release文件夹中。 所以我现在有一个由集成团队构建的发布文件夹和所有的pdb文件。 现在我可以加载所有相应的源代码(在GIT中),所以我确信二进制文件对应于源代码。 那么我是否需要重新构建才能在Visual Studio中进行调试? 如果不是,为了快速