I've been trying to write my own compiler for educational purposes and I'm stuck on an issue. I've taken the recursive descent approach with some previous knowledge on lex and yacc/bison.
So far I'm just trying to handle the parsing aspect without regards to the generation of the AST or code generation.
I'm trying to write the expression parsing for this particular grammar file part
primary_expression
: IDENTIFIER
| CONSTANT
| STRING_LITERAL
| '(' expression ')'
;
postfix_expression
: primary_expression
| postfix_expression '[' expression ']'
| postfix_expression '(' ')'
| postfix_expression '(' argument_expression_list ')'
| postfix_expression '.' IDENTIFIER
| postfix_expression PTR_OP IDENTIFIER
| postfix_expression INC_OP
| postfix_expression DEC_OP
;
So far I have this code
void Parser::primaryExpression()
{
if (accept(Token::eIdentifier))
{
}
else if (accept(Token::eIntNumber))
{
}
else if (accept('('))
{
expression();
expect(')');
}
}
void Parser::postfixExpression()
{
}
I'm having some problems dealing with the recursiveness of the postfix_expression
and I don't know how to continue with postfixExpression
function.
I'm under the impression that for a recursive descent parser, I should probably arrange my grammar in a different way.
Could anyone point me in the right direction?