Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

TinyLisp: A Language and Parser to See LINQ Expressions in Action

, 12 Jun 2010
A small program that parses expressions and evaluates them using LINQ Expressions
<Window x:Class="TinyLisp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="TinyLisp" Height="400" Width="600"
        xmlns:tl="clr-namespace:TinyLisp"
        >
    <Window.Resources>
        <!-- Expand all treenodes -->
        <Style TargetType="TreeViewItem">
            <Setter Property="IsExpanded" Value="True" />
        </Style>
    </Window.Resources>
    
    <Grid>
        
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="46" />
            <RowDefinition Height="18" />
            <RowDefinition Height="432*" />
        </Grid.RowDefinitions>
            
        <!--First row has input, button and output-->
        <TextBox Grid.Row="0" Grid.Column="0" Name="Input" TextAlignment="Center" VerticalContentAlignment="Center" FontSize="16">(+(/(*3(*2 3 4)) 2) 1 2 3)</TextBox>        
        <Button Content="Evaluate" Grid.Column="1" Click="Button_Click" />
         
        <!--First colums has the AST-->
        <TextBlock Grid.Column="0" Grid.Row="1" TextAlignment="Center" HorizontalAlignment="Center">Abstract syntax tree</TextBlock>
        <TreeView Name="tvAst" Grid.Row="2" ItemsSource="{Binding}" >
            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding Operands}" >
                    <TextBlock Text="{Binding Text}"/>
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
        </TreeView>

        <!-- Second column has the Linq Expression-->
        <TextBlock Grid.Column="1" Grid.Row="1" HorizontalAlignment="Center">Linq Expression</TextBlock>
        <TreeView Name="tvExpr" Grid.Column="1" Grid.Row="2" ItemsSource="{Binding}" >
            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate DataType="x:Type local:ExprWrapper" ItemsSource="{Binding Children}">
                    <TextBlock Text="{Binding Text}" />
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
        </TreeView>
        
    </Grid>
</Window>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

gjvdkamp
Leaseplan Corporation
Netherlands Netherlands
Gert-Jan is a Senior Quantitative Risk Manager at Leaseplan Corporation. In that job he doesn't get to code much he does these little projects to keep his skills up and feed the inner geek.
Follow on   LinkedIn

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 12 Jun 2010
Article Copyright 2010 by gjvdkamp
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid