Skip to content

Commit

Permalink
Финальная полировка.
Browse files Browse the repository at this point in the history
Обработка ошибок и вывод их в строку. Составлена БНФ.
Покрыл всё тестами, исправил мелкие баги.
  • Loading branch information
rincew1nd committed Nov 25, 2016
1 parent a9e58d7 commit fb3c54f
Show file tree
Hide file tree
Showing 10 changed files with 627 additions and 84 deletions.
2 changes: 2 additions & 0 deletions CodeTranslator/CodeTranslator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Exceptions\OredrException.cs" />
<Compile Include="Exceptions\SyntaxException.cs" />
<Compile Include="Translator.cs" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
Expand Down
16 changes: 16 additions & 0 deletions CodeTranslator/Exceptions/OredrException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeTranslator.Exceptions
{
public class OredrException : Exception
{
public OredrException() : base() { }
public OredrException(string exception, int line, params object[] args)
: base(string.Format(exception, line, args[0])) { }
public OredrException(string exceptionMessage, Exception inner) : base(exceptionMessage, inner) { }
}
}
18 changes: 18 additions & 0 deletions CodeTranslator/Exceptions/SyntaxException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeTranslator.Exceptions
{
public class SyntaxException : Exception
{
public SyntaxException() : base() { }

public SyntaxException(string exception, int line, params object[] args)
: base(string.Format(exception, line, args[0])) { }

public SyntaxException(string exceptionMessage, Exception inner) : base(exceptionMessage, inner) { }
}
}
89 changes: 83 additions & 6 deletions CodeTranslator/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:CodeTranslator"
mc:Ignorable="d"
Title="MainWindow" Height="764" Width="800" Visibility="Visible" WindowStyle="None" Padding="0" Margin="0">
Title="MainWindow" Height="784" Width="1200" Visibility="Visible" WindowStyle="ToolWindow" Padding="0" Margin="0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
Expand All @@ -16,12 +16,12 @@
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="1.5*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>

<Label Grid.Row="0" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="16" Content="Код"/>
<Label Grid.Row="0" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="16" Content="Формула Бекуса-Наура"/>
<Label Grid.Row="0" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="16" Content="Форма Бекуса-Наура"/>
<Label Grid.Row="2" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="16" Content="Результат выполнения"/>
<RichTextBox Grid.Row="1" Grid.Column="0" Grid.RowSpan="3" FontSize="16" Block.LineHeight="1" Name="CodeBox">
<FlowDocument>
Expand All @@ -47,14 +47,91 @@
<Run Text="50 : йцук5 = (10+5)/(54+5)"/>
</Paragraph>
<Paragraph>
<Run Text="60 : йцук6 = ((10+5)/(54+5))/0.2"/>
<Run Text="60 : йцук6 = ((10+5)/(54+5))/2"/>
</Paragraph>
<Paragraph>
<Run Text="70 : йцук7 = 1&amp;(0|1)"/>
</Paragraph>
<Paragraph>
<Run Text="70 : йцук8 = 1&amp;(0|!1)"/>
</Paragraph>
<Paragraph>
<Run Text="Конец программа"/>
</Paragraph>
</FlowDocument>
</RichTextBox>
<RichTextBox Grid.Row="1" Grid.Column="1" FontSize="16" Block.LineHeight="1" Name="BnfBox"/>
<RichTextBox Grid.Row="1" Grid.Column="1" FontSize="16" Block.LineHeight="1" Name="BnfBox">
<FlowDocument>
<Paragraph>
<Run Text="«Язык» = 'Программа' «Заголовок» «Опер» ';' ... «Опер» 'Конец программа'"/>
</Paragraph>
<Paragraph>
<Run Text=""/>
</Paragraph>
<Paragraph>
<Run Text="«Заголовок» = «Метки» «Знак» ... «Знак»"/>
</Paragraph>
<Paragraph>
<Run Text="«Метка» = «Числа»"/>
</Paragraph>
<Paragraph>
<Run Text=""/>
</Paragraph>
<Paragraph>
<Run Text="«Опер» = «Метка» ':' «Перем» '=' «Прав.часть»';"/>
</Paragraph>
<Paragraph>
<Run Text="«Прав.часть» = «Блок» «Знак» ... «Блок»"/>
</Paragraph>
<Paragraph>
<Run Text=""/>
</Paragraph>
<Paragraph>
<Run Text="«Блок» = «БлокОбычный» ! «БлокБульевый»"/>
</Paragraph>
<Paragraph>
<Run Text="«БлокОбычный» = «Числа»«Знаки»«Числа» ! '('«БлокОбычный»')' !
«БлокОбычный»«Знаки»«БлокОбычный» ! «Числа»«Знаки»«БлокОбычный»"/>
</Paragraph>
<Paragraph>
<Run Text="«БлокБулевый» = «БулевыЧисла»«БульевыЗнаки»«БулевыЧисла» ! '('«БлокБулевый»')' !
«БлокБулевый»«БульевыЗнаки»«БлокБулевый» ! «БулевыЧисла»«БульевыЗнаки»«БлокБулевый»"/>
</Paragraph>
<Paragraph>
<Run Text=""/>
</Paragraph>
<Paragraph>
<Run Text="«Операторы» = «БульевыЗнаки» ! «Знаки»"/>
</Paragraph>
<Paragraph>
<Run Text="«Знаки» = '+'!'-'!'*'!'/'"/>
</Paragraph>
<Paragraph>
<Run Text="«БульевыЗнаки» = '|'!'&amp;'"/>
</Paragraph>
<Paragraph>
<Run Text=""/>
</Paragraph>
<Paragraph>
<Run Text="«БулевыЧисла» = '0'!'1'"/>
</Paragraph>
<Paragraph>
<Run Text="«Числа» = «Число» ... «Число»"/>
</Paragraph>
<Paragraph>
<Run Text="«Число» = '0'!'1'!'2'!...!'9'"/>
</Paragraph>
<Paragraph>
<Run Text=""/>
</Paragraph>
<Paragraph>
<Run Text="«Буквы» = «Буква» ... «Буква»"/>
</Paragraph>
<Paragraph>
<Run Text="«Буква» = 'A'!'Б'!'В'!...!'Я'"/>
</Paragraph>
</FlowDocument>
</RichTextBox>
<DataGrid Grid.Row="3" Grid.Column="1" Name="ResultBox" FontSize="16"
ItemsSource="{Binding Results}" AutoGenerateColumns="False">
<DataGrid.Columns >
Expand Down
8 changes: 7 additions & 1 deletion CodeTranslator/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CodeTranslator.Exceptions;

namespace CodeTranslator
{
Expand All @@ -33,8 +34,13 @@ public MainWindow()

private void Button_Click(object sender, RoutedEventArgs e)
{
ErrorBox.Content = "";
var codeBoxText = new TextRange(CodeBox.Document.ContentStart, CodeBox.Document.ContentEnd).Text;
ErrorBox.Content = _translator.CheckSyntax(codeBoxText);
try { _translator.CheckSyntax(codeBoxText); }
catch (Exception ex) when (ex is SyntaxException | ex is OredrException)
{
ErrorBox.Content = ex.Message;
}
if ((string) ErrorBox.Content == "")
{
Results.Clear();
Expand Down
Loading

0 comments on commit fb3c54f

Please sign in to comment.