Cheap and Secure Web Hosting Provider : See Now

Duplicating the quotation marks in in the quotation-mark enclosed strings

, , No Comments
Problem Detail: 

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?

Asked By : Valentin Tihomirov
Answered By : rici

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 ".

Best Answer from StackOverflow

Question Source :

3200 people like this

 Download Related Notes/Documents


Post a Comment

Let us know your responses and feedback