As it stands, this is a bit on the simplistic side to make much sense as a parser. The whole thing can be written as a simple regular expression: "[ab]?c". If you really insist on writing it as a parser, the code could be something like:
Boolean parseA() {
// an A is a B followed by a `c`:
return parseB() && (get_token() == Token.c);
}
Boolean parseB {
// Get a token.
// If it's an `a` or a `b`, consume it.
// Otherwise, throw it back (match null string by consuming nothing).
// Either way, return true (successful match).
//
token current_token = get_token();
if (token != Token.a && token != Token.b)
push_back(current_token);
return true;
}
Edit (in response to comment on another answer): No, when you're matching B, you should not look for a Token.c. As far as B cares, there are three possibilities: match 'a', match 'b', or match nothing at all. It's then up to the part that parses A to check that it has a B followed by a Token.c.
For example, if you were to change the grammar to something like:
A ::= B C
B ::= a | b | ε
C ::= c | d
Since 'B' still has the same definition, you should not have to change it just because some other definition changed. Likewise, you might add to the grammar to allow (for example) an arbitrary string of B's followed by a C.