示例#1
0
        private bool m_trimReductions = true; // Allowes to minimize reduction tree.

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Initializes new instance of Parser class.
        /// </summary>
        /// <param name="textReader">TextReader instance to read data from.</param>
        /// <param name="grammar">Grammar with parsing tables to parser input stream.</param>
        public Parser(TextReader textReader, Grammar grammar)
        {
            if (textReader == null)
            {
                throw new ArgumentNullException("textReader");
            }
            if (grammar == null)
            {
                throw new ArgumentNullException("grammar");
            }

            m_textReader = textReader;
            m_bufferSize = MinimumBufferSize;
            m_buffer = new char[m_bufferSize + 1];
            m_lineLength = Undefined;
            ReadBuffer();

            m_inputTokens = new Token[MinimumInputTokenCount];
            m_lrStack = new LRStackItem[MinimumLRStackSize];

            m_grammar = grammar;

            // Put grammar start symbol into LR parsing stack.
            m_lrState = m_grammar.InitialLRState;
            LRStackItem start = new LRStackItem();
            start.m_token.m_symbol = m_grammar.StartSymbol;
            start.m_state = m_lrState;
            m_lrStack[m_lrStackIndex] = start;

            m_reductionCount = Undefined; // there are no reductions yet.
        }
示例#2
0
        static Tokenizer()
        {
            var grammarStream = new MemoryStream(Resources.Tokenizer); // new FileStream("Preprocessor.cgt", FileMode.Open, FileAccess.Read);

            grammar = new GoldParser.Grammar(new BinaryReader(grammarStream));
            grammarStream.Dispose();
        }
示例#3
0
		/// <summary>
		/// Initializes new instance of Parser class.
		/// </summary>
		/// <param name="textReader">TextReader instance to read data from.</param>
		/// <param name="grammar">Grammar with parsing tables to parser input stream.</param>
		public Parser(TextReader textReader, Grammar grammar)
		{
			if (textReader == null)
			{
				throw new ArgumentNullException("textReader");
			}
			if (grammar == null)
			{
				throw new ArgumentNullException("grammar");
			}

			m_TextReader = textReader;
			m_BufferSize = MinimumBufferSize;
			m_Buffer = new Char[m_BufferSize + 1];
			m_LineLength = Undefined;
			ReadBuffer();

			m_InputTokens = new Token[MinimumInputTokenCount];
			m_LRStack = new LRStackItem[MinimumLRStackSize];

			m_Grammar = grammar;

			// Put grammar start symbol into LR parsing stack.
			m_LRState = m_Grammar.InitialLRState;
			var start = new LRStackItem { Token = { Symbol = m_Grammar.StartSymbol }, State = m_LRState };
			m_LRStack[m_LRStackIndex] = start;

			m_CommentSymbols = new List<Regex>();
			m_ReadOnlyCommentSymbols = new ReadOnlyCollection<Regex>(m_CommentSymbols);
			m_CommentEndSymbols = new Stack<Regex>();

			m_ReductionCount = Undefined; // there are no reductions yet.
		}
示例#4
0
        public static void InitializeFactoryFromFile(string fullCGTFilePath)
        {
            if (!_init)
            {
                BinaryReader reader = new BinaryReader(new FileStream(fullCGTFilePath, FileMode.Open));

                _grammar = new Grammar(reader);
                _init = true;
            }
        }
示例#5
0
 public static void InitializeFactoryFromResource(string resourceName)
 {
     lock (Locker)
     {
         if (!_init)
         {
             BinaryReader reader = GetResourceReader(resourceName);
             _grammar = new Grammar(reader);
             _init = true;
         }
     }
 }
示例#6
0
文件: Parser.cs 项目: cg123/xenko
		private const int  Undefined = -1;             // Used for undefined int values. 
		
		#endregion

		#region Constructors

		/// <summary>
		/// Initializes new instance of Parser class.
		/// </summary>
		/// <param name="textReader">TextReader instance to read data from.</param>
		/// <param name="grammar">Grammar with parsing tables to parser input stream.</param>
		public Parser(Grammar grammar)
		{
			if (grammar == null)
			{
				throw new ArgumentNullException("grammar");
			}

			m_lineLength = Undefined;

			m_inputTokens = new Token[MinimumInputTokenCount];
			m_lrStack     = new LRStackItem[MinimumLRStackSize];

			m_grammar = grammar;
		}
        public GlifInterpreter(string filename)
        {
            var streamReader = new StreamReader(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\" + filename);
            _fileText = streamReader.ReadToEnd();
            streamReader.Close();

            var currentAssembly = Assembly.GetExecutingAssembly();
            var stream = currentAssembly.GetManifestResourceStream("SP2.Glif.Interpreter.res.glifgrammar.cgt");
            if (stream != null)
            {
                var binaryReader = new BinaryReader(stream);
                _grammar = new Grammar(binaryReader);
            }
            else
            {
                throw new FileNotFoundException("Grammar file not found!");
            }

            _parser = new Parser(new StringReader(_fileText), _grammar) {TrimReductions = true};
            _context = new GlifContext(_parser);
        }
示例#8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HeaderParser"/> class.
 /// </summary>
 /// <param name="grammarPath">The path to the compiled GOLD grammar file.</param>
 public HeaderParser(string grammarPath)
 {
     using (var grammarReader = new BinaryReader(File.OpenRead(grammarPath)))
         grammar = new Grammar(grammarReader);
 }
示例#9
0
 public GPBParser()
 {
     LRParser = null;
     LanguageGrammar = null;
 }
示例#10
0
 public GPBParser(GoldParser.Grammar grammar)
 {
 	LRParser = null;
 	LanguageGrammar = grammar;
 }
示例#11
0
 public GPBParser(Stream stream)
 {
     LRParser = null;
     LanguageGrammar = new GoldParser.Grammar(new BinaryReader(stream));
 }
示例#12
0
 static Tokenizer()
 {
     var grammarStream = new MemoryStream(Resources.Tokenizer); // new FileStream("Preprocessor.cgt", FileMode.Open, FileAccess.Read);
     grammar = new GoldParser.Grammar(new BinaryReader(grammarStream));
     grammarStream.Dispose();
 }
示例#13
0
		public GoldXpidlParser(BinaryReader grammarBinaryReader)
		{
			m_Grammar = new Grammar(grammarBinaryReader);
		}