next up previous
Next: The break statement Up: Blocks and statements Previous: Labeled statements

The switch statement

The switch statement[17]:
SYMBOL SwitchStatement INHERITS CaseRangeScope END;
SYMBOL SwitchStatement: SwitchExpType: DefTableKey;

RULE: SwitchStatement ::= 'switch' '(' Expression ')' SwitchBlock COMPUTE
  SwitchStatement.SwitchExpType=Expression.Type;
  Expression.Required=intType;
END;

RULE: SwitchLabel ::= 'case' Expression ':' COMPUTE
  IF(EQ(Expression.Constant,NoStrIndex),
    message(ERROR,"Selector must be a constant",0,COORDREF),
  IF(NoAssign(
      Expression.Type,
      INCLUDING SwitchStatement.SwitchExpType,
      Expression.Constant),
    message(ERROR,"Selector not assignable to switch",0,COORDREF)))
  <- INCLUDING Goal.GotAllConstants;
END;
This macro is defined in definitions 17 and 18.
This macro is invoked in definition 14.

The switch statement[18]:
SYMBOL SwitchLabel INHERITS CaseIdDefScope, MultDefChk END;
SYMBOL SwitchLabel: Sym: int;

RULE: SwitchLabel ::= 'case' Expression ':' COMPUTE
  SwitchLabel.Sym=
    CastPrimitive(
      Expression.Constant,
      Expression.Type,
      INCLUDING SwitchStatement.SwitchExpType);
END;

RULE: SwitchLabel ::= 'default' ':' COMPUTE
  SwitchLabel.Sym=MakeName("default");
END;
This macro is defined in definitions 17 and 18.
This macro is invoked in definition 14.

Instantiate required modules[19]:
$/Name/AlgScope.gnrc +instance=Case :inst
This macro is defined in definitions 7 and 19.
This macro is invoked in definition 2.


next up previous
Next: The break statement Up: Blocks and statements Previous: Labeled statements
2008-09-11