comparison trunk/src/Parser.d @ 220:0c647e319b8e

- Removed assert from parseStatement(). - Implemented parseCaseDefaultBody().
author aziz
date Thu, 26 Jul 2007 16:37:05 +0000
parents 0d14a09227a4
children 4f31e4671e06
comparison
equal deleted inserted replaced
219:0d14a09227a4 220:0c647e319b8e
1371 return statements; 1371 return statements;
1372 } 1372 }
1373 1373
1374 Statement parseStatement() 1374 Statement parseStatement()
1375 { 1375 {
1376 assert(token.type != T.RBrace && token.type != T.EOF);
1377
1378 // writefln("°parseStatement:(%d)token='%s'°", lx.loc, token.srcText); 1376 // writefln("°parseStatement:(%d)token='%s'°", lx.loc, token.srcText);
1379 1377
1380 Statement s; 1378 Statement s;
1381 Declaration d; 1379 Declaration d;
1382 switch (token.type) 1380 switch (token.type)
1768 require(T.RParen); 1766 require(T.RParen);
1769 auto switchBody = parseScopeStatement(); 1767 auto switchBody = parseScopeStatement();
1770 return new SwitchStatement(condition, switchBody); 1768 return new SwitchStatement(condition, switchBody);
1771 } 1769 }
1772 1770
1771 Statement parseCaseDefaultBody()
1772 {
1773 // This function is similar to parseNoScopeStatement()
1774 Statement s;
1775 if (token.type == T.LBrace)
1776 {
1777 nT();
1778 auto ss = new Statements();
1779 while (token.type != T.Case &&
1780 token.type != T.Default &&
1781 token.type != T.RBrace &&
1782 token.type != T.EOF)
1783 ss ~= parseStatement();
1784 require(T.RBrace);
1785 s = ss;
1786 }
1787 else if (token.type == T.RBrace)
1788 {}
1789 else
1790 s = parseStatement();
1791 return new ScopeStatement(s);
1792 }
1793
1773 Statement parseCaseStatement() 1794 Statement parseCaseStatement()
1774 { 1795 {
1775 assert(token.type == T.Case); 1796 assert(token.type == T.Case);
1776 // T.Case skipped in do-while. 1797 // T.Case skipped in do-while.
1777 Expression[] values; 1798 Expression[] values;
1780 nT(); 1801 nT();
1781 values ~= parseAssignExpression(); 1802 values ~= parseAssignExpression();
1782 } while (token.type == T.Comma) 1803 } while (token.type == T.Comma)
1783 require(T.Colon); 1804 require(T.Colon);
1784 1805
1785 auto caseBody = parseScopeStatement(); 1806 auto caseBody = parseCaseDefaultBody();
1786 return new CaseStatement(values, caseBody); 1807 return new CaseStatement(values, caseBody);
1787 } 1808 }
1788 1809
1789 Statement parseDefaultStatement() 1810 Statement parseDefaultStatement()
1790 { 1811 {
1791 assert(token.type == T.Default); 1812 assert(token.type == T.Default);
1792 nT(); 1813 nT();
1793 require(T.Colon); 1814 require(T.Colon);
1794 return new DefaultStatement(parseScopeStatement()); 1815 return new DefaultStatement(parseCaseDefaultBody());
1795 } 1816 }
1796 1817
1797 Statement parseContinueStatement() 1818 Statement parseContinueStatement()
1798 { 1819 {
1799 assert(token.type == T.Continue); 1820 assert(token.type == T.Continue);