There is such a grammar

string_literal ::= " { graphic_character } "

The double-quotes that you see must appear in the user program and curly braces mean "any number of graphic characters in the string". The characters are defined further

graphic_character ::= basic_graphic_character | lower_case_letter | other_special_character
basic_graphic_character ::=
upper_case_letter | digit | special_character | space_character 

with special characters listed

" # & ' () * + , - . / : ; < = > ? @ [ ] _ `

I have encountered a situation where I need the double quote to be the part of the string. This is admitted indeed: double quote is a first special character and it enters the basic graphic characters and, thus, graphic characters. So, I can legally put it into my string. But, this means that terminating quotation mark will be considered a part of the string also and parsing will fail. The language specification says that we need to double the quotation marks to produce a single qmark in the string. I do not get why this requirement it is not a part of the grammar. How should proper grammar had to look in this case?


Just replace " in the list of possible characters with "".

That might have consequences for other grammar productions which use the same non-terminals, in which case you might need to separate special_character into special_character_not_quote and ".

| cite | improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.