I am trying to understand strings well using JavaCC without mistakenly matching them with another token. These lines must have spaces, letters and numbers.
My identifier and token are listed as follows:
<IDENTIFIER: (["a"-"z", "A"-"Z"])+>
<NUMBER: (["0"-"9"])+>
My current token:
<STRING: "\"" (<IDENTIFIER> | <NUMBERS> | " ")+ "\"">
Ideally, I only want to keep the material inside the quotation marks. I have a separate file in which I actually save variables and values. Should I delete quotes there?
Initially, I had a method in the parser file:
variable=<INDENTIFIER> <ASSIGN> <QUOTE> message=<IDENTIFIER> <QUOTE>
{File.saveVariable(variable.image, message.image);}
But, as you might have guessed, this did not allow spaces or numbers. For identifiers, such as variable names, I only want to allow letters.
So, I would like to get some tips on how I can collect string literals. In particular, I would like to make lines such as:
" hello", "hello ", " hello " and "\nhello", "hello\n", "\nhello\n"
.