示例#1
0
 private void AnalyzeFuncCall(FunctionItem currentFunction)
 {
     _expressionAnalyzer.Add(_token);
     NextToken();
 }
示例#2
0
        private void AnalyzeFuncDcl()
        {
            _isAnalyzingFunction = true;
            NextToken();

            if (_token.Symbol != Symbols.SIdentificador)
            {
                RaiseUnexpectedTokenError("identificador");
            }

            var item = _symbolTable.Search(_token.Lexeme);

            if (item != null)
            {
                RaiseDoubleError(Symbols.SFuncao);
            }

            var funcItem = new FunctionItem
            {
                Lexeme = _token.Lexeme,
                Level = _level,
                Label = _codeGenerator.GetStringLabelFor(_lastLabel)
            };
            
            _funcInfo = new FunctionInfo { Name = _token.Lexeme };
            _rootNode = new SyntaxTreeNode { Value = _token.Symbol };
            _currentNode = _rootNode;
            _codeGenerator.GenerateLabel(_lastLabel);
            _level++;
            NextToken();

            if (_token.Symbol != Symbols.SDoisPontos)
            {
                RaiseUnexpectedTokenError("\":\"");
            }

            NextToken();

            if (_token.Symbol != Symbols.SInteiro && _token.Symbol != Symbols.SBooleano)
            {
                RaiseUnexpectedTokenError("\"inteiro\" ou \"booleano\"");
            }

            var type = _token.Symbol == Symbols.SInteiro ? ItemType.Integer : ItemType.Boolean;

            funcItem.Type = type;
            _symbolTable.Insert(funcItem);
            NextToken();

            if (_token.Symbol != Symbols.SPontoVirgula)
            {
                RaiseMissingSemicolonError();
            }

            AnalyzeBlock(true);
            
            if (!FunctionHelper.AllPathsReturns(_rootNode))
            {
                RaiseMissingFunctionReturn();
            }
            
            _symbolTable.CleanUpToLevel(_level);
            _level--;
            _rootNode = _currentNode = null;
            _funcInfo = null;
        }