Delimited comment in C#

68 views Asked by At

Referring to the below production fragment from C# language standard specification,

fragment Delimited_Comment
    : '/*' Delimited_Comment_Section* ASTERISK+ '/'
    ;
    
fragment Delimited_Comment_Section
    : SLASH
    | ASTERISK* Not_Slash_Or_Asterisk
    ;

fragment Not_Slash_Or_Asterisk
    : ~('/' | '*')    // Any except SLASH or ASTERISK
    ;

I don't understand ASTERISK* Not_Slash_Or_Asterisk part. If ASTERISK* means zero or more asterisks, why are additional asterisks restricted by Not_Slash_Or_Asterisk.

Please help me understand the above production found in C# language standard specification.

1

There are 1 answers

3
canton7 On BEST ANSWER
fragment Delimited_Comment
    : '/*' Delimited_Comment_Section* ASTERISK+ '/'
    ;
    
fragment Delimited_Comment_Section
    : SLASH
    | ASTERISK* Not_Slash_Or_Asterisk
    ;

fragment Not_Slash_Or_Asterisk
    : ~('/' | '*')    // Any except SLASH or ASTERISK
    ;

So a delimited comment is /*, followed by stuff which isn't */, followed by 1 or more *'s, followed by /.

The Delimited_Comment_Section is saying that if you have one or more *'s, they can't be followed by a / (or by another *, but that's redundant). The only way to have a / is if it isn't preceded by a *.