コード例 #1
0
        public SimpleParser(ILexer lexer)
        {
            m_startRuleToken = new Token { TokenType = TokenType.NEW_RULE };
            m_tree = new Node<string>();
            m_lexer = lexer;
            m_consumed = new Stack<Token>();
            m_err = new Queue<Error>();

            // Setup rule pre-calling conditions
            m_rulePreHook = name =>
                                {
                                    if (m_tree.Value == null)
                                    {
                                        m_tree.Value = name;
                                        return m_tree;
                                    }

                                    var tempNode = m_tree;
                                    var newTopNode = m_tree.AddChild(name);
                                    m_tree = newTopNode;
                                    return tempNode;
                                };

            // Setup rule post-calling conditions
            m_rulePostHook = node => m_tree = node;
        }
コード例 #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            var token = new Token
                            {
                                TokenType = (TokenType)Enum.Parse(typeof (TokenType), cmbTokens.SelectedItem.ToString()),
                                Value = txtValue.Text
                            };

            m_tokens.Add(token);
        }
コード例 #3
0
ファイル: AbstractParser.cs プロジェクト: spreeker/waebric
 /// <summary>
 /// Get NextToken and verify if it exists
 /// </summary>
 /// <param name="name">Name of expected token</param>
 /// <param name="syntax">Syntax of expected token</param>
 /// <returns>True if new token found, otherwise false</returns>
 protected bool NextToken(String name, String syntax)
 {
     if (TokenStream.HasNext())
     {
         CurrentToken = TokenStream.NextToken();
         return true;
     }
     else
     {
         //Unexpected token
         throw new UnexpectedToken("Unexpected token found:", CurrentToken.GetValue().ToString(), CurrentToken.GetLine());
     }
 }