I'm trying to parse a txt file that represents a grammar to be used in a recursive descent parser. The txt file would look something like this:
SPRIME ::= Expr eof
Expr ::= Term Expr'
Expr' ::= + Term Expr' | - Term Expr' | e
To isolate the left hand side and split the right hand side into seperate production rules, I take each line and call:
String[] firstSplit = line.split("::=");
String LHS = firstSplit[0];
String productionRules = firstSplit[1].split("|");
However, when I call the second split method, I am not returned an array of the Strings separated by the "|" character, but an array of each indiviudual character on the right hand side, including "|". So for instance, if I was parsing the Expr' rule and printed the productionRules array, it would look like this:
"+"
"Term"
"Expr'"
""
"|"
When what I really want should look like this:
- Term Expr'
Anyone have any ideas what I'm doing wrong?