MCPcopy Create free account
hub / github.com/WheretIB/nullc / ParseSwitchExpr

Function ParseSwitchExpr

NULLC/Parser.cpp:1637–1678  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1635}
1636
1637bool ParseSwitchExpr(Lexeme** str)
1638{
1639 if(!ParseLexem(str, lex_switch))
1640 return false;
1641
1642 if(!ParseLexem(str, lex_oparen))
1643 ThrowError((*str)->pos, "ERROR: '(' not found after 'switch'");
1644
1645 const char *condPos = (*str)->pos;
1646 if(!ParseVaribleSet(str))
1647 ThrowError((*str)->pos, "ERROR: expression not found after 'switch('");
1648 BeginSwitch(condPos);
1649
1650 if(!ParseLexem(str, lex_cparen))
1651 ThrowError((*str)->pos, "ERROR: closing ')' not found after expression in 'switch' statement");
1652
1653 if(!ParseLexem(str, lex_ofigure))
1654 ThrowError((*str)->pos, "ERROR: '{' not found after 'switch(...)'");
1655
1656 while(ParseLexem(str, lex_case) || ParseLexem(str, lex_default))
1657 {
1658 Lexeme *condPos = *str;
1659 if(condPos[-1].type == lex_case && !ParseVaribleSet(str))
1660 ThrowError((*str)->pos, "ERROR: expression expected after 'case' of 'default'");
1661 if(!ParseLexem(str, lex_colon))
1662 ThrowError((*str)->pos, "ERROR: ':' expected");
1663
1664 if(!ParseExpression(str))
1665 AddVoidNode();
1666 while(ParseExpression(str))
1667 AddTwoExpressionNode();
1668 if(condPos[-1].type == lex_default)
1669 AddDefaultNode();
1670 else
1671 AddCaseNode(condPos->pos);
1672 }
1673
1674 if(!ParseLexem(str, lex_cfigure))
1675 ThrowError((*str)->pos, "ERROR: '}' not found after 'switch' statement");
1676 EndSwitch();
1677 return true;
1678}
1679
1680bool ParseReturnExpr(Lexeme** str, bool yield)
1681{

Callers 1

ParseExpressionFunction · 0.85

Calls 10

ParseLexemFunction · 0.85
ThrowErrorFunction · 0.85
ParseVaribleSetFunction · 0.85
BeginSwitchFunction · 0.85
ParseExpressionFunction · 0.85
AddVoidNodeFunction · 0.85
AddTwoExpressionNodeFunction · 0.85
AddDefaultNodeFunction · 0.85
AddCaseNodeFunction · 0.85
EndSwitchFunction · 0.85

Tested by

no test coverage detected