有人可以使用main语法C来解释递归下降解析器 [英] Can someone explain a recursive descent parser using the main for syntax C

查看:76
本文介绍了有人可以使用main语法C来解释递归下降解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法理解这个公式。有人可以解释使用main作为语法。



main()

{

}



如何将其分解为要解析的递归公式?



公式只是基于某些代码的公式吗?或者它也包含在符号表中的某些代码中。



我试图在源代码中解析我自己的主函数。

如果这不是方法,那么我采取什么方法来使c理解我的语言主要因此我可以使用rr for语句?这不是家庭作业



我尝试过:



试读一些关于rr。我不明白rr究竟是如何得到它的结构,或者是以它制作语言的方式定义的。如果你使用rr语句和表达式,你如何解析函数。

解决方案

main 函数可以永远不会以递归的方式使用,因为 main 是一个特殊的函数,它是你程序的入口点。

引用:

如何将其分解为递归公式?



简短回答,你不要因为函数是空的。

为了将函数分解为递归代码,需要一个具有递归定义的函数,如factorial或Fibonacci。

递归 - 维基百科 [ ^ ]

[更新]

引用:

有人可以解释一下使用主C的递归下降



在这句话中,缺少的单词很重要。

当你寻求帮助时,只有同学可以在没有细节的情况下知道你所说的话,因为他已经知道了。但是我们不知道细节。

对于我们来说,你的标题以混淆的方式告诉你想要做一个main的递归函数,而不是你何时使用递归下降解析器解析main。


main 函数通常不是递归的:这不是不可能的,但是当你尝试时它会使问题变得复杂(如果只是因为它是你应用程序中调用的第一个函数,所以在第一次调用它之前设置它将要处理的数据几乎是不可能的。)



通常情况下,你会做这样的事情:

  int  main()
{
/ * 设置数据* /
...
/ * 调用递归函数* /
int i = func(parameterValue);
...
return 0 ;
}
int func( int x)
{
...
func(modifiedValueOfX);
...
}

按照这种方式思考,然后重新阅读你的作业问题。


一个递归函数必须有一个退出条件,否则它理论上运行无限但实际上堆栈耗尽内存,因为每次调用都会占用一些内存。



递归函数的最佳例子是Fibonacci或< a href =https://www.tutorialspoint.com/cprogramming/c_recursion.htm> factorial 功能。



我喜欢划分和征服算法的力量。那是什么编程取笑。 ; - )

I am having trouble understanding the formula. Can someone explain using the main as the syntax.

main()
{
}

How do I break that into a recursive formula to parse?

Is the formula just a formula to base some code on? Or is it also included with some code in the symbol table or something.

I am trying to parse my own main function in a source.
If this is not the approach, then what approach do I take to get c to understand my languages main so I can use rr for statements? This is not homework

What I have tried:

Tried reading some tuts on rr. I do not understand how exactly the rr gets its structure, or defined in the way it does to make a language. And if you use rr for statements and expressions how do you parse the function.

解决方案

The main function can never be used in a recursive manner because main is a special function, it is the entry point of your program.

Quote:

How do I break that into a recursive formula?


Short answer, you don't because the function is empty.
In order to break a function into recursive code, you need a function with a recursive definition like factorial or Fibonacci.
Recursion - Wikipedia[^]
[Update]

Quote:

Can someone explain a recursive descent using a main C


In this sentence, the missing word parser matters.
When you ask for help, only a classmate can know what you talk about without details because he already know them. But we don't know the details.
For us, your title tells in a confuse way that you want to do a recursive function of main when instead you when to parse main with a recursive descent parser.


The main function isn't usually recursive: it's not impossible to do that, but it complicates matters when you try (if only because it's the first function called in your app, so it's pretty much impossible to set up the data it's going to process before the first call to it).

Normally, you'd do something like this:

int main()
   {
   /* Set up the data */
   ...
   /* Call recursive function */
   int i = func(parameterValue);
   ...
   return 0;
   }
int func(int x)
   {
   ...
   func(modifiedValueOfX);
   ...
   }

Think of it that way, and then re-read your homework question.


a recursive function must have an exit condition, else it runs theoreticly infinite but in reality the stack runs out of memory because every call eats some memory.

Best examples for recursive functions are Fibonacci or factorial function.

I like the Divide-and-conquer algorithm for its power. Thats what programming makes fun. ;-)


这篇关于有人可以使用main语法C来解释递归下降解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆