I am new to context free grammar and i’ve only learned stuff like left/rightmost derivation and G=(V, E, R ,S) so far. But the problem I’m trying to solve involves java prototype and I’m not very good at java. So I don’t really know where to start.
Give a context-free grammar for the sub-language of Java prototypes.
int myMethod();
double myMethod(int x, double y);
static double f(int x, double y, int z);
public static double g();
These are methods and variables, how can I relate to things like S => Sa | e ? And what is the start symbol?
Thank you!
All java you need to know about method signatures is located on single doc page. You start writing grammar by identifying grammar variables. The obvious ones to start with are
You introduce more variables while writing grammar rules, for example
As soon as you finish your grammar you’d have the “top most rule”:
The
method_signatureis the start symbol.