Exemple #1
0
 /// <summary>
 /// Initializes a new instance of the parser
 /// </summary>
 /// <param name="automaton">The parser's automaton</param>
 /// <param name="variables">The parser's variables</param>
 /// <param name="virtuals">The parser's virtuals</param>
 /// <param name="actions">The parser's actions</param>
 /// <param name="lexer">The input lexer</param>
 protected LRkParser(LRkAutomaton automaton, Symbol[] variables, Symbol[] virtuals, SemanticAction[] actions, Lexer.BaseLexer lexer)
     : base(variables, virtuals, actions, lexer)
 {
     this.automaton = automaton;
     stack          = new int[INIT_STACK_SIZE];
     stackIDs       = new int[INIT_STACK_SIZE];
     head           = 0;
     builder        = new LRkASTBuilder(lexer.tokens, symVariables, symVirtuals);
 }
Exemple #2
0
        /// <summary>
        /// Loads an automaton from a resource
        /// </summary>
        /// <param name="type">The lexer's type</param>
        /// <param name="resource">The name of the resource containing the lexer</param>
        /// <returns>The automaton</returns>
        public static LRkAutomaton Find(System.Type type, string resource)
        {
#if NETSTANDARD1_0
            Assembly assembly = type.GetTypeInfo().Assembly;
#else
            Assembly assembly = type.Assembly;
#endif
            string[] resources = assembly.GetManifestResourceNames();
            foreach (string existing in resources)
            {
                if (existing.EndsWith(resource))
                {
                    BinaryReader reader    = new BinaryReader(assembly.GetManifestResourceStream(existing));
                    LRkAutomaton automaton = new LRkAutomaton(reader);
#if NETSTANDARD1_0
                    reader.Dispose();
#else
                    reader.Close();
#endif
                    return(automaton);
                }
            }
            throw new IOException(string.Format("The resource {0} cannot be found in the assembly {1}", resource, assembly.GetName().Name));
        }