コード例 #1
0
        private bool step()
        {
            if (currentToken == null)
            {
                int pos = 0;
                if (previousToken != null)
                {
                    pos = previousToken.getPosition() + previousToken.getLexeme().Length;
                }

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

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

            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(PARSER_ERROR[x], currentToken.getLinha());
                }
            }
            else if (isNonTerminal(x))
            {
                if (pushProduction(x, a))
                {
                    return(false);
                }
                else
                {
                    //Console.WriteLine(currentToken.getLexeme());
                    throw new SyntaticError(PARSER_ERROR[x], currentToken.getLinha());
                }
            }
            else // isSemanticAction(x)
            {
                semanticAnalyser.executeAction(x - FIRST_SEMANTIC_ACTION, previousToken);
                return(false);
            }
        }
コード例 #2
0
ファイル: Sintatico.cs プロジェクト: carolmkl/TrabalhoBD2
        public void parse(Lexico scanner, Semantico semanticAnalyser)
        {
            this.scanner = scanner;
            this.semanticAnalyser = semanticAnalyser;

            stack.Clear();
            stack.Push(DOLLAR);
            stack.Push(START_SYMBOL);

            currentToken = scanner.nextToken();

            while (!step());
        }
コード例 #3
0
        public void parse(Lexico scanner, Semantico semanticAnalyser)
        {
            this.scanner          = scanner;
            this.semanticAnalyser = semanticAnalyser;

            stack.Clear();
            stack.Push(DOLLAR);
            stack.Push(START_SYMBOL);

            currentToken = scanner.nextToken();

            while (!step())
            {
                ;
            }
        }