Implement Recursive Descent Parsing C Program

By | October 18, 2016

Let us learn how to develop a recursive descent parsing program in C programming language using functions.

The header file ctype.h is used because the definition for isalnum() function is defined in it and similarly the definitions of strlen() method is in string.h header file.

What is a Recursive Descent Parser?

A recursive descent parser is a top-down parser. This is one of the most simple forms of parsing. It is used to build a parse tree from top to bottom and reads the input from left to right.

A form of recursive descent parsing that does not require backtracking algorithm is known as a predictive parser. The parsers that use backtracking may require exponential time. This parser is normally used for compiler designing purpose.

The parser gets an input and reads it from left to right and checks it. If the source code fails to parse properly, then the parser exits by giving an error (flag) message. If it parses the source code properly then it exits without giving an error message.

Must Read: C Program To Find First and Follow of a Grammar

 

Recursive Descent Parser Algorithm

 

C Program To Develop A Recursive Descent Parser

Output

Develop Recursive Descent Parsing C Program with Algorithm

If you have any compilation error or doubts in this  C program for recursive descent parser code, let us know about it in the comment section below.

13 thoughts on “Implement Recursive Descent Parsing C Program

  1. Akash Pillai

    At last, I found a working program for this code. I am developing a basic compiler using recursive descent parsing technique. I hope it goes well.

    Reply
  2. Mahesh Ganguly

    LL parsing technique is much more efficient than recursive descent parsing in C programming. Please try to implement LL parsing in C programming. LL parsers are always linear in time too.

    Reply
  3. Chaitrali Naik

    Thanks for this parser generator c program. Recursive Descent Parsers can actually handle greater classes of grammars than LL1 Parsers. Both have their own pros and cons.

    Reply
    1. Tushar Soni Post author

      Apart from Recursive Descent Parser, there are so many other parsing algorithms used in compiler designing such as:

      1. GLR
      2. LL
      3. LR
      4. Simple Precedence Parser
      5. Top-Down
      6. Bottom-Up
      7. LARL
      8. Bounded Context
      9. CYK
      10. SLR
      Reply
  4. Akshay Bramhe

    This recursive descent parser in C programming is really good. Thanks for the efforts.

    Reply
  5. Arshan Reddy

    Actually it process the following strings also e=
    e=e any symbols e*e/ so if any terminals
    Other than ( *,+,digit/num )these symbols it just
    Comes out of all recursive procedures
    SOL:
    so in order to correct it keep the following
    Additional condition to flag ==0 && (count==length)
    Where length=strlen(expression)
    If any symbols other than above mentioned symbols occurs it comes out so count does
    Not gets equal to length it means it met with terminal that is not written in our code .

    Reply

Let's Discuss