/NerdSharp.Net_Studio/NerdSharp_UberNet/Science/Math/MathCompiler.cs
C# | 179 lines | 174 code | 4 blank | 1 comment | 0 complexity | 2667d1c065b1429604ea1c2442f2aa54 MD5 | raw file
- 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; }
- }
- }
-
- }