Esempio n. 1
0
        public SwitchCaseExpression parseCase()
        {
            CaseExpression caseExp;
            DefaultExpression defaultExp;

            if (currentTokenEquals(Token.TokenValue.CASE))
            {
                caseExp = new CaseExpression();

                nextToken();

                caseExp.literal = parseLiteralExpression();

                nextTokenIfEquals(Token.TokenValue.TWOPOINTS);

                //case 'a': break;
                if (currentTokenEquals(Token.TokenValue.BREAK))
                {
                    caseExp.body = null;
                    nextToken();
                    nextTokenIfEquals(Token.TokenValue.SEMICOLON);
                }
                //case 'a':
                //case 'b': ...
                else if (currentTokenEquals(Token.TokenValue.CASE) || currentTokenEquals(Token.TokenValue.DEFAULT))
                {
                    caseExp.body = null;
                    caseExp.next = parseCase();
                }
                //case 'a':
                //  e
                //  break;
                else
                {
                    caseExp.body = parseExpression();
                    caseExp.next = null;

                    nextTokenIfEquals(Token.TokenValue.BREAK);
                    nextTokenIfEquals(Token.TokenValue.SEMICOLON);
                }

                return caseExp;

            }
            else if (currentTokenEquals(Token.TokenValue.DEFAULT))
            {
                defaultExp = new DefaultExpression();

                nextToken();
                nextTokenIfEquals(Token.TokenValue.TWOPOINTS);

                //default: break;
                if (currentTokenEquals(Token.TokenValue.BREAK))
                {
                    defaultExp.body = null;
                    nextToken();
                    nextTokenIfEquals(Token.TokenValue.SEMICOLON);
                }
                //default:
                //  e
                //  break;
                else
                {
                    defaultExp.body = parseExpression();
                    nextTokenIfEquals(Token.TokenValue.BREAK);
                    nextTokenIfEquals(Token.TokenValue.SEMICOLON);
                }

                return defaultExp;
            }

            throw new SyntaxError(lineNumber, colNumber, Token.TokenValue.CASE);
        }
Esempio n. 2
0
        public void addDefault(DefaultExpression de)
        {
            if (cases == null)
            {
                cases = new List<SwitchCaseExpression>();
            }

            cases.Add(de);
            hasDefaultCase = true;
        }