|
| audinue (35) | |
I have a little example of syntax rule here (using regex syntax):number = [1-9]([0-9]+) | [0-9]([1-9]+).([0-9])+ | 0x([a-f0-9])+Could somebody give me an example how to implement syntax rule above using recursive descent algorithm? A nice and simple one will be very grateful of course :) Thanks in advance. | |
Last edited on | |
| Duoas (2964) | |
| The Wikipedia has a pretty good example... http://en.wikipedia.org/wiki/Recursive_descent It takes a minute to figure it out but it is relatively straight-forward. You'll have to write the getsym() function to gather symbols from the input stream. If this is homework, it is poorly-designed. The above would better fall under the category of lexing, whereas recursive descent is parsing, or analysis of lexed tokens. Alas, I know this doesn't help too much. Can you be more specific in terms of what you are doing? | |
| Grey Wolf (1407) | |
| The following post may help: http://www.cplusplus.com/forum/general/1116/page2.html (the post that starts "Here is some code put together from Stroustrups book") | |
| audinue (35) | |
| Wow guys! Thats very helpful! Why they use scanner/lexer? Is it makes easier to recognize the syntax? I think it slow things down because to parse the source we need to do several processes... Btw, this is not a homework :) I just want to learn how recursive descent works. | |
Last edited on | |
| audinue (35) | |||||
| Btw, any example how to convert this traditional parsing into recursive descent one? Based on this rule:
| |||||
Last edited on | |||||
| Duoas (2964) | |
| It doesn't affect speed significantly. But it makes the whole process much easier to control. To fix the routine, the getsym() compares to getchar() (since each 'symbol' in a number is a single character) and use functions like in the Wikipedia article to work your way through the number to either validate it or reject it. Good luck! | |
| audinue (35) | |
| A little example please... I still don't understand Wikipedia's example *sob*,... please. | |
This topic is archived - New replies not allowed.
