Example #1
0
            //private bool ConditionStatement(Tree.TreeNode parent)
            //{
            //    if (currentToken.Name == "IF")
            //    {
            //        var newNode = tree.Add("<condition-statement>", parent);
            //        LeftCondition(newNode);
            //        RightCondition(newNode);
            //        if (currentToken.Name == ";")
            //        {
            //            newNode.AddToChildren(new Tree.TreeNode(currentToken.Name, newNode));
            //        }
            //        else
            //        {
            //            Errors.AddToken(currentToken, locationNumber,
            //                $"';' expected but {currentToken.Name} found", tree);
            //            return false;
            //        }
            //        return true;
            //    }

            //    return false;
            //}

            //private bool LeftCondition(Tree.TreeNode parent)
            //{
            //    var newNode = tree.Add("<left-condition>", parent);
            //    newNode.AddToChildren(new Tree.TreeNode(currentToken.Name, newNode));
            //    currentToken = GetNext();
            //    IncrementLocation(currentToken);
            //    Constant(newNode);
            //    currentToken = GetNext();
            //    IncrementLocation(currentToken);
            //    if (currentToken.Name == "THEN")
            //    {
            //        newNode.AddToChildren(new Tree.TreeNode(currentToken.Name, newNode));
            //        currentToken = GetNext();
            //        IncrementLocation(currentToken);
            //        DeclarationList(newNode);
            //    }
            //    else
            //    {
            //        Errors.AddToken(currentToken, locationNumber,
            //            $"'THEN' expected but {currentToken.Name} found", tree);
            //        return false;
            //    }

            //    return true;
            //}

            //private bool RightCondition(Tree.TreeNode parent)
            //{
            //    var newNode = tree.Add("<right-condition>", parent);
            //    if (currentToken.Name == ";")
            //    {
            //        newNode.AddToChildren(new Tree.TreeNode("<empty>", newNode));
            //    }
            //    else
            //    {
            //        if (currentToken.Name == "ELSE")
            //        {
            //            newNode.AddToChildren(new Tree.TreeNode(currentToken.Name, newNode));
            //            currentToken = GetNext();
            //            IncrementLocation(currentToken);
            //            DeclarationList(newNode);
            //        }
            //        else
            //        {
            //            Errors.AddToken(currentToken, locationNumber,
            //                $"'ELSE' expected but {currentToken.Name} found", tree);
            //            return false;
            //        }
            //    }
            //    return true;
            //}


            private bool Declaration(Tree.TreeNode parent)
            {
                var newNode = tree.Add("<declaration>", parent);

                VariableIdentifier(newNode);
                currentToken = GetNext();
                IncrementLocation(currentToken);
                if (currentToken.Name == ":")
                {
                    newNode.AddToChildren(currentToken.Code + " " + currentToken.Name);
                    AttributeProc(newNode);
                    if (currentToken.Name != ";")
                    {
                        Errors.AddToken(currentToken, locationNumber,
                                        $"';' expected but {currentToken.Name} found", tree);
                        return(false);
                    }
                    else
                    {
                        newNode.AddToChildren(currentToken.Code + " " + currentToken.Name);
                        currentToken = GetNext();
                        IncrementLocation(currentToken);
                        return(true);
                    }
                }
                else
                {
                    Errors.AddToken(currentToken, locationNumber,
                                    $"':' expected but {currentToken.Name} found", tree);
                    return(false);
                }
            }
Example #2
0
            private bool Block(Tree.TreeNode parent)
            {
                var newNode = tree.Add("<block>", parent);

                Declarations(newNode);
                if (currentToken.Name == "BEGIN")
                {
                    newNode.AddToChildren(currentToken.Code + " " + currentToken.Name);
                    StatementsList(newNode);
                    if (currentToken.Name == "END")
                    {
                        newNode.AddToChildren(currentToken.Code + " " + currentToken.Name);
                        currentToken = GetNext();
                        IncrementLocation(currentToken);
                        return(true);
                    }
                    else
                    {
                        Errors.AddToken(currentToken, locationNumber,
                                        $"'END' expected but {currentToken.Name} found", tree);
                        return(false);
                    }
                }
                else
                {
                    Errors.AddToken(currentToken, locationNumber,
                                    $"'BEGIN' expected but {currentToken.Name} found", tree);
                    return(false);
                }
            }
Example #3
0
            private bool ProcedureIdentifier(Tree.TreeNode parent)
            {
                var newNode = tree.Add("<procedure-identifier>", parent);

                currentToken = GetNext();
                IncrementLocation(currentToken);
                return(Identifier(newNode));
            }
Example #4
0
            private bool Constant(Tree.TreeNode parent)
            {
                var newNode = tree.Add("<constant>", parent);

                if (_constantsTable.Tokens.ContainsKey(currentToken.Name))
                {
                    newNode.AddToChildren(currentToken.Code + " " + currentToken.Name);
                    return(true);
                }
                return(false);
            }
Example #5
0
            private bool Identifier(Tree.TreeNode parent)
            {
                var newNode = tree.Add("<identifier>", parent);

                if (_identifiersTable.Tokens.ContainsKey(currentToken.Name))
                {
                    newNode.AddToChildren(currentToken.Code + " " + currentToken.Name);
                    return(true);
                }

                return(false);
            }
Example #6
0
            private bool ConstantDeclarations(Tree.TreeNode parent)
            {
                var newNode = tree.Add("<constant-declarations>", parent);

                currentToken = GetNext();
                IncrementLocation(currentToken);
                if (currentToken.Name == "CONST")
                {
                    newNode.AddToChildren(currentToken.Code + " " + currentToken.Name);
                    return(ConstantDeclarationsList(newNode));
                }
                newNode.AddToChildren(new Tree.TreeNode("<empty>", newNode));
                return(true);
            }
Example #7
0
            private bool StatementsList(Tree.TreeNode parent)
            {
                var newNode = tree.Add("<statements-list>", parent);

                currentToken = GetNext();
                IncrementLocation(currentToken);
                //if (!ConditionStatement(newNode))
                //{
                newNode.AddToChildren(new Tree.TreeNode("<empty>", newNode));
                //}

                //currentToken = GetNext();
                //IncrementLocation(currentToken);
                return(true);
            }
Example #8
0
            private bool AttributeProc(Tree.TreeNode parent)
            {
                var newNode = tree.Add("<attribute>", parent);

                currentToken = GetNext();
                IncrementLocation(currentToken);
                if ((currentToken.Name != "INTEGER") && (currentToken.Name != "FLOAT"))
                {
                    Errors.AddToken(currentToken, locationNumber,
                                    $"'INTEGER' or 'FLOAT' expected but {currentToken.Name} found", tree);
                    return(false);
                }
                newNode.AddToChildren(currentToken.Code + " " + currentToken.Name);
                currentToken = GetNext();
                IncrementLocation(currentToken);
                return(true);
            }
Example #9
0
            private bool DeclarationList(Tree.TreeNode parent)
            {
                var newNode = tree.Add("<declaration-list>", parent);

                if ((currentToken.Name == ")") || (currentToken.Name == ";") || (currentToken.Name == "ELSE"))
                {
                    newNode.AddToChildren(new Tree.TreeNode("<empty>", newNode));
                    return(true);
                }

                while ((currentToken.Name != ")") && (currentToken.Name != ";") && (currentToken.Name != "ELSE"))
                {
                    Declaration(newNode);
                }

                return(true);
            }
Example #10
0
            private bool ConstantDeclarationsList(Tree.TreeNode parent)
            {
                var newNode = tree.Add("<constant-declarations-list>", parent);

                currentToken = GetNext();
                IncrementLocation(currentToken);
                if (!ConstantDeclaration(newNode))
                {
                    currentToken = GetNext();
                    IncrementLocation(currentToken);
                    newNode.AddToChildren(new Tree.TreeNode("<empty>", newNode));
                    return(true);
                }

                while (currentToken.Name != "BEGIN")
                {
                    ConstantDeclaration(newNode);
                }

                return(true);
            }
Example #11
0
            private bool ConstantDeclaration(Tree.TreeNode parent)
            {
                var newNode = tree.Add("<constant-declaration>", parent);

                ConstantIdentifier(newNode);
                currentToken = GetNext();
                IncrementLocation(currentToken);
                if (currentToken.Name == "=")
                {
                    newNode.AddToChildren(currentToken.Code + " " + currentToken.Name);
                    currentToken = GetNext();
                    IncrementLocation(currentToken);
                    Constant(newNode);
                    currentToken = GetNext();
                    IncrementLocation(currentToken);
                    if (currentToken.Name == ";")
                    {
                        newNode.AddToChildren(currentToken.Code + " " + currentToken.Name);
                        currentToken = GetNext();
                        IncrementLocation(currentToken);
                        return(true);
                    }
                    else
                    {
                        Errors.AddToken(currentToken, locationNumber,
                                        $"';' expected but {currentToken.Name} found", tree);
                        return(false);
                    }
                }
                else
                {
                    Errors.AddToken(currentToken, locationNumber,
                                    $"'=' expected but {currentToken.Name} found", tree);
                    return(false);
                }
            }
Example #12
0
            private bool ParametersList(Tree.TreeNode parent)
            {
                var newNode = tree.Add("<parameters-list>", parent);

                currentToken = GetNext();
                IncrementLocation(currentToken);
                if (currentToken.Name == ";")
                {
                    newNode.AddToChildren(new Tree.TreeNode("<empty>", newNode));
                    return(true);
                }

                if (currentToken.Name == "(")
                {
                    newNode.AddToChildren(currentToken.Code + " " + currentToken.Name);
                    currentToken = GetNext();
                    IncrementLocation(currentToken);
                    DeclarationList(newNode);
                    if (currentToken.Name != ")")
                    {
                        Errors.AddToken(currentToken, locationNumber,
                                        $"')' expected but {currentToken.Name} found", tree);
                        return(false);
                    }
                    newNode.AddToChildren(currentToken.Code + " " + currentToken.Name);
                    currentToken = GetNext();
                    IncrementLocation(currentToken);
                    return(true);
                }
                else
                {
                    Errors.AddToken(currentToken, locationNumber,
                                    $"'(' expected but {currentToken.Name} found", tree);
                    return(false);
                }
            }
Example #13
0
            private bool VariableIdentifier(Tree.TreeNode parent)
            {
                var newNode = tree.Add("<variable-identifier>", parent);

                return(Identifier(newNode));
            }
Example #14
0
            private bool ConstantIdentifier(Tree.TreeNode parent)
            {
                var newNode = tree.Add("<constant-identifier>", parent);

                return(Identifier(newNode));
            }
Example #15
0
            private bool Declarations(Tree.TreeNode parent)
            {
                var newNode = tree.Add("<declarations>", parent);

                return(ConstantDeclarations(newNode));
            }