Mercury library 1.0 Translation of CFG grammars into an object model (Bachelor's thesis).

- Main Page
- Packages
- Classes
- Files

- File List

All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties
Defaults.cs
Go to the documentation of this file.
1 using Mercury.Exceptions;
2 using Mercury.Interpreting;
3 using Mercury.Nucleus.Trees;
4 using Mercury.Syntax;
5 using System;
6 using System.Collections.Generic;
7 using System.IO;
8 using System.Linq;
9
10 namespace Mercury
11 {
15 public static class Defaults
16 {
17 //--[ Private and internal stuff ]-----------------------------------
18
19 private static string epsilon = "e";
20 private static string root = "S";
21 private static char[] alpha = new[] { '@', '_' };
22 internal static string alphastr = new string(alpha);
23
24 // ParameterType to ArgumentType translation table
25 private static IReadOnlyDictionary<ParameterType, ArgumentType> typeMap
26 = new Dictionary<ParameterType, ArgumentType>
27 {
28 { ParameterType.IntegralConstant, ArgumentType.Integer | ArgumentType.Real },
29 { ParameterType.RealConstant, ArgumentType.Real },
30 { ParameterType.StringConstant, ArgumentType.String },
31 { ParameterType.BooleanConstant, ArgumentType.Boolean },
32 { ParameterType.Variable, ArgumentType.Symbol | ArgumentType.Tree },
33 };
34
35 // .NET type to ArgumentType translation table
36 private static Dictionary<Type, ArgumentType> rtmap = new Dictionary<Type, ArgumentType>
37 {
38 { typeof(int), ArgumentType.Integer },
39 { typeof(double), ArgumentType.Real },
40 { typeof(string), ArgumentType.String },
41 { typeof(bool), ArgumentType.Boolean },
42 { typeof(Symbol), ArgumentType.Symbol },
43 { typeof(Tree<Symbol>), ArgumentType.Tree },
44 { typeof(object), ArgumentType.Any },
45 };
46
47 //--[ Properties ]---------------------------------------------------
48
50 public static string Epsilon { get { return epsilon; } }
51
53 public static string Root { get { return root; } }
54
66 public static ArgumentType ParamToArgType(ParameterType ptype)
67 { return ptype == ParameterType.ActionCall ? ArgumentType.None : typeMap[ptype]; }
68
83 public static ArgumentType TypeToArgType<T,U>()
84 {
85 Type tpt = typeof(T);
86 Type tpu = typeof(U);
87
88 ArgumentType rargt = ArgumentType.None;
89 if (!rtmap.TryGetValue(tpu, out rargt) || tpu.Equals(tpt))
90 rargt |= ArgumentType.TValue;
91
92 return rargt;
93 }
94
95 }
96 }
Mercury.Defaults
Global class containing cool static / convenience stuff.
Definition: Defaults.cs:15
Mercury.Interpreting.ArgumentType
ArgumentType
Defines argument types using in the Mercury library
Definition: Argument.cs:11
Mercury.Defaults.Epsilon
static string Epsilon
Default epsilon symbol name
Definition: Defaults.cs:50
Mercury.Interpreting.ParameterType
ParameterType
Formal Parameter Type
Definition: FormalParameter.cs:11
Mercury.Defaults.ParamToArgType
static ArgumentType ParamToArgType(ParameterType ptype)
Translates formal Mercury.Interpreting.ParameterType into Mercury.Interpreting.ArgumentType. If the input is Mercury.Interpreting.ParameterType.ActionCall, this function will yield Mercury.Interpreting.ArgumentType.None as it cannot resolve return types of the Mercury.Interpreting.ActionCall. In that case use ReturnType field of the Mercury.Interpreting.InterpreterAction{T} class wrapped in the Mercury.Interpreting.ActionCall.
Definition: Defaults.cs:66
Mercury.Defaults.Root
static string Root
Default root symbol name
Definition: Defaults.cs:53
Mercury.Defaults.TypeToArgType< T, U >
static ArgumentType TypeToArgType< T, U >()
Translates a .NET type into Mercury.Interpreting.ArgumentType. If T equals U , T:System.Object or dynamic this function will return Mercury.Interpreting.ArgumentType.Any. If T is one of int, double, bool, string, Symbol or Tree
Definition: Defaults.cs:83
Mercury.Syntax.Symbol
Represents a single symbol of the grammar. This is an immutable class. For a symbol name to be val...
Definition: Symbol.cs:51