I'm writing a program in C for my programming languages class which must implement a RDP using a certain EBNF grammar for legal C statements. I have never programmed in C, so I have been having a tough time formulating the steps that can do this without being ugly, so I would like some advice on writing the parser if anyone can help.
Here is the EBNF grammar
Code:
<statement> ::= ; | <assignment> | <ifStatement> | <whileStatement>
<assignment> ::= <identifier> = <expression> ;
<ifStatement> ::= if ( <expression> ) <statement> [ else <statement> ]
<whileStatment> ::= while ( <expression> ) <statement>
<expression> ::= <conjunction> { | | <conjunction> }*
<conjunction> ::= <relation> { && <relation> }*
<relation> ::= <addition> { (< | <= | > | >= | == | !=) <addition> }*
<addition> ::= <term> { (+ | -) <term> }*
<term> ::= <negation> { (* | /) <negation> }*
<negation> ::= [ ! ] <factor>
<factor> ::= <identifier> | <literal> | ( <expression> )
<identifier> ::= <letter> | <identifier> <letter> | <identifier> <digit>
<letter> ::= a | b | ... | z | A | B | ... | Z
<digit> ::= 0 | 1 | 2 | ... | 9
<literal> ::= <boolean> | <integer>
<boolean> ::= true | false
<integer> ::= <digit> | <integer> <digit>
right now, my program is reading input from a sample text file which contains single lines of sample code. It saves each line in a character array, so that is how I am planning on working with each line of text.
I am thinking of making a statement function, that will parse through the string until it finds either a ";" or "=" or a "(" and then depending on what it finds, passing the string down into the appropriate function for that character, ie. if I find the equal sign, it will be an assignment, so I jump into an assignment function.
Does this seem feasible?