scide-cad-scilife /NerdSharp.Net_Studio/NerdSharp_UberNet/Science/Math/MathCompiler.cs

Language C# Lines 180
MD5 Hash 2667d1c065b1429604ea1c2442f2aa54 Estimated Cost $3,326 (why?)
Repository https://bitbucket.org/pastageek/scide-cad-scilife View Raw File View Project SPDX
  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
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;
using System.Xml.XPath;
using System.Numerics;
//these libraries used for debugging purposes
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace NerdSharp.Net_Studio.NerdSharp_UberNet.Science.Math
{
    public static partial class MathCompiler
    {
        public enum CompileOptions { Method, Object }

        public static void CleanMethod(string methodBody)
        {

        }

        private static string pathToDecoder = @"";

        /// <summary>
        /// This method will transform/compile texCode as defined by Donald Knuth
        /// into Sci#.UberNet code. It can produce methods as well as objects for use
        /// inside other things. It adds a RAD aspect in a similar way that
        /// visual programming does.
        /// </summary>
        /// <param name="texCode">From Donald Knuth a type setting language
        /// that can be input to this method plus some directives to produce 
        /// C# code from the tex input
        /// </param>
        /// 
        /// <param name="outputType">Different uses of the compiler such as producing
        /// a method form an equation or a matrix object from a texmatrix
        /// </param>
        /// 
        /// <param name="returnType">If compiling to a method, can have a return type.
        /// <code>If outputType == CompileOptions.Object</code>, then return type should be either 
        /// <value>null</value> || <value>void</value> otherwise it will throw
        /// and invallid argument exception
        /// </param>
        /// 
        /// <returns>Returns a string that is the C# code compiled 
        /// from the input Knuth's tex</returns>
        public static string TexToSciSharp(string texCode, CompileOptions outputType, Type returnType)
        {
            #region local vars
            Token einToken = null;
            #region flags
            bool newToken = false;
            bool readingDirectives = false;
            bool lookingForSymbol = false;
            bool previousSlashToken = false;
            bool currentlyInSlashToken = false;
            #endregion
            char neededSymbol = ' ';
            char[] codeCharArray = texCode.ToCharArray();
            XPathDocument tokenXPthDoc = new XPathDocument(new StreamReader(@""));
            XPathNavigator xNav = tokenXPthDoc.CreateNavigator();
            List<Token> tokens = new List<Token>();
            StringBuilder tokenBuffer = new StringBuilder();
            StringBuilder methodBody = new StringBuilder();
            StringBuilder methodHeader = new StringBuilder();
            string method = "";
            #endregion
            CharacterItterator(ref einToken, ref newToken, ref previousSlashToken, 
                ref currentlyInSlashToken, codeCharArray, xNav, tokens, methodBody);
            return method;
        }//end method

        private static void CharacterItterator(ref Token einToken, ref bool newToken, 
            ref bool previousSlashToken, ref bool currentlyInSlashToken, char[] codeCharArray, 
            XPathNavigator xNav, List<Token> tokens, StringBuilder methodBody)
        {
            for (long i = 0; i < codeCharArray.LongLength; i++)
            {

                if (!newToken)
                {
                    if (char.IsLetter(codeCharArray[i]))
                    {
                        //works with the current token
                        einToken.TokenData.Append(codeCharArray[i]);
                        //needs to see if this token matches any
                        if (true)
                        {
                            
                        }
                    }
                    else if (char.IsWhiteSpace(codeCharArray[i]))
                    {
                        newToken = true;
                    }
                }//end if newtoken
                else
                {
                    newToken = true;
                    einToken = new Token();
                    if (codeCharArray[i] == '\\')
                    {
                        currentlyInSlashToken = true;
                        einToken.TokenType = Token.TokenEnum.slash;
                        tokens.Add(einToken);
                    }
                    else if (codeCharArray[i] == '+')
                    {
                        if (currentlyInSlashToken)
                        {
                            currentlyInSlashToken = false;
                            previousSlashToken = true;
                        }
                        einToken.TokenType = Token.TokenEnum.symbOperator;
                        tokens.Add(einToken);
                        newToken = true;
                    }
                    else if (codeCharArray[i] == '#')
                    {

                    }
                }
            }//end main token creator for loop
            for (int i = 0; i < tokens.Count; i++)
            {
                if (tokens[i].TokenType == Token.TokenEnum.slash)
                {
                    string nameSpace = xNav.GetAttribute
                        ("", @"/functions/function[@texText=" + @tokens[i].TokenData.ToString()) + "]";
                    methodBody.Append(nameSpace);


                }
                else if (tokens[i].TokenType == Token.TokenEnum.symbOperator ||
                    tokens[i].TokenType == Token.TokenEnum.parens)
                {
                    methodBody.Append(tokens[i].TokenData.ToString());
                }
            }//end token converter for loop
        }
    }//end compiler class

    public class Token
    {
        public enum TokenEnum { slash, symbOperator, parens, directive, variable }

        private TokenEnum tokenType;

        public TokenEnum TokenType
        {
            get { return tokenType; }
            set { tokenType = value; }
        }

        private StringBuilder tokenData;

        public StringBuilder TokenData
        {
            get { return tokenData; }
            set { tokenData = value; }
        }
    }
    
}
Back to Top