Пример #1
0
    public object program;     //You might derive a specific object

    public void Setup()
    {
        //This procedure can be called to load the parse tables. The class can
        //read tables using a BinaryReader.

        parser.LoadTables(Path.Combine(Application.StartupPath, "grammar.egt"));
    }
Пример #2
0
        public void Parse(string code)
        {
            this.Structures = new List<LogicStructure>();
            this.Functions = new List<LogicFunction>();

            var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Protogame.Scripting.LogicControl.Grammar.egt");

            var parser = new Parser();
            if (stream != null)
            {
                using (var reader = new BinaryReader(stream))
                {
                    parser.LoadTables(reader);
                }
            }
            else
            {
                throw new InvalidOperationException();
            }

            parser.Open(ref code);

            Reduction root = null;
            var done = false;
            while (!done)
            {
                var response = parser.Parse();

                switch (response)
                {
                    case GOLD.ParseMessage.LexicalError:
                        throw new Exception("Lexical Error:\n" +
                                      "Position: " + parser.CurrentPosition().Line + ", " + parser.CurrentPosition().Column + "\n" +
                                      "Read: " + parser.CurrentToken().Data);
                    case GOLD.ParseMessage.SyntaxError:
                        throw new Exception("Syntax Error:\n" +
                                      "Position: " + parser.CurrentPosition().Line + ", " + parser.CurrentPosition().Column + "\n" +
                                      "Read: " + parser.CurrentToken().Data + "\n" +
                                      "Expecting: " + parser.ExpectedSymbols().Text());
                    case GOLD.ParseMessage.Accept:
                        root = (GOLD.Reduction)parser.CurrentReduction;
                        done = true;
                        break;

                    case GOLD.ParseMessage.InternalError:
                        throw new Exception("Internal error");
                    case GOLD.ParseMessage.NotLoadedError:
                        throw new Exception("Tables not loaded");
                    case GOLD.ParseMessage.GroupError:
                        throw new Exception("Runaway group");
                }
            }

            this.TraverseNodes(root);
        }
Пример #3
0
 public bool Setup(BinaryReader reader)
 {
     return(parser.LoadTables(reader));
 }