示例#1
0
 /// <summary>
 /// Initializes a new instance of the LRkParser class with the given lexer
 /// </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>
 public RNGLRParser(RNGLRAutomaton automaton, Symbol[] variables, Symbol[] virtuals, SemanticAction[] actions, Lexer.BaseLexer lexer)
     : base(variables, virtuals, actions, lexer)
 {
     parserAutomaton = automaton;
     gss             = new GSS();
     sppf            = new SPPFBuilder(lexer.tokens, symVariables, symVirtuals);
     nullables       = new int[variables.Length];
     BuildNullables(variables.Length);
     sppf.ClearHistory();
 }
示例#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 RNGLRAutomaton 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));
                    RNGLRAutomaton automaton = new RNGLRAutomaton(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));
        }