My favorites | Sign in
Project Home Downloads Wiki Issues Source
Repository:
Checkout   Browse   Changes   Clones    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sprache;

namespace LinqyCalculator
{
class Program
{
static void Main()
{
var line = "";
while (Prompt(out line))
{
try
{
var parsed = ExpressionParser.ParseExpression(line);
Console.WriteLine("Parsed as {0}", parsed);
Console.WriteLine("Value is {0}", parsed.Compile()());
}
catch (ParseException ex)
{
Console.WriteLine("There was a problem with your input: {0}", ex.Message);
}

Console.WriteLine();
}
}

static bool Prompt(out string value)
{
Console.Write("Enter a numeric expression, or 'q' to quit: ");
var line = Console.ReadLine();
if (line.ToLowerInvariant().Trim() == "q")
{
value = null;
return false;
}
else
{
value = line;
return true;
}
}
}
}

Change log

24395bacc560 by Nicholas Blumhardt <> on Jan 20, 2010   Diff
Major improvements in error reporting.
Go to: 
Project members, sign in to write a code review

Older revisions

4d7b1c865e2e by Nicholas Blumhardt <> on Jan 8, 2010   Diff
Cleaned up error message.
5a3c9d7c92cb by Nicholas Blumhardt <> on Jan 2, 2010   Diff
Added support for grammars with left
recursion.
9a23bc4aff8a by Nicholas Blumhardt <> on Jan 2, 2010   Diff
Upgraded solution to VS2010, included
expression parsing example.
All revisions of this file

File info

Size: 1261 bytes, 47 lines
Powered by Google Project Hosting