www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9529] New: Switch Statement grammar bug for the chain of case statements

http://d.puremagic.com/issues/show_bug.cgi?id=9529

           Summary: Switch Statement grammar bug for the chain of case
                    statements
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid, spec
          Severity: normal
          Priority: P2
         Component: websites
        AssignedTo: nobody puremagic.com
        ReportedBy: k.hara.pg gmail.com



Currently the chain of case statement is not allowed in grammar.

void main() {
    int c;
    switch (c) {
        case 1:
        case 2:  // chain
            break;
        default: break;
    }
}

But it is no sense. Because it is just equivalent with:

    switch (c) {
        case 1 : .. case 2:
            break;


http://dlang.org/statement.html#SwitchStatement
--------
SwitchStatement:
    switch ( Expression ) ScopeStatement

CaseStatement:
    case ArgumentList : ScopeStatementList

CaseRangeStatement:
    case FirstExp : .. case LastExp : ScopeStatementList

FirstExp:
    AssignExpression

LastExp:
    AssignExpression

DefaultStatement:
    default : ScopeStatementList

ScopeStatementList:
    StatementListNoCaseNoDefault

StatementListNoCaseNoDefault:
    StatementNoCaseNoDefault
    StatementNoCaseNoDefault StatementListNoCaseNoDefault

StatementNoCaseNoDefault:
    ;
    NonEmptyStatementNoCaseNoDefault
    ScopeBlockStatement
--------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 17 2013