write a program for left recursion?

Recommended Answers

All 2 Replies

write a program for left recursion?

Setting aside the fact that you are asking us to do your work for you, which is against the general policy of Daniweb, this sentence (fragment) doesn't make much sense.

I assume what you meant was that you need to write a parser that handles left recursion in the target grammar. There are two basic approaches to doing this, but neither of them a simple, and they certainly aren't something even the wizards of Daniweb could just whip up, at least not without knowing the grammar in question.

The first approach is to write a bottom-up parser, assuming an LR(k) grammar. However, writing a such a parser by hand simply isn't feasible; they are usually generated, which means you would need to write a parser generator rather than a parser per se. That, needless to say, is a lot of work, and we'd need to see the grammar first to know just what type of parser would be suitable.

The other alternative is to convert the left recursions to right recursions, making it feasible to write a top-down recursive-descent LL(k) parser, which is pretty much the only type suitable for writing by hand. That isn't an easy thing to get right, and no matter what the working grammar will still differ subtly for the language's reference grammar. This is probably what you wanted, but if so, where's the grammar to transform?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.