Beispiel #1
0
    private bool step()
    {
        if (currentToken == null)
        {
            int pos = 0;
            if (previousToken != null)
            {
                pos = previousToken.Position + previousToken.Lexeme.Length;
            }

            currentToken = new Token(DOLLAR, "$", pos);
        }

        int x = ((int)stack.Pop());
        int a = currentToken.Id;

        if (x == EPSILON)
        {
            return(false);
        }
        else if (isTerminal(x))
        {
            if (x == a)
            {
                if (stack.Count == 0)
                {
                    return(true);
                }
                else
                {
                    previousToken = currentToken;
                    currentToken  = scanner.nextToken();
                    return(false);
                }
            }
            else
            {
                throw new SyntaticError(parserConst.PARSER_ERROR[x], currentToken.Position);
            }
        }
        else if (isNonTerminal(x))
        {
            if (pushProduction(x, a))
            {
                return(false);
            }
            else
            {
                throw new SyntaticError(parserConst.PARSER_ERROR[x], currentToken.Position);
            }
        }
        else // isSemanticAction(x)
        {
            semanticAnalyser.executeAction(x - parserConst.FIRST_SEMANTIC_ACTION, previousToken);
            return(false);
        }
    }