Init
This commit is contained in:
330
.gitignore
vendored
Normal file
330
.gitignore
vendored
Normal file
@@ -0,0 +1,330 @@
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
|
||||
# Visual Studio 2015/2017 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# Visual Studio 2017 auto generated files
|
||||
Generated\ Files/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUNIT
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# Benchmark Results
|
||||
BenchmarkDotNet.Artifacts/
|
||||
|
||||
# .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
**/Properties/launchSettings.json
|
||||
|
||||
# StyleCop
|
||||
StyleCopReport.xml
|
||||
|
||||
# Files built by Visual Studio
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_i.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.iobj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.ipdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# Visual Studio Trace Files
|
||||
*.e2e
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# JustCode is a .NET coding add-in
|
||||
.JustCode
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# AxoCover is a Code Coverage Tool
|
||||
.axoCover/*
|
||||
!.axoCover/settings.json
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/[Pp]ackages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/[Pp]ackages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/[Pp]ackages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
*.appx
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
orleans.codegen.cs
|
||||
|
||||
# Including strong name files can present a security risk
|
||||
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||
#*.snk
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
ServiceFabricBackup/
|
||||
*.rptproj.bak
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
*.ndf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
*.rptproj.rsuser
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
node_modules/
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
*.vbw
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
*.sln.iml
|
||||
|
||||
# CodeRush
|
||||
.cr/
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/**
|
||||
# !tools/packages.config
|
||||
|
||||
# Tabs Studio
|
||||
*.tss
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
*.jmconfig
|
||||
|
||||
# BizTalk build output
|
||||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
|
||||
# OpenCover UI analysis results
|
||||
OpenCover/
|
||||
|
||||
# Azure Stream Analytics local run output
|
||||
ASALocalRun/
|
||||
|
||||
# MSBuild Binary and Structured Log
|
||||
*.binlog
|
||||
|
||||
# NVidia Nsight GPU debugger configuration file
|
||||
*.nvuser
|
||||
|
||||
# MFractors (Xamarin productivity tool) working folder
|
||||
.mfractor/
|
||||
86
Axiom.Core/Axiom.Core.csproj
Normal file
86
Axiom.Core/Axiom.Core.csproj
Normal file
@@ -0,0 +1,86 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{F0F0F2B4-BB86-49B5-BA93-2642637033D6}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>Axiom.Core</RootNamespace>
|
||||
<AssemblyName>Axiom.Core</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MarketDataLib">
|
||||
<HintPath>..\References\MarketDataLib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xaml">
|
||||
<RequiredTargetFramework>4.0</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="WindowsBase" />
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Interpreter\Assembler.cs" />
|
||||
<Compile Include="Interpreter\AxiomException.cs" />
|
||||
<Compile Include="Interpreter\AxiomTrace.cs" />
|
||||
<Compile Include="Interpreter\CodeRunner.cs" />
|
||||
<Compile Include="Interpreter\Emitter.cs" />
|
||||
<Compile Include="Interpreter\AxiomResult.cs" />
|
||||
<Compile Include="Interpreter\GenericData.cs" />
|
||||
<Compile Include="Interpreter\Parser.cs" />
|
||||
<Compile Include="Interpreter\ParseSymbols.cs" />
|
||||
<Compile Include="Interpreter\Scanner.cs" />
|
||||
<Compile Include="Interpreter\StackElement.cs" />
|
||||
<Compile Include="Interpreter\Symbol.cs" />
|
||||
<Compile Include="Interpreter\SymbolTable.cs" />
|
||||
<Compile Include="Utility\Utility.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
1118
Axiom.Core/Interpreter/Assembler.cs
Normal file
1118
Axiom.Core/Interpreter/Assembler.cs
Normal file
File diff suppressed because it is too large
Load Diff
21
Axiom.Core/Interpreter/AxiomException.cs
Normal file
21
Axiom.Core/Interpreter/AxiomException.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
|
||||
// FileName : AxiomException.cs
|
||||
// Author : Sean Kessler
|
||||
|
||||
namespace Axiom.Interpreter
|
||||
{
|
||||
public class AxiomException : Exception
|
||||
{
|
||||
public AxiomResult AxiomResult{get;set;}
|
||||
public AxiomException()
|
||||
{
|
||||
}
|
||||
public AxiomException(AxiomResult axiomResult,Exception exception)
|
||||
: base(exception.Message,exception)
|
||||
{
|
||||
this.AxiomResult=axiomResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
26
Axiom.Core/Interpreter/AxiomResult.cs
Normal file
26
Axiom.Core/Interpreter/AxiomResult.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
|
||||
// FileName : AxiomResult.cs
|
||||
// Author : Sean Kessler
|
||||
|
||||
namespace Axiom.Interpreter
|
||||
{
|
||||
public class AxiomResult
|
||||
{
|
||||
public AxiomResult()
|
||||
{
|
||||
Success = false;
|
||||
}
|
||||
public AxiomResult(bool success,String lastMessage)
|
||||
{
|
||||
Success = success;
|
||||
LastMessage = lastMessage;
|
||||
}
|
||||
public bool Success { get; set; }
|
||||
public String LastMessage { get; set; }
|
||||
public DataTable DataTable { get; set; }
|
||||
public int ContextSpecificId{get;set;}
|
||||
public Object ContextSpecificObj { get; set; }
|
||||
}
|
||||
}
|
||||
44
Axiom.Core/Interpreter/AxiomTrace.cs
Normal file
44
Axiom.Core/Interpreter/AxiomTrace.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
|
||||
// FileName : AxiomTrace.cs
|
||||
// Author : Sean Kessler
|
||||
|
||||
namespace Axiom.Interpreter
|
||||
{
|
||||
public class AxiomTrace
|
||||
{
|
||||
public AxiomTrace()
|
||||
{
|
||||
IsTracing = false;
|
||||
}
|
||||
public bool IsTracing { get; set; }
|
||||
public String[] Values { get; set; }
|
||||
public int Column { get; set; }
|
||||
|
||||
public static AxiomTrace FromConfig()
|
||||
{
|
||||
AxiomTrace trace = new AxiomTrace();
|
||||
try
|
||||
{
|
||||
String tracingEnabled = ConfigurationManager.AppSettings["AXIOM_TRACE_ENABLED"];
|
||||
if (null == tracingEnabled) return trace;
|
||||
trace.IsTracing = Boolean.Parse(tracingEnabled);
|
||||
trace.Column = int.Parse(ConfigurationManager.AppSettings["AXIOM_TRACE_COLUMN"]);
|
||||
trace.Values = ConfigurationManager.AppSettings["AXIOM_TRACE_VALUES"].Split(',');
|
||||
return trace;
|
||||
}
|
||||
catch (Exception /*exception*/)
|
||||
{
|
||||
return trace;
|
||||
}
|
||||
}
|
||||
public bool Break()
|
||||
{
|
||||
if (!Debugger.IsAttached) return false;
|
||||
Debugger.Break(); // if you wind up here you are in the debugger AND AXIOM_TRACE_ENABLED is set in the congifuration AND the break condition has been met. Step over this breakpoint to continue debugging OR set AXIOM_TRACE_ENABLED to false in config and restart
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
422
Axiom.Core/Interpreter/CodeRunner.cs
Normal file
422
Axiom.Core/Interpreter/CodeRunner.cs
Normal file
@@ -0,0 +1,422 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Data;
|
||||
using log4net;
|
||||
using Axiom.Utils;
|
||||
|
||||
// FileName : CodeRunner.cs
|
||||
// Author : Sean Kessler
|
||||
|
||||
namespace Axiom.Interpreter
|
||||
{
|
||||
public class CodeRunner : IDisposable
|
||||
{
|
||||
private static ILog logger = LogManager.GetLogger(typeof(CodeRunner));
|
||||
private SymbolTable symbolTable = null;
|
||||
private Dictionary<int, Stream> precompiles = new Dictionary<int, Stream>();
|
||||
private bool useCache=false;
|
||||
private bool trace=false;
|
||||
private bool parseStrict=false;
|
||||
private bool scanStrict=false;
|
||||
private bool disposed = false;
|
||||
private int parseSymbolCount=0;
|
||||
|
||||
public CodeRunner()
|
||||
{
|
||||
symbolTable=new SymbolTable();
|
||||
IsInError=false;
|
||||
}
|
||||
~CodeRunner()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if(disposing)
|
||||
{
|
||||
List<Stream> streams=new List<Stream>(precompiles.Values);
|
||||
foreach(Stream stream in streams)
|
||||
{
|
||||
try{stream.Close();stream.Dispose();}catch(Exception){;}
|
||||
}
|
||||
}
|
||||
disposed = true;
|
||||
}
|
||||
public int ParseSymbolsCount
|
||||
{
|
||||
get{return parseSymbolCount;}
|
||||
}
|
||||
public String LastMessage{ get; private set;}
|
||||
public bool IsInError { get; private set;}
|
||||
public bool ScanStrict
|
||||
{
|
||||
get{return scanStrict;}
|
||||
set{scanStrict=value;}
|
||||
}
|
||||
public bool ParseStrict
|
||||
{
|
||||
get{return parseStrict;}
|
||||
set{parseStrict=value;}
|
||||
}
|
||||
public bool Trace
|
||||
{
|
||||
get {return trace;}
|
||||
set {trace=value;}
|
||||
}
|
||||
public bool UseCache
|
||||
{
|
||||
get { return useCache; }
|
||||
set { useCache = value; }
|
||||
}
|
||||
public String GetValue(String name)
|
||||
{
|
||||
if (!symbolTable.ContainsKey(name)) return "null";
|
||||
Symbol symbol = symbolTable[name];
|
||||
GenericData genericData = symbol.GenericData;
|
||||
if (null == genericData || genericData.IsNull()) return "null";
|
||||
return genericData.Get<String>();
|
||||
}
|
||||
public T GetValue<T>(String name)
|
||||
{
|
||||
if(!symbolTable.ContainsKey(name)) return default(T);
|
||||
Symbol symbol=symbolTable[name];
|
||||
GenericData genericData=symbol.GenericData;
|
||||
if(null==genericData||genericData.IsNull()) return default(T);
|
||||
return genericData.Get<T>();
|
||||
}
|
||||
public SymbolTable SymbolTable
|
||||
{
|
||||
get {return symbolTable;}
|
||||
}
|
||||
public void Reset()
|
||||
{
|
||||
if (null == symbolTable) return;
|
||||
symbolTable.Reset();
|
||||
}
|
||||
public bool Execute(DataTable dataTable, int row, String expression)
|
||||
{
|
||||
Reset();
|
||||
return ExecuteExpressionOnRow(dataTable, row, expression);
|
||||
}
|
||||
private bool ExecuteExpressionOnRow(DataTable dataTable, int row, String expression)
|
||||
{
|
||||
symbolTable.AddUserSymbols(dataTable); // add symbol names from the data table columns
|
||||
symbolTable.AddUserValues(dataTable.Rows[row], dataTable);
|
||||
if (UseCache)
|
||||
{
|
||||
if (!ApplyRuleWithCache(expression)) return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!Execute(expression))return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Execute(String expression)
|
||||
{
|
||||
BinaryReader binaryReader = null;
|
||||
BinaryWriter binaryWriter = null;
|
||||
BinaryReader parserReader = null;
|
||||
BinaryWriter parserWriter = null;
|
||||
BinaryReader assemblerReader = null;
|
||||
Assembler assembler = null;
|
||||
|
||||
try
|
||||
{
|
||||
IsInError=false;
|
||||
LastMessage="";
|
||||
binaryReader = new BinaryReader(Utility.StreamFromString(expression));
|
||||
binaryWriter = new BinaryWriter(new MemoryStream());
|
||||
Scanner scanner = new Scanner(binaryReader, binaryWriter, symbolTable);
|
||||
scanner.Debug = Trace;
|
||||
if (!scanner.Analyze())
|
||||
{
|
||||
LastMessage="Failed to scan the input document, possible invalid character sequence.";
|
||||
IsInError=true;
|
||||
logger.ErrorFormat(LastMessage);
|
||||
return false;
|
||||
}
|
||||
binaryWriter.BaseStream.Seek(0, SeekOrigin.Begin);
|
||||
parserReader = new BinaryReader(binaryWriter.BaseStream);
|
||||
parserWriter = new BinaryWriter(new MemoryStream());
|
||||
Parser parser = new Parser(parserReader, parserWriter, symbolTable);
|
||||
parser.Debug = Trace;
|
||||
parser.Parse();
|
||||
parseSymbolCount=parser.ParseSymbolsCount;
|
||||
if (parser.IsInError)
|
||||
{
|
||||
LastMessage=String.Format("Failed to parse the input, {0} at {1}", parser.LastMessage, parser.LastLineNumber);
|
||||
IsInError=true;
|
||||
logger.ErrorFormat(LastMessage);
|
||||
return false;
|
||||
}
|
||||
parserWriter.BaseStream.Seek(0, SeekOrigin.Begin);
|
||||
assemblerReader = new BinaryReader(parserWriter.BaseStream);
|
||||
assembler = new Assembler(assemblerReader, symbolTable);
|
||||
assembler.Debug = Trace;
|
||||
assembler.Assemble();
|
||||
if(assembler.IsInError)
|
||||
{
|
||||
LastMessage=String.Format("Error: Failed to run the assembler, {0}", assembler.LastMessage);
|
||||
IsInError=true;
|
||||
logger.ErrorFormat(LastMessage);
|
||||
return false;
|
||||
}
|
||||
if (Trace) DumpSymbolTable();
|
||||
assembler.Dispose();
|
||||
assembler = null;
|
||||
return true;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
LastMessage=String.Format("Exception:{0}",exception.ToString());
|
||||
IsInError=true;
|
||||
logger.ErrorFormat(LastMessage);
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (null != binaryReader) { binaryReader.Close();binaryReader.Dispose(); }
|
||||
if (null != binaryWriter) { binaryWriter.Close();binaryWriter.Dispose(); }
|
||||
if (null != parserReader) { parserReader.Close();parserReader.Dispose(); }
|
||||
if (null != parserWriter) { parserWriter.Close(); parserWriter.Dispose(); }
|
||||
if (null != assemblerReader) { assemblerReader.Close(); assemblerReader.Dispose(); }
|
||||
if (null != assembler) { assembler.Dispose();assembler = null; }
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> Disassemble(String expression)
|
||||
{
|
||||
BinaryReader binaryReader = null;
|
||||
BinaryWriter binaryWriter = null;
|
||||
BinaryReader parserReader = null;
|
||||
BinaryWriter parserWriter = null;
|
||||
BinaryReader assemblerReader = null;
|
||||
Assembler assembler = null;
|
||||
List<String> disassembly=new List<String>();
|
||||
|
||||
try
|
||||
{
|
||||
IsInError=false;
|
||||
LastMessage="";
|
||||
binaryReader = new BinaryReader(Utility.StreamFromString(expression));
|
||||
binaryWriter = new BinaryWriter(new MemoryStream());
|
||||
Scanner scanner = new Scanner(binaryReader, binaryWriter, symbolTable);
|
||||
scanner.Debug = Trace;
|
||||
if (!scanner.Analyze())
|
||||
{
|
||||
LastMessage="Failed to scan the input document, possible invalid character sequence.";
|
||||
IsInError=true;
|
||||
logger.ErrorFormat(LastMessage);
|
||||
return disassembly;
|
||||
}
|
||||
binaryWriter.BaseStream.Seek(0, SeekOrigin.Begin);
|
||||
parserReader = new BinaryReader(binaryWriter.BaseStream);
|
||||
parserWriter = new BinaryWriter(new MemoryStream());
|
||||
Parser parser = new Parser(parserReader, parserWriter, symbolTable);
|
||||
parser.Debug = Trace;
|
||||
parser.Parse();
|
||||
parseSymbolCount=parser.ParseSymbolsCount;
|
||||
if (parser.IsInError)
|
||||
{
|
||||
LastMessage=String.Format("Failed to parse the input, {0} at {1}", parser.LastMessage, parser.LastLineNumber);
|
||||
IsInError=true;
|
||||
logger.ErrorFormat(LastMessage);
|
||||
return disassembly;
|
||||
}
|
||||
parserWriter.BaseStream.Seek(0, SeekOrigin.Begin);
|
||||
assemblerReader = new BinaryReader(parserWriter.BaseStream);
|
||||
assembler = new Assembler(assemblerReader, symbolTable);
|
||||
assembler.Debug = Trace;
|
||||
return assembler.Disassemble();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
LastMessage=String.Format("Exception:{0}",exception.ToString());
|
||||
IsInError=true;
|
||||
logger.ErrorFormat(LastMessage);
|
||||
return disassembly;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (null != binaryReader) { binaryReader.Close();binaryReader.Dispose(); }
|
||||
if (null != binaryWriter) { binaryWriter.Close();binaryWriter.Dispose(); }
|
||||
if (null != parserReader) { parserReader.Close();parserReader.Dispose(); }
|
||||
if (null != parserWriter) { parserWriter.Close(); parserWriter.Dispose(); }
|
||||
if (null != assemblerReader) { assemblerReader.Close(); assemblerReader.Dispose(); }
|
||||
if (null != assembler) { assembler.Dispose();assembler = null; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// The cache will not work as effectively if the expression variables are not loaded directly into the SymbolTable
|
||||
public bool ApplyRuleWithCache(String expression)
|
||||
{
|
||||
BinaryReader assemblerReader = null;
|
||||
Stream precompiledStream = null;
|
||||
Assembler assembler = null;
|
||||
try
|
||||
{
|
||||
int hashcode = expression.GetHashCode();
|
||||
if (Trace) logger.InfoFormat("Trace:{0}", expression);
|
||||
if (precompiles.ContainsKey(hashcode))
|
||||
{
|
||||
precompiledStream = precompiles[hashcode]; // if the precompiled cache contains the expression then fetch it
|
||||
}
|
||||
else
|
||||
{
|
||||
precompiledStream = Compile(expression,true); // otherwise compile the expression and add it to the cache.
|
||||
precompiles.Add(hashcode, precompiledStream);
|
||||
}
|
||||
if (null == precompiledStream) return false;
|
||||
precompiledStream.Seek(0, SeekOrigin.Begin);
|
||||
assemblerReader = new BinaryReader(precompiledStream);
|
||||
assembler = new Assembler(assemblerReader, symbolTable);
|
||||
assembler.Assemble();
|
||||
if(assembler.IsInError)
|
||||
{
|
||||
LastMessage=String.Format("Error: Failed to run the assembler, {0}", assembler.LastMessage);
|
||||
logger.ErrorFormat(LastMessage);
|
||||
return false;
|
||||
}
|
||||
assembler.Dispose();
|
||||
assembler = null;
|
||||
return true;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
LastMessage=String.Format("Exception:{0}", exception.ToString());
|
||||
logger.ErrorFormat(LastMessage);
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (null != assembler) { assembler.Dispose(); }
|
||||
}
|
||||
}
|
||||
public AxiomResult SyntaxCheck(String expression)
|
||||
{
|
||||
BinaryReader binaryReader = null;
|
||||
BinaryWriter binaryWriter = null;
|
||||
BinaryReader parserReader = null;
|
||||
BinaryWriter parserWriter = null;
|
||||
AxiomResult axiomResult = new AxiomResult();
|
||||
|
||||
try
|
||||
{
|
||||
axiomResult.Success = true;
|
||||
binaryWriter = new BinaryWriter(new MemoryStream());
|
||||
binaryReader = new BinaryReader(Utility.StreamFromString(expression));
|
||||
Scanner scanner = new Scanner(binaryReader, binaryWriter, symbolTable);
|
||||
if (!scanner.Analyze())
|
||||
{
|
||||
axiomResult.Success = false;
|
||||
axiomResult.LastMessage = "Failed to scan the input document, possible invalid character sequence.";
|
||||
return axiomResult;
|
||||
}
|
||||
binaryWriter.BaseStream.Seek(0, SeekOrigin.Begin);
|
||||
parserReader = new BinaryReader(binaryWriter.BaseStream);
|
||||
parserWriter = new BinaryWriter(new MemoryStream());
|
||||
Parser parser = new Parser(parserReader, parserWriter, symbolTable);
|
||||
// parser.StrictMode=false; // we do not require all variable declarations to be present.
|
||||
parser.StrictStatementMode=true; // we require at least one valid statement to be processed.
|
||||
parser.Parse();
|
||||
if (parser.IsInError)
|
||||
{
|
||||
axiomResult.Success = false;
|
||||
axiomResult.LastMessage = "Message:" + parser.LastMessage;
|
||||
return axiomResult;
|
||||
}
|
||||
return axiomResult;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
axiomResult.LastMessage = String.Format("Exception:{0}", exception.ToString());
|
||||
logger.Error(axiomResult.LastMessage);
|
||||
return axiomResult;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (null != binaryReader) { binaryReader.Close(); binaryReader.Dispose(); }
|
||||
if (null != binaryWriter) { binaryWriter.Close(); binaryWriter.Dispose(); }
|
||||
if (null != parserReader) { parserReader.Close(); parserReader.Dispose(); }
|
||||
if (null != parserWriter) { parserWriter.Close(); parserWriter.Dispose(); }
|
||||
}
|
||||
}
|
||||
private Stream Compile(String expression, bool includeCodeEnd = true)
|
||||
{
|
||||
BinaryReader binaryReader = null;
|
||||
BinaryWriter binaryWriter = null;
|
||||
BinaryReader parserReader = null;
|
||||
BinaryWriter parserWriter = null;
|
||||
|
||||
try
|
||||
{
|
||||
binaryReader = new BinaryReader(Utility.StreamFromString(expression));
|
||||
binaryWriter = new BinaryWriter(new MemoryStream());
|
||||
Scanner scanner = new Scanner(binaryReader, binaryWriter, symbolTable);
|
||||
scanner.Debug = Trace;
|
||||
if(!scanner.Analyze())
|
||||
{
|
||||
LastMessage = "Failed to scan the input document, possible invalid character sequence";
|
||||
logger.Info(LastMessage);
|
||||
return null;
|
||||
}
|
||||
binaryReader.Close();
|
||||
binaryReader.Dispose();
|
||||
binaryWriter.BaseStream.Seek(0, SeekOrigin.Begin);
|
||||
parserReader = new BinaryReader(binaryWriter.BaseStream);
|
||||
parserWriter = new BinaryWriter(new MemoryStream());
|
||||
Parser parser = new Parser(parserReader, parserWriter, symbolTable);
|
||||
parser.Debug = Trace;
|
||||
parser.Parse(includeCodeEnd);
|
||||
if (parser.IsInError)
|
||||
{
|
||||
LastMessage = String.Format("Error:{0} at {1}", parser.LastMessage, parser.LastLineNumber);
|
||||
logger.Info(LastMessage);
|
||||
return null;
|
||||
}
|
||||
parserReader.Close();
|
||||
parserReader.Dispose();
|
||||
parserReader = null;
|
||||
binaryWriter.Close();
|
||||
binaryWriter.Dispose();
|
||||
binaryWriter = null;
|
||||
parserWriter.BaseStream.Seek(0, SeekOrigin.Begin);
|
||||
return parserWriter.BaseStream;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.ErrorFormat("Exception:{0}", exception.ToString());
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (null != binaryReader) { binaryReader.Close(); binaryReader.Dispose(); }
|
||||
if (null != binaryWriter) { binaryWriter.Close(); binaryWriter.Dispose(); }
|
||||
if (null != parserReader) { parserReader.Close();parserReader.Dispose(); }
|
||||
}
|
||||
}
|
||||
private void DumpSymbolTable()
|
||||
{
|
||||
logger.Info("********************************************************* O U T P U T ************************************************");
|
||||
List<Symbol> list = new List<Symbol>(symbolTable.Values);
|
||||
list = (from Symbol symbol in list where symbol.TypeOfSymbol.Equals(Symbol.SymbolType.UserSymbol) select symbol).ToList();
|
||||
foreach (Symbol symbol in list)
|
||||
{
|
||||
logger.Info(String.Format("SYMBOL NAME:'{0}',VALUE:'{1}'", symbol.SymbolName, null == symbol.GenericData ? "<null>" : symbol.GenericData.ToString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
204
Axiom.Core/Interpreter/Emitter.cs
Normal file
204
Axiom.Core/Interpreter/Emitter.cs
Normal file
@@ -0,0 +1,204 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using log4net;
|
||||
|
||||
// FileName : Emitter.cs
|
||||
// Author : Sean Kessler
|
||||
|
||||
namespace Axiom.Interpreter
|
||||
{
|
||||
public class Emitter
|
||||
{
|
||||
private static ILog logger = LogManager.GetLogger(typeof(Emitter));
|
||||
private bool emitting = true;
|
||||
private int lastSymbol;
|
||||
private BinaryReader inputStream;
|
||||
private BinaryWriter outputStream;
|
||||
private bool debug = true;
|
||||
|
||||
public Emitter(BinaryReader inputStream, BinaryWriter outputStream)
|
||||
{
|
||||
this.inputStream = inputStream;
|
||||
this.outputStream = outputStream;
|
||||
}
|
||||
public bool Debug
|
||||
{
|
||||
get { return debug; }
|
||||
set { debug = value; }
|
||||
}
|
||||
public void Emit(String literalValue)
|
||||
{
|
||||
if (!emitting) return;
|
||||
outputStream.Write(literalValue.Length);
|
||||
outputStream.Write(literalValue);
|
||||
}
|
||||
// ************************************************************************
|
||||
public void Emit(Scanner.ScanSymbols code)
|
||||
{
|
||||
if (!emitting) return;
|
||||
outputStream.Write((int)code);
|
||||
if(Debug)logger.Info(Scanner.SymbolToString(code));
|
||||
}
|
||||
public void Emit(Scanner.ScanSymbols code,int value)
|
||||
{
|
||||
if (!emitting) return;
|
||||
outputStream.Write((int)code);
|
||||
outputStream.Write(value);
|
||||
if(Debug)logger.Info(Scanner.SymbolToString(code)+","+value.ToString());
|
||||
}
|
||||
public void Emit(Scanner.ScanSymbols code,double value)
|
||||
{
|
||||
if (!emitting) return;
|
||||
outputStream.Write((int)code);
|
||||
outputStream.Write(value);
|
||||
if(Debug)logger.Info(Scanner.SymbolToString(code)+","+value.ToString());
|
||||
}
|
||||
public void Emit(Scanner.ScanSymbols code,String value)
|
||||
{
|
||||
if (!emitting) return;
|
||||
outputStream.Write((int)code);
|
||||
outputStream.Write(value);
|
||||
if(Debug)logger.Info(Scanner.SymbolToString(code)+","+value.ToString());
|
||||
}
|
||||
// **********************************************************************************************************************************************
|
||||
public long CodePointer()
|
||||
{
|
||||
return outputStream.BaseStream.Position;
|
||||
}
|
||||
public void Seek(long position)
|
||||
{
|
||||
outputStream.BaseStream.Seek(position, SeekOrigin.Begin);
|
||||
}
|
||||
public void Emit(Parser.ParserSymbols code)
|
||||
{
|
||||
if (!emitting) return;
|
||||
long positionBefore=outputStream.BaseStream.Position;
|
||||
outputStream.Write((int)code);
|
||||
long positionAfter=outputStream.BaseStream.Position;
|
||||
if(Debug)logger.Info(Parser.SymbolToString(code)+"["+positionBefore+","+positionAfter+"]");
|
||||
|
||||
}
|
||||
public void Emit(Parser.ParserSymbols code,Object value)
|
||||
{
|
||||
if (!emitting) return;
|
||||
long positionBefore=outputStream.BaseStream.Position;
|
||||
outputStream.Write((int)code);
|
||||
Type type = value.GetType();
|
||||
outputStream.Write(type.ToString());
|
||||
outputStream.Write(value.ToString());
|
||||
long positionAfter=outputStream.BaseStream.Position;
|
||||
if(Debug)logger.Info(Parser.SymbolToString(code)+","+type.ToString()+","+value.ToString()+"["+positionBefore+","+positionAfter+"]");
|
||||
}
|
||||
public void Emit(Parser.ParserSymbols code,Object value,int intValue)
|
||||
{
|
||||
if (!emitting) return;
|
||||
long positionBefore=outputStream.BaseStream.Position;
|
||||
outputStream.Write((int)code);
|
||||
Type type = value.GetType();
|
||||
outputStream.Write(type.ToString());
|
||||
outputStream.Write(value.ToString());
|
||||
outputStream.Write(intValue);
|
||||
long positionAfter=outputStream.BaseStream.Position;
|
||||
if(Debug)logger.Info(Parser.SymbolToString(code)+","+type.ToString()+","+value.ToString()+","+intValue+"["+positionBefore+","+positionAfter+"]");
|
||||
}
|
||||
public void Emit(Parser.ParserSymbols code,long value)
|
||||
{
|
||||
if (!emitting) return;
|
||||
long positionBefore=outputStream.BaseStream.Position;
|
||||
outputStream.Write((int)code);
|
||||
outputStream.Write(value);
|
||||
long positionAfter=outputStream.BaseStream.Position;
|
||||
if(Debug)logger.Info(Parser.SymbolToString(code)+","+value.ToString()+","+value.ToString()+"["+positionBefore+","+positionAfter+"]");
|
||||
}
|
||||
public void EmitAsNull(Parser.ParserSymbols code)
|
||||
{
|
||||
if (!emitting) return;
|
||||
long positionBefore=outputStream.BaseStream.Position;
|
||||
outputStream.Write((int)code);
|
||||
Type type = typeof(System.Nullable); //value.GetType();
|
||||
outputStream.Write(type.ToString());
|
||||
outputStream.Write("null".ToString());
|
||||
long positionAfter=outputStream.BaseStream.Position;
|
||||
if(Debug)logger.Info(Parser.SymbolToString(code)+","+type.ToString()+","+"null".ToString()+"["+positionBefore+","+positionAfter+"]");
|
||||
}
|
||||
// ************************************************************************
|
||||
public void Emit(int code, int op)
|
||||
{
|
||||
if (!emitting) return;
|
||||
outputStream.Write(code);
|
||||
outputStream.Write(op);
|
||||
}
|
||||
public void Emit(int identifier)
|
||||
{
|
||||
if (!emitting) return;
|
||||
outputStream.Write(identifier);
|
||||
}
|
||||
public void Emit(byte value)
|
||||
{
|
||||
if (!emitting) return;
|
||||
outputStream.Write(value);
|
||||
}
|
||||
public int Peek(ref int value)
|
||||
{
|
||||
value = inputStream.PeekChar();
|
||||
return value;
|
||||
}
|
||||
public int Peek()
|
||||
{
|
||||
int value = inputStream.PeekChar();
|
||||
return value;
|
||||
}
|
||||
|
||||
public int PeekIgnore(ref int value,int[] ignoreChars)
|
||||
{
|
||||
long streamPosition=inputStream.BaseStream.Position;
|
||||
while(true)
|
||||
{
|
||||
int readValue;
|
||||
readValue=(int)inputStream.ReadChar();
|
||||
value=readValue;
|
||||
if(!ignoreChars.Any(x=>x.Equals(readValue)))break;
|
||||
}
|
||||
inputStream.BaseStream.Seek(streamPosition,SeekOrigin.Begin);
|
||||
return value;
|
||||
}
|
||||
public int Read()
|
||||
{
|
||||
lastSymbol = inputStream.Read();
|
||||
return lastSymbol;
|
||||
}
|
||||
public int Read(ref String literal)
|
||||
{
|
||||
literal=inputStream.ReadString();
|
||||
return 0;
|
||||
}
|
||||
public int Read(ref byte value)
|
||||
{
|
||||
try { value = inputStream.ReadByte(); return 0; }
|
||||
catch (EndOfStreamException) { return 0xFFFF; }
|
||||
}
|
||||
public int Read(ref int value)
|
||||
{
|
||||
try { value = inputStream.ReadInt32(); return 0; }
|
||||
catch (EndOfStreamException) { return 0xFFFF; }
|
||||
|
||||
}
|
||||
public int Read(ref double value)
|
||||
{
|
||||
try { value = inputStream.ReadDouble(); return 0; }
|
||||
catch (EndOfStreamException) { return 0xFFFF; }
|
||||
}
|
||||
public bool Emitting
|
||||
{
|
||||
get
|
||||
{
|
||||
return emitting;
|
||||
}
|
||||
set
|
||||
{
|
||||
emitting = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
713
Axiom.Core/Interpreter/GenericData.cs
Normal file
713
Axiom.Core/Interpreter/GenericData.cs
Normal file
@@ -0,0 +1,713 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using log4net;
|
||||
using MarketData.DataAccess;
|
||||
using MarketData.MarketDataModel;
|
||||
using System.Diagnostics;
|
||||
using Axiom.Utils;
|
||||
|
||||
// FileName : GenericData.cs
|
||||
// Author : Sean Kessler
|
||||
|
||||
namespace Axiom.Interpreter
|
||||
{
|
||||
public class GenericData
|
||||
{
|
||||
private static ILog logger = LogManager.GetLogger(typeof(GenericData));
|
||||
private Object objData = null;
|
||||
private String objDataType = "";
|
||||
private bool isModified=false;
|
||||
|
||||
public Object Data
|
||||
{
|
||||
set
|
||||
{
|
||||
objData = value;
|
||||
if(null!=objData)objDataType =objData.GetType().ToString();
|
||||
}
|
||||
get
|
||||
{
|
||||
return objData;
|
||||
}
|
||||
}
|
||||
public bool IsNull()
|
||||
{
|
||||
return null == objData ? true : false;
|
||||
}
|
||||
public bool IsModified
|
||||
{
|
||||
get {return isModified;}
|
||||
set {isModified=value;}
|
||||
}
|
||||
public static GenericData PerformConvert(GenericData data1, GenericData data2) // convert data of param1 to the type described in data2
|
||||
{
|
||||
GenericData genericData = new GenericData();
|
||||
genericData.SetData(data1.GetStringRepData(),data2.Get<String>());
|
||||
return genericData;
|
||||
}
|
||||
public GenericData GetPrice(GenericData dateData,GenericData opData)
|
||||
{
|
||||
GenericData resultData = new GenericData();
|
||||
double result=default(double);
|
||||
try
|
||||
{
|
||||
String strSymbol=this.Get<String>();
|
||||
DateTime date = dateData.Get<DateTime>();
|
||||
Price price=PricingDA.GetPrice(strSymbol,date);
|
||||
if(null != price)
|
||||
{
|
||||
String strOperation=opData.Get<String>().ToUpper();
|
||||
if(strOperation.Equals("OPEN"))result = price.Open;
|
||||
else if(strOperation.Equals("HIGH"))result = price.High;
|
||||
else if(strOperation.Equals("LOW"))result = price.Low;
|
||||
else result = price.Close;
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Debug.WriteLine(exception.ToString());
|
||||
}
|
||||
resultData.SetData(result);
|
||||
return resultData;
|
||||
}
|
||||
public GenericData Substring(GenericData startIndexData,GenericData lengthData)
|
||||
{
|
||||
GenericData resultData = new GenericData();
|
||||
String result = null;
|
||||
try
|
||||
{
|
||||
int startIndex = startIndexData.Get<int>();
|
||||
int length = lengthData.Get<int>();
|
||||
String strArgument = this.Get<String>();
|
||||
result = strArgument.Substring(startIndex - 1, length);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
resultData.SetData(result);
|
||||
return resultData;
|
||||
}
|
||||
public GenericData Trim()
|
||||
{
|
||||
GenericData resultData = new GenericData();
|
||||
String result = null;
|
||||
try
|
||||
{
|
||||
String strArgument = this.Get<String>();
|
||||
result = strArgument.Trim();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
resultData.SetData(result);
|
||||
return resultData;
|
||||
}
|
||||
public GenericData Upper()
|
||||
{
|
||||
GenericData resultData = new GenericData();
|
||||
String result = null;
|
||||
try
|
||||
{
|
||||
String strArgument = this.Get<String>();
|
||||
result = strArgument.ToUpper();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
resultData.SetData(result);
|
||||
return resultData;
|
||||
}
|
||||
public GenericData Lower()
|
||||
{
|
||||
GenericData resultData = new GenericData();
|
||||
String result = null;
|
||||
try
|
||||
{
|
||||
String strArgument = this.Get<String>();
|
||||
result = strArgument.ToLower();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
resultData.SetData(result);
|
||||
return resultData;
|
||||
}
|
||||
public GenericData Like(GenericData argument)
|
||||
{
|
||||
GenericData genericData = new GenericData();
|
||||
String thisString = this.Get<String>();
|
||||
String strArgument = argument.GetStringRepData();
|
||||
if (null == thisString || null == strArgument)
|
||||
{
|
||||
genericData.SetData(false);
|
||||
return genericData;
|
||||
}
|
||||
strArgument = strArgument.Replace("%", null);
|
||||
genericData.SetData(thisString.Contains(strArgument));
|
||||
return genericData;
|
||||
}
|
||||
public void SetNull()
|
||||
{
|
||||
objDataType="System.Nullable";
|
||||
objData=Convert.ChangeType(null,Type.GetType(objDataType));
|
||||
}
|
||||
public void SetNull(String strDataType)
|
||||
{
|
||||
objDataType=GetTypeString(strDataType);
|
||||
objData=Convert.ChangeType(null,Type.GetType(objDataType));
|
||||
}
|
||||
public void SetData(double data)
|
||||
{
|
||||
Type targetType = data.GetType();
|
||||
objDataType = targetType.Name;
|
||||
objData = data;
|
||||
}
|
||||
public void SetData(bool data)
|
||||
{
|
||||
Type targetType = data.GetType();
|
||||
objDataType = targetType.Name;
|
||||
objData = data;
|
||||
}
|
||||
public void SetData(String data)
|
||||
{
|
||||
Type targetType = data.GetType();
|
||||
objDataType = targetType.Name;
|
||||
objData = data;
|
||||
}
|
||||
public void SetData(String stringRep, String typeName)
|
||||
{
|
||||
Type targetType = Type.GetType(typeName);
|
||||
objDataType = typeName;
|
||||
objData = Convert.ChangeType(stringRep, targetType);
|
||||
}
|
||||
public static GenericData Clone(GenericData genericData)
|
||||
{
|
||||
GenericData copyGenericData = new GenericData();
|
||||
if (null == genericData) return copyGenericData;
|
||||
copyGenericData.SetData(genericData.GetStringRepData(),genericData.GetStringRepType());
|
||||
return copyGenericData;
|
||||
}
|
||||
// *************************************************************************************************************************************************************************************
|
||||
// *********************************************************************************** L O G I C A L O P E R A T I O N S *************************************************************
|
||||
// *************************************************************************************************************************************************************************************
|
||||
public GenericData Not()
|
||||
{
|
||||
GenericData data = new GenericData();
|
||||
String stringRepType = GetStringRepType();
|
||||
|
||||
if (IsNull())
|
||||
{
|
||||
data.SetNull();
|
||||
}
|
||||
else if ("System.Boolean".Equals(stringRepType))
|
||||
{
|
||||
data.Data=!(Get<Boolean>());
|
||||
}
|
||||
else if ("System.Int32".Equals(stringRepType))
|
||||
{
|
||||
data.Data = (Get<Int32>() == 0);
|
||||
}
|
||||
else if ("System.String".Equals(stringRepType))
|
||||
{
|
||||
data.Data = !(Get<Boolean>());
|
||||
}
|
||||
else if ("System.Double".Equals(stringRepType))
|
||||
{
|
||||
data.Data = (Get<double>() == 0.00);
|
||||
}
|
||||
else data.SetNull();
|
||||
return data;
|
||||
}
|
||||
public GenericData LessEqual(GenericData genericData)
|
||||
{
|
||||
GenericData data = new GenericData();
|
||||
if (IsNull())
|
||||
{
|
||||
data.SetData(false);
|
||||
}
|
||||
else if ("System.Double".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
try
|
||||
{
|
||||
data.Data = Get<double>()<=genericData.Get<double>();
|
||||
}
|
||||
catch (Exception) { data.Data = 0.00; }
|
||||
}
|
||||
else if ("System.Int32".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
try
|
||||
{
|
||||
data.Data = Get<Int32>()<=genericData.Get<Int32>();
|
||||
}
|
||||
catch (Exception) { data.Data = 0.00; }
|
||||
}
|
||||
else if ("System.String".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
data.Data = Get<String>().Length<=genericData.Get<String>().Length;
|
||||
}
|
||||
else data.SetNull();
|
||||
return data;
|
||||
}
|
||||
public GenericData Or(GenericData genericData)
|
||||
{
|
||||
GenericData data = new GenericData();
|
||||
if (IsNull())
|
||||
{
|
||||
data.SetData(false);
|
||||
}
|
||||
else if ("System.Double".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
try
|
||||
{
|
||||
data.Data = (0.00!=Get<double>())||(0.00!=genericData.Get<double>());
|
||||
}
|
||||
catch (Exception) { data.Data = 0.00; }
|
||||
}
|
||||
else if ("System.Int32".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
try
|
||||
{
|
||||
data.Data = (0!=Get<Int32>())||(0!=genericData.Get<Int32>());
|
||||
}
|
||||
catch (Exception) { data.Data = 0.00; }
|
||||
}
|
||||
else if ("System.Boolean".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
data.Data = Get<Boolean>()||genericData.Get<Boolean>();
|
||||
}
|
||||
else data.SetNull();
|
||||
return data;
|
||||
}
|
||||
public GenericData And(GenericData genericData)
|
||||
{
|
||||
GenericData data = new GenericData();
|
||||
if (IsNull())
|
||||
{
|
||||
data.SetData(false);
|
||||
}
|
||||
else if ("System.Double".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
try
|
||||
{
|
||||
data.Data = (0.00 != Get<double>()) && (0.00 != genericData.Get<double>());
|
||||
}
|
||||
catch (Exception) { data.Data = 0.00; }
|
||||
}
|
||||
else if ("System.Int32".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
try
|
||||
{
|
||||
data.Data = (0 != Get<Int32>()) && (0 != genericData.Get<Int32>());
|
||||
}
|
||||
catch (Exception) { data.Data = 0.00; }
|
||||
}
|
||||
else if ("System.Boolean".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
data.Data = Get<Boolean>() && genericData.Get<Boolean>();
|
||||
}
|
||||
else data.SetNull();
|
||||
return data;
|
||||
}
|
||||
public GenericData Greater(GenericData genericData)
|
||||
{
|
||||
GenericData data = new GenericData();
|
||||
if (IsNull())
|
||||
{
|
||||
data.SetData(false);
|
||||
}
|
||||
else if ("System.Double".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
try
|
||||
{
|
||||
data.Data = Get<double>()>genericData.Get<double>();
|
||||
}
|
||||
catch (Exception) { data.Data = 0.00; }
|
||||
}
|
||||
else if ("System.DateTime".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
try
|
||||
{
|
||||
data.Data = Get<DateTime>()>genericData.Get<DateTime>();
|
||||
}
|
||||
catch (Exception) { data.Data = 0.00; }
|
||||
}
|
||||
else if ("System.Int32".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
try
|
||||
{
|
||||
data.Data = Get<Int32>()>genericData.Get<Int32>();
|
||||
}
|
||||
catch (Exception) { data.Data = 0.00; }
|
||||
}
|
||||
else if ("System.String".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
data.Data = Get<String>().Length>genericData.Get<String>().Length;
|
||||
}
|
||||
else data.SetNull();
|
||||
return data;
|
||||
}
|
||||
public GenericData GreaterEqual(GenericData genericData)
|
||||
{
|
||||
GenericData data = new GenericData();
|
||||
if (IsNull())
|
||||
{
|
||||
data.SetData(false);
|
||||
}
|
||||
else if ("System.Double".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
try
|
||||
{
|
||||
data.Data = Get<double>()>=genericData.Get<double>();
|
||||
}
|
||||
catch (Exception) { data.Data = 0.00; }
|
||||
}
|
||||
else if ("System.Int32".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
try
|
||||
{
|
||||
data.Data = Get<Int32>()>=genericData.Get<Int32>();
|
||||
}
|
||||
catch (Exception) { data.Data = 0.00; }
|
||||
}
|
||||
else if ("System.String".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
data.Data = Get<String>().Length>=genericData.Get<String>().Length;
|
||||
}
|
||||
else data.SetNull();
|
||||
return data;
|
||||
}
|
||||
public GenericData EqualEqual(GenericData genericData)
|
||||
{
|
||||
GenericData data = new GenericData();
|
||||
|
||||
if (IsNull() && genericData.IsNull())
|
||||
{
|
||||
data.SetData(true);
|
||||
}
|
||||
else if (IsNull())
|
||||
{
|
||||
data.SetData(false);
|
||||
}
|
||||
else if ("System.Double".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
try { data.Data = (0 == Get<double>().CompareTo(genericData.Get<double>())); }
|
||||
catch (Exception) { data.Data = 0.00; }
|
||||
}
|
||||
else if ("System.Int32".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
try { data.Data = (0 == Get<Int32>().CompareTo(genericData.Get<Int32>())); }
|
||||
catch (Exception) { data.Data = 0.00; }
|
||||
}
|
||||
else if ("System.String".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
data.Data = (Get<String>().Equals(genericData.Get<String>()));
|
||||
}
|
||||
else data.SetNull();
|
||||
return data;
|
||||
}
|
||||
public GenericData NotEqual(GenericData genericData)
|
||||
{
|
||||
GenericData data = new GenericData();
|
||||
if (IsNull() && !genericData.IsNull())
|
||||
{
|
||||
data.SetData(true);
|
||||
}
|
||||
else if (!IsNull() && genericData.IsNull())
|
||||
{
|
||||
data.SetData(true);
|
||||
}
|
||||
else if (IsNull())
|
||||
{
|
||||
data.SetData(false);
|
||||
}
|
||||
else if ("System.Double".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
try { data.Data = (0 != Get<double>().CompareTo(genericData.Get<double>())); }
|
||||
catch (Exception) { data.Data = 0.00; }
|
||||
}
|
||||
else if ("System.Int32".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
try { data.Data = (0 != Get<Int32>().CompareTo(genericData.Get<Int32>())); }
|
||||
catch (Exception) { data.Data = 0.00; }
|
||||
}
|
||||
else if ("System.String".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
data.Data = !(Get<String>().Equals(genericData.Get<String>()));
|
||||
}
|
||||
else data.SetNull();
|
||||
return data;
|
||||
}
|
||||
public GenericData Less(GenericData genericData)
|
||||
{
|
||||
GenericData data = new GenericData();
|
||||
if (IsNull())
|
||||
{
|
||||
data.SetData(false);
|
||||
}
|
||||
else if ("System.Double".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
try { data.Data = (-1==Get<double>().CompareTo(genericData.Get<double>())); }
|
||||
catch (Exception) { data.Data = 0.00; }
|
||||
}
|
||||
else if ("System.Int32".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
try { data.Data = (-1==Get<Int32>().CompareTo(genericData.Get<Int32>())); }
|
||||
catch (Exception) { data.Data = 0.00; }
|
||||
}
|
||||
else if ("System.String".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
data.Data = Get<String>().Equals(genericData.Get<String>());
|
||||
}
|
||||
else data.SetNull();
|
||||
return data;
|
||||
}
|
||||
// **************************************************************************************************************************************************************************************
|
||||
// ********************************************************************************** M A T H E M A T I C A L O P E R A T I O N S ****************************************************
|
||||
// **************************************************************************************************************************************************************************************
|
||||
public GenericData Negate()
|
||||
{
|
||||
GenericData data = new GenericData();
|
||||
String stringRepType = GetStringRepType();
|
||||
|
||||
if (IsNull())
|
||||
{
|
||||
data.SetNull();
|
||||
}
|
||||
else if ("System.Double".Equals(stringRepType))
|
||||
{
|
||||
try
|
||||
{
|
||||
data.Data = Get<double>() * -1.00;
|
||||
}
|
||||
catch (Exception) { data.Data = 0.00; }
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
data.Data = Get<Int32>() * -1;
|
||||
}
|
||||
catch (Exception){data.SetNull();}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
public GenericData Abs()
|
||||
{
|
||||
GenericData data = new GenericData();
|
||||
String stringRepType = GetStringRepType();
|
||||
if (IsNull())
|
||||
{
|
||||
data.SetNull();
|
||||
}
|
||||
if ("System.Double".Equals(stringRepType))
|
||||
{
|
||||
try
|
||||
{
|
||||
data.Data = Math.Abs(Get<double>());
|
||||
}
|
||||
catch (Exception) { data.Data = 0.00; }
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
data.Data = Math.Abs(Get<Int32>());
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
data.SetNull();
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public GenericData Multiply(GenericData genericData)
|
||||
{
|
||||
GenericData data = new GenericData();
|
||||
if (IsNull())
|
||||
{
|
||||
data.SetNull();
|
||||
}
|
||||
else if ("System.Double".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
try { data.Data = Get<double>() * genericData.Get<double>(); }
|
||||
catch (Exception) { data.Data = double.NaN; }
|
||||
}
|
||||
else if ("System.Int32".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
try { data.Data = Get<Int32>() * genericData.Get<Int32>(); }
|
||||
catch (Exception) { data.Data = Int32.MinValue; }
|
||||
}
|
||||
else if ("System.String".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
try { data.Data = Get<double>() * genericData.Get<double>(); } // genericData is a string but try to cast and perform the multiplication anyway
|
||||
catch (Exception) { data.Data = double.NaN; }
|
||||
}
|
||||
else data.SetNull();
|
||||
return data;
|
||||
}
|
||||
public GenericData Divide(GenericData genericData)
|
||||
{
|
||||
GenericData data = new GenericData();
|
||||
if (IsNull())
|
||||
{
|
||||
data.SetNull();
|
||||
}
|
||||
else if ("System.Double".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
try { data.Data = Get<double>() / genericData.Get<double>(); }
|
||||
catch (Exception) { data.Data = double.NaN; }
|
||||
}
|
||||
else if ("System.Int32".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
try { data.Data = Get<Int32>() / genericData.Get<Int32>(); }
|
||||
catch (Exception) { data.Data = Int32.MinValue; }
|
||||
}
|
||||
else if ("System.String".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
data.Data = double.NaN;
|
||||
}
|
||||
else data.SetNull();
|
||||
return data;
|
||||
}
|
||||
public GenericData Add(GenericData genericData)
|
||||
{
|
||||
GenericData data = new GenericData();
|
||||
if (IsNull())
|
||||
{
|
||||
data.SetNull();
|
||||
}
|
||||
else if ("System.Double".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
data.Data = Get<double>()+genericData.Get<double>();
|
||||
}
|
||||
else if ("System.Int32".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
data.Data = Get<Int32>()+genericData.Get<Int32>();
|
||||
}
|
||||
else if ("System.String".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
data.Data = Get<String>() + genericData.Get<String>();
|
||||
}
|
||||
else data.SetNull();
|
||||
return data;
|
||||
}
|
||||
public GenericData Subtract(GenericData genericData)
|
||||
{
|
||||
GenericData data = new GenericData();
|
||||
if (IsNull())
|
||||
{
|
||||
data.SetNull();
|
||||
}
|
||||
else if ("System.Double".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
data.Data = Get<double>() - genericData.Get<double>();
|
||||
}
|
||||
else if ("System.Int32".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
data.Data = Get<Int32>() - genericData.Get<Int32>();
|
||||
}
|
||||
else if ("System.String".Equals(genericData.GetStringRepType()))
|
||||
{
|
||||
data.Data = (Get<String>()).Replace(genericData.Get<String>(), null);
|
||||
}
|
||||
else data.SetNull();
|
||||
return data;
|
||||
}
|
||||
// ********************************************************************************************************** E N D O P E R A T I O N S ********************************************************************************************
|
||||
public String GetStringRepData()
|
||||
{
|
||||
if (null == objData) return null;
|
||||
String stringRepType = GetStringRepType();
|
||||
return (String)Convert.ChangeType(objData, typeof(String));
|
||||
}
|
||||
public String GetStringRepType()
|
||||
{
|
||||
if (null == objData) return "System.Nullable";
|
||||
return objData.GetType().ToString();
|
||||
}
|
||||
public Type DataType
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == objData) throw new Exception("No type data for null value.");
|
||||
return objData.GetType();
|
||||
}
|
||||
}
|
||||
public override String ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append(GetStringRepType()).Append(":").Append("'").Append(GetStringRepData()).Append("'");
|
||||
return sb.ToString();
|
||||
}
|
||||
public T Get<T>()
|
||||
{
|
||||
T result = default(T);
|
||||
try
|
||||
{
|
||||
result = (T)Convert.ChangeType(objData, typeof(T));
|
||||
}
|
||||
catch(Exception /*exception*/)
|
||||
{
|
||||
result = default(T);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// **********************************************************************************************************************************************************************************
|
||||
// ************************************************************************ P U B L I C S T A T I C H E L P E R S ****************************************************************
|
||||
// **********************************************************************************************************************************************************************************
|
||||
public static Object ConvertType(String destinationType,String stringRep)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (destinationType.Equals("System.DBNull")) destinationType = "System.String";
|
||||
Type targetType = Type.GetType(destinationType);
|
||||
String objDataType = destinationType;
|
||||
Object objData = Convert.ChangeType(stringRep, targetType);
|
||||
return objData;
|
||||
}
|
||||
catch(Exception /*exception*/)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static Object ConvertType(Type targetType,String stringRep)
|
||||
{
|
||||
try
|
||||
{
|
||||
Object objData = null;
|
||||
String stringRepType = targetType.ToString();
|
||||
if(targetType.Equals("System.Double")&&null==stringRep||stringRep.Equals(""))return objData;
|
||||
else if (stringRepType.Equals("System.DBNull")) stringRep = "System.String";
|
||||
objData = Convert.ChangeType(stringRep, targetType);
|
||||
return objData;
|
||||
}
|
||||
catch(Exception /*exception*/)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static Type GetType(String strType)
|
||||
{
|
||||
strType=strType.ToUpper();
|
||||
if(strType.Equals("STRING")||strType.Equals("SYSTEM.STRING"))return Type.GetType("System.String");
|
||||
else if(strType.Equals("NUMERIC")||strType.Equals("DOUBLE")||strType.Equals("SYSTEM.DOUBLE"))return Type.GetType("System.Double");
|
||||
else if(strType.Equals("DATETIME")||strType.Equals("SYSTEM.DATETIME"))return Type.GetType("System.DateTime");
|
||||
return Type.GetType("System.String");
|
||||
}
|
||||
public static String GetTypeString(String strType)
|
||||
{
|
||||
strType=strType.ToUpper();
|
||||
if(strType.Equals("STRING")||strType.Equals("SYSTEM.STRING"))return "System.String";
|
||||
else if(strType.Equals("NUMERIC")||strType.Equals("DOUBLE")||strType.Equals("SYSTEM.DOUBLE"))return "System.Double";
|
||||
else if(strType.Equals("DATETIME")||strType.Equals("SYSTEM.DATETIME"))return "System.DateTime";
|
||||
return "System.String";
|
||||
}
|
||||
public static String ToExpressionData(System.Data.DataColumn dataColumn,String value)
|
||||
{
|
||||
if (dataColumn.DataType.Name.ToUpper().Equals("STRING")) return "'"+Utility.SqlString(value)+"'";
|
||||
if (dataColumn.DataType.Name.ToUpper().Equals("DATETIME")) return "'"+Utility.SqlString(value)+"'";
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
91
Axiom.Core/Interpreter/ParseSymbols.cs
Normal file
91
Axiom.Core/Interpreter/ParseSymbols.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
// FileName : ParseSymbols.cs
|
||||
// Author : Sean Kessler
|
||||
|
||||
namespace Axiom.Interpreter
|
||||
{
|
||||
public class ParseSymbols : List<ParseSymbol>
|
||||
{
|
||||
private Dictionary<Scanner.ScanSymbols, Scanner.ScanSymbols> uniqueSymbols = new Dictionary<Scanner.ScanSymbols, Scanner.ScanSymbols>();
|
||||
|
||||
public ParseSymbols()
|
||||
{
|
||||
}
|
||||
public ParseSymbols(List<ParseSymbol> symbols)
|
||||
{
|
||||
foreach (ParseSymbol symbol in symbols) InsertSymbols(symbol);
|
||||
}
|
||||
public new void Add(ParseSymbol parseSymbol)
|
||||
{
|
||||
InsertSymbols(parseSymbol);
|
||||
}
|
||||
public void InsertSymbols(ParseSymbols symbols)
|
||||
{
|
||||
foreach (ParseSymbol parseSymbol in symbols)
|
||||
{
|
||||
base.Add(parseSymbol);
|
||||
if (!uniqueSymbols.ContainsKey(parseSymbol.Symbol)) uniqueSymbols.Add(parseSymbol.Symbol,parseSymbol.Symbol);
|
||||
}
|
||||
}
|
||||
public void InsertSymbols(ParseSymbol parseSymbol)
|
||||
{
|
||||
base.Add(parseSymbol);
|
||||
if (!uniqueSymbols.ContainsKey(parseSymbol.Symbol)) uniqueSymbols.Add(parseSymbol.Symbol,parseSymbol.Symbol);
|
||||
}
|
||||
public void RemoveSymbols(ParseSymbols symbols)
|
||||
{
|
||||
for (int index = symbols.Count - 1; index >= 0;index--)
|
||||
{
|
||||
ParseSymbol symbol = symbols[index];
|
||||
base.Remove(symbol);
|
||||
int count = (from ParseSymbol parseSymbol in this where parseSymbol.Symbol.Equals(symbol.Symbol) select parseSymbol).Count();
|
||||
if (0 == count && uniqueSymbols.ContainsKey(symbol.Symbol)) uniqueSymbols.Remove(symbol.Symbol);
|
||||
}
|
||||
}
|
||||
public void RemoveSymbols(ParseSymbol symbol)
|
||||
{
|
||||
base.Remove(symbol);
|
||||
int count = (from ParseSymbol parseSymbol in this where parseSymbol.Symbol.Equals(symbol.Symbol) select parseSymbol).Count();
|
||||
if(0==count&&uniqueSymbols.ContainsKey(symbol.Symbol))uniqueSymbols.Remove(symbol.Symbol);
|
||||
}
|
||||
public bool SymbolIn(Scanner.ScanSymbols symbol)
|
||||
{
|
||||
return uniqueSymbols.ContainsKey(symbol);
|
||||
}
|
||||
public bool SymbolIn(ParseSymbols parseSymbols)
|
||||
{
|
||||
foreach (ParseSymbol symbol in parseSymbols) if (uniqueSymbols.ContainsKey(symbol.Symbol)) return true;
|
||||
return false;
|
||||
}
|
||||
public bool SymbolIn(ParseSymbol parseSymbol)
|
||||
{
|
||||
return uniqueSymbols.ContainsKey(parseSymbol.Symbol);
|
||||
}
|
||||
}
|
||||
public class ParseSymbol : IEquatable<ParseSymbol>
|
||||
{
|
||||
private Scanner.ScanSymbols symbol;
|
||||
public ParseSymbol()
|
||||
{
|
||||
}
|
||||
public ParseSymbol(Scanner.ScanSymbols symbol)
|
||||
{
|
||||
this.symbol = symbol;
|
||||
}
|
||||
public Scanner.ScanSymbols Symbol
|
||||
{
|
||||
get
|
||||
{
|
||||
return symbol;
|
||||
}
|
||||
}
|
||||
public bool Equals(ParseSymbol parseSymbol)
|
||||
{
|
||||
if (parseSymbol == null) return false;
|
||||
return Symbol.Equals(parseSymbol.Symbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
1748
Axiom.Core/Interpreter/Parser.cs
Normal file
1748
Axiom.Core/Interpreter/Parser.cs
Normal file
File diff suppressed because it is too large
Load Diff
625
Axiom.Core/Interpreter/Scanner.cs
Normal file
625
Axiom.Core/Interpreter/Scanner.cs
Normal file
@@ -0,0 +1,625 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
// FileName : ParseSymbols.cs
|
||||
// Author : Sean Kessler
|
||||
|
||||
namespace Axiom.Interpreter
|
||||
{
|
||||
public class Scanner : Emitter
|
||||
{
|
||||
public enum ScanSymbols { unknown1, directive_clear_modified1,declare1, null1, isnull1, convert1, getprice1, substring1, in1, like1, trim1, upper1, lower1, assign1, if1, while1, then1,else1,goto1,equal1,equalequal1,less1,lessequal1,greater1,greaterequal1, notequal1,variable1, asterisk1, apostrophe1, comma1, label1, literal1, leftcurly1, rightcurly1, leftbracket1, rightbracket1, numeral1, char1, divide1, plus1, minus1, leftparen1, rightparen1, newline1, semicolon1,endtext1, andand1, oror1, abs1, not1, pow1, sqrt1, break1, end1 };
|
||||
private enum WhiteSpace{spacechar=32,tabchar=9};
|
||||
private int character;
|
||||
private StringBuilder word;
|
||||
private SymbolTable symbolTable;
|
||||
|
||||
public Scanner(BinaryReader binaryReader, BinaryWriter binaryWriter,SymbolTable symbolTable)
|
||||
: base(binaryReader, binaryWriter)
|
||||
{
|
||||
this.symbolTable = symbolTable;
|
||||
}
|
||||
public bool Analyze()
|
||||
{
|
||||
if(!ReadCh())return false;
|
||||
while ((int)character != -1 && character != 0x001A)
|
||||
{
|
||||
SkipSeparators();
|
||||
if(-1==(int)character)break;
|
||||
if (0xFFFF == character || 0x001A == character) break;
|
||||
if (IsDigit(character) || '.'.Equals((char)character)) ScanNumeral();
|
||||
else if ('\r' == character) ScanNewLine();
|
||||
else if (';' == character) { Emit(ScanSymbols.semicolon1); ReadCh(); }
|
||||
else if (',' == character) { Emit(ScanSymbols.comma1); ReadCh(); }
|
||||
else if ('[' == character) { Emit(ScanSymbols.leftbracket1); ReadCh(); }
|
||||
else if (']' == character) { Emit(ScanSymbols.rightbracket1); ReadCh(); }
|
||||
else if ('*' == character) { Emit(ScanSymbols.asterisk1); ReadCh(); }
|
||||
else if ('/' == character) { ScanDivide(); }
|
||||
else if ('+' == character) { Emit(ScanSymbols.plus1); ReadCh(); }
|
||||
else if ('-' == character) { Emit(ScanSymbols.minus1); ReadCh(); }
|
||||
else if ('(' == character) { Emit(ScanSymbols.leftparen1); ReadCh(); }
|
||||
else if (')' == character) { Emit(ScanSymbols.rightparen1); ReadCh(); }
|
||||
else if ('!' == character) { Emit(ScanSymbols.not1); ReadCh(); }
|
||||
else if ('{' == character) { Emit(ScanSymbols.leftcurly1); ReadCh(); }
|
||||
else if ('}' == character) { Emit(ScanSymbols.rightcurly1); ReadCh(); }
|
||||
else if ('\'' == character) ScanLiteral();
|
||||
else if (';' == character) ScanComment();
|
||||
else if ('=' == character) ScanEqual();
|
||||
else if ('<' == character) ScanLess();
|
||||
else if ('>' == character) ScanGreater();
|
||||
else if ('&' == character) ScanAnd();
|
||||
else if ('|' == character) ScanOr();
|
||||
else if (IsAlpha(character))
|
||||
{
|
||||
if (!ScanWord()) return false;
|
||||
}
|
||||
else if ('#' == character)
|
||||
{
|
||||
if (!ScanDirective()) return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
ScanUnknown();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Emit(Scanner.ScanSymbols.endtext1);
|
||||
return true;
|
||||
}
|
||||
public bool ReadCh()
|
||||
{
|
||||
try
|
||||
{
|
||||
character = Read();
|
||||
if (-1 == character) return false;
|
||||
return true;
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
character = -1;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public void ScanDivide()
|
||||
{
|
||||
Emit(ScanSymbols.divide1);
|
||||
ReadCh();
|
||||
}
|
||||
public bool PeekCh(ref char ch)
|
||||
{
|
||||
try
|
||||
{
|
||||
int character=Peek();
|
||||
if(-1==character)return false;
|
||||
ch=(Char)character;
|
||||
return true;
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool ScanDirective()
|
||||
{
|
||||
char nextChar='\0';
|
||||
if(!PeekCh(ref nextChar))return false;
|
||||
if(!nextChar.Equals('#'))return ScanWord();
|
||||
while (-1!=character && 0x0D != character && 0xFFFF != character)ReadCh(); // if we have ## then take the line as a comment
|
||||
return true;
|
||||
}
|
||||
public bool ScanWord()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
while (-1!=character && 0x0D != character && !IsKeySymbol() && 0xFFFF != character && (int)WhiteSpace.spacechar!=character && (int)WhiteSpace.tabchar != character)
|
||||
{
|
||||
sb.Append((char)character);
|
||||
ReadCh();
|
||||
}
|
||||
if (0 == sb.Length) return true;
|
||||
String symbolName = sb.ToString();
|
||||
if (':'.Equals((char)character))
|
||||
{
|
||||
Emit(ScanSymbols.label1);
|
||||
Emit(symbolName);
|
||||
ReadCh();
|
||||
}
|
||||
else if(symbolTable.ContainsKey(symbolName))
|
||||
{
|
||||
Symbol symbol = symbolTable[symbolName];
|
||||
if (Symbol.SymbolType.FunctionSymbol.Equals(symbol.TypeOfSymbol)) Emit(symbol.Identifier);
|
||||
else if(Symbol.SymbolType.KeywordSymbol.Equals(symbol.TypeOfSymbol)) Emit(symbol.Identifier);
|
||||
else if(Symbol.SymbolType.DirectiveSymbol.Equals(symbol.TypeOfSymbol)) Emit(symbol.Identifier);
|
||||
else Emit(ScanSymbols.variable1, symbol.SymbolName);
|
||||
}
|
||||
else if(symbolTable.ContainsKey(symbolName.ToLower()))
|
||||
{
|
||||
symbolName = symbolName.ToLower();
|
||||
Symbol symbol = symbolTable[symbolName];
|
||||
if (Symbol.SymbolType.FunctionSymbol.Equals(symbol.TypeOfSymbol)) Emit(symbol.Identifier);
|
||||
else if(Symbol.SymbolType.KeywordSymbol.Equals(symbol.TypeOfSymbol)) Emit(symbol.Identifier);
|
||||
else Emit(ScanSymbols.variable1, symbol.SymbolName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Emit(ScanSymbols.variable1, symbolName);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool ScanNumeral()
|
||||
{
|
||||
int[] chBuffer = new int[128];
|
||||
int chIndex = 0;
|
||||
while (0xFFFF != character && (IsDigit(character) || IsInHex(character) || '.'.Equals((char)character)))
|
||||
{
|
||||
if (chIndex >= chBuffer.Length) return false;
|
||||
chBuffer[chIndex++] = character;
|
||||
ReadCh();
|
||||
}
|
||||
if (character == 69) Exponent(chBuffer, chIndex);
|
||||
else if ('h' == character || 'H' == character) { Hex(chBuffer, chIndex); ReadCh(); }
|
||||
else if ('b' == character || 'B' == character) { Binary(chBuffer, chIndex); ReadCh(); }
|
||||
else if (chIndex > 0 && ('b' == chBuffer[chIndex - 1] || 'B' == chBuffer[chIndex - 1])) Binary(chBuffer, chIndex - 1);
|
||||
else Decimal(chBuffer, chIndex);
|
||||
return true;
|
||||
}
|
||||
public void Exponent(int[] chBuffer, int chIndex)
|
||||
{
|
||||
chBuffer[chIndex++] = character;
|
||||
ReadCh();
|
||||
while (0xFFFF != character && (character == 43 || character == 45 || IsDigit(character)))
|
||||
{
|
||||
if (chIndex >= chBuffer.Length) return;
|
||||
chBuffer[chIndex++] = character;
|
||||
ReadCh();
|
||||
}
|
||||
Decimal(chBuffer, chIndex);
|
||||
}
|
||||
public void Binary(int[] chBuffer,int chIndex)
|
||||
{
|
||||
int value=0;
|
||||
int multiplier=1;
|
||||
|
||||
for(--chIndex;chIndex>=0;chIndex--)
|
||||
{
|
||||
switch(chBuffer[chIndex])
|
||||
{
|
||||
case '0' : break;
|
||||
case '1' : {value+=multiplier;break;}
|
||||
default : {Emit(ScanSymbols.unknown1);return;}
|
||||
}
|
||||
multiplier*=2;
|
||||
}
|
||||
Emit(ScanSymbols.numeral1,value);
|
||||
}
|
||||
public void Decimal(int[] chBuffer,int chIndex)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int index = 0; index < chBuffer.Length; index++) sb.Append((char)chBuffer[index]);
|
||||
double value = double.Parse(sb.ToString());
|
||||
Emit(ScanSymbols.numeral1,value);
|
||||
}
|
||||
public bool IsInHex(int character)
|
||||
{
|
||||
if ('A'.Equals(character) || 'B'.Equals(character) || 'C'.Equals(character) || 'D'.Equals(character) || 'E'.Equals(character) || 'F'.Equals(character) ||
|
||||
'a'.Equals(character) || 'b'.Equals(character) || 'c'.Equals(character) || 'd'.Equals(character) || 'e'.Equals(character) || 'f'.Equals(character)) return true;
|
||||
return false;
|
||||
}
|
||||
void Hex(int[] chBuffer, int chIndex)
|
||||
{
|
||||
int value=0;
|
||||
int multiplier=1;
|
||||
|
||||
for(--chIndex;chIndex>=0;chIndex--)
|
||||
{
|
||||
switch(chBuffer[chIndex])
|
||||
{
|
||||
case '0' : break;
|
||||
case '1' : {value+=multiplier;break;}
|
||||
case '2' : {value+=multiplier*2;break;}
|
||||
case '3' : {value+=multiplier*3;break;}
|
||||
case '4' : {value+=multiplier*4;break;}
|
||||
case '5' : {value+=multiplier*5;break;}
|
||||
case '6' : {value+=multiplier*6;break;}
|
||||
case '7' : {value+=multiplier*7;break;}
|
||||
case '8' : {value+=multiplier*8;break;}
|
||||
case '9' : {value+=multiplier*9;break;}
|
||||
case 'a' :
|
||||
case 'A' : {value+=multiplier*10;break;}
|
||||
case 'b' :
|
||||
case 'B' : {value+=multiplier*11;break;}
|
||||
case 'c' :
|
||||
case 'C' : {value+=multiplier*12;break;}
|
||||
case 'd' :
|
||||
case 'D' : {value+=multiplier*13;break;}
|
||||
case 'e' :
|
||||
case 'E' : {value+=multiplier*14;break;}
|
||||
case 'f' :
|
||||
case 'F' : {value+=multiplier*15;break;}
|
||||
default : {Emit(ScanSymbols.unknown1);return;}
|
||||
}
|
||||
multiplier*=16;
|
||||
}
|
||||
Emit(ScanSymbols.numeral1,value);
|
||||
}
|
||||
|
||||
public void SkipSeparators()
|
||||
{
|
||||
while (character.Equals((int)WhiteSpace.spacechar) || character.Equals((int)WhiteSpace.tabchar)) ReadCh();
|
||||
}
|
||||
public void ScanNewLine()
|
||||
{
|
||||
Emit(ScanSymbols.newline1);
|
||||
ReadCh();
|
||||
while (character.Equals('\n') || character.Equals('\n')) ReadCh();
|
||||
}
|
||||
public void ScanAnd()
|
||||
{
|
||||
int character=0;
|
||||
|
||||
Peek(ref character);
|
||||
if ('&'.Equals((char)character))
|
||||
{
|
||||
Emit(ScanSymbols.andand1);
|
||||
ReadCh();
|
||||
ReadCh();
|
||||
}
|
||||
else
|
||||
{
|
||||
Emit(ScanSymbols.unknown1);
|
||||
ReadCh();
|
||||
}
|
||||
}
|
||||
public void ScanOr()
|
||||
{
|
||||
int character=0;
|
||||
|
||||
Peek(ref character);
|
||||
if ('|'.Equals((char)character))
|
||||
{
|
||||
Emit(ScanSymbols.oror1);
|
||||
ReadCh();
|
||||
ReadCh();
|
||||
}
|
||||
else
|
||||
{
|
||||
Emit(ScanSymbols.unknown1);
|
||||
ReadCh();
|
||||
}
|
||||
}
|
||||
public void ScanEqual()
|
||||
{
|
||||
int character=0;
|
||||
|
||||
Peek(ref character);
|
||||
if ('='.Equals((char)character))
|
||||
{
|
||||
Emit(ScanSymbols.equalequal1);
|
||||
ReadCh();
|
||||
ReadCh();
|
||||
}
|
||||
else
|
||||
{
|
||||
Emit(ScanSymbols.equal1);
|
||||
ReadCh();
|
||||
}
|
||||
}
|
||||
public void ScanLess()
|
||||
{
|
||||
int character=0;
|
||||
|
||||
Peek(ref character);
|
||||
if ('='.Equals((char)character))
|
||||
{
|
||||
Emit(ScanSymbols.lessequal1);
|
||||
ReadCh();
|
||||
ReadCh();
|
||||
}
|
||||
else if ('>'.Equals((char)character))
|
||||
{
|
||||
Emit(ScanSymbols.notequal1);
|
||||
ReadCh();
|
||||
ReadCh();
|
||||
}
|
||||
else
|
||||
{
|
||||
Emit(ScanSymbols.less1);
|
||||
ReadCh();
|
||||
}
|
||||
}
|
||||
public void ScanGreater()
|
||||
{
|
||||
int character=0;
|
||||
|
||||
Peek(ref character);
|
||||
if ('='.Equals((char)character))
|
||||
{
|
||||
Emit(ScanSymbols.greaterequal1);
|
||||
ReadCh();
|
||||
ReadCh();
|
||||
}
|
||||
else
|
||||
{
|
||||
Emit(ScanSymbols.greater1);
|
||||
ReadCh();
|
||||
}
|
||||
}
|
||||
public void ScanComment()
|
||||
{
|
||||
ReadCh();
|
||||
while(!character.Equals('\r')&&!character.Equals(0xFFFF))ReadCh();
|
||||
}
|
||||
public bool IsAlpha(int character)
|
||||
{
|
||||
return Char.IsLetter((char)character);
|
||||
}
|
||||
public bool IsDigit(int character)
|
||||
{
|
||||
return Char.IsDigit((char)character);
|
||||
}
|
||||
public bool IsKeySymbol()
|
||||
{
|
||||
return ('}'==character||'{'==character||'<'==character||'>'==character||';'==character || ' ' == character || ',' == character || '[' == character || ']' == character || ':' == character || '*' == character || '/' == character || '+' == character || '-' == character || '(' == character || ')' == character ||'='==character);
|
||||
}
|
||||
public void ScanLiteral()
|
||||
{
|
||||
int character;
|
||||
word = new StringBuilder();
|
||||
ReadCh();
|
||||
character = this.character;
|
||||
if (character == '\'')
|
||||
{
|
||||
Emit(ScanSymbols.literal1,word.ToString());
|
||||
ReadCh();
|
||||
return;
|
||||
}
|
||||
while (-1!=character && 0xFFFF != this.character && 0x0D != this.character)
|
||||
{
|
||||
if ('\'' == this.character)
|
||||
{
|
||||
char peekChar=(char)0;
|
||||
PeekCh(ref peekChar);
|
||||
if ('\'' != peekChar) break;
|
||||
ReadCh();
|
||||
}
|
||||
word.Append((char)this.character);
|
||||
if (!ReadCh()) break;
|
||||
}
|
||||
ReadCh();
|
||||
Emit(ScanSymbols.literal1,word.ToString());
|
||||
}
|
||||
public void ScanUnknown()
|
||||
{
|
||||
ReadCh();
|
||||
Emit(ScanSymbols.unknown1);
|
||||
}
|
||||
public static String SymbolToLiteralString(Scanner.ScanSymbols code)
|
||||
{
|
||||
switch(code)
|
||||
{
|
||||
case Scanner.ScanSymbols.directive_clear_modified1 :
|
||||
return "directive_clear_modified1";
|
||||
case Scanner.ScanSymbols.declare1 :
|
||||
return "declare";
|
||||
case Scanner.ScanSymbols.unknown1 :
|
||||
return "unknown symbol";
|
||||
case Scanner.ScanSymbols.assign1 :
|
||||
return "assignment";
|
||||
case Scanner.ScanSymbols.if1 :
|
||||
return "if";
|
||||
case Scanner.ScanSymbols.while1 :
|
||||
return "while";
|
||||
case Scanner.ScanSymbols.then1 :
|
||||
return "then";
|
||||
case Scanner.ScanSymbols.else1 :
|
||||
return "else";
|
||||
case Scanner.ScanSymbols.goto1 :
|
||||
return "goto";
|
||||
case Scanner.ScanSymbols.equal1 :
|
||||
return "=";
|
||||
case Scanner.ScanSymbols.equalequal1 :
|
||||
return "==";
|
||||
case Scanner.ScanSymbols.less1 :
|
||||
return "<";
|
||||
case Scanner.ScanSymbols.lessequal1 :
|
||||
return "<=";
|
||||
case Scanner.ScanSymbols.greater1 :
|
||||
return ">";
|
||||
case Scanner.ScanSymbols.greaterequal1 :
|
||||
return ">=";
|
||||
case Scanner.ScanSymbols.notequal1 :
|
||||
return "<>";
|
||||
case Scanner.ScanSymbols.variable1 :
|
||||
return "variable";
|
||||
case Scanner.ScanSymbols.asterisk1 :
|
||||
return "*";
|
||||
case Scanner.ScanSymbols.apostrophe1 :
|
||||
return "'";
|
||||
case Scanner.ScanSymbols.comma1 :
|
||||
return ",";
|
||||
case Scanner.ScanSymbols.label1 :
|
||||
return "label";
|
||||
case Scanner.ScanSymbols.literal1 :
|
||||
return "'";
|
||||
case Scanner.ScanSymbols.leftcurly1 :
|
||||
return "{";
|
||||
case Scanner.ScanSymbols.rightcurly1 :
|
||||
return "}";
|
||||
case Scanner.ScanSymbols.leftbracket1 :
|
||||
return "[";
|
||||
case Scanner.ScanSymbols.rightbracket1 :
|
||||
return "]";
|
||||
case Scanner.ScanSymbols.numeral1 :
|
||||
return "numeral";
|
||||
case Scanner.ScanSymbols.char1 :
|
||||
return "character";
|
||||
case Scanner.ScanSymbols.divide1 :
|
||||
return "/";
|
||||
case Scanner.ScanSymbols.plus1 :
|
||||
return "+";
|
||||
case Scanner.ScanSymbols.minus1 :
|
||||
return "-";
|
||||
case Scanner.ScanSymbols.leftparen1 :
|
||||
return "(";
|
||||
case Scanner.ScanSymbols.rightparen1 :
|
||||
return ")";
|
||||
case Scanner.ScanSymbols.newline1 :
|
||||
return "newline";
|
||||
case Scanner.ScanSymbols.semicolon1 :
|
||||
return ";";
|
||||
case Scanner.ScanSymbols.endtext1 :
|
||||
return ";";
|
||||
case Scanner.ScanSymbols.end1 :
|
||||
return "end";
|
||||
case Scanner.ScanSymbols.andand1 :
|
||||
return "&&";
|
||||
case Scanner.ScanSymbols.oror1 :
|
||||
return "||";
|
||||
case Scanner.ScanSymbols.abs1 :
|
||||
return "abs";
|
||||
case Scanner.ScanSymbols.pow1 :
|
||||
return "pow";
|
||||
case Scanner.ScanSymbols.sqrt1 :
|
||||
return "sqrt";
|
||||
case Scanner.ScanSymbols.not1 :
|
||||
return "!";
|
||||
case Scanner.ScanSymbols.convert1 :
|
||||
return "convert";
|
||||
case Scanner.ScanSymbols.in1 :
|
||||
return "in";
|
||||
case Scanner.ScanSymbols.like1 :
|
||||
return "like";
|
||||
case Scanner.ScanSymbols.trim1 :
|
||||
return "trim";
|
||||
case Scanner.ScanSymbols.upper1 :
|
||||
return "upper";
|
||||
case Scanner.ScanSymbols.lower1 :
|
||||
return "lower";
|
||||
case Scanner.ScanSymbols.substring1 :
|
||||
return "substring";
|
||||
case Scanner.ScanSymbols.getprice1 :
|
||||
return "getprice";
|
||||
case Scanner.ScanSymbols.null1 :
|
||||
return "null";
|
||||
case Scanner.ScanSymbols.isnull1 :
|
||||
return "isnull";
|
||||
default :
|
||||
return "";
|
||||
}
|
||||
}
|
||||
public static String SymbolToString(Scanner.ScanSymbols code)
|
||||
{
|
||||
switch(code)
|
||||
{
|
||||
case Scanner.ScanSymbols.directive_clear_modified1 :
|
||||
return "directive_clear_modified1";
|
||||
case Scanner.ScanSymbols.declare1 :
|
||||
return "declare1";
|
||||
case Scanner.ScanSymbols.unknown1 :
|
||||
return "unknown1";
|
||||
case Scanner.ScanSymbols.assign1 :
|
||||
return "assign1";
|
||||
case Scanner.ScanSymbols.if1 :
|
||||
return "if1";
|
||||
case Scanner.ScanSymbols.while1 :
|
||||
return "while1";
|
||||
case Scanner.ScanSymbols.then1 :
|
||||
return "then1";
|
||||
case Scanner.ScanSymbols.else1 :
|
||||
return "else1";
|
||||
case Scanner.ScanSymbols.goto1 :
|
||||
return "goto1";
|
||||
case Scanner.ScanSymbols.equal1 :
|
||||
return "equal1";
|
||||
case Scanner.ScanSymbols.equalequal1 :
|
||||
return "equalequal1";
|
||||
case Scanner.ScanSymbols.less1 :
|
||||
return "less1";
|
||||
case Scanner.ScanSymbols.lessequal1 :
|
||||
return "lessequal1";
|
||||
case Scanner.ScanSymbols.greater1 :
|
||||
return "greater1";
|
||||
case Scanner.ScanSymbols.greaterequal1 :
|
||||
return "greaterequal1";
|
||||
case Scanner.ScanSymbols.notequal1 :
|
||||
return "notequal1";
|
||||
case Scanner.ScanSymbols.variable1 :
|
||||
return "variable1";
|
||||
case Scanner.ScanSymbols.asterisk1 :
|
||||
return "asterisk1";
|
||||
case Scanner.ScanSymbols.apostrophe1 :
|
||||
return "apostrophe1";
|
||||
case Scanner.ScanSymbols.comma1 :
|
||||
return "comma1";
|
||||
case Scanner.ScanSymbols.label1 :
|
||||
return "label1";
|
||||
case Scanner.ScanSymbols.literal1 :
|
||||
return "literal1";
|
||||
case Scanner.ScanSymbols.leftcurly1 :
|
||||
return "leftcurly1";
|
||||
case Scanner.ScanSymbols.rightcurly1 :
|
||||
return "rightcurly1";
|
||||
case Scanner.ScanSymbols.leftbracket1 :
|
||||
return "leftbracket1";
|
||||
case Scanner.ScanSymbols.rightbracket1 :
|
||||
return "rightbracket1";
|
||||
case Scanner.ScanSymbols.numeral1 :
|
||||
return "numeral1";
|
||||
case Scanner.ScanSymbols.char1 :
|
||||
return "char1";
|
||||
case Scanner.ScanSymbols.divide1 :
|
||||
return "divide1";
|
||||
case Scanner.ScanSymbols.plus1 :
|
||||
return "plus1";
|
||||
case Scanner.ScanSymbols.minus1 :
|
||||
return "minus1";
|
||||
case Scanner.ScanSymbols.leftparen1 :
|
||||
return "leftparen1";
|
||||
case Scanner.ScanSymbols.rightparen1 :
|
||||
return "rightparen1";
|
||||
case Scanner.ScanSymbols.newline1 :
|
||||
return "newline1";
|
||||
case Scanner.ScanSymbols.semicolon1 :
|
||||
return "semicolon1";
|
||||
case Scanner.ScanSymbols.endtext1 :
|
||||
return "endtext1";
|
||||
case Scanner.ScanSymbols.end1 :
|
||||
return "end1";
|
||||
case Scanner.ScanSymbols.andand1 :
|
||||
return "andand1";
|
||||
case Scanner.ScanSymbols.oror1 :
|
||||
return "oror1";
|
||||
case Scanner.ScanSymbols.abs1 :
|
||||
return "abs1";
|
||||
case Scanner.ScanSymbols.pow1 :
|
||||
return "pow1";
|
||||
case Scanner.ScanSymbols.sqrt1 :
|
||||
return "sqrt1";
|
||||
case Scanner.ScanSymbols.not1 :
|
||||
return "not1";
|
||||
case Scanner.ScanSymbols.convert1 :
|
||||
return "convert1";
|
||||
case Scanner.ScanSymbols.in1 :
|
||||
return "in1";
|
||||
case Scanner.ScanSymbols.like1 :
|
||||
return "like1";
|
||||
case Scanner.ScanSymbols.trim1 :
|
||||
return "trim1";
|
||||
case Scanner.ScanSymbols.upper1 :
|
||||
return "upper1";
|
||||
case Scanner.ScanSymbols.lower1 :
|
||||
return "lower1";
|
||||
case Scanner.ScanSymbols.substring1 :
|
||||
return "substring1";
|
||||
case Scanner.ScanSymbols.getprice1 :
|
||||
return "getprice1";
|
||||
case Scanner.ScanSymbols.null1 :
|
||||
return "null1";
|
||||
case Scanner.ScanSymbols.isnull1 :
|
||||
return "isnull1";
|
||||
default :
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
Axiom.Core/Interpreter/StackElement.cs
Normal file
31
Axiom.Core/Interpreter/StackElement.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
// FileName : StackElement.cs
|
||||
// Author : Sean Kessler
|
||||
|
||||
namespace Axiom.Interpreter
|
||||
{
|
||||
public class CodeStack
|
||||
{
|
||||
private Stack<StackElement> codeStack = new Stack<StackElement>();
|
||||
public CodeStack()
|
||||
{
|
||||
}
|
||||
public void Push(StackElement stackElement)
|
||||
{
|
||||
codeStack.Push(stackElement);
|
||||
}
|
||||
public StackElement Pop()
|
||||
{
|
||||
return codeStack.Pop();
|
||||
}
|
||||
}
|
||||
public class StackElement
|
||||
{
|
||||
public StackElement()
|
||||
{
|
||||
}
|
||||
public GenericData Value { get; set; }
|
||||
public Symbol Symbol { get; set; }
|
||||
}
|
||||
}
|
||||
40
Axiom.Core/Interpreter/Symbol.cs
Normal file
40
Axiom.Core/Interpreter/Symbol.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
|
||||
// FileName : Symbol.cs
|
||||
// Author : Sean Kessler
|
||||
|
||||
namespace Axiom.Interpreter
|
||||
{
|
||||
public class Symbol
|
||||
{
|
||||
public enum SymbolType { KeywordSymbol,FunctionSymbol, UserSymbol, UserDynamicSymbol, DirectiveSymbol};
|
||||
private bool isMutable=true;
|
||||
private bool isModified=false;
|
||||
public Symbol()
|
||||
{
|
||||
IsMutable = true;
|
||||
}
|
||||
public Symbol(String symbolName, Scanner.ScanSymbols identifier,SymbolType symbolType = SymbolType.UserSymbol)
|
||||
{
|
||||
this.SymbolName = symbolName;
|
||||
this.Identifier = identifier;
|
||||
this.TypeOfSymbol = symbolType;
|
||||
if (symbolType.Equals(SymbolType.UserSymbol)) IsMutable = true;
|
||||
else IsMutable = false;
|
||||
}
|
||||
public String SymbolName{get;set;}
|
||||
public Scanner.ScanSymbols Identifier{get;set;}
|
||||
public SymbolType TypeOfSymbol{get;set;}
|
||||
public GenericData GenericData { get; set; }
|
||||
public bool IsMutable
|
||||
{
|
||||
get { return isMutable; }
|
||||
set {isMutable=value;}
|
||||
}
|
||||
public bool IsModified
|
||||
{
|
||||
get {return isModified;}
|
||||
set {isModified=value;}
|
||||
}
|
||||
}
|
||||
}
|
||||
205
Axiom.Core/Interpreter/SymbolTable.cs
Normal file
205
Axiom.Core/Interpreter/SymbolTable.cs
Normal file
@@ -0,0 +1,205 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Data;
|
||||
using log4net;
|
||||
using System.Reflection;
|
||||
using Axiom.Utils;
|
||||
|
||||
// FileName : SymbolTable.cs
|
||||
// Author : Sean Kessler
|
||||
|
||||
namespace Axiom.Interpreter
|
||||
{
|
||||
public class SymbolTable : Dictionary<String, Symbol>
|
||||
{
|
||||
private static ILog logger = LogManager.GetLogger(typeof(SymbolTable));
|
||||
private Dictionary<int, Symbol> symbolsById = new Dictionary<int, Symbol>();
|
||||
public SymbolTable()
|
||||
{
|
||||
CreateSymbolTable();
|
||||
}
|
||||
// Example: symbolTable.AddObjects(new Object[]{position}.ToList());
|
||||
public void AddObjects(List<Object> objects)
|
||||
{
|
||||
foreach(Object obj in objects)
|
||||
{
|
||||
AddObject(obj);
|
||||
}
|
||||
}
|
||||
// Example: symbolTable.AddObject("Num",55.00);
|
||||
public void AddObject(String symbolName,Object obj)
|
||||
{
|
||||
Type objectType=obj.GetType();
|
||||
Symbol symbol=new Symbol(symbolName,Scanner.ScanSymbols.variable1,Symbol.SymbolType.UserSymbol);
|
||||
Add(symbolName,symbol);
|
||||
symbol.GenericData = new GenericData();
|
||||
String stringRepData = obj.ToString();
|
||||
symbol.GenericData.Data = GenericData.ConvertType(objectType, stringRepData);
|
||||
}
|
||||
// Example: symbolTable.AddObject(position)
|
||||
public void AddObject(Object obj)
|
||||
{
|
||||
DataTable dataTable=new DataTable();
|
||||
Type classType=obj.GetType();
|
||||
PropertyInfo[] properties = classType.GetProperties();
|
||||
foreach(PropertyInfo propertyInfo in properties)
|
||||
{
|
||||
MethodInfo methodInfo=propertyInfo.GetGetMethod();
|
||||
String methodName=methodInfo.Name;
|
||||
if(!methodName.StartsWith("get_"))continue;
|
||||
methodName=methodName.Replace("get_",null);
|
||||
DataColumn dataColumn=new DataColumn();
|
||||
dataColumn.ColumnName=methodName;
|
||||
dataColumn.DataType=methodInfo.ReturnType; // capture the data type
|
||||
dataTable.Columns.Add(dataColumn);
|
||||
}
|
||||
DataRow dataRow=dataTable.NewRow();
|
||||
foreach(PropertyInfo propertyInfo in properties)
|
||||
{
|
||||
MethodInfo methodInfo=propertyInfo.GetGetMethod();
|
||||
String methodName=methodInfo.Name;
|
||||
if(!methodName.StartsWith("get_"))continue;
|
||||
methodName=methodName.Replace("get_",null);
|
||||
dataRow[methodName]=methodInfo.Invoke(obj,null);
|
||||
}
|
||||
AddUserSymbols(dataTable);
|
||||
AddUserValues(dataRow,dataTable);
|
||||
}
|
||||
public void AddUserSymbols(DataTable dataTable)
|
||||
{
|
||||
DataColumnCollection columns=dataTable.Columns;
|
||||
foreach (DataColumn column in columns)
|
||||
{
|
||||
String symbolName = column.ColumnName;
|
||||
if(ContainsKey(symbolName))continue;
|
||||
Symbol symbol=new Symbol(symbolName,Scanner.ScanSymbols.variable1,Symbol.SymbolType.UserSymbol);
|
||||
Add(symbolName,symbol);
|
||||
}
|
||||
}
|
||||
public void AddUserValues(DataRow dataRow,DataTable dataTable)
|
||||
{
|
||||
DataColumnCollection columns = dataTable.Columns;
|
||||
for(int index=0;index<columns.Count;index++)
|
||||
{
|
||||
DataColumn column = columns[index];
|
||||
String symbolName = column.ColumnName;
|
||||
if(!ContainsKey(symbolName))continue;
|
||||
Symbol symbol = this[symbolName];
|
||||
symbol.GenericData = new GenericData();
|
||||
String stringRepData = dataRow[index].ToString();
|
||||
symbol.GenericData.Data = GenericData.ConvertType(column.DataType, stringRepData);
|
||||
}
|
||||
}
|
||||
public List<Symbol> GetModfied()
|
||||
{
|
||||
List<Symbol> symbols = this.Values.ToList();
|
||||
symbols = (from Symbol symbol in symbols where symbol.TypeOfSymbol.Equals(Symbol.SymbolType.UserSymbol) && symbol.IsModified select symbol).ToList();
|
||||
return symbols;
|
||||
}
|
||||
public String GetModifiedSymbolNames()
|
||||
{
|
||||
List<Symbol> symbols = this.Values.ToList();
|
||||
List<String> symbolNames = (from Symbol symbol in symbols where symbol.TypeOfSymbol.Equals(Symbol.SymbolType.UserSymbol) && symbol.IsModified select symbol.SymbolName).ToList();
|
||||
return Utility.ListToString(symbolNames);
|
||||
}
|
||||
public void Reset()
|
||||
{
|
||||
ClearModified();
|
||||
ClearData();
|
||||
RemoveUserDynamicSymbols();
|
||||
}
|
||||
public void RemoveUserDynamicSymbols()
|
||||
{
|
||||
List<Symbol> symbols = this.Values.ToList();
|
||||
symbols = (from Symbol symbol in symbols where symbol.TypeOfSymbol.Equals(Symbol.SymbolType.UserDynamicSymbol) select symbol).ToList();
|
||||
foreach (Symbol symbol in symbols) this.Remove(symbol.SymbolName);
|
||||
}
|
||||
public void ClearModified()
|
||||
{
|
||||
List<Symbol> symbols = this.Values.ToList();
|
||||
symbols = (from Symbol symbol in symbols where symbol.TypeOfSymbol.Equals(Symbol.SymbolType.UserSymbol) select symbol).ToList();
|
||||
foreach (Symbol symbol in symbols) symbol.IsModified = false;
|
||||
}
|
||||
public void ClearData()
|
||||
{
|
||||
List<Symbol> symbols = this.Values.ToList();
|
||||
foreach (Symbol symbol in symbols) symbol.GenericData = null;
|
||||
}
|
||||
public bool IsModified()
|
||||
{
|
||||
List<Symbol> symbols = this.Values.ToList();
|
||||
symbols = (from Symbol symbol in symbols where symbol.TypeOfSymbol.Equals(Symbol.SymbolType.UserSymbol) select symbol).ToList();
|
||||
foreach (Symbol symbol in symbols) if(symbol.IsModified)return true;
|
||||
return false;
|
||||
}
|
||||
private void CreateSymbolTable()
|
||||
{
|
||||
Add("#directive_clear_modified",new Symbol("#directive_clear_modified",Scanner.ScanSymbols.directive_clear_modified1,Symbol.SymbolType.DirectiveSymbol));
|
||||
Add("declare",new Symbol("declare",Scanner.ScanSymbols.declare1,Symbol.SymbolType.KeywordSymbol));
|
||||
Add("if",new Symbol("if",Scanner.ScanSymbols.if1,Symbol.SymbolType.KeywordSymbol));
|
||||
Add("break",new Symbol("break",Scanner.ScanSymbols.break1,Symbol.SymbolType.KeywordSymbol));
|
||||
Add("while",new Symbol("while",Scanner.ScanSymbols.while1,Symbol.SymbolType.KeywordSymbol));
|
||||
Add("then", new Symbol("then", Scanner.ScanSymbols.then1, Symbol.SymbolType.KeywordSymbol));
|
||||
Add("else", new Symbol("else", Scanner.ScanSymbols.else1, Symbol.SymbolType.KeywordSymbol));
|
||||
Add("and", new Symbol("and", Scanner.ScanSymbols.andand1, Symbol.SymbolType.KeywordSymbol));
|
||||
Add("or", new Symbol("or", Scanner.ScanSymbols.oror1, Symbol.SymbolType.KeywordSymbol));
|
||||
Add("null", new Symbol("null", Scanner.ScanSymbols.null1, Symbol.SymbolType.KeywordSymbol));
|
||||
// high level functions
|
||||
Symbol symbol=null;
|
||||
|
||||
symbol=new Symbol("abs", Scanner.ScanSymbols.abs1, Symbol.SymbolType.FunctionSymbol); // abs(x)
|
||||
Add("abs",symbol);
|
||||
symbolsById.Add((int)Scanner.ScanSymbols.abs1,symbol);
|
||||
|
||||
symbol=new Symbol("pow", Scanner.ScanSymbols.pow1, Symbol.SymbolType.FunctionSymbol); // pow(x,y)
|
||||
Add("pow",symbol);
|
||||
symbolsById.Add((int)Scanner.ScanSymbols.pow1,symbol);
|
||||
|
||||
symbol=new Symbol("sqrt", Scanner.ScanSymbols.sqrt1, Symbol.SymbolType.FunctionSymbol); // sqrt(x)
|
||||
Add("sqrt",symbol);
|
||||
symbolsById.Add((int)Scanner.ScanSymbols.sqrt1,symbol);
|
||||
|
||||
symbol=new Symbol("convert", Scanner.ScanSymbols.convert1, Symbol.SymbolType.FunctionSymbol); // convert(x,'{type}') convert(variable|literal,'{datatype}') convert('01-02-2018','System.DateTime')
|
||||
Add("convert",symbol);
|
||||
symbolsById.Add((int)Scanner.ScanSymbols.convert1,symbol);
|
||||
|
||||
symbol=new Symbol("substring", Scanner.ScanSymbols.substring1, Symbol.SymbolType.FunctionSymbol); // substring(variable|literal,numeral|variable,numeral|variable)
|
||||
Add("substring",symbol);
|
||||
symbolsById.Add((int)Scanner.ScanSymbols.substring1,symbol);
|
||||
|
||||
symbol=new Symbol("getprice", Scanner.ScanSymbols.getprice1, Symbol.SymbolType.FunctionSymbol); // getprice(variable|literal,variable|literal) getprice('midd','07-12-2021')
|
||||
Add("getprice",symbol);
|
||||
symbolsById.Add((int)Scanner.ScanSymbols.getprice1,symbol);
|
||||
|
||||
symbol=new Symbol("in", Scanner.ScanSymbols.in1, Symbol.SymbolType.FunctionSymbol); // in('X','Y','Z')
|
||||
Add("in",symbol);
|
||||
symbolsById.Add((int)Scanner.ScanSymbols.in1,symbol);
|
||||
|
||||
symbol=new Symbol("like", Scanner.ScanSymbols.like1, Symbol.SymbolType.FunctionSymbol); // like 'x%'
|
||||
Add("like",symbol);
|
||||
symbolsById.Add((int)Scanner.ScanSymbols.like1,symbol);
|
||||
|
||||
symbol=new Symbol("trim", Scanner.ScanSymbols.trim1, Symbol.SymbolType.FunctionSymbol); // trim('x')
|
||||
Add("trim",symbol);
|
||||
symbolsById.Add((int)Scanner.ScanSymbols.trim1,symbol);
|
||||
|
||||
symbol=new Symbol("upper", Scanner.ScanSymbols.upper1, Symbol.SymbolType.FunctionSymbol); // upper('x')
|
||||
Add("upper",symbol);
|
||||
symbolsById.Add((int)Scanner.ScanSymbols.upper1,symbol);
|
||||
|
||||
symbol=new Symbol("lower", Scanner.ScanSymbols.lower1, Symbol.SymbolType.FunctionSymbol); // lower('x')
|
||||
Add("lower",symbol);
|
||||
symbolsById.Add((int)Scanner.ScanSymbols.lower1,symbol);
|
||||
|
||||
symbol=new Symbol("isnull", Scanner.ScanSymbols.isnull1, Symbol.SymbolType.FunctionSymbol); // isnull(variable)
|
||||
Add("isnull",symbol);
|
||||
symbolsById.Add((int)Scanner.ScanSymbols.isnull1,symbol);
|
||||
}
|
||||
public Symbol Find(Scanner.ScanSymbols identifier)
|
||||
{
|
||||
if (!symbolsById.ContainsKey((int)identifier)) return null;
|
||||
return this[symbolsById[(int)identifier].SymbolName];
|
||||
}
|
||||
}
|
||||
}
|
||||
134
Axiom.Core/Utility/Utility.cs
Normal file
134
Axiom.Core/Utility/Utility.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Globalization;
|
||||
using log4net;
|
||||
|
||||
namespace Axiom.Utils
|
||||
{
|
||||
public class Utility
|
||||
{
|
||||
private static ILog logger = LogManager.GetLogger(typeof(Utility));
|
||||
private Utility()
|
||||
{
|
||||
}
|
||||
public static Stream StreamFromString(string s)
|
||||
{
|
||||
var stream = new MemoryStream();
|
||||
var writer = new StreamWriter(stream);
|
||||
writer.Write(s);
|
||||
writer.Flush();
|
||||
stream.Position = 0;
|
||||
return stream;
|
||||
}
|
||||
public static String ListToString(List<String> list)
|
||||
{
|
||||
if (null == list || 0 == list.Count) return "";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int index = 0; index < list.Count; index++)
|
||||
{
|
||||
sb.Append(list[index]);
|
||||
if (index < list.Count-1) sb.Append(",");
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
public static String DateTimeToStringYYYYMMDD(DateTime dateTime)
|
||||
{
|
||||
return dateTime.ToString("yyyyMMdd");
|
||||
}
|
||||
public static String DateTimeToStringMMHDDHYYYY(DateTime dateTime)
|
||||
{
|
||||
return dateTime.ToString("MM-dd-yyyy");
|
||||
}
|
||||
public static String DateTimeToStringMMSDDSYYYYHHMMSS(DateTime dateTime)
|
||||
{
|
||||
return dateTime.ToString("MM/dd/yyyy hh:mm:ss tt");
|
||||
}
|
||||
public static String DateTimeToTicks(DateTime dateTime)
|
||||
{
|
||||
return dateTime.Ticks.ToString();
|
||||
}
|
||||
public static String KeepAfter(String strString,char ch)
|
||||
{
|
||||
int startPos = strString.IndexOf(ch);
|
||||
if (-1 == startPos) return strString;
|
||||
return strString.Substring(startPos + 1);
|
||||
}
|
||||
public static String KeepBefore(String strString, char ch)
|
||||
{
|
||||
int startPos = strString.IndexOf(ch);
|
||||
if (-1 == startPos) return strString;
|
||||
return strString.Substring(0,startPos);
|
||||
}
|
||||
public static DateTime ParseDate(String strDate)
|
||||
{
|
||||
logger.InfoFormat("Parsing date {0}",strDate);
|
||||
System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("en-US");
|
||||
String[] formats = new[] { "yyyy/MM/dd","M-d-yyyy", "dd-MM-yyyy", "MM-dd-yyyy", "M.d.yyyy", "dd.MM.yyyy", "MM.dd.yyyy","yyyyMMdd" }.Union(cultureInfo.DateTimeFormat.GetAllDateTimePatterns()).ToArray();
|
||||
strDate = strDate.Trim();
|
||||
DateTime dateTime=DateTime.ParseExact(strDate, formats, new System.Globalization.CultureInfo("en-US"), DateTimeStyles.AssumeLocal);
|
||||
return dateTime;
|
||||
}
|
||||
public static String AddQuotes(String item)
|
||||
{
|
||||
return "\"" + item + "\"";
|
||||
}
|
||||
public static String RemoveCC(String item)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (char ch in item)
|
||||
{
|
||||
if (!Char.IsControl(ch)) sb.Append(ch);
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
public static String SqlString(String value)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (char ch in value)
|
||||
{
|
||||
sb.Append(ch);
|
||||
if (ch == '\'') sb.Append("'");
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
public static String IsNull(String s1,String s2)
|
||||
{
|
||||
if (null == s1) return s2;
|
||||
return s1;
|
||||
}
|
||||
public static String NullIfOrCat(String s1,String s2,String s3)
|
||||
{
|
||||
if (string.IsNullOrEmpty(s1)) return s2;
|
||||
return s1+s3;
|
||||
}
|
||||
public static String Pad(string str, char filler, int length)
|
||||
{
|
||||
int stringLength = str.Length;
|
||||
if (stringLength >= length) return str;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
while (stringLength < length)
|
||||
{
|
||||
sb.Append(filler);
|
||||
stringLength++;
|
||||
}
|
||||
return sb.ToString() + str;
|
||||
}
|
||||
public static String CreateInClause(String commaSepList,String dataType)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("(");
|
||||
String[] items = commaSepList.Split(',');
|
||||
for (int index = 0; index < items.Length; index++)
|
||||
{
|
||||
sb.Append("'").Append(items[index]).Append("'");
|
||||
if (index < items.Length - 1) sb.Append(",");
|
||||
}
|
||||
sb.Append(")");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Axiom.Core/app.config
Normal file
11
Axiom.Core/app.config
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.0.8.0" newVersion="2.0.8.0"/>
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/></startup></configuration>
|
||||
29
Axiom.sln
Normal file
29
Axiom.sln
Normal file
@@ -0,0 +1,29 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.21005.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Axiom.Core", "Axiom.Core\Axiom.Core.csproj", "{F0F0F2B4-BB86-49B5-BA93-2642637033D6}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{88CECEDC-E4EE-4E86-8FE0-B670FA5C710F}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
Notes.txt = Notes.txt
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {C0AFCD8E-4455-40BA-BE0B-79C0C85CC83D}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
30
AxiomConsole.sln
Normal file
30
AxiomConsole.sln
Normal file
@@ -0,0 +1,30 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.21005.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Axiom.Core", "Axiom.Core\Axiom.Core.csproj", "{F0F0F2B4-BB86-49B5-BA93-2642637033D6}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AxiomConsole", "AxiomConsole\AxiomConsole.csproj", "{33E3DF62-2592-4040-B858-F8D115686531}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{33E3DF62-2592-4040-B858-F8D115686531}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{33E3DF62-2592-4040-B858-F8D115686531}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{33E3DF62-2592-4040-B858-F8D115686531}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{33E3DF62-2592-4040-B858-F8D115686531}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {C0AFCD8E-4455-40BA-BE0B-79C0C85CC83D}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
6
AxiomConsole/App.config
Normal file
6
AxiomConsole/App.config
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
|
||||
</startup>
|
||||
</configuration>
|
||||
66
AxiomConsole/AxiomConsole.csproj
Normal file
66
AxiomConsole/AxiomConsole.csproj
Normal file
@@ -0,0 +1,66 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{33E3DF62-2592-4040-B858-F8D115686531}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>AxiomConsole</RootNamespace>
|
||||
<AssemblyName>AxiomConsole</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Axiom.Core\Axiom.Core.csproj">
|
||||
<Project>{f0f0f2b4-bb86-49b5-ba93-2642637033d6}</Project>
|
||||
<Name>Axiom.Core</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
28
AxiomConsole/AxiomConsole.sln
Normal file
28
AxiomConsole/AxiomConsole.sln
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.21005.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AxiomConsole", "AxiomConsole.csproj", "{33E3DF62-2592-4040-B858-F8D115686531}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Axiom.Core", "..\Axiom.Core\Axiom.Core.csproj", "{F0F0F2B4-BB86-49B5-BA93-2642637033D6}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{33E3DF62-2592-4040-B858-F8D115686531}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{33E3DF62-2592-4040-B858-F8D115686531}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{33E3DF62-2592-4040-B858-F8D115686531}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{33E3DF62-2592-4040-B858-F8D115686531}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
52
AxiomConsole/Program.cs
Normal file
52
AxiomConsole/Program.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Axiom.Utils;
|
||||
using Axiom.Interpreter;
|
||||
using System.IO;
|
||||
|
||||
namespace AxiomConsole
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
|
||||
// String expression=@"
|
||||
// A=1;
|
||||
// WHILE(A<10)
|
||||
// {
|
||||
// IF(A==1)THEN break;
|
||||
// }";
|
||||
String expression=@"
|
||||
A=1;
|
||||
B=1;
|
||||
WHILE(A<10)
|
||||
{
|
||||
WHILE(B<10)
|
||||
{
|
||||
IF(B==1)THEN BREAK;
|
||||
B=B+1;
|
||||
}
|
||||
IF(A==1)THEN BREAK;
|
||||
A=A+1;
|
||||
}";
|
||||
CodeRunner codeRunner=new CodeRunner();
|
||||
List<String> disassembly=codeRunner.Disassemble(expression);
|
||||
if(codeRunner.IsInError)
|
||||
{
|
||||
Console.WriteLine("CodeRunner Failed with {0}",codeRunner.LastMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine(expression);
|
||||
foreach(String line in disassembly)
|
||||
{
|
||||
Console.WriteLine(line);
|
||||
}
|
||||
}
|
||||
Console.Read();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
36
AxiomConsole/Properties/AssemblyInfo.cs
Normal file
36
AxiomConsole/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("AxiomConsole")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("AxiomConsole")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2024")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("650e4f18-bbd4-400b-b445-5c497023c280")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
28
AxiomUnitTestProject/AxiomUnitTestProject.sln
Normal file
28
AxiomUnitTestProject/AxiomUnitTestProject.sln
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.21005.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AxiomUnitTestProject", "AxiomUnitTestProjectr\AxiomUnitTestProject.csproj", "{E2FC10FA-2B8A-4CEB-B7C6-960FA6A3AC6F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Axiom.Core", "..\Axiom.Core\Axiom.Core.csproj", "{F0F0F2B4-BB86-49B5-BA93-2642637033D6}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{E2FC10FA-2B8A-4CEB-B7C6-960FA6A3AC6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E2FC10FA-2B8A-4CEB-B7C6-960FA6A3AC6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E2FC10FA-2B8A-4CEB-B7C6-960FA6A3AC6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E2FC10FA-2B8A-4CEB-B7C6-960FA6A3AC6F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F0F0F2B4-BB86-49B5-BA93-2642637033D6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
11
AxiomUnitTestProject/AxiomUnitTestProjectr/App.config
Normal file
11
AxiomUnitTestProject/AxiomUnitTestProjectr/App.config
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0"?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="market_data" value="Database=market_data;Datasource=localhost;Username=root;Password=dbas"/>
|
||||
<add key="portfolio_data" value="Database=portfolio_data;Datasource=localhost;Username=root;Password=dbas"/>
|
||||
|
||||
</appSettings>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
|
||||
</startup>
|
||||
</configuration>
|
||||
736
AxiomUnitTestProject/AxiomUnitTestProjectr/AssemblerTests.cs
Normal file
736
AxiomUnitTestProject/AxiomUnitTestProjectr/AssemblerTests.cs
Normal file
@@ -0,0 +1,736 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System.Collections.Generic;
|
||||
using Axiom.Utils;
|
||||
using Axiom.Interpreter;
|
||||
using System.IO;
|
||||
|
||||
namespace AxiomUnitTestProject
|
||||
{
|
||||
|
||||
[TestClass]
|
||||
public class AssemblerTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void BreakStatementVariant4()
|
||||
{
|
||||
String expression=@"
|
||||
A=1;
|
||||
B=1;
|
||||
WHILE(A<10)
|
||||
{
|
||||
WHILE(B<10)
|
||||
{
|
||||
IF(B==100)THEN BREAK;
|
||||
B=B+1;
|
||||
}
|
||||
IF(A==100)THEN BREAK;
|
||||
A=A+1;
|
||||
}";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("A").Equals(10));
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("B").Equals(10));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void BreakStatementVariant3()
|
||||
{
|
||||
String expression=@"
|
||||
A=1;
|
||||
B=1;
|
||||
WHILE(A<10)
|
||||
{
|
||||
WHILE(B<10)
|
||||
{
|
||||
IF(B==1)THEN BREAK;
|
||||
B=B+1;
|
||||
}
|
||||
IF(A==1)THEN BREAK;
|
||||
A=A+1;
|
||||
}";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("A").Equals(1));
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("B").Equals(1));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void BreakStatementVariant2()
|
||||
{
|
||||
String expression=@"
|
||||
A=1;
|
||||
WHILE(A<10)
|
||||
{
|
||||
IF(A==1)THEN BREAK;
|
||||
A=A+1;
|
||||
}
|
||||
";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("A").Equals(1));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void BreakStatementVariant1()
|
||||
{
|
||||
String expression=@"
|
||||
break;
|
||||
";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsFalse(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DeclarationStatementVariant3()
|
||||
{
|
||||
String expression=@"
|
||||
DECLARE A;
|
||||
DECLARE B;
|
||||
B=5;
|
||||
DECLARE C;
|
||||
D=6;
|
||||
";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("D").Equals(6));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DeclarationStatementVariant2()
|
||||
{
|
||||
String expression=@"
|
||||
DECLARE A;
|
||||
DECLARE B;
|
||||
B=5;
|
||||
DECLARE C;
|
||||
";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("B").Equals(5));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DeclarationStatementVariant1()
|
||||
{
|
||||
String expression=@"
|
||||
DECLARE A;
|
||||
DECLARE B;
|
||||
B=5;
|
||||
";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("B").Equals(5));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WhileStatementVariant4()
|
||||
{
|
||||
String expression=@"
|
||||
DECLARE A,B;
|
||||
A=1;
|
||||
B=5;
|
||||
ITERATIONS=0;
|
||||
WHILE(A<=10)
|
||||
{
|
||||
B=1;
|
||||
WHILE(B<=5)
|
||||
{
|
||||
B=B+1;
|
||||
ITERATIONS=ITERATIONS+1;
|
||||
}
|
||||
A=A+1;
|
||||
}";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("A").Equals(11));
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("ITERATIONS").Equals(50));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WhileStatementVariant3()
|
||||
{
|
||||
String expression=@"
|
||||
DECLARE A,B;
|
||||
A=1;
|
||||
B=5;
|
||||
WHILE(A<B)
|
||||
{
|
||||
A=A+1;
|
||||
}";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("A").Equals(5));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WhileStatementVariant2()
|
||||
{
|
||||
String expression="DECLARE A,B;A=1;B=5;WHILE(A<B)A=A+1;";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("A").Equals(5));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WhileStatementVariant1()
|
||||
{
|
||||
String expression="DECLARE A,B;A=1;B=5;WHILE(A<B){A=A+1;}";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("A").Equals(5));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DeclarationsVariant4()
|
||||
{
|
||||
String expression="DECLARE R,user_a,user_b,user_c;R=7;user_a=66;user_b=66;user_c=66;IF(R>=5){user_a=1;user_b=1;user_c=1;}";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DeclarationsVariant3()
|
||||
{
|
||||
String expression="DECLARE VAR1,VAR1;";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsFalse(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.LastMessage.Contains("The variable 'VAR1' has already been declared."));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DeclarationsVariant2()
|
||||
{
|
||||
String expression="DECLARE VAR1,VAR2;";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DeclarationsVariant1()
|
||||
{
|
||||
String expression="DECLARE VAR1;DECLARE VAR2;";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void LowerCall()
|
||||
{
|
||||
String expression="DECLARE VAR1;VAR1='Hello ';VAR1=TRIM(VAR1);VAR1=LOWER(VAR1);";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<String>("VAR1").Equals("hello"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void UpperCall()
|
||||
{
|
||||
String expression="DECLARE VAR1;VAR1='Hello ';VAR1=TRIM(VAR1);VAR1=UPPER(VAR1);";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<String>("VAR1").Equals("HELLO"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TrimCall()
|
||||
{
|
||||
String expression="DECLARE VAR1;VAR1='Hello ';VAR1=TRIM(VAR1);";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<String>("VAR1").Equals("Hello"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfStatementVariant20()
|
||||
{
|
||||
// There is a missing right paren in the if statement nesting so we expect a syntax error
|
||||
String expression="DECLARE VAR1,VAR2,VAR4,RESULT;VAR1='YES';VAR2='NO';VAR4=1;IF((((((VAR1=='YES'))))) THEN RESULT='TRUE' ELSE RESULT='FALSE';";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsFalse(codeRunner.Execute(expression));
|
||||
Assert.IsTrue(codeRunner.LastMessage.Contains("<Syntax Error>"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfStatementVariant19()
|
||||
{
|
||||
String expression = "DECLARE a,b;a=1;b=1;IF(1+1)upper('Foo');";
|
||||
CodeRunner codeRunner=new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.ParseSymbolsCount.Equals(0),"Expected parse symbols count to be zero.");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfStatementVariant18()
|
||||
{
|
||||
String expression="DECLARE VAR1,VAR2,VAR4,RESULT;VAR1=2;IF(VAR1==2) THEN RESULT='TRUE' ELSE RESULT='FALSE';";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<String>("RESULT").Equals("TRUE"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfStatementVariant17()
|
||||
{
|
||||
String expression="DECLARE VAR1,VAR2,VAR4,RESULT;VAR1='YES';VAR2='NO';VAR4=1;IF(VAR1=='YES') THEN RESULT='TRUE' ELSE RESULT='FALSE';";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<String>("RESULT").Equals("TRUE"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfStatementVariant16()
|
||||
{
|
||||
String expression="DECLARE VAR1,VAR2,VAR4,RESULT;VAR1='YES';VAR2='NO';VAR4=1;IF((((((VAR1=='YES')))))) THEN RESULT='TRUE' ELSE RESULT='FALSE';";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<String>("RESULT").Equals("TRUE"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfStatementVariant15()
|
||||
{
|
||||
String expression="DECLARE VAR1,VAR2,VAR4,RESULT;VAR1='YES';VAR2='YES';VAR4=1;IF((VAR1=='YES') AND VAR2=='NO') THEN RESULT='TRUE' ELSE RESULT='FALSE';";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<String>("RESULT").Equals("FALSE"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfStatementVariant14()
|
||||
{
|
||||
String expression="DECLARE VAR1,VAR2,VAR4,RESULT;VAR1='YES';VAR2='YES';VAR4=2;IF(VAR1=='YES' AND (VAR2=='YES') AND VAR4==1) THEN RESULT='TRUE' ELSE RESULT='FALSE';";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<String>("RESULT").Equals("FALSE"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfStatementVariant13()
|
||||
{
|
||||
String expression="DECLARE VAR1,VAR2,VAR4,RESULT;VAR1='YES';VAR2='YES';VAR4=1;IF(VAR1=='YES' AND (VAR2=='YES') AND VAR4==1) THEN RESULT='TRUE' ELSE RESULT='FALSE';";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<String>("RESULT").Equals("TRUE"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfStatementVariant12()
|
||||
{
|
||||
String expression="DECLARE VAR1,VAR2,VAR4,RESULT;VAR1='YES';VAR2='YES';VAR4=1;IF((VAR1=='YES') OR (VAR2=='YES') AND (VAR4==1)) THEN RESULT='TRUE' ELSE RESULT='FALSE';";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<String>("RESULT").Equals("TRUE"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfStatementVariant11()
|
||||
{
|
||||
String expression="DECLARE VAR1,VAR2,VAR4,RESULT;VAR1='NO';VAR2='YES';VAR4=1;IF(VAR1=='YES' OR VAR2=='YES' AND VAR4==2) THEN RESULT='TRUE' ELSE RESULT='FALSE';";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<String>("RESULT").Equals("FALSE"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfStatementVariant10()
|
||||
{
|
||||
String expression="DECLARE VAR1,VAR2,VAR4,RESULT;VAR1='YES';VAR2='YES';VAR4=1;IF(VAR1=='YES' OR VAR2=='YES' AND VAR4==2) THEN RESULT='TRUE' ELSE RESULT='FALSE';";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<String>("RESULT").Equals("TRUE"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfStatementVariant9()
|
||||
{
|
||||
String expression="DECLARE VAR1,VAR2,VAR4,RESULT;VAR1='YES';VAR2='YES';VAR4=2;IF(VAR1=='NO' OR (VAR2=='YES' AND VAR4==1)) THEN RESULT='TRUE' ELSE RESULT='FALSE';";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<String>("RESULT").Equals("FALSE"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfStatementVariant8()
|
||||
{
|
||||
String expression="DECLARE VAR1,VAR2,VAR4,RESULT;VAR1='YES';VAR2='YES';VAR4=1;IF(VAR1=='NO' OR (VAR2=='YES' AND VAR4==1)) THEN RESULT='TRUE' ELSE RESULT='FALSE';";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<String>("RESULT").Equals("TRUE"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfStatementVariant7()
|
||||
{
|
||||
String expression="DECLARE VAR1,VAR2,VAR4,RESULT;VAR1='YES';VAR2='NO';VAR4=2;IF((VAR1=='YES') AND VAR2=='NO' AND VAR4==1) THEN RESULT='TRUE' ELSE RESULT='FALSE';";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<String>("RESULT").Equals("FALSE"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfStatementVariant6()
|
||||
{
|
||||
String expression="DECLARE VAR1,VAR2,VAR4,RESULT;VAR1='YES';VAR2='NO';VAR4=1;IF((VAR1=='YES') AND VAR2=='NO' AND VAR4==1) THEN RESULT='TRUE' ELSE RESULT='FALSE';";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<String>("RESULT").Equals("TRUE"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfStatementVariant5()
|
||||
{
|
||||
String expression="DECLARE A,B,RESULT;A=1;B=2;IF(A==1 AND B==2)THEN RESULT=1 ELSE RESULT=0;";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("RESULT").Equals(1.00));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfStatementVariant4()
|
||||
{
|
||||
String expression="DECLARE A,B;A=99;if(A<>99)then B=1 else B=2;";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("B").Equals(2.00));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfStatementVariant3()
|
||||
{
|
||||
String expression="DECLARE R,user_a,user_b,user_c;R=7;user_a=66;user_b=66;user_c=66;IF(R>=5){user_a=1;user_b=1;user_c=1;}";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("user_a").Equals(1.00));
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("user_b").Equals(1.00));
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("user_c").Equals(1.00));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfStatementVariant2()
|
||||
{
|
||||
String expression="DECLARE A,B,C;A=1;B=2;C=3;IF(B<A){A=0;B=0;C=0;}ELSE{A=1;B=1;C=1;}";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("A").Equals(1.00));
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("B").Equals(1.00));
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("C").Equals(1.00));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfStatementVariant1()
|
||||
{
|
||||
String expression="R_THRESHHOLD=4;";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
double b = codeRunner.GetValue<double>("R_THRESHHOLD");
|
||||
Assert.IsTrue(b.Equals(4.00));
|
||||
}
|
||||
|
||||
private class InjectionClass
|
||||
{
|
||||
public double RMultiple { get { return (CurrentPrice-PurchasePrice)/R; } }
|
||||
public double CurrentPrice{ get; set; }
|
||||
public double PurchasePrice{ get; set; }
|
||||
public double R { get; set; }
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Injection()
|
||||
{
|
||||
String expression=@"
|
||||
R_THRESHHOLD=4;
|
||||
MAX_ATR=3;
|
||||
MAX_R=10;
|
||||
FACTOR=MAX_ATR/MAX_R;
|
||||
MULTIPLIER=MAX_ATR;
|
||||
IF(RMultiple>R_THRESHHOLD)
|
||||
{
|
||||
MULTIPLIER=FACTOR*RMultiple;
|
||||
}";
|
||||
|
||||
InjectionClass injectionClass = new InjectionClass();
|
||||
injectionClass.CurrentPrice=220;
|
||||
injectionClass.PurchasePrice=195.90;
|
||||
injectionClass.R=5.00;
|
||||
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
SymbolTable symbolTable=codeRunner.SymbolTable;
|
||||
symbolTable.AddObjects(new Object[]{injectionClass}.ToList());
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("MULTIPLIER").Equals(1.446));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Substring()
|
||||
{
|
||||
String expression="DECLARE CURRENCY,START_INDEX,LENGTH,CURRENCY_CODE;CURRENCY='MXN12345';START_INDEX=1;LENGTH=3;CURRENCY_CODE=SUBSTRING(CURRENCY,START_INDEX,LENGTH);";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<String>("CURRENCY_CODE").Equals("MXN"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void InStatement()
|
||||
{
|
||||
String expression="DECLARE CURRENCY,A;CURRENCY='MXN';A=CURRENCY in('USD','JPY');";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<bool>("A").Equals(false));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void InStatement2()
|
||||
{
|
||||
String expression="DECLARE CURRENCY,A;CURRENCY='MXN';A=CURRENCY in('USD','JPY','MXN');";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<bool>("A").Equals(true));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void NestedParens()
|
||||
{
|
||||
String expression="DECLARE A,B,C;A=100/50;B=100-(((2*2)*8)*9);";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("B").Equals(-188));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Power()
|
||||
{
|
||||
String expression="DECLARE A,B,C;A=100;B=.5;C=pow(A,B);";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("C").Equals(10));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OrderOfOperations()
|
||||
{
|
||||
String expression="DECLARE NUM1;NUM1=3*4*(2+1)";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("NUM1").Equals(36));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void NumericalEquality()
|
||||
{
|
||||
String expression="DECLARE NOTIONAL,DELTA,DELTA_ADJUSTED_NOTIONAL;NOTIONAL=20.00;if(2==2)then DELTA=.01 else DELTA=1.00;";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("DELTA").Equals(.01));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Division()
|
||||
{
|
||||
String expression="DECLARE NOTIONAL,DELTA,DELTA_ADJUSTED_NOTIONAL;NOTIONAL=1000.00;DELTA=.25;DELTA_ADJUSTED_NOTIONAL=NOTIONAL/DELTA;";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("DELTA_ADJUSTED_NOTIONAL").Equals(4000));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Addition()
|
||||
{
|
||||
String expression="DECLARE a,b,c;a=100;b=100+a;c=-100;";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("b").Equals(200));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void NullCoalescing()
|
||||
{
|
||||
String expression="DECLARE RESULT,A,B,C,D;A=null;B=null;C='NotNull';RESULT=ISNULL(A,B,C);";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<String>("RESULT").Equals("NotNull"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DateComparisons()
|
||||
{
|
||||
String expression="DECLARE RESULT,A,B,C,D;A=CONVERT('01-01-2018','System.DateTime');B=CONVERT('01-02-2018','System.DateTime');IF(A>B) THEN RESULT='01-01-2018 IS GREATER THAN 01-02-2018' ELSE RESULT='01-02-2018 IS GREATER THAN 01-01-2018';";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<String>("RESULT").Equals("01-02-2018 IS GREATER THAN 01-01-2018"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void StringMultiplication()
|
||||
{
|
||||
String expression="DECLARE A,B,C;A='45';B='2';C=A*B;";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("C").Equals(90.00));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ExponentialNotation()
|
||||
{
|
||||
String expression="DECLARE OAC;OAC=-3.52E-05;";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("OAC").Equals(-3.52E-05));
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void StringConcatenation()
|
||||
{
|
||||
String expression="DECLARE ENTITY_ID,AXIOM_META_TAG;ENTITY_ID=148;IF(ENTITY_ID==148)THEN AXIOM_META_TAG=ENTITY_ID+'_BG' ELSE AXIOM_META_TAG=null;";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<String>("AXIOM_META_TAG").Equals("148_BG"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void StringConcatenation2()
|
||||
{
|
||||
String expression="DECLARE A,B,C;A='45';B='2';C=A+B;";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<String>("C").Equals("452"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void StringComparison()
|
||||
{
|
||||
String expression="DECLARE ENTITY_ID;ENTITY_ID='';IF(ENTITY_ID=='')THEN ENTITY_ID='ENTITY_ID IS BLANK'ELSE ENTITY_ID='ENTITY_ID IS NOT BLANK';";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<String>("ENTITY_ID").Equals("ENTITY_ID IS BLANK"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DateConversion()
|
||||
{
|
||||
String expression="DECLARE ENTITY_ID,EFFECTIVE_DATE;ENTITY_ID=null;IF(ENTITY_ID==null)THEN EFFECTIVE_DATE=CONVERT('2/1/2024','System.DateTime');";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<DateTime>("EFFECTIVE_DATE").Equals(new DateTime(2024,2,1)));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void LikeClause()
|
||||
{
|
||||
String expression="DECLARE FIN.Securities.IndustryClass4,FIN.Securities.Country,FIN.Securities.ISIN;FIN.Securities.ISIN='ARARGE';IF(FIN.Securities.ISIN LIKE 'ARARGE'){FIN.Securities.IndustryClass4 = 'Treasury Bond';FIN.Securities.Country='USD'};";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<string>("FIN.Securities.IndustryClass4").Equals("Treasury Bond"));
|
||||
Assert.IsTrue(codeRunner.GetValue<string>("FIN.Securities.Country").Equals("USD"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AbsoluteValueVariant2()
|
||||
{
|
||||
String expression="DECLARE VAR1,VAR2,VAR4,RESULT;VAR1=-1;VAR2=-3;VAR2=ABS(VAR2)+1;";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("VAR2").Equals(4));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AbsoluteValueVariant1()
|
||||
{
|
||||
String expression="DECLARE VAR1,VAR2,VAR4,RESULT;VAR1=((ABS(-1)+2)+3);";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("VAR1").Equals(6));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Multiplication()
|
||||
{
|
||||
String expression="DECLARE var1,var2,var3,var4;var1=1;var2=2;var3=3;var4=var1*var2*var3*var1*var2*var3*abs(var1);";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("var4").Equals(36.00));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AbsoluteValueConvesion()
|
||||
{
|
||||
String expression="DECLARE var1,var2,var3,var4;var1=-1;var2=-2;var3=-3;var4=abs(var2)*abs(var2)*abs(var2)*abs(var2)*abs(var2)*abs(var2)*abs(var2)*abs(var2)*abs(var2)*abs(var2)*abs(var2)*abs(var2);";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("var4").Equals(4096.00));
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void StringToDoubleConvesion()
|
||||
{
|
||||
String expression="DECLARE var1,var2,var3,var4;var1='2';var2='4';var3='6';var4=CONVERT(var1,'System.Double')*CONVERT(var2,'System.Double')*CONVERT(var3,'System.Double');";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<double>("var1").Equals(2.00));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void UpperCaseShouldConvert()
|
||||
{
|
||||
String expression="DECLARE var1,var2,var3,var4;var1='Hello';var2=' ';var3='World';var4=UPPER(var1)+UPPER(var2)+UPPER(var3)";
|
||||
CodeRunner codeRunner = new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.GetValue<String>("var4").Equals("HELLO WORLD"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AssembleAllUseCases()
|
||||
{
|
||||
foreach(String expression in TestData.CodeLines())
|
||||
{
|
||||
CodeRunner codeRunner= new CodeRunner();
|
||||
Assert.IsTrue(codeRunner.Execute(expression),codeRunner.LastMessage);
|
||||
Assert.IsTrue(codeRunner.ParseSymbolsCount.Equals(0),"Expected parse symbols to be zero.");
|
||||
}
|
||||
}
|
||||
|
||||
//[TestMethod]
|
||||
//public void AssembleAllData()
|
||||
//{
|
||||
// List<String> codeLines=TestData.CodeLines();
|
||||
// foreach(String expression in codeLines)
|
||||
// {
|
||||
// Console.WriteLine("*********************************************************************************************************************************");
|
||||
// BinaryWriter binaryWriter=new BinaryWriter(new MemoryStream());
|
||||
// SymbolTable symbolTable = new SymbolTable();
|
||||
// BinaryReader binaryReader = null;
|
||||
// binaryReader = new BinaryReader(Utility.StreamFromString(expression));
|
||||
// Scanner scanner = new Scanner(binaryReader, binaryWriter, symbolTable);
|
||||
// scanner.Debug=false;
|
||||
// Console.WriteLine("Expression:\""+expression+"\"");
|
||||
// Assert.IsTrue(scanner.Analyze());
|
||||
// binaryWriter.BaseStream.Seek(0, SeekOrigin.Begin);
|
||||
// BinaryReader parserReader = new BinaryReader(binaryWriter.BaseStream);
|
||||
// BinaryWriter parserWriter = new BinaryWriter(new MemoryStream());
|
||||
// Parser parser = new Parser(parserReader,parserWriter,symbolTable);
|
||||
// parser.Debug=false;
|
||||
// parser.Parse();
|
||||
// Assert.IsFalse(parser.IsInError);
|
||||
// parserWriter.BaseStream.Seek(0, SeekOrigin.Begin);
|
||||
// BinaryReader assemblerReader = new BinaryReader(parserWriter.BaseStream);
|
||||
// Assembler assembler = new Assembler(assemblerReader, symbolTable);
|
||||
// bool result=assembler.Assemble();
|
||||
// assembler.Disassemble();
|
||||
// Assert.IsTrue(result);
|
||||
// Console.WriteLine("********************************************************* O U T P U T ************************************************");
|
||||
// List<Symbol> list = new List<Symbol>(symbolTable.Values);
|
||||
// list=(from Symbol symbol in list where (symbol.TypeOfSymbol.Equals(Symbol.SymbolType.UserSymbol)||symbol.TypeOfSymbol.Equals(Symbol.SymbolType.UserDynamicSymbol)) && symbol.IsModified select symbol).ToList();
|
||||
// foreach (Symbol symbol in list)
|
||||
// {
|
||||
// Console.WriteLine(String.Format("SYMBOL NAME:'{0}',VALUE:'{1}'",symbol.SymbolName,null==symbol.GenericData?"<null>":symbol.GenericData.ToString()));
|
||||
// }
|
||||
// Console.WriteLine("*********************************************************************************************************************************");
|
||||
// assembler.Dispose();
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{E2FC10FA-2B8A-4CEB-B7C6-960FA6A3AC6F}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>AxiomUnitTestProjectr</RootNamespace>
|
||||
<AssemblyName>AxiomUnitTestProjectr</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
|
||||
<IsCodedUITest>False</IsCodedUITest>
|
||||
<TestProjectType>UnitTest</TestProjectType>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MySql.Data, Version=8.0.33.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\References\MySql.Data.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<Choose>
|
||||
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
|
||||
</ItemGroup>
|
||||
</When>
|
||||
<Otherwise>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
|
||||
</ItemGroup>
|
||||
</Otherwise>
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="AssemblerTests.cs" />
|
||||
<Compile Include="ParserTests.cs" />
|
||||
<Compile Include="ScannerTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="TestData.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Axiom.Core\Axiom.Core.csproj">
|
||||
<Project>{f0f0f2b4-bb86-49b5-ba93-2642637033d6}</Project>
|
||||
<Name>Axiom.Core</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<Choose>
|
||||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
</Choose>
|
||||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
37
AxiomUnitTestProject/AxiomUnitTestProjectr/ParserTests.cs
Normal file
37
AxiomUnitTestProject/AxiomUnitTestProjectr/ParserTests.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System.Collections.Generic;
|
||||
using Axiom.Utils;
|
||||
using Axiom.Interpreter;
|
||||
using System.IO;
|
||||
|
||||
namespace AxiomUnitTestProject
|
||||
{
|
||||
[TestClass]
|
||||
public class ParserTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void ParserShouldParseAll()
|
||||
{
|
||||
List<String> codeLines = TestData.CodeLines();
|
||||
foreach(String expression in codeLines)
|
||||
{
|
||||
BinaryWriter binaryWriter=new BinaryWriter(new MemoryStream());
|
||||
SymbolTable symbolTable = new SymbolTable();
|
||||
BinaryReader binaryReader = null;
|
||||
binaryReader = new BinaryReader(Utility.StreamFromString(expression));
|
||||
Scanner scanner = new Scanner(binaryReader, binaryWriter, symbolTable);
|
||||
scanner.Debug=false;
|
||||
Console.WriteLine("Expression:\""+expression+"\"");
|
||||
Assert.IsTrue(scanner.Analyze());
|
||||
binaryWriter.BaseStream.Seek(0, SeekOrigin.Begin);
|
||||
BinaryReader parserReader = new BinaryReader(binaryWriter.BaseStream);
|
||||
BinaryWriter parserWriter = new BinaryWriter(new MemoryStream());
|
||||
Parser parser = new Parser(parserReader,parserWriter,symbolTable);
|
||||
parser.Debug=true;
|
||||
parser.Parse();
|
||||
Assert.IsFalse(parser.IsInError,parser.LastMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("AxiomUnitTestProjectr")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("AxiomUnitTestProjectr")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2024")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("d86be38f-cf72-4df8-a28e-c95922ecbadd")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
30
AxiomUnitTestProject/AxiomUnitTestProjectr/ScannerTests.cs
Normal file
30
AxiomUnitTestProject/AxiomUnitTestProjectr/ScannerTests.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System.Collections.Generic;
|
||||
using Axiom.Utils;
|
||||
using Axiom.Interpreter;
|
||||
using System.IO;
|
||||
|
||||
namespace AxiomUnitTestProject
|
||||
{
|
||||
[TestClass]
|
||||
public class ScannerTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void ScannerShouldScan()
|
||||
{
|
||||
List<String> codeLines = TestData.CodeLines();
|
||||
foreach(String expression in codeLines)
|
||||
{
|
||||
BinaryWriter binaryWriter=new BinaryWriter(new MemoryStream());
|
||||
SymbolTable symbolTable = new SymbolTable();
|
||||
BinaryReader binaryReader = null;
|
||||
binaryReader = new BinaryReader(Utility.StreamFromString(expression));
|
||||
Scanner scanner = new Scanner(binaryReader, binaryWriter, symbolTable);
|
||||
Console.WriteLine("Expression:\""+expression+"\"");
|
||||
Assert.IsTrue(scanner.Analyze());
|
||||
Console.WriteLine("**************************");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
94
AxiomUnitTestProject/AxiomUnitTestProjectr/TestData.cs
Normal file
94
AxiomUnitTestProject/AxiomUnitTestProjectr/TestData.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AxiomUnitTestProject
|
||||
{
|
||||
public class TestData
|
||||
{
|
||||
public static List<String> CodeLines()
|
||||
{
|
||||
List<String> codeLines = new List<String>();
|
||||
codeLines.Add("DECLARE A,B;A=1;B=5;WHILE(A<B)A=A+1;");
|
||||
codeLines.Add("DECLARE A,B;A=1;B=5;WHILE(A<B){A=A+1;}");
|
||||
codeLines.Add("DECLARE R,user_a,user_b,user_c;R=7;user_a=66;user_b=66;user_c=66;IF(R>=5){user_a=1;user_b=1;user_c=1;}");
|
||||
codeLines.Add("DECLARE price,operation;operation='OPEN';price=GETPRICE('MIDD','07-12-2021',operation);");
|
||||
codeLines.Add("DECLARE var1,var2,var3,var4;var1='Hello';var2=' ';var3='World';var4=UPPER(var1)+UPPER(var2)+UPPER(var3)");
|
||||
codeLines.Add("DECLARE var1,var2,var3,var4;var1='2';var2='4';var3='6';var4=CONVERT(var1,'System.Double')+CONVERT(var2,'System.Double')+CONVERT(var3,'System.Double');");
|
||||
codeLines.Add("DECLARE var1,var2,var3,var4;var1='2';var2='4';var3='6';var4=CONVERT(var1,'System.Double')*CONVERT(var2,'System.Double')*CONVERT(var3,'System.Double');");
|
||||
codeLines.Add("DECLARE var1,var2,var3,var4;var1=-1;var2=-2;var3=-3;var4=abs(var2)*abs(var2)*abs(var2)*abs(var2)*abs(var2)*abs(var2)*abs(var2)*abs(var2)*abs(var2)*abs(var2)*abs(var2)*abs(var2);");
|
||||
codeLines.Add("DECLARE var1,var2,var3,var4;var1=1;var2=2;var3=3;var4=var1*var2*var3*var1*var2*var3*abs(var1);");
|
||||
codeLines.Add("DECLARE var1,var2,var3,var4;var1=1;var2=2;var3=3;var4=var1*var2*var3*var1*var2*var3;");
|
||||
codeLines.Add("DECLARE FIN.Securities.IndustryClass4,FIN.Securities.Country,FIN.Securities.ISIN;FIN.Securities.ISIN='ARARGE';IF(FIN.Securities.ISIN LIKE 'ARARGE'){FIN.Securities.IndustryClass4 = 'Treasury Bond';FIN.Securities.Country='USD'};");
|
||||
codeLines.Add("#directive_clear_modified;");
|
||||
codeLines.Add("DECLARE ENTITY_ID,EFFECTIVE_DATE;ENTITY_ID=null;IF(ENTITY_ID==null)THEN EFFECTIVE_DATE=CONVERT('1/1/1','System.DateTime');");
|
||||
codeLines.Add("DECLARE ENTITY_ID;ENTITY_ID='';IF(ENTITY_ID=='')THEN ENTITY_ID='ENTITY_ID IS BLANK'ELSE ENTITY_ID='ENTITY_ID IS NOT BLANK';");
|
||||
codeLines.Add("DECLARE ENTITY_ID,AXIOM_META_TAG;ENTITY_ID=148;IF(ENTITY_ID==148)THEN AXIOM_META_TAG=ENTITY_ID+'_BG' ELSE AXIOM_META_TAG=null;");
|
||||
codeLines.Add("DECLARE OAC;OAC=-3.52E-05;");
|
||||
codeLines.Add("DECLARE FIN.Analytics.OAD,LAND.STG_EC.SecurityIdentifier;FIN.Analytics.OAD=0.50;LAND.STG_EC.SecurityIdentifier = '397863';IF(LAND.STG_EC.SecurityIdentifier == '397863') THEN FIN.Analytics.OAD = FIN.Analytics.OAD*2.00;");
|
||||
codeLines.Add("DECLARE A,B;A=99;if(A<>99)then B=1 else B=2;");
|
||||
codeLines.Add("DECLARE A,B,C;A='45';B='2';C=A+B;"); // Ok, concatenation of two strings
|
||||
codeLines.Add("DECLARE A,B,C;A='45';B='2';C=A*B;"); // Converts the strings to double and then performs the multiplication
|
||||
codeLines.Add("DECLARE A,B,C,D;A='45';B='2';D='2';C=CONVERT(A,'System.Double')*CONVERT(B,'System.Double')*CONVERT(D,'System.Double');"); // Ok, multiplying numerical values
|
||||
codeLines.Add("DECLARE A,B,C,D;A='45';B='2';D='2';C=CONVERT(A,'System.Double')*CONVERT(B,'System.Double')*2;"); // Ok, multiplying numerical values
|
||||
codeLines.Add("DECLARE A,B,C,D;A='45';B='2';D='2';C=CONVERT(A,'System.Double')+CONVERT(B,'System.Double');"); // Ok, multiplying numerical values
|
||||
codeLines.Add("DECLARE A,B,C,D;A='45';B='2';D='2';C=CONVERT(A,'System.Double')+CONVERT(B,'System.Double')+CONVERT(D,'System.Double');"); // Ok, multiplying numerical values
|
||||
codeLines.Add("DECLARE RESULT,A,B,C,D;A=CONVERT('01-01-2018','System.DateTime');B=CONVERT('01-02-2018','System.DateTime');IF(A>B) THEN RESULT='01-01-2018 IS GREATER THAN 01-02-2018' ELSE RESULT='01-02-2018 IS GREATER THAN 01-01-2018';");
|
||||
codeLines.Add("DECLARE RESULT,A,B,C,D;A=null;B=null;C='NotNull';RESULT=ISNULL(A,B,C);");
|
||||
codeLines.Add("DECLARE a,b,c;a=100;b=100+a;c=-100;");
|
||||
codeLines.Add("DECLARE NOTIONAL,DELTA,DELTA_ADJUSTED_NOTIONAL;NOTIONAL=1000.00;DELTA=.2017;DELTA_ADJUSTED_NOTIONAL=NOTIONAL/DELTA;");
|
||||
codeLines.Add("DECLARE NOTIONAL,DELTA,DELTA_ADJUSTED_NOTIONAL;NOTIONAL=20;DELTA=100;DELTA_ADJUSTED_NOTIONAL=NOTIONAL/DELTA;");
|
||||
codeLines.Add("DECLARE NOTIONAL,DELTA,DELTA_ADJUSTED_NOTIONAL;NOTIONAL=20.00;if(NOTIONAL==20)then DELTA=.01 else DELTA=1.00;");
|
||||
codeLines.Add("DECLARE NOTIONAL,DELTA,DELTA_ADJUSTED_NOTIONAL;NOTIONAL=10.00;if(NOTIONAL<>20) then DELTA=.01 else DELTA=1.00;");
|
||||
codeLines.Add("DECLARE NOTIONAL,DELTA,DELTA_ADJUSTED_NOTIONAL;NOTIONAL=20.00;if(2==2)then DELTA=.01 else DELTA=1.00;");
|
||||
codeLines.Add("DECLARE NOTIONAL,DELTA,DELTA_ADJUSTED_NOTIONAL;NOTIONAL=20.00;if(3==2)then DELTA=.01 else DELTA=1.00;");
|
||||
codeLines.Add("DECLARE NUM1;NUM1=3*4*(2+1)");
|
||||
codeLines.Add("DECLARE A,B,C;A=2;B=.5;C=pow(A,B);");
|
||||
codeLines.Add("DECLARE A,B,C;A=100;IF(A<200) THEN B=1 ELSE B=0;");
|
||||
codeLines.Add("DECLARE A,B,C;A=CONVERT('03-10-2018','System.DateTime');");
|
||||
codeLines.Add("DECLARE A,B,C;A=CONVERT('2','System.Int32');B=CONVERT('3','System.Int32');");
|
||||
codeLines.Add("DECLARE A,B,C;A=100/50;B=100-(((2*2)*8)*9);");
|
||||
codeLines.Add("DECLARE A,B,C;A=abs(-50);");
|
||||
codeLines.Add("DECLARE A,B,C;A=abs(-50);");
|
||||
codeLines.Add("DECLARE A,B,C;A=99;");
|
||||
codeLines.Add("DECLARE A,B,C;A=CONVERT('2','System.Int32');B=CONVERT('2','System.Int32');IF(A==B)THEN C=1 ELSE C=2;");
|
||||
codeLines.Add("DECLARE CURRENCY,A;CURRENCY='MXN';A=CURRENCY in('USD','JPY');");
|
||||
codeLines.Add("DECLARE CURRENCY,RESULT;CURRENCY='MXN';if(CURRENCY in('USD','JPY','MXN'))THEN RESULT='TRUE' ELSE RESULT='FALSE';");
|
||||
codeLines.Add("DECLARE CURRENCY,RESULT;CURRENCY='MXN';if(CURRENCY LIKE '%MXN%') THEN RESULT='TRUE' ELSE RESULT='FALSE';");
|
||||
codeLines.Add("DECLARE CURRENCY,START_INDEX,LENGTH,CURRENCY_CODE;CURRENCY='MXN12345';START_INDEX=1;LENGTH=3;CURRENCY_CODE=SUBSTRING(CURRENCY,START_INDEX,LENGTH);");
|
||||
codeLines.Add("DECLARE IS_PRIMARY_LEG,SEC_ID,LEG;IS_PRIMARY_LEG='FALSE';SEC_ID='FXF12345678_1';LEG=SUBSTRING(SEC_ID,13,1);IF(LEG==1) THEN IS_PRIMARY_LEG='TRUE' ELSE IS_PRIMARY_LEG='FALSE';");
|
||||
codeLines.Add("DECLARE A,B;A=100/50;B=100-(((2*2)*8)*9);");
|
||||
codeLines.Add("DECLARE IS_PRIMARY_LEG,SEC_ID;IS_PRIMARY_LEG='FALSE';SEC_ID='FXF12345678_1';IF(SUBSTRING(SEC_ID,13,1)==1)THEN IS_PRIMARY_LEG='TRUE' ELSE IS_PRIMARY_LEG='FALSE';");
|
||||
codeLines.Add("DECLARE SEC_ID,B;SEC_ID='FXF12345678_1';B=SUBSTRING(SEC_ID,13,1);");
|
||||
codeLines.Add("DECLARE IS_PRIMARY_LEG,SEC_ID;IS_PRIMARY_LEG='FALSE';SEC_ID='FXF12345678_1';IF(SEC_ID LIKE '%_1')THEN IS_PRIMARY_LEG='TRUE' ELSE IS_PRIMARY_LEG='FALSE';");
|
||||
codeLines.Add("DECLARE IS_FX,SEC_ID;IS_FX='FALSE';SEC_ID='FXF12345678_1';IF(SEC_ID LIKE 'FXF2%' OR SEC_ID LIKE 'FXF1%')THEN IS_FX='TRUE' ELSE IS_FX='FALSE';");
|
||||
codeLines.Add("DECLARE A;A=2;");
|
||||
codeLines.Add("DECLARE A,B,C,D;A=2;B=0;C=9;IF(A==2 AND B==0 AND C==10) THEN D=1 ELSE D=0;");
|
||||
codeLines.Add("DECLARE LOCAL_AMT,SECURITY_ID,ENTRYCOST;LOCAL_AMT=50.00;SECURITY_ID='BP071917P1HY5';IF(SECURITY_ID in('BP071917P1HY5','BP071917P2HY5','BP071917P3HY5','BP071917P4HY5','BP071917P5HY5','BP071917P6HY5')) THEN ENTRYCOST=100.00 ELSE ENTRYCOST=LOCAL_AMT;");
|
||||
codeLines.Add("DECLARE A;A=null;");
|
||||
codeLines.Add("DECLARE A,B;A=1;B=2;IF(A==1){IF(B==2)THEN A=10 ELSE A=5;}else{A=3;B=4;}");
|
||||
codeLines.Add("DECLARE A,B,C;A=null;B='TRUE';C=ISNULL(A,B);");
|
||||
codeLines.Add("DECLARE A,B;A=1;B=2;IF(A==2)THEN B=100 ELSE B=200;");
|
||||
codeLines.Add("DECLARE AssetLevel1,IndustryClass4,RESULT;AssetLevel1='FUTURE';IndustryClass4='BOND_FUTURES';IF(AssetLevel1 like 'FUTURE' AND IndustryClass4=='BOND_FUTURES')THEN RESULT=1 ELSE RESULT=0;");
|
||||
codeLines.Add("DECLARE A,B,RESULT;A=1;B=2;IF(A==1 AND B==2)THEN RESULT=1 ELSE RESULT=0;");
|
||||
codeLines.Add("DECLARE VAR1,VAR2,VAR4,RESULT;VAR1='YES';VAR2='NO';VAR4=1;IF((VAR1=='YES') AND VAR2=='NO' AND VAR4==1) THEN RESULT='TRUE' ELSE RESULT='FALSE';");
|
||||
codeLines.Add("DECLARE VAR1,VAR2,VAR4,RESULT;VAR1='YES';VAR2='YES';VAR4=1;IF(VAR1=='NO' OR (VAR2=='YES' AND VAR4==1)) THEN RESULT='TRUE' ELSE RESULT='FALSE';");
|
||||
codeLines.Add("DECLARE VAR1,VAR2,VAR4,RESULT;VAR1='YES';VAR2='YES';VAR4=1;IF(VAR1=='YES' OR VAR2=='YES' AND VAR4==2) THEN RESULT='TRUE' ELSE RESULT='FALSE';");
|
||||
codeLines.Add("DECLARE VAR1,VAR2,VAR4,RESULT;VAR1='YES';VAR2='YES';VAR4=1;IF((VAR1=='YES') OR (VAR2=='YES') AND (VAR4==1)) THEN RESULT='TRUE' ELSE RESULT='FALSE';");
|
||||
codeLines.Add("DECLARE VAR1,VAR2,VAR4,RESULT;VAR1='YES';VAR2='YES';VAR4=1;IF(VAR1=='YES' AND (VAR2=='YES') AND VAR4==1) THEN RESULT='TRUE' ELSE RESULT='FALSE';");
|
||||
codeLines.Add("DECLARE VAR1,VAR2,VAR4,RESULT;VAR1='YES';VAR2='YES';VAR4=1;IF((VAR1=='YES') AND VAR2=='NO') THEN RESULT='TRUE' ELSE RESULT='FALSE';");
|
||||
codeLines.Add("DECLARE VAR1,VAR2,VAR4,RESULT;VAR1='YES';VAR2='NO';VAR4=1;IF((VAR1=='YES') AND VAR2=='NO') THEN RESULT='TRUE' ELSE RESULT='FALSE';");
|
||||
codeLines.Add("DECLARE VAR1,VAR2,VAR4,RESULT;VAR1='YES';VAR2='NO';VAR4=1;IF((((((VAR1=='YES')))))) THEN RESULT='TRUE' ELSE RESULT='FALSE';");
|
||||
codeLines.Add("DECLARE VAR1,VAR2,VAR4,RESULT;VAR1='YES';VAR2='NO';VAR4=1;IF(VAR1=='YES') THEN RESULT='TRUE' ELSE RESULT='FALSE';");
|
||||
codeLines.Add("DECLARE VAR1,VAR2,VAR4,RESULT;VAR1=2;IF(VAR1==2) THEN RESULT='TRUE' ELSE RESULT='FALSE';");
|
||||
codeLines.Add("DECLARE VAR1,VAR2,VAR4,RESULT;VAR1=((ABS(-1)+2)+3);");
|
||||
codeLines.Add("DECLARE VAR1,VAR2,VAR4,RESULT;VAR1=-1;VAR2=-3;VAR2=ABS(VAR2)+1;");
|
||||
codeLines.Add("DECLARE A,B,C;A=1;B=2;C=3;IF(B>A){A=0;B=0;C=0;}ELSE{A=1;B=1;C=1;}");
|
||||
codeLines.Add("DECLARE A,B,C;A=1;B=2;C=3;IF(B<A){A=0;B=0;C=0;}ELSE{A=1;B=1;C=1;}");
|
||||
codeLines.Add("DECLARE A,B,C;A=1;B=2;C=3;IF(B<A){A=0;B=0;C=0;}ELSE{A=1;B=1;C=1;}");
|
||||
return codeLines;
|
||||
}
|
||||
}
|
||||
}
|
||||
70
Configs/PROD/Janus.AxiomConsole.exe.config
Normal file
70
Configs/PROD/Janus.AxiomConsole.exe.config
Normal file
@@ -0,0 +1,70 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
||||
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
|
||||
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
|
||||
</configSections>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/>
|
||||
</startup>
|
||||
<appSettings>
|
||||
<add key="AXIOM_TRACE_ENABLED" value="FALSE"/>
|
||||
<add key="AXIOM_TRACE_COLUMN" value="1"/>
|
||||
<add key="AXIOM_TRACE_VALUES" value="490638"/>
|
||||
</appSettings>
|
||||
<connectionStrings>
|
||||
<add name="AssetAllocationDBConnectionString" connectionString="Data Source=p-allocsql01;Initial Catalog=AssetAllocationDb;Persist Security Info=True;Integrated Security=true;Connection Timeout=120" providerName="System.Data.SqlClient"/>
|
||||
<add name="RiskDBConnectionString" connectionString="Data Source=s-eqsql01;Initial Catalog=RiskDB;Persist Security Info=True;Integrated Security=true;Connection Timeout=120" providerName="System.Data.SqlClient"/>
|
||||
<add name="AxiomConnectionString" connectionString="Data Source=d-qntmsql03;Initial Catalog=Axiom;Persist Security Info=True;Integrated Security=true;Connection Timeout=120" providerName="System.Data.SqlClient"/>
|
||||
<add name="AxiomLocal" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Axiom;Persist Security Info=True;Integrated Security=true;Connection Timeout=120" providerName="System.Data.SqlClient"/>
|
||||
</connectionStrings>
|
||||
<entityFramework>
|
||||
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
|
||||
<providers>
|
||||
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
|
||||
</providers>
|
||||
</entityFramework>
|
||||
<log4net>
|
||||
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
|
||||
<file value=".\Logs\AxiomEngineLog.log"/>
|
||||
<staticLogFileName value="false"/>
|
||||
<appendToFile value="true"/>
|
||||
<rollingStyle value="Date"/>
|
||||
<datePattern value="yyyyMMdd"/>
|
||||
<maxSizeRollBackups value="31"/>
|
||||
<maximumFileSize value="1MB"/>
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"/>
|
||||
</layout>
|
||||
<lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
|
||||
</appender>
|
||||
<appender name="ColoredConsoleAppender" type="log4net.Appender.ColoredConsoleAppender">
|
||||
<mapping>
|
||||
<level value="ERROR"/>
|
||||
<foreColor value="White"/>
|
||||
<backColor value="Red, HighIntensity"/>
|
||||
</mapping>
|
||||
<mapping>
|
||||
<level value="DEBUG"/>
|
||||
<backColor value="Green"/>
|
||||
</mapping>
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"/>
|
||||
</layout>
|
||||
</appender>
|
||||
<root>
|
||||
<level value="DEBUG"/>
|
||||
<appender-ref ref="RollingFileAppender"/>
|
||||
<appender-ref ref="ColoredConsoleAppender"/>
|
||||
</root>
|
||||
</log4net>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.0.8.0" newVersion="2.0.8.0"/>
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
70
Configs/STAGE/Janus.AxiomConsole.exe.config
Normal file
70
Configs/STAGE/Janus.AxiomConsole.exe.config
Normal file
@@ -0,0 +1,70 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
||||
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
|
||||
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
|
||||
</configSections>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/>
|
||||
</startup>
|
||||
<appSettings>
|
||||
<add key="AXIOM_TRACE_ENABLED" value="FALSE"/>
|
||||
<add key="AXIOM_TRACE_COLUMN" value="1"/>
|
||||
<add key="AXIOM_TRACE_VALUES" value="490638"/>
|
||||
</appSettings>
|
||||
<connectionStrings>
|
||||
<add name="AssetAllocationDBConnectionString" connectionString="Data Source=p-allocsql01;Initial Catalog=AssetAllocationDb;Persist Security Info=True;Integrated Security=true;Connection Timeout=120" providerName="System.Data.SqlClient"/>
|
||||
<add name="RiskDBConnectionString" connectionString="Data Source=s-eqsql01;Initial Catalog=RiskDB;Persist Security Info=True;Integrated Security=true;Connection Timeout=120" providerName="System.Data.SqlClient"/>
|
||||
<add name="AxiomConnectionString" connectionString="Data Source=d-qntmsql03;Initial Catalog=Axiom;Persist Security Info=True;Integrated Security=true;Connection Timeout=120" providerName="System.Data.SqlClient"/>
|
||||
<add name="AxiomLocal" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Axiom;Persist Security Info=True;Integrated Security=true;Connection Timeout=120" providerName="System.Data.SqlClient"/>
|
||||
</connectionStrings>
|
||||
<entityFramework>
|
||||
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
|
||||
<providers>
|
||||
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
|
||||
</providers>
|
||||
</entityFramework>
|
||||
<log4net>
|
||||
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
|
||||
<file value=".\Logs\AxiomEngineLog.log"/>
|
||||
<staticLogFileName value="false"/>
|
||||
<appendToFile value="true"/>
|
||||
<rollingStyle value="Date"/>
|
||||
<datePattern value="yyyyMMdd"/>
|
||||
<maxSizeRollBackups value="31"/>
|
||||
<maximumFileSize value="1MB"/>
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"/>
|
||||
</layout>
|
||||
<lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
|
||||
</appender>
|
||||
<appender name="ColoredConsoleAppender" type="log4net.Appender.ColoredConsoleAppender">
|
||||
<mapping>
|
||||
<level value="ERROR"/>
|
||||
<foreColor value="White"/>
|
||||
<backColor value="Red, HighIntensity"/>
|
||||
</mapping>
|
||||
<mapping>
|
||||
<level value="DEBUG"/>
|
||||
<backColor value="Green"/>
|
||||
</mapping>
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"/>
|
||||
</layout>
|
||||
</appender>
|
||||
<root>
|
||||
<level value="DEBUG"/>
|
||||
<appender-ref ref="RollingFileAppender"/>
|
||||
<appender-ref ref="ColoredConsoleAppender"/>
|
||||
</root>
|
||||
</log4net>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.0.8.0" newVersion="2.0.8.0"/>
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
4
README.md
Normal file
4
README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# Axiom
|
||||
|
||||
## A rules engine for processing overrides.
|
||||
|
||||
BIN
References/MarketDataLib.dll
Normal file
BIN
References/MarketDataLib.dll
Normal file
Binary file not shown.
BIN
References/MySql.Data.dll
Normal file
BIN
References/MySql.Data.dll
Normal file
Binary file not shown.
Reference in New Issue
Block a user