简体   繁体   English

C ++中的未知类型的宏

[英]Unknown type of macro in C++

I noticed something when looking the kind of language of a software (openFOAM) which is written in C++. 在查看用C ++编写的软件(openFOAM)的语言时,我注意到了一些东西。 It was something like, 就像

field value;

For example, 例如,

temperature 25;

I wonder how this works. 我不知道这是如何工作的。 I mean how temperature is set to 25 without using equality sign. 我的意思是在不使用等号的情况下如何将温度设置为25。 Any idea? 任何想法?

Because openFOAM has a parser that understands that format. 因为openFOAM具有可理解该格式的解析器。

Such a parser is not hard to make, and C++ (with the help of a parser-generator tool like yacc, bison) is a popular choice for parsers because it can be very fast. 这样的解析器并不难制作,C ++(借助yacc,bison等解析器生成器工具)是解析器的一种流行选择,因为它可以非常快。

C++ is a Turing-complete language, therefore it can do anything that any other language can. C ++是图灵完备的语言,因此它可以执行任何其他语言可以执行的操作。 Specifically, it can process data that doesn't look like C++ code. 具体来说,它可以处理看起来不像C ++代码的数据。

Programming languages are typically context free. 编程语言通常是上下文无关的。 If the language is context free it can be parsed (I won't say it's trivial but it's a problem that has been solved so many times before and if you take a compilers class you'll have to do it for simple langauges). 如果语言是上下文无关的,则可以对其进行解析(我不会说这很简单,但这是一个已经被解决了很多次的问题,如果您选择编译器类,则必须使用简单的语言来解决)。

The parser is simply looking for a declarations of the format field value; 解析器只是在寻找格式field value;的声明field value; . It appears there is no type check happening so it is simply splitting on semi colon then on the space. 似乎没有进行类型检查,因此它只是在半冒号上然后在空格上分开。 Read about parsing context-free langauges, push down automata, and context free grammars if you're interested in learning about parsing source code. 如果您对解析源代码感兴趣,请阅读有关解析上下文无关语言,下推自动机和上下文无关语法的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM