Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取函数的类型_C#_String_Parsing_Types - Fatal编程技术网

C# 获取函数的类型

C# 获取函数的类型,c#,string,parsing,types,C#,String,Parsing,Types,我试图用C语言解析这个表达式,如下所示: 给出以下示例,如何获取表达式中所有内容的“类型”: fun ---> function p1, p2 ---> variables 33 ---> constant "lina" ---> constant g ---> function x ---> variable 5 ---> constant 在一般情况下,您不能用正则表达式解析这样的字符串:当您需要上

我试图用C语言解析这个
表达式
,如下所示:

给出以下示例,如何获取
表达式中所有内容的“类型”:

fun    ---> function
p1, p2 ---> variables
33     ---> constant
"lina" ---> constant 
g      ---> function 
x      ---> variable
5      ---> constant 
在一般情况下,您不能用正则表达式解析这样的字符串:当您需要上下文无关的语法时,正则表达式只能使用正则语法(带有一些较小的扩展)。您需要一个解析器(例如or)。看

详情请参阅。为了显示您可能面临的困难,让我们只玩字符串和注释:

 fun (1 + p1 + 1);                  // p1 is an argument
 fun (/*1 + p1 + 1*/);              // p1 is NOT an argument
 fun ("/*1" + p1 + "1*/");          // p1 is an argument 
 fun (/*"/*1" + p1 + "1*+/"*/);     // p1 is NOT an argument 
 fun ("/*""/*1" + p1 + "1*+/""*/"); // p1 is an argument  
 ...

不能使用正则表达式获取字符串的“类型”。您需要某种类型的解析器将此字符串转换为某种类型的数据结构。由于您提供的数据不足以理解您的问题,请详细说明。正确无误。你需要更类似于解释器/解析器的东西,而不仅仅是一个简单的正则表达式。但是,imho,对于OP来说,最好能提出一些建议,他如何解决他的问题,可能是以不同的方式。@tym32167:解析不是一件容易的事,但你说得很对:当说“X不是解决方案”时,应该提供一个本源的“Y可以使用”。我看不出一个简单的方法可以把老好人Lex/Yacc/Bison和.net结合起来,所以我提到了Antlr和Irony
 fun (1 + p1 + 1);                  // p1 is an argument
 fun (/*1 + p1 + 1*/);              // p1 is NOT an argument
 fun ("/*1" + p1 + "1*/");          // p1 is an argument 
 fun (/*"/*1" + p1 + "1*+/"*/);     // p1 is NOT an argument 
 fun ("/*""/*1" + p1 + "1*+/""*/"); // p1 is an argument  
 ...