Ejemplo n.º 1
0
        private void OnRunButtonClick(object sender, RoutedEventArgs e)
        {
            // Create the lexer and parser
            Lexer lexer = new Lexer(QueryText.Text);
            Parser parser = new Parser(lexer);

            // Get the root of the AST and evaluate the query, printing the results
            Expr rootExpr = parser.GetExpression();
            if (rootExpr == null)
            {
                ResultsText.Text = "Error: No expression produced";
            }
            else
            {
                Result result = rootExpr.Evaluate();
                if (result.ValueType == ResultValueType.String)
                {
                    ResultsText.Text = result.StringValue;
                }
                else if (result.ValueType == ResultValueType.Int)
                {
                    ResultsText.Text = "Int value: " + result.IntValue.ToString();
                }
                else if (result.ValueType == ResultValueType.Rows)
                {
                    StringBuilder builder = new StringBuilder();

                    int index = 0;
                    foreach (ResultRow row in result.RowsValue)
                    {
                        builder.Append(index++);

                        foreach (string field in row)
                        {
                            builder.Append(" | ");
                            builder.Append(field);
                        }

                        builder.AppendLine();
                    }

                    ResultsText.Text = builder.ToString();
                }
            }
        }
Ejemplo n.º 2
0
        private void OnLexButtonClick(object sender, RoutedEventArgs e)
        {
            Lexer lexer = new Lexer(QueryText.Text);

            while (true)
            {
                Token token = lexer.Next();
                if (token.Type == TokenType.EndOfFile)
                {
                    break;
                }
                else if (token.Type == TokenType.Error)
                {
                    Console.WriteLine("Error in {0}", token.Value);
                    break;
                }
                else
                {
                    Console.WriteLine("token: {0} (value: '{1}')", token.Type.ToString(), token.Value);
                }
            }
        }
Ejemplo n.º 3
0
 public Parser(Lexer lexer)
 {
     mLexer = lexer;
 }