Exemple #1
0
        private void HandleNotationOper(GOLD.Reduction productionNode)
        {
            GOLD.Token operToken = productionNode[1];
            string     operText  = (string)operToken.Data;

            m_builder.NewNotationOperation(m_inputFile, CurrentLine(operToken));
        }
Exemple #2
0
        private void HandleIdent(GOLD.Reduction productionNode)
        {
            GOLD.Token identToken = productionNode[0];
            string     identText  = (string)identToken.Data;

            m_builder.IdentExpr(identText, CurrentLine(identToken));
        }
Exemple #3
0
        private void HandleBool(GOLD.Reduction productionNode)
        {
            GOLD.Token boolToken = productionNode[0];
            string     boolText  = (string)boolToken.Data;

            m_builder.PrimExpr(System.Boolean.Parse(boolText), CurrentLine(boolToken));
        }
Exemple #4
0
        private void HandleFloat(GOLD.Reduction productionNode)
        {
            GOLD.Token floatToken = productionNode[0];
            string     floatText  = (string)floatToken.Data;

            m_builder.PrimExpr(double.Parse(floatText), CurrentLine(floatToken));
        }
        public object Execute(GOLD.Reduction node)
        {
            Console.WriteLine(Environment.NewLine + "(VVV) Program Line (VVV)" + Environment.NewLine);

            // Itt vagy Expression, vagy Statement, vagy CommentLine vagy semmi !!!
            try {
                string type             = Regex.Replace(node[0].Parent.ToString(), "[^0-9a-zA-Z]+", "");
                Enums.eNonTerminals ntt = (Enums.eNonTerminals)Enum.Parse(typeof(Enums.eNonTerminals), type);

                switch (ntt)
                {
                case Enums.eNonTerminals.Expression:
                    var returnValue = Context.NonTerminalContext.Execute(ntt, (GOLD.Reduction)node[0].Data);
                    Console.WriteLine("################################################################");
                    Console.WriteLine("# Programline value: " + returnValue + "\ttype: " + returnValue.GetType());
                    Console.WriteLine("################################################################" + Environment.NewLine);
                    return(returnValue);

                default:
                    throw new NotImplementedException();
                }
            }
            catch (Exception)
            {
                string EMPTY = "Empty ProgramLine";
                return(EMPTY);
            }
        }
Exemple #6
0
        private void HandleInt(GOLD.Reduction productionNode)
        {
            GOLD.Token intToken = productionNode[0];
            string     intText  = (string)intToken.Data;

            m_builder.PrimExpr(int.Parse(intText), CurrentLine(intToken));
        }
Exemple #7
0
        public Results(AnalyseType analyser, bool errors, string failMessage, GOLD.Reduction root)
        {
            InitializeComponent();
            this.ShowInTaskbar = true;
            this.Title = analyser == AnalyseType.lexical
                ? "Lexical analyzer results"
                : "Syntax analyzer results";

            if (errors)
                txtTree.Text = String.Format("An error occured while trying to parse code.\n{0}", failMessage);
            else
            {
                _root = root;

                switch (analyser)
                {
                    case (AnalyseType.lexical):
                        ShowTokens();
                        break;
                    case (AnalyseType.syntax):
                        ShowParseTree();
                        break;
                    default:
                        break;
                }
            }
        }
Exemple #8
0
        private static void DrawReduction(StringBuilder tree, GOLD.Reduction reduction, int indent)
        {
            //This is a simple recursive procedure that draws an ASCII version of the parse
            //tree

            int    n;
            string indentText = "";

            for (n = 1; n <= indent; n++)
            {
                indentText += "| ";
            }

            //=== Display the children of the reduction
            for (n = 0; n < reduction.Count(); n++)
            {
                switch (reduction[n].Type())
                {
                case GOLD.SymbolType.Nonterminal:
                    GOLD.Reduction branch = (GOLD.Reduction)reduction[n].Data;

                    tree.AppendLine(indentText + "+-" + branch.Parent.Text(false));
                    DrawReduction(tree, branch, indent + 1);
                    break;

                default:
                    string leaf = (string)reduction[n].Data;

                    tree.AppendLine(indentText + "+-" + leaf);
                    break;
                }
            }
        }
Exemple #9
0
        private List <string> GetSQLLeafNodes(GOLD.Reduction root)
        {
            List <string> tokens = new List <string>();

            FindLeaf(tokens, root);
            return(tokens);
        }
Exemple #10
0
        private void HandleString(GOLD.Reduction productionNode)
        {
            GOLD.Token strToken = productionNode[0];
            string     text     = (string)strToken.Data;
            string     textDiscardDelimiters = text.Substring(1, text.Length - 2);

            m_builder.PrimExpr(textDiscardDelimiters, CurrentLine(strToken));
        }
Exemple #11
0
        private object CreateNewObject(GOLD.Reduction r)
        {
            object result = null;

            switch ((ProductionIndex)r.Parent.TableIndex())
            {
            case ProductionIndex.Translation_unit_Eof:
                // <translation_unit> ::= <global_expr_list> EOF
                break;

            case ProductionIndex.Global_expr_list:
                // <global_expr_list> ::= <global_expr> <global_expr_list>
                break;

            case ProductionIndex.Global_expr:
                // <global_expr> ::= <block>
                break;

            case ProductionIndex.Global_expr2:
                // <global_expr> ::= <assignment_expr>
                break;

            case ProductionIndex.Block_Identifier_Lbrace_Rbrace:
                // <block> ::= identifier '{' <expr_list> '}'
                break;

            case ProductionIndex.Expr_list:
                // <expr_list> ::= <assignment_expr> <expr_list>
                break;

            case ProductionIndex.Expr_list2:
                // <expr_list> ::=
                break;

            case ProductionIndex.Assignment_expr_Identifier_Eq_Semi:
                // <assignment_expr> ::= identifier '=' <value> ';'
                break;

            case ProductionIndex.Value_Integer:
                // <value> ::= integer
                break;

            case ProductionIndex.Value_Float:
                // <value> ::= float
                break;

            case ProductionIndex.Value_Quoted_string:
                // <value> ::= 'quoted_string'
                break;

            case ProductionIndex.Value_Identifier:
                // <value> ::= identifier
                break;
            }

            return(result);
        }
Exemple #12
0
        private static string GetStrData(int p, GOLD.Reduction r)
        {
            if (r.get_Data(p) == null)
            {
                throw new InvalidReductionException();
            }

            return((string)r.get_Data(p));
        }
Exemple #13
0
        private void runHandler(ProductionIndex productionIndex, GOLD.Reduction reduction)
        {
            ProductionHandler handler = m_Handlers[(int)productionIndex];

            if (handler != null)
            {
                handler(reduction);
            }
        }
Exemple #14
0
        private static void DrawReductionTree(GOLD.Reduction Root)
        {
            //This procedure starts the recursion that draws the parse tree.
            StringBuilder tree = new StringBuilder();

            tree.AppendLine("+-" + Root.Parent.Text(false));
            DrawReduction(tree, Root, 1);

            Console.WriteLine(tree.ToString());
        }
Exemple #15
0
        /// <summary>
        /// A parszolási fa generálását elindító rekurziós fej
        /// </summary>
        /// <param name="Root">A lebontási fa gyökéreleme</param>
        /// <returns>a lebontási fa tagoltan, szöveg formátumban</returns>
        private string DrawReductionTree(GOLD.Reduction Root)
        {
            //This procedure starts the recursion that draws the parse tree.
            StringBuilder tree = new StringBuilder();

            tree.AppendLine("Non Terminal\t+-" + Root.Parent.Text(false));
            DrawReduction(tree, Root, 1);

            return(tree.ToString());
        }
Exemple #16
0
        public static UIGroup FromReduction(GOLD.Reduction r)
        {
            UIGroup result = new UIGroup();
            // <Object> ::= BeginLiteral <Content> EndLiteral
            var content     = (List <UINode>)r.get_Data(1);
            var sharedProps = content.FirstOrDefault(x => x.Name == "SetSharedProperties");

            result.SharedProperties = sharedProps;
            result.Children         = content.Where(x => x != sharedProps).ToList();

            return(result);
        }
Exemple #17
0
        private void HandleOper(GOLD.Reduction productionNode)
        {
            GOLD.Token operToken = productionNode[1];
            string     operText  = (string)operToken.Data;

            if (operText == "drawbitmap") // Special case with an extra parameter
            {
                m_builder.NewDrawBitmapOperation(Path.GetFullPath(m_inputFile), CurrentLine(operToken));
            }
            else
            {
                m_builder.NewOperation(operText, CurrentLine(operToken));
            }
        }
Exemple #18
0
        // Traverses recursively the parse tree and looks for grammar productions
        protected void ProcessParseTree(GOLD.Reduction topLevelNode)
        {
            ProductionIndex productionIndex = (ProductionIndex)topLevelNode.Parent.TableIndex();

            runHandler(productionIndex, topLevelNode);

            // Process child nodes recursively
            for (int i = 0; i < topLevelNode.Count(); i++)
            {
                if (topLevelNode[i].Type() == GOLD.SymbolType.Nonterminal) // Skip terminals at this level
                {
                    ProcessParseTree((GOLD.Reduction)topLevelNode[i].Data);
                }
            }
        }
        } // End of func FindNodeValue

        private void collectExpressionText(StringBuilder expressionText, GOLD.Reduction reduction)
        {
            for (int n = 0; n < reduction.Count(); n++)
            {
                switch (reduction[n].Type())
                {
                case GOLD.SymbolType.Nonterminal:
                    GOLD.Reduction subNode = (GOLD.Reduction)reduction[n].Data;
                    collectExpressionText(expressionText, subNode);
                    break;

                default:
                    string leafText = (string)reduction[n].Data;
                    expressionText.Append(leafText);
                    break;
                }
            }
        }
Exemple #20
0
        private void FindLeaf(List <string> tokens, GOLD.Reduction reduction)
        {
            for (int n = 0; n < reduction.Count(); ++n)
            {
                switch (reduction[n].Type())
                {
                case GOLD.SymbolType.Nonterminal:
                    GOLD.Reduction branch = (GOLD.Reduction)reduction[n].Data;
                    FindLeaf(tokens, branch);
                    break;

                default:
                    string leaf = (string)reduction[n].Data;
                    tokens.Add(leaf);
                    break;
                }
            }
        }
 /// <summary>
 /// A megfelelő nemterminálishoz tartozó lefutási függvény hívását vezérlő eljárás
 /// </summary>
 /// <param name="type">Az eljárást végző nemterminális</param>
 /// <param name="node">Adott levél a parszolási fában</param>
 /// <returns>Az adott nemterminális által, az adott levélhez kiértékelt objektum</returns>
 public static object Execute(Enums.eNonTerminals type, GOLD.Reduction node)
 {
     return(_strategies[type].Execute(node));
 }
Exemple #22
0
        /// <summary>
        /// A parszolás megtódusát ténylegesen elvégző eljárás
        /// 
        /// This procedure starts the GOLD Parser Engine and handles each of the
        /// messages it returns.
        /// Each time a reduction is made, you can create new
        /// custom object and reassign the .CurrentReduction property. Otherwise, 
        /// the system will use the Reduction object that was returned.
        ///
        /// The resulting tree will be a pure representation of the language 
        /// and will be ready to implement.
        /// </summary>
        /// <param name="reader">A bemeneti string, egy TextReader objektumba csomagolva</param>
        /// <returns>Logikai igaz, ha a bemenet szintaktikailag elfogadható</returns>
        public bool Parse(TextReader reader)
        {
            GOLD.ParseMessage response;
            bool done;                      //Controls when we leave the loop
            bool accepted = false;          //Was the parse successful?

            parser.Open(reader);
            parser.TrimReductions = false;  //Please read about this feature before enabling  

            done = false;
            while (!done)
            {
                response = parser.Parse();

                switch (response)
                {
                    case GOLD.ParseMessage.LexicalError:
                        //Cannot recognize token
                        FailMessage = "Lexical Error:\n" +
                                      "Position: " + parser.CurrentPosition().Line + ", " + parser.CurrentPosition().Column + "\n" +
                                      "Read: " + parser.CurrentToken().Data;
                        done = true;
                        break;

                    case GOLD.ParseMessage.SyntaxError:
                        //Expecting a different token
                        FailMessage = "Syntax Error:\n" +
                                      "Position: " + parser.CurrentPosition().Line + ", " + parser.CurrentPosition().Column + "\n" +
                                      "Read: " + parser.CurrentToken().Data + "\n" +
                                      "Expecting: " + parser.ExpectedSymbols().Text();
                        done = true;
                        break;

                    case GOLD.ParseMessage.Reduction:
                        //For this project, we will let the parser build a tree of Reduction objects
                        //parser.CurrentReduction = CreateNewObject(parser.CurrentReduction);
                        break;

                    case GOLD.ParseMessage.Accept:
                        //Accepted!
                        Root = (GOLD.Reduction)parser.CurrentReduction;    //The root node!                                  
                        done = true;
                        accepted = true;
                        break;

                    case GOLD.ParseMessage.TokenRead:
                        //You don't have to do anything here.
                        break;

                    case GOLD.ParseMessage.InternalError:
                        //INTERNAL ERROR! Something is horribly wrong.
                        done = true;
                        break;

                    case GOLD.ParseMessage.NotLoadedError:
                        //This error occurs if the CGT was not loaded.                   
                        FailMessage = "Tables not loaded";
                        done = true;
                        break;

                    case GOLD.ParseMessage.GroupError:
                        //GROUP ERROR! Unexpected end of file
                        FailMessage = "Runaway group";
                        done = true;
                        break;
                }
            } //while

            return accepted;
        }
        public object Execute(GOLD.Reduction node)
        {
            if (node.Count() == 3)
            {
                // van operátor és két operandus, először a két nem terminálist bontom, majd a terminálisként adott operátorral
                // elvégzem a megfelelő műveletet és értéket adok/másolom

                string _operator = null;
                object _operand1 = null
                , _operand2      = null
                ;

                for (int i = 0; i < node.Count(); i++)
                {
                    switch (node[i].Type())
                    {
                    case GOLD.SymbolType.Nonterminal:     // Nemterminálisok vizsgálata

                        string type             = Regex.Replace(node[i].Parent.ToString(), "[^0-9a-zA-Z]+", "");
                        Enums.eNonTerminals ntt = (Enums.eNonTerminals)Enum.Parse(typeof(Enums.eNonTerminals), type);

                        if (_operand1 == null)
                        {
                            _operand1 = Context.NonTerminalContext.Execute(ntt, (GOLD.Reduction)node[i].Data);
                        }
                        else
                        {
                            _operand2 = Context.NonTerminalContext.Execute(ntt, (GOLD.Reduction)node[i].Data);
                        }

                        break;

                    case GOLD.SymbolType.Error:
                        Console.WriteLine("ERROR in Logical_Engine.Classes.Processor.ProcessTree");
                        break;

                    default:
                        // Terminálisok vizsgálata - itt operátor jel
                        _operator = node[i].Data as string;
                        break;
                    }
                }

                if (_operator != null)
                {
                    _operand1 = Operation(_operand1, _operator, _operand2);
                }
                Console.WriteLine("Simple Expression value: " + _operand1 + "\ttype: " + _operand1.GetType());
                return(_operand1);
            }
            else
            {
                // egy nem terminális van, azt kell lebontani, majd
                // értékadás/másolás
                string type             = Regex.Replace(node[0].Parent.ToString(), "[^0-9a-zA-Z]+", "");
                Enums.eNonTerminals ntt = (Enums.eNonTerminals)Enum.Parse(typeof(Enums.eNonTerminals), type);

                object returnValue = Context.NonTerminalContext.Execute(ntt, (GOLD.Reduction)node[0].Data);
                Console.WriteLine("Simple Expression value: " + returnValue + "\ttype: " + returnValue.GetType());
                return(returnValue);
            }
        }
Exemple #24
0
        public object Execute(GOLD.Reduction node)
        {
            if (node.Count() == 3)
            {
                // zárójel és benne egy expression van
                // az expressiont kiértékelem és azzal majd valamit kezdek

                string _operator1 = null
                , _operator2      = null
                ;
                object _operand = null;

                for (int i = 0; i < node.Count(); i++)
                {
                    switch (node[i].Type())
                    {
                    case GOLD.SymbolType.Nonterminal:     // Nemterminálisok vizsgálata

                        string type             = Regex.Replace(node[i].Parent.ToString(), "[^0-9a-zA-Z]+", "");
                        Enums.eNonTerminals ntt = (Enums.eNonTerminals)Enum.Parse(typeof(Enums.eNonTerminals), type);

                        _operand = Context.NonTerminalContext.Execute(ntt, (GOLD.Reduction)node[i].Data);

                        break;

                    case GOLD.SymbolType.Error:
                        Console.WriteLine("ERROR in Logical_Engine.Classes.Processor.ProcessTree");
                        break;

                    default:
                        // Terminálisok vizsgálata - itt operátor jel
                        if (_operator1 == null)
                        {
                            _operator1 = node[i].Data as string;
                        }
                        else
                        {
                            _operator2 = node[i].Data as string;
                        }
                        break;
                    }
                }

                if (_operator1 == null && _operator2 == null)
                {
                    throw new OperationCanceledException("Missing bracket(s)");
                }
                Console.WriteLine("Factor value: " + _operand + "\ttype: " + _operand.GetType());
                return(_operand);
            }
            else if (node.Count() == 2)
            {
                // valamilyen operátor és egy nem terminális
                // kiértékelem a nem terminálist, majd alkalmazom az operátor által megszabott műveletet
                string _operator = null;
                object _operand  = null;

                for (int i = 0; i < node.Count(); i++)
                {
                    switch (node[i].Type())
                    {
                    case GOLD.SymbolType.Nonterminal:     // Nemterminálisok vizsgálata

                        string type             = Regex.Replace(node[i].Parent.ToString(), "[^0-9a-zA-Z]+", "");
                        Enums.eNonTerminals ntt = (Enums.eNonTerminals)Enum.Parse(typeof(Enums.eNonTerminals), type);

                        _operand = Context.NonTerminalContext.Execute(ntt, (GOLD.Reduction)node[i].Data);

                        break;

                    case GOLD.SymbolType.Error:
                        Console.WriteLine("ERROR in Logical_Engine.Classes.Processor.ProcessTree");
                        break;

                    default:
                        // Terminálisok vizsgálata - itt operátor jel
                        _operator = node[i].Data as string;
                        break;
                    }
                }

                if (_operator != null)
                {
                    _operand = Operation(_operand, _operator, null);
                }
                Console.WriteLine("Factor value: " + _operand + "\ttype: " + _operand.GetType());
                return(_operand);
            }
            else
            {
                // egy nem terminális van, azt kell lebontani, majd
                // értékadás/másolás
                object returnValue = null;
                try
                {
                    if (node[0].Parent.ToString().Equals("NumberLiteral"))
                    {
                        returnValue = Int32.Parse(node[0].Data.ToString());
                        Console.WriteLine("Factor value: " + returnValue + "\ttype: " + returnValue.GetType());
                        return(Int32.Parse(node[0].Data.ToString()));
                    }
                    else if (node[0].Parent.ToString().Equals("RealLiteral"))
                    {
                        returnValue = float.Parse(node[0].Data.ToString());
                        Console.WriteLine("Factor value: " + returnValue + "\ttype: " + returnValue.GetType());
                        return(float.Parse(node[0].Data.ToString()));
                    }
                    else if (node[0].Parent.ToString().Equals("StringLiteral"))
                    {
                        returnValue = node[0].Data.ToString();
                        Console.WriteLine("Factor value: " + returnValue + "\ttype: " + returnValue.GetType());
                        return(node[0].Data.ToString());
                    }
                    else if (node[0].Parent.ToString().Equals("BooleanLiteral"))
                    {
                        if (node[0].Data.ToString().Equals("true") || node[0].Data.ToString().Equals("yes"))
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else if (node[0].Parent.ToString().Equals("<Chain>"))
                    {
                        string type             = Regex.Replace(node[0].Parent.ToString(), "[^0-9a-zA-Z]+", "");
                        Enums.eNonTerminals ntt = (Enums.eNonTerminals)Enum.Parse(typeof(Enums.eNonTerminals), type);
                        try
                        {
                            returnValue = Context.NonTerminalContext.Execute(ntt, (GOLD.Reduction)node[0].Data);
                            returnValue = ServiceHandler.ServiceHandler.getData(returnValue as string);
                            int s;
                            if (int.TryParse(returnValue.ToString(), out s))
                            {
                                return(s);
                            }

                            float t;
                            if (float.TryParse(returnValue.ToString(), out t))
                            {
                                return(t);
                            }

                            if (returnValue.ToString().Contains("."))
                            {
                                string[] u = returnValue.ToString().Split('.');
                                if (u.Length == 4)
                                {
                                    try
                                    {
                                        return(new DateTime(Int32.Parse(u[0]), Int32.Parse(u[1]), Int32.Parse(u[2])));
                                    }
                                    catch (Exception exc)
                                    {
                                        Console.WriteLine(exc.Message);
                                        string ERROR = "ERROR";
                                        return(ERROR);
                                    }
                                }
                            }
                        }
                        catch (Exception exc)
                        {
                            Console.WriteLine(exc.Message);
                            string ERROR = "ERROR";
                            return(ERROR);
                        }

                        Console.WriteLine("Factor value: " + returnValue + "\ttype: " + returnValue.GetType());
                        return(returnValue);
                    }
                    else if (node[0].Parent.ToString().Equals("<DateTimeLiteral>"))
                    {
                        string type             = Regex.Replace(node[0].Parent.ToString(), "[^0-9a-zA-Z]+", "");
                        Enums.eNonTerminals ntt = (Enums.eNonTerminals)Enum.Parse(typeof(Enums.eNonTerminals), type);
                        try
                        {
                            returnValue = Context.NonTerminalContext.Execute(ntt, (GOLD.Reduction)node[0].Data);
                        }
                        catch (Exception Exc)
                        {
                            Console.WriteLine(Exc.Message);
                            string ERROR = "ERROR";
                            return(ERROR);
                        }
                        return(returnValue);
                    }
                    else
                    {
                        throw new Exception("Literal define error - Luna_interpreter.Model.Structure.Classes.Factor.Execute");
                    }
                }
                catch (InvalidCastException ice)
                {
                    Console.WriteLine(ice.Message);
                }
                catch (Exception exc)
                {
                    Console.WriteLine(exc.Message);
                }
            }
            Console.WriteLine(Environment.NewLine + "(AAA) Factor (AAA)" + Environment.NewLine);
            return(null);
        }
 /// <summary>
 /// Elindítja a kész lebontási fa feldolgozását
 /// </summary>
 /// <param name="Root">A már korábban kiértékelt lebontási fa gyökéreleme</param>
 public Processor(GOLD.Reduction Root)
 {
     this.Root = Root;
     Model.Structure.Context.NonTerminalContext.Execute(Model.Enums.eNonTerminals.ProgramLine, (GOLD.Reduction) Root[0].Data);
 }
        public bool Parse(TextReader reader)
        {
            //This procedure starts the GOLD Parser Engine and handles each of the
            //messages it returns. Each time a reduction is made, you can create new
            //custom object and reassign the .CurrentReduction property. Otherwise,
            //the system will use the Reduction object that was returned.
            //
            //The resulting tree will be a pure representation of the language
            //and will be ready to implement.

            GOLD.ParseMessage response;
            bool done;                      //Controls when we leave the loop
            bool accepted = false;          //Was the parse successful?

            parser.Open(reader);
            parser.TrimReductions = false;  //Please read about this feature before enabling

            done = false;
            while (!done)
            {
                response = parser.Parse();

                switch (response)
                {
                case GOLD.ParseMessage.LexicalError:
                    //Cannot recognize token
                    FailMessage = "Lexical Error:\n" +
                                  "Position: " + parser.CurrentPosition().Line + ", " + parser.CurrentPosition().Column + "\n" +
                                  "Read: " + parser.CurrentToken().Data;
                    done = true;
                    break;

                case GOLD.ParseMessage.SyntaxError:
                    //Expecting a different token
                    FailMessage = "Syntax Error:\n" +
                                  "Position: " + parser.CurrentPosition().Line + ", " + parser.CurrentPosition().Column + "\n" +
                                  "Read: " + parser.CurrentToken().Data + "\n" +
                                  "Expecting: " + parser.ExpectedSymbols().Text();
                    done = true;
                    break;

                case GOLD.ParseMessage.Reduction:
                    //For this project, we will let the parser build a tree of Reduction objects
                    //parser.CurrentReduction = CreateNewObject(parser.CurrentReduction);
                    break;

                case GOLD.ParseMessage.Accept:
                    //Accepted!
                    Root     = (GOLD.Reduction)parser.CurrentReduction;    //The root node!
                    done     = true;
                    accepted = true;
                    break;

                case GOLD.ParseMessage.TokenRead:
                    //You don't have to do anything here.
                    break;

                case GOLD.ParseMessage.InternalError:
                    //INTERNAL ERROR! Something is horribly wrong.
                    done = true;
                    break;

                case GOLD.ParseMessage.NotLoadedError:
                    //This error occurs if the CGT was not loaded.
                    FailMessage = "Tables not loaded";
                    done        = true;
                    break;

                case GOLD.ParseMessage.GroupError:
                    //GROUP ERROR! Unexpected end of file
                    FailMessage = "Runaway group";
                    done        = true;
                    break;
                }
            } //while

            return(accepted);
        }
Exemple #27
0
 /// <summary>
 /// Elindítja a kész lebontási fa feldolgozását
 /// </summary>
 /// <param name="Root">A már korábban kiértékelt lebontási fa gyökéreleme</param>
 public Processor(GOLD.Reduction Root)
 {
     this.Root = Root;
     Model.Structure.Context.NonTerminalContext.Execute(Model.Enums.eNonTerminals.ProgramLine, (GOLD.Reduction)Root[0].Data);
 }
Exemple #28
0
        private object CreateNewObject(GOLD.Reduction r)
        {
            object result = null;

            switch ((ProductionIndex)r.Parent.TableIndex())
            {
            case ProductionIndex.Json:
                // <Json> ::= <Object>
                break;

            case ProductionIndex.Json2:
                // <Json> ::= <Array>
                break;

            case ProductionIndex.Object_Lbrace_Rbrace:
                // <Object> ::= '{' '}'
                break;

            case ProductionIndex.Object_Lbrace_Rbrace2:
                // <Object> ::= '{' <Members> '}'
                break;

            case ProductionIndex.Members:
                // <Members> ::= <Pair>
                break;

            case ProductionIndex.Members_Comma:
                // <Members> ::= <Pair> ',' <Members>
                break;

            case ProductionIndex.Pair_String_Colon:
                // <Pair> ::= String ':' <Value>
                break;

            case ProductionIndex.Array_Lbracket_Rbracket:
                // <Array> ::= '[' ']'
                break;

            case ProductionIndex.Array_Lbracket_Rbracket2:
                // <Array> ::= '[' <Elements> ']'
                break;

            case ProductionIndex.Elements:
                // <Elements> ::= <Value>
                break;

            case ProductionIndex.Elements_Comma:
                // <Elements> ::= <Value> ',' <Elements>
                break;

            case ProductionIndex.Value_String:
                // <Value> ::= String
                break;

            case ProductionIndex.Value_Number:
                // <Value> ::= Number
                break;

            case ProductionIndex.Value:
                // <Value> ::= <Object>
                break;

            case ProductionIndex.Value2:
                // <Value> ::= <Array>
                break;

            case ProductionIndex.Value_True:
                // <Value> ::= true
                break;

            case ProductionIndex.Value_False:
                // <Value> ::= false
                break;

            case ProductionIndex.Value_Null:
                // <Value> ::= null
                break;
            }              //switch

            return(result);
        }
Exemple #29
0
 private void HandleNil(GOLD.Reduction productionNode)
 {
     GOLD.Token nilToken = productionNode[0];
     m_builder.PrimExpr(null, CurrentLine(nilToken));
 }
Exemple #30
0
 private void HandleRparen(GOLD.Reduction productionNode)
 {
     m_builder.EndOperation();
 }
        public string FindNodeValue(string searchPath)
        {
            string value = null;

            string[] searchPathValues = searchPath.Split('.');

            GOLD.Reduction currentNode;
            if (Root != null)
            {
                //currentNode = Root[0].Data as GOLD.Reduction; // TODO: Update gramars to skip root production
                currentNode = Root;
            }
            else
            {
                return(null); // Cannot continue without search tree
            }
            //int token = 0;
            bool currentNodeFound = false;

            // Iterate over search path nodes
            for (int i = 0; i < searchPathValues.Length; i++)
            {
                // Match a tree node with the same name as the specified path node
                currentNodeFound = false;
                while (!currentNodeFound) // Guard loop allowing to recover from traversing top level grammar nodes
                {
                    for (int j = 0; j < currentNode.Count() && !currentNodeFound; j++)
                    {
                        string currentTokenProductionName = currentNode[j].Parent.Name();
                        if (currentTokenProductionName == searchPathValues[i])
                        {
                            GOLD.Reduction iteratedReduction = currentNode[j].Data as GOLD.Reduction;
                            currentNode      = iteratedReduction;
                            currentNodeFound = true;
                            break;
                        }
                    } // End of for j
                    if (!currentNodeFound) // Searched path fragment not found in current production
                    {
                        if ((i == 0) && (currentNode.Count() == 1)) // Potentially a dummy top level grammar node, try to skip it
                        {
                            currentNode = currentNode[0].Data as GOLD.Reduction;
                        }
                        else
                        {
                            return(null); // Cannot recover, specified path does not exist.
                        }
                    }
                } // End of while
            }     // End of for i

            if (currentNodeFound)
            {
                StringBuilder expressionText = new StringBuilder();
                collectExpressionText(expressionText, currentNode);

                if (expressionText.Length > 0)
                {
                    value = expressionText.ToString();
                }
            }

            return(value);
        } // End of func FindNodeValue
        public bool Parse(TextReader reader)
        {
            GOLD.ParseMessage response;
            bool done;                      //Controls when we leave the loop
            bool accepted = false;          //Was the parse successful?

            parser.Open(reader);
            parser.TrimReductions = false;  //Please read about this feature before enabling

            done = false;
            while (!done)
            {
                response = parser.Parse();

                switch (response)
                {
                case GOLD.ParseMessage.LexicalError:
                    //Cannot recognize token
                    FailMessage = "Lexical Error:\n" +
                                  "Position: " + parser.CurrentPosition().Line + ", " + parser.CurrentPosition().Column + "\n" +
                                  "Read: " + parser.CurrentToken().Data;
                    done = true;
                    break;

                case GOLD.ParseMessage.SyntaxError:
                    //Expecting a different token
                    FailMessage = "Syntax Error:\n" +
                                  "Position: " + parser.CurrentPosition().Line + ", " + parser.CurrentPosition().Column + "\n" +
                                  "Read: " + parser.CurrentToken().Data + "\n" +
                                  "Expecting: " + parser.ExpectedSymbols().Text();
                    done = true;
                    break;

                case GOLD.ParseMessage.Reduction:
                    //For this project, we will let the parser build a tree of Reduction objects
                    //parser.CurrentReduction = CreateNewObject(parser.CurrentReduction);
                    break;

                case GOLD.ParseMessage.Accept:
                    //Accepted!
                    Root     = (GOLD.Reduction)parser.CurrentReduction;    //The root node!
                    done     = true;
                    accepted = true;
                    break;

                case GOLD.ParseMessage.TokenRead:
                    //You don't have to do anything here.
                    break;

                case GOLD.ParseMessage.InternalError:
                    //INTERNAL ERROR! Something is horribly wrong.
                    done = true;
                    break;

                case GOLD.ParseMessage.NotLoadedError:
                    //This error occurs if the CGT was not loaded.
                    FailMessage = "Tables not loaded";
                    done        = true;
                    break;

                case GOLD.ParseMessage.GroupError:
                    //GROUP ERROR! Unexpected end of file
                    FailMessage = "Runaway group";
                    done        = true;
                    break;
                }
            } //while

            return(accepted);
        }
Exemple #33
0
 public CookV5Reduction(GOLD.Reduction reduction)
 {
     this.reduction  = reduction;
     this.production = reduction.Parent.Text(); // Parent is the lhs
 }