diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index b9e2e93..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,411 +0,0 @@
-## 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/main/VisualStudio.gitignore
-
-# User-specific files
-*.rsuser
-*.suo
-*.user
-*.userosscache
-*.sln.docstates
-
-# User-specific files (MonoDevelop/Xamarin Studio)
-*.userprefs
-
-# Mono auto generated files
-mono_crash.*
-
-# Build results
-[Dd]ebug/
-[Dd]ebugPublic/
-[Rr]elease/
-[Rr]eleases/
-x64/
-x86/
-[Ww][Ii][Nn]32/
-[Aa][Rr][Mm]/
-[Aa][Rr][Mm]64/
-[Aa][Rr][Mm]64[Ee][Cc]/
-bld/
-[Bb]in/
-[Oo]bj/
-[Oo]ut/
-[Ll]og/
-[Ll]ogs/
-
-# 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
-nunit-*.xml
-
-# Approval Tests result files
-*.received.*
-
-# 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/
-
-# ASP.NET Scaffolding
-ScaffoldingReadMe.txt
-
-# StyleCop
-StyleCopReport.xml
-
-# Files built by Visual Studio
-*_i.c
-*_p.c
-*_h.h
-*.ilk
-*.meta
-*.obj
-*.idb
-*.iobj
-*.pch
-*.pdb
-*.ipdb
-*.pgc
-*.pgd
-*.rsp
-# but not Directory.Build.rsp, as it configures directory-level build defaults
-!Directory.Build.rsp
-*.sbr
-*.tlb
-*.tli
-*.tlh
-*.tmp
-*.tmp_proj
-*_wpftmp.csproj
-*.log
-*.tlog
-*.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
-
-# TeamCity is a build add-in
-_TeamCity*
-
-# DotCover is a Code Coverage Tool
-*.dotCover
-
-# AxoCover is a Code Coverage Tool
-.axoCover/*
-!.axoCover/settings.json
-
-# Coverlet is a free, cross platform Code Coverage Tool
-coverage*.json
-coverage*.xml
-coverage*.info
-
-# Visual Studio code coverage results
-*.coverage
-*.coveragexml
-
-# NCrunch
-_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
-# NuGet Symbol Packages
-*.snupkg
-# 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
-*.appxbundle
-*.appxupload
-
-# 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
-*- [Bb]ackup.rdl
-*- [Bb]ackup ([0-9]).rdl
-*- [Bb]ackup ([0-9][0-9]).rdl
-
-# 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 6 auto-generated project file (contains which files were open etc.)
-*.vbp
-
-# Visual Studio 6 workspace and project file (working project files containing files to include in project)
-*.dsw
-*.dsp
-
-# Visual Studio 6 technical files
-*.ncb
-*.aps
-
-# 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/
-
-# CodeRush personal settings
-.cr/personal
-
-# 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
-
-# AWS SAM Build and Temporary Artifacts folder
-.aws-sam
-
-# NVidia Nsight GPU debugger configuration file
-*.nvuser
-
-# MFractors (Xamarin productivity tool) working folder
-.mfractor/
-
-# Local History for Visual Studio
-.localhistory/
-
-# Visual Studio History (VSHistory) files
-.vshistory/
-
-# BeatPulse healthcheck temp database
-healthchecksdb
-
-# Backup folder for Package Reference Convert tool in Visual Studio 2017
-MigrationBackup/
-
-# Ionide (cross platform F# VS Code tools) working folder
-.ionide/
-
-# Fody - auto-generated XML schema
-FodyWeavers.xsd
-
-# VS Code files for those working on multiple tools
-.vscode/*
-!.vscode/settings.json
-!.vscode/tasks.json
-!.vscode/launch.json
-!.vscode/extensions.json
-*.code-workspace
-
-# Local History for Visual Studio Code
-.history/
-
-# Windows Installer files from build outputs
-*.cab
-*.msi
-*.msix
-*.msm
-*.msp
-/src/core/cocor/Parser.cs.old
-/src/core/cocor/Scanner.cs.old
-/src/core/cocor/Parser.cs
-/src/core/cocor/Scanner.cs
diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
new file mode 100644
index 0000000..afec3eb
--- /dev/null
+++ b/CODE_OF_CONDUCT.md
@@ -0,0 +1,46 @@
+# Contributor Covenant Code of Conduct
+
+## Our Pledge
+
+In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
+
+## Our Standards
+
+Examples of behavior that contributes to creating a positive environment include:
+
+* Using welcoming and inclusive language
+* Being respectful of differing viewpoints and experiences
+* Gracefully accepting constructive criticism
+* Focusing on what is best for the community
+* Showing empathy towards other community members
+
+Examples of unacceptable behavior by participants include:
+
+* The use of sexualized language or imagery and unwelcome sexual attention or advances
+* Trolling, insulting/derogatory comments, and personal or political attacks
+* Public or private harassment
+* Publishing others' private information, such as a physical or electronic address, without explicit permission
+* Other conduct which could reasonably be considered inappropriate in a professional setting
+
+## Our Responsibilities
+
+Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
+
+Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
+
+## Scope
+
+This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
+
+## Enforcement
+
+Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at jordan@jordanwages.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
+
+Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
+
+## Attribution
+
+This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
+
+[homepage]: http://contributor-covenant.org
+[version]: http://contributor-covenant.org/version/1/4/
diff --git a/CS-MIC/csmic/.vs/csmic/DesignTimeBuild/.dtbcache b/CS-MIC/csmic/.vs/csmic/DesignTimeBuild/.dtbcache
new file mode 100644
index 0000000..25e0b96
Binary files /dev/null and b/CS-MIC/csmic/.vs/csmic/DesignTimeBuild/.dtbcache differ
diff --git a/CS-MIC/csmic/.vs/csmic/v15/.suo b/CS-MIC/csmic/.vs/csmic/v15/.suo
new file mode 100644
index 0000000..865e086
Binary files /dev/null and b/CS-MIC/csmic/.vs/csmic/v15/.suo differ
diff --git a/CS-MIC/csmic/.vs/csmic/v15/Server/sqlite3/db.lock b/CS-MIC/csmic/.vs/csmic/v15/Server/sqlite3/db.lock
new file mode 100644
index 0000000..e69de29
diff --git a/CS-MIC/csmic/.vs/csmic/v15/Server/sqlite3/storage.ide b/CS-MIC/csmic/.vs/csmic/v15/Server/sqlite3/storage.ide
new file mode 100644
index 0000000..56758a8
Binary files /dev/null and b/CS-MIC/csmic/.vs/csmic/v15/Server/sqlite3/storage.ide differ
diff --git a/CS-MIC/csmic/.vs/csmic/v15/Server/sqlite3/storage.ide-shm b/CS-MIC/csmic/.vs/csmic/v15/Server/sqlite3/storage.ide-shm
new file mode 100644
index 0000000..2538363
Binary files /dev/null and b/CS-MIC/csmic/.vs/csmic/v15/Server/sqlite3/storage.ide-shm differ
diff --git a/CS-MIC/csmic/.vs/csmic/v15/Server/sqlite3/storage.ide-wal b/CS-MIC/csmic/.vs/csmic/v15/Server/sqlite3/storage.ide-wal
new file mode 100644
index 0000000..b82d38e
Binary files /dev/null and b/CS-MIC/csmic/.vs/csmic/v15/Server/sqlite3/storage.ide-wal differ
diff --git a/CS-MIC/csmic/CSMICTests/AuthoringTests.txt b/CS-MIC/csmic/CSMICTests/AuthoringTests.txt
new file mode 100644
index 0000000..64bab94
--- /dev/null
+++ b/CS-MIC/csmic/CSMICTests/AuthoringTests.txt
@@ -0,0 +1,136 @@
+==========================================================================
+ Visual Studio Team System: Overview of Authoring and Running Tests
+==========================================================================
+
+This overview describes the features for authoring and running tests in
+Visual Studio Team System and Visual Studio Team Edition for Software Testers.
+
+Opening Tests
+-------------
+To open a test, open a test project or a test metadata file (a file with
+extension .vsmdi) that contains the definition of the test. You can find
+test projects and metadata files in Solution Explorer.
+
+Viewing Tests
+-------------
+To see which tests are available to you, open the Test View window. Or,
+if you have installed Team Edition for Software Testers, you can also open
+the Test List Editor window to view tests.
+
+To open the Test View window, click the Test menu, point to Windows, and
+then click Test View. To open the Test List Editor window (if you have
+installed Team Edition for Software Testers), click Test, point to Windows,
+and then click Test List Editor.
+
+Running Tests
+-------------
+You can run tests from the Test View window and the Test List Editor window.
+See Viewing Tests to learn how to open these windows. To run one or more
+tests displayed in the Test View window, first select the tests in that
+window; to select multiple tests, hold either the Shift or CTRL key while
+clicking tests. Then click the Run Tests button in the Test View window
+toolbar.
+
+If you have installed Visual Studio Team Edition for Software Testers, you can
+also use the Test List Editor window to run tests. To run tests in Test List Editor,
+select the check box next to each test that you want to run. Then click the
+Run Tests button in the Test List Editor window toolbar.
+
+Viewing Test Results
+--------------------
+When you run a test or a series of tests, the results of the test run will be
+shown in the Test Results window. Each individual test in the run is shown on
+a separate line so that you can see its status. The window contains an
+embedded status bar in the top half of the window that provides you with
+summary details of the complete test run.
+
+To see more detailed results for a particular test result, double-click it in
+the Test Results window. This opens a window that provides more information
+about the particular test result, such as any specific error messages returned
+by the test.
+
+Changing the way that tests are run
+-----------------------------------
+Each time you run one or more tests, a collection of settings is used to
+determine how those tests are run. These settings are contained in a “test
+run configuration” file.
+
+Here is a partial list of the changes you can make with a test run
+configuration file:
+
+ - Change the naming scheme for each test run.
+ - Change the test controller that the tests are run on so that you can run
+ tests remotely.
+ - Gather code coverage data for the code being tested so that you can see
+ which lines of code are covered by your tests.
+ - Enable and disable test deployment.
+ - Specify additional files to deploy before tests are run.
+ - Select a different host, ASP.NET, for running ASP.NET unit tests.
+ - Select a different host, the smart device test host, for running smart device unit tests.
+ - Set various properties for the test agents that run your tests.
+ - Run custom scripts at the start and end of each test run so that you can
+ set up the test environment exactly as required each time tests are run.
+ - Set time limits for tests and test runs.
+ - Set the browser mix and the number of times to repeat Web tests in the
+ test run.
+
+By default, a test run configuration file is created whenever you create a
+new test project. You make changes to this file by double-clicking it in
+Solution Explorer and then changing its settings. (Test run configuration
+files have the extension .testrunconfig.)
+
+A solution can contain multiple test run configuration files. Only one of
+those files, known as the “Active” test run configuration file, is used to
+determine the settings that are currently used for test runs. You select
+the active test run configuration by clicking Select Active Test Run
+Configuration on the Test menu.
+
+-------------------------------------------------------------------------------
+
+Test Types
+----------
+Using Visual Studio Team Edition for Software Testers, you can create a number
+of different test types:
+
+Unit test: Use a unit test to create a programmatic test in C++, Visual C# or
+Visual Basic that exercises source code. A unit test calls the methods of a
+class, passing suitable parameters, and verifies that the returned value is
+what you expect.
+There are three specialized variants of unit tests:
+ - Data-driven unit tests are created when you configure a unit test to be
+ called repeatedly for each row of a data source. The data from each row
+ is used by the unit test as input data.
+ - ASP.NET unit tests are unit tests that exercise code in an ASP.NET Web
+ application.
+ - Smart device unit tests are unit tests that are deployed to a smart device
+ or emulator and then executed by the smart device test host.
+
+Web Test: Web tests consist of an ordered series of HTTP requests that you
+record in a browser session using Microsoft Internet Explorer. You can have
+the test report specific details about the pages or sites it requests, such
+as whether a particular page contains a specified string.
+
+Load Test: You use a load test to encapsulate non-manual tests, such as
+unit, Web, and generic tests, and then run them simultaneously by using
+virtual users. Running these tests under load generates test results,
+including performance and other counters, in tables and in graphs.
+
+Generic test: A generic test is an existing program wrapped to function as a
+test in Visual Studio. The following are examples of tests or programs that
+you can turn into generic tests:
+ - An existing test that uses process exit codes to communicate whether the
+ test passed or failed. 0 indicates passing and any other value indicates
+ a failure.
+ - A general program to obtain specific functionality during a test scenario.
+ - A test or program that uses a special XML file (called a “summary results
+ file”), to communicate detailed results.
+
+Manual test: The manual test type is used when the test tasks are to be
+completed by a test engineer as opposed to an automated script.
+
+Ordered test: Use an ordered test to execute a set of tests in an order you
+specify.
+
+-------------------------------------------------------------------------------
+
+
diff --git a/CS-MIC/csmic/CSMICTests/CSMICTests.csproj b/CS-MIC/csmic/CSMICTests/CSMICTests.csproj
new file mode 100644
index 0000000..be90d28
--- /dev/null
+++ b/CS-MIC/csmic/CSMICTests/CSMICTests.csproj
@@ -0,0 +1,118 @@
+
+
+
+ Debug
+ AnyCPU
+ 9.0.21022
+ 2.0
+ {C03AD9DF-630F-4C88-A9D4-8B4B450CCB54}
+ Library
+ Properties
+ CSMICTests
+ CSMICTests
+ v4.0
+ 512
+ {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
+
+
+ 3.5
+
+ publish\
+ true
+ Disk
+ false
+ Foreground
+ 7
+ Days
+ false
+ false
+ true
+ 0
+ 1.0.0.%2a
+ false
+ false
+ true
+ SAK
+ SAK
+ SAK
+ SAK
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+ AllRules.ruleset
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+ AllRules.ruleset
+
+
+
+
+
+ 3.5
+
+
+
+ 3.5
+
+
+
+ 3.5
+
+
+
+
+
+
+
+
+
+
+
+ {7BBA4BA2-E885-4D89-8710-F1A609616B7D}
+ csmic
+
+
+
+
+ False
+ Microsoft .NET Framework 4 %28x86 and x64%29
+ true
+
+
+ False
+ .NET Framework 3.5 SP1 Client Profile
+ false
+
+
+ False
+ .NET Framework 3.5 SP1
+ false
+
+
+ False
+ Windows Installer 3.1
+ true
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CS-MIC/csmic/CSMICTests/CSMICTests.csproj.vspscc b/CS-MIC/csmic/CSMICTests/CSMICTests.csproj.vspscc
new file mode 100644
index 0000000..feffdec
--- /dev/null
+++ b/CS-MIC/csmic/CSMICTests/CSMICTests.csproj.vspscc
@@ -0,0 +1,10 @@
+""
+{
+"FILE_VERSION" = "9237"
+"ENLISTMENT_CHOICE" = "NEVER"
+"PROJECT_FILE_RELATIVE_PATH" = ""
+"NUMBER_OF_EXCLUDED_FILES" = "0"
+"ORIGINAL_PROJECT_FILE_PATH" = ""
+"NUMBER_OF_NESTED_PROJECTS" = "0"
+"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
+}
diff --git a/CS-MIC/csmic/CSMICTests/InputInterpreterTest.cs b/CS-MIC/csmic/CSMICTests/InputInterpreterTest.cs
new file mode 100644
index 0000000..78aeca9
--- /dev/null
+++ b/CS-MIC/csmic/CSMICTests/InputInterpreterTest.cs
@@ -0,0 +1,216 @@
+using csmic;
+using csmic.Extensions;
+using System.Text;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+namespace CSMICTests
+{
+
+
+ ///
+ ///This is a test class for InputInterpreterTest and is intended
+ ///to contain all InputInterpreterTest Unit Tests
+ ///
+ [TestClass()]
+ public class InputInterpreterTest
+ {
+
+
+ private TestContext testContextInstance;
+
+ ///
+ ///Gets or sets the test context which provides
+ ///information about and functionality for the current test run.
+ ///
+ public TestContext TestContext
+ {
+ get
+ {
+ return testContextInstance;
+ }
+ set
+ {
+ testContextInstance = value;
+ }
+ }
+
+ #region Additional test attributes
+ //
+ //You can use the following additional attributes as you write your tests:
+ //
+ //Use ClassInitialize to run code before running the first test in the class
+ //[ClassInitialize()]
+ //public static void MyClassInitialize(TestContext testContext)
+ //{
+ //}
+ //
+ //Use ClassCleanup to run code after all tests in a class have run
+ //[ClassCleanup()]
+ //public static void MyClassCleanup()
+ //{
+ //}
+ //
+ //Use TestInitialize to run code before running each test
+ //[TestInitialize()]
+ //public void MyTestInitialize()
+ //{
+ //}
+ //
+ //Use TestCleanup to run code after each test has run
+ //[TestCleanup()]
+ //public void MyTestCleanup()
+ //{
+ //}
+ //
+ #endregion
+
+
+ ///
+ ///A test for Interpret
+ ///
+ [TestMethod()]
+ public void InterpretTest()
+ {
+ InputInterpreter target = new InputInterpreter();
+ target.CodedFunctions.Add(CodedFunctionFactory.Create("addfive", 1, rf => rf[0] + 5));
+
+ //HighLoadTest(target, "+1");
+ //HighLoadTest(target, "+sin(1)");
+ //HighLoadTest(target, "+precision(0.123456789, 7)");
+ //HighLoadTest(target, "+2*(2 + 5)/tan(sin(4))");
+ //HighLoadTest(target, "+2*2/3-1.23456");
+
+ ExpressionDecimalTest(target, "2+2", 4);
+ ExpressionDecimalTest(target, "1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10", 55);
+ ExpressionDecimalTest(target, "4 + 2 / 1 - 3 * 2", 0);
+ ExpressionDecimalTest(target, "16*2 - 2*3", 26);
+ ExpressionDecimalTest(target, "7-6+3*2", 7);
+ ExpressionDecimalTest(target, "1/-2*-1", 0.5M);
+ ExpressionDecimalTest(target, "12 + 26 / -2 + 3", 2);
+ ExpressionDecimalTest(target, "0.02395/1000", 0.00002395M);
+ ExpressionDecimalTest(target, "0100010101b", 277);
+ ExpressionDecimalTest(target, "0xabcdef", 11259375);
+ ExpressionDecimalTest(target, "11111111b + 0xFF", 510);
+ ExpressionDecimalTest(target, "10011001b * 0x01bAc", 1083852);
+
+ ExpressionDecimalTest(target, "log(sin(((25*200) - 5000)^1943),2)", decimal.MinValue);
+ ExpressionDecimalTest(target, "log(cos(((25*200) - 5000)^1943),2)", 0);
+ ExpressionDecimalTest(target, "cos(2^3)", -0.145500033808614M);
+ ExpressionDecimalTest(target, "addfive(30)", 35);
+ ExpressionDecimalTest(target, "precision(1.23456789, 4)", 1.2346M);
+ ExpressionDecimalTest(target, "3000 * (log(1 + 3162, 2))", 34881.2335215522M);
+ ExpressionDecimalTest(target, "(((12)))", 12);
+
+ ExpressionOutputTest(target, "z := (3*x) - (2*y)", "(3*x)-(2*y)");
+ ExpressionOutputTest(target, "x :: 3", "3");
+ ExpressionOutputTest(target, "y :: 2", "2");
+ ExpressionOutputTest(target, "x", "3");
+ ExpressionOutputTest(target, "y", "2");
+ ExpressionOutputTest(target, "z", "5");
+ ExpressionOutputTest(target, "z + 2", "7");
+ ExpressionOutputTest(target, "y :: 3", "3");
+ ExpressionOutputTest(target, "z", "3");
+ ExpressionOutputTest(target, "arr -> [3,6,9,12]", "3,6,9,12");
+ ExpressionOutputTest(target, "arr[1]", "6");
+ ExpressionOutputTest(target, "arr[1+1]", "9");
+ ExpressionOutputTest(target, "arr[2+44]", "0");
+
+ ExpressionOutputTest(target, "log(sin(((25*200) - 5000)^1943),2)", "log(sin(((25*200) - 5000)^1943),2)".Interpret());
+ ExpressionOutputTest(target, "log(cos(((25*200) - 5000)^1943),2)", "log(cos(((25*200) - 5000)^1943),2)".Interpret());
+
+ }
+
+ [TestMethod]
+ public void AsyncTest()
+ {
+ InputInterpreter interpreter = new InputInterpreter();
+ interpreter.InterpretAsync("2 + 2", i =>
+ {
+ Assert.IsTrue(i.Output == "4");
+ });
+ }
+
+ [TestMethod]
+ public void ComputableTest()
+ {
+ InputInterpreter interpreter = new InputInterpreter();
+
+ interpreter.Interpret("1");
+ Assert.IsTrue(interpreter.AsComputable(c => c.Add(5)).Resolve().Decimal == 6);
+ Assert.IsTrue(interpreter.AsComputable(c => c.Subtract(5)).Resolve().Decimal == 1);
+ Assert.IsTrue(interpreter.AsComputable(c => c.Multiply(5)).Resolve().Decimal == 5);
+ Assert.IsTrue(interpreter.AsComputable(c => c.Divide(1)).Resolve().Decimal == 5);
+ Assert.IsTrue(interpreter.AsComputable(c => c.Mod(1)).Resolve().Decimal == 0);
+ Assert.IsTrue(interpreter.AsComputable(c => c.RaiseToPower(5)).Resolve().Decimal == 0);
+
+ interpreter.Interpret("1");
+ Assert.IsTrue(interpreter.ToComputable().Add(5).Resolve().Decimal == 6);
+ Assert.IsTrue(interpreter.ToComputable().Subtract(5).Resolve().Decimal == 1);
+ Assert.IsTrue(interpreter.ToComputable().Multiply(5).Resolve().Decimal == 5);
+ Assert.IsTrue(interpreter.ToComputable().Divide(1).Resolve().Decimal == 5);
+ Assert.IsTrue(interpreter.ToComputable().Mod(1).Resolve().Decimal == 0);
+ Assert.IsTrue(interpreter.ToComputable().RaiseToPower(5).Resolve().Decimal == 0);
+
+ interpreter.Interpret("1");
+ Assert.IsTrue(interpreter.AsComputable(c => c.Add(5)).ResolveTo(i => i.Decimal) == 6);
+ Assert.IsTrue(interpreter.AsComputable(c => c.Subtract(5)).ResolveTo(i => i.Int) == 1);
+
+ interpreter.Interpret("5");
+ int[] ia = new int[] { 1,2,3 };
+ var test = interpreter.AsComputable(computable => computable.ForAll(ia, sub => sub.RaiseToPower)).Resolve();
+ Assert.IsTrue(test.Output == "15625");
+ }
+
+ ///
+ /// Tests a value repeated 10,000 times and checks for an execution time less than 200 milliseconds.
+ ///
+ /// The input interpreter.
+ /// The value to repeat and test.
+ public void HighLoadTest(InputInterpreter target, string value)
+ {
+ StringBuilder builder = new StringBuilder();
+ string input = string.Empty;
+ System.TimeSpan baseTime = new System.TimeSpan();
+ for (int i = 0; i < 1000; i++)
+ {
+ builder.Append(value);
+ }
+ input = builder.ToString();
+ target.Interpret(input);
+ baseTime = target.LastExecutionTime;
+
+ builder = new StringBuilder();
+ for (int i = 0; i < 100000; i++)
+ {
+ builder.Append(value);
+ }
+ input = builder.ToString();
+ target.Interpret(input);
+
+ Assert.IsTrue(target.LastExecutionTime <= System.TimeSpan.FromTicks((baseTime.Ticks + 1 * 100) + 100), string.Format("{0} failed the high load test.", value));
+ }
+
+ ///
+ /// Tests a given expression for a decimal result.
+ ///
+ /// The input interpreter.
+ /// The input to execute.
+ /// The expected value.
+ public void ExpressionDecimalTest(InputInterpreter target, string input, decimal expected)
+ {
+ target.Interpret(input);
+ Assert.AreEqual(expected, target.Decimal, string.Format("{0} returned {1} but {2} was expected.", input, target.Decimal, expected));
+ }
+
+ ///
+ /// Tests a given expression for a string result.
+ ///
+ /// The input interpreter.
+ /// The input to execute.
+ /// The expected value.
+ public void ExpressionOutputTest(InputInterpreter target, string input, string expected)
+ {
+ target.Interpret(input);
+ Assert.AreEqual(expected, target.Output, string.Format("{0} returned {1} but {2} was expected.", input, target.Decimal, expected));
+ }
+ }
+}
diff --git a/CS-MIC/csmic/CSMICTests/Properties/AssemblyInfo.cs b/CS-MIC/csmic/CSMICTests/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..4c637fa
--- /dev/null
+++ b/CS-MIC/csmic/CSMICTests/Properties/AssemblyInfo.cs
@@ -0,0 +1,35 @@
+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("CSMICTests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("CSMICTests")]
+[assembly: AssemblyCopyright("Copyright © 2010")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM componenets. 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("8e6bded0-27ba-4d6b-a785-988958ca4b10")]
+
+// 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 Revision and Build Numbers
+// by using the '*' as shown below:
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/CS-MIC/csmic/CSMICTests/bin/Debug/CSMICTests.dll b/CS-MIC/csmic/CSMICTests/bin/Debug/CSMICTests.dll
new file mode 100644
index 0000000..63b6cc2
Binary files /dev/null and b/CS-MIC/csmic/CSMICTests/bin/Debug/CSMICTests.dll differ
diff --git a/CS-MIC/csmic/CSMICTests/bin/Debug/CSMICTests.pdb b/CS-MIC/csmic/CSMICTests/bin/Debug/CSMICTests.pdb
new file mode 100644
index 0000000..0cc07cf
Binary files /dev/null and b/CS-MIC/csmic/CSMICTests/bin/Debug/CSMICTests.pdb differ
diff --git a/CS-MIC/csmic/CSMICTests/bin/Debug/Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll b/CS-MIC/csmic/CSMICTests/bin/Debug/Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
new file mode 100644
index 0000000..eb92aa1
Binary files /dev/null and b/CS-MIC/csmic/CSMICTests/bin/Debug/Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll differ
diff --git a/CS-MIC/csmic/CSMICTests/bin/Debug/csmic.dll b/CS-MIC/csmic/CSMICTests/bin/Debug/csmic.dll
new file mode 100644
index 0000000..f707ec3
Binary files /dev/null and b/CS-MIC/csmic/CSMICTests/bin/Debug/csmic.dll differ
diff --git a/CS-MIC/csmic/CSMICTests/bin/Debug/csmic.pdb b/CS-MIC/csmic/CSMICTests/bin/Debug/csmic.pdb
new file mode 100644
index 0000000..6a42ea8
Binary files /dev/null and b/CS-MIC/csmic/CSMICTests/bin/Debug/csmic.pdb differ
diff --git a/CS-MIC/csmic/CSMICTests/bin/Debug/csmic.xml b/CS-MIC/csmic/CSMICTests/bin/Debug/csmic.xml
new file mode 100644
index 0000000..b170882
--- /dev/null
+++ b/CS-MIC/csmic/CSMICTests/bin/Debug/csmic.xml
@@ -0,0 +1,1028 @@
+
+
+
+ csmic
+
+
+
+ Coded function factory.
+
+ This class generates new coded functions dynamically.
+
+
+
+ Creates a new ICodedFunction interface object that implements the dynamic method described.
+ Name of the function.
+ Number of expected arguments.
+ The method body.
+ An ICodedFunction interface object.
+
+
+
+ A coded implementation of the absolute value function.
+
+
+
+
+ Expects 1 argument.
+
+
+
+
+ The name of the function.
+
+
+
+
+ Executes a code block.
+
+ The arguments used in the code block.
+ The absolute value of the argument.
+
+
+
+ A coded implementation of the exponential function based on the constant e.
+
+
+
+
+ Expects 1 argument.
+
+
+
+
+ The name of the function.
+
+
+
+
+ Executes a code block.
+
+ The arguments used in the code block.
+ The constant e raised to the power of the argument.
+
+
+
+ A coded implementation of the log function.
+
+
+
+
+ Expects 2 arguments.
+
+
+
+
+ The name of the function.
+
+
+
+
+ Executes a code block.
+
+ The arguments used in the code block.
+ The log of the first argument to the base of the second argument.
+
+
+
+ A coded implementation of a precision function.
+
+
+
+
+ Expects 2 arguments.
+
+
+
+
+ The name of the function.
+
+
+
+
+ Executes a code block.
+
+ The arguments used in the code block.
+ The first argument to the precision of the argument.
+
+
+
+ A coded implementation of the squre root function.
+
+
+
+
+ Expects 1 argument.
+
+
+
+
+ The name of the function.
+
+
+
+
+ Executes a code block.
+
+ The arguments used in the code block.
+ The square root of the argument.
+
+
+
+ A coded implementation of the cosine function.
+
+
+
+
+ Expects 1 argument.
+
+
+
+
+ The name of the function.
+
+
+
+
+ Executes a code block.
+
+ The arguments used in the code block.
+ The cosine of the argument.
+
+
+
+ A coded implementation of a rounded function.
+
+
+
+
+ Expects 1 argument.
+
+
+
+
+ The name of the function.
+
+
+
+
+ Executes a code block.
+
+ The arguments used in the code block.
+ The rounded argument.
+
+
+
+ A coded implementation of the sine function.
+
+
+
+
+ Expects 1 argument.
+
+
+
+
+ The name of the function.
+
+
+
+
+ Executes a code block.
+
+ The arguments used in the code block.
+ The sine of the argument.
+
+
+
+ A coded implementation of the tangent function.
+
+
+
+
+ Expects 1 argument.
+
+
+
+
+ The name of the function.
+
+
+
+
+ Executes a code block.
+
+ The arguments used in the code block.
+ The tangent of the argument.
+
+
+ Computable class.
+
+
+ The expression to be built.
+
+
+ The interpreter to act as a base.
+
+
+ The add symbol.
+
+
+ The substract symbol.
+
+
+ The divide symbol.
+
+
+ The multiply symbol.
+
+
+ The modifier symbol.
+
+
+ The power symbol.
+
+
+ Gets the expression.
+ The expression.
+
+
+ Creates a Computable instance.
+ The expression.
+ The interpreter.
+
+
+ Resolves the computable as an input interpreter having calculated the input.
+ The computable as an input interpreter.
+
+
+ Resolve the computer to a type .
+ Generic type parameter.
+ The selector function.
+ .
+
+
+ Form the operation given the operation constant and an argument.
+ The operation constant.
+ The argument.
+ A string with the given operation appended.
+
+
+ Form the function with the current expression as the first argument, followed by .
+ The name of the function.
+ The arguments.
+ .
+
+
+ Adds addend.
+ The decimal to add.
+ A computable class after the addition.
+
+
+ Subtracts the subtrahend.
+ The subtrahend.
+ A computable class after the subtraction.
+
+
+ Multiplies the multiplicand.
+ The multiplicand.
+ A computable class after the mulitplication.
+
+
+ Divides the divisor.
+ The divisor.
+ A computable class after the divison.
+
+
+ Mods using a given divisor.
+ The divisor.
+ A computable class after the mod.
+
+
+ Raises to power of the given integer value.
+ The power.
+ A computable class after the power operation.
+
+
+ Applies the function with the current expression as the first argument, followed by .
+ The name of the function.
+ The arguments.
+ A computable class after the function is applied.
+
+
+ Executes a command for all items in a collection.
+ Generic type parameter.
+ The items of type .
+ The action belonging to type .
+ .
+
+
+ CS-MIC extension methods.
+
+
+ A string extension method that interprets as input the string that calls it.
+ The input to act on.
+ The output from the interpretation of the string.
+
+
+ A string extension method that executes as macro operation.
+ The script to act on.
+ The final output of the script.
+
+
+
+ A string extension method that interprets as input the string that calls it.
+
+ The collection to act on.
+ The output from the interpretation of the string.
+
+
+
+ A string extension method that interprets as input the string that calls it.
+
+ The collection to act on.
+ The action.
+ The output from the interpretation of the string.
+
+
+ Enumerates input in this collection, returning a selection on the interpreter.
+ Generic type parameter.
+ The collection to act on.
+ The selection.
+
+ An enumerator that allows foreach to be used to process interpret< t> in this
+ collection.
+
+
+
+ A string extension method that executes as macro operation.
+ The collection to act on.
+ The final output of the script.
+
+
+ Enumerates input in parallel in this collection.
+ The collection to act on.
+
+ An enumerator that allows foreach to be used to process interpret in parallel in this
+ collection.
+
+
+
+ Enumerates input in parallel this collection, returning a selection on the interpreter.
+ Generic type parameter.
+ The collection to act on.
+ The selection.
+
+ An enumerator that allows foreach to be used to process interpret in parallel< t> in
+ this collection.
+
+
+
+
+ A string extension method that interprets as input the strings that calls it in parallel.
+
+ The collection to act on.
+ The output from the interpretation of the string.
+
+
+
+ A generically coded implementation of the ICodedFunction interface.
+
+
+
+ Number of expected arguments.
+
+
+ Name of the function.
+
+
+ The method body.
+
+
+ Constructor.
+ Name of the function.
+ Number of expected arguments.
+ The method body.
+
+
+ Gets the number of expected arguments.
+ The total number of expected arguments.
+
+
+ Gets the name of the function.
+ The name of the function.
+
+
+ Executes a code block that computes the value of the function.
+ A variable-length parameters list containing arguments.
+ The decimal value computed by the function.
+
+
+
+ Implements a function that is coded in the .Net environment.
+
+ This interface is required to implement a method or function
+ that can be used by the CS-MIC inputInterpreter. It is worth noting that the
+ function's name will be the text that is used in the inputInterpreter as the
+ executable text.
+
+
+
+ Gets the number of expected arguments.
+
+
+
+
+ Gets the name of the function.
+
+ The input inputInterpreter will use this function name as
+ executable text, expecting an opening and closing parenthesis following
+ it.
+
+
+
+ Executes a code block that computes the value of the function.
+
+ An array of arguments passed to the function.
+ The decimal value computed by the function.
+ Any code block is valid. Error handling must be done by the
+ developer, as the inputInterpreter cannot determine if there is an error.
+
+ This example shows how to implement the sine function through the interface's
+ Execute() function.
+
+ public decimal Execute(params decimal[] args)
+ {
+ //Set up an output variable.
+ decimal output = 0;
+
+ //Check to see if the number or arguments recieved
+ //is equal to the number of arguments expected.
+ if (args.Length == this.NumExpectedArguments)
+ {
+ //Grab the argument and set a local variable for clarity.
+ decimal input = args[0];
+
+ //Set the output as a sine of the input.
+ output = (decimal)Math.Sin((double)input);
+ }
+
+ //Return the output. The function will return the sine if the arguments
+ //matched what was expected, and will return 0 otherwise. Returning 0 on
+ //errors is the standard in CS-MIC.
+ return output;
+ }
+
+
+
+
+
+ An interpreter object that reads user input and evaluates the code.
+
+ The interpreter does not support exceptions by design. Instead, invalid
+ calculations, parameters, etc. will result in a result of zero.
+
+ InputInterpreter interpreter = new InputInterpreter();
+ interpreter.Interpret("1/0"); // The result will be 0, not an exception.
+
+
+
+
+
+ The output generated.
+
+
+
+
+ The variables assigned.
+
+
+
+
+ The time for execution.
+
+
+
+
+ The verbose message of the calculation.
+
+
+
+
+ The list of coded functions that can be executed.
+
+
+
+
+ The list of user defined functions that can be executed.
+
+
+
+
+ The private calculated value.
+
+
+
+
+ Creates a new InputInterpreter.
+
+
+
+
+ Creates a new InputInterpreter from an original.
+
+ The orginal input interpreter to copy.
+
+
+
+ Gets the message that represents the InputInterpreters output.
+
+
+
+
+ Gets the verbose message that is generated with a calculation.
+
+
+
+
+ Gets the value of the output as a decimal.
+
+
+
+
+ Gets the value of the output cast as an int.
+
+
+
+
+ Gets the value of the output cast as a float.
+
+
+
+
+ Gets the value of the output cast as a double.
+
+
+
+
+ Gets the value (cast as a long) converted to its binary equivalent.
+
+
+
+
+ Gets the execution time of the last calculation.
+
+
+
+
+ Gets or sets a list of coded functions that the interpreter supports.
+
+
+
+
+ Gets or sets a list of user generated interpreted functions that the interpreter supports.
+
+ The interpreted functions.
+
+
+ Gets the variables.
+ The variables.
+
+
+
+ Interprets and executes given input.
+
+ The input to interpret and execute.
+
+
+
+ Computes an expression and returns the result as a decimal.
+
+ The expression to be calculated.
+ The value that was computed.
+
+
+
+ Assigns a decimal value to a variable.
+
+ The name of the variable.
+ The value of the variable.
+ True if the variable was set, false otherwise.
+
+
+
+ Assigns a decimal value to a variable.
+
+ The name of the variable.
+ The expression of the variable.
+ True if the variable was set, false otherwise.
+
+
+
+ Assigns a decimal value to a variable.
+
+ The name of the variable.
+ The values of the variable.
+ True if the variable was set, false otherwise.
+
+
+
+ Executes a function stored in the interpreter.
+
+ The name of the function to execute.
+ The arguments to pass to the function.
+ The value computed from the function execution.
+
+
+
+ Loads the default coded functions supported by the interpreter.
+
+
+
+
+ Produces output given a single object.
+
+ The object representing the output.
+
+
+
+ Produces output given an object and a message.
+
+ The object representing the output.
+ The message to be displayed with the output.
+
+
+ Interpret an input asynchronously.
+ The input to interpret and execute.
+ The callback.
+
+
+ Interpret asynchronous threading work.
+ The input to interpret and execute.
+
+
+ Interpret asynchronous delegate.
+ The input.
+ .
+
+
+ Converts this object to a computable.
+ This object as a Computable.
+
+
+ Treats the current object as a computable and performs an action in that context.
+ The action to execute as a computable object.
+ This object as a Computable, after the given action.
+
+
+
+ Represents a user defined function that can be executed by the interpreter.
+
+
+
+
+ The name of the function.
+
+
+
+
+ The number of expected arguments.
+
+
+
+
+ The set of instructions to be passed to the internal inputInterpreter.
+
+
+
+
+ A set of arguments used in computation of the function.
+
+
+
+
+ The internal macro builder used for computation.
+
+
+
+
+ The internal input inputInterpreter that macro builder will use for computation.
+
+
+
+
+ Creates a new interpreted function.
+
+ The name of the fuction.
+ The node to be used in computation.
+ A set of argument names to be used in computation.
+
+
+
+ Gets the name of the function.
+
+
+
+
+ Gets the number of expected arguments for the function.
+
+
+
+
+ Computes the value of the function.
+
+ The arguments used for computation.
+ The decimal value computed by the function.
+
+
+
+ Because a function's internal pattern may be different, we must manually check to see if the function
+ names are the same.
+
+ The object to test.
+ True if the functions are the same.
+
+
+ Serves as a hash function for a particular type.
+ A hash code for the current .
+
+
+
+ Represents an argument made in an interpreted function.
+
+
+
+
+ The name of the argument.
+
+
+
+
+ The value of the argument.
+
+
+
+
+ Creates a new interpreted function argument.
+
+
+
+
+ Creates a new interpreted function argument.
+
+ The name of the argument in the interpreted function.
+ The value of the argument to use in the interpreted function.
+
+
+
+ Gets or sets the name of the argument.
+
+
+
+
+ Gets or sets the value of the argument.
+
+
+
+
+ A builder object that executes macro scripts.
+
+
+
+
+ The input inputInterpreter.
+
+
+
+ The script to run as a macro.
+
+
+
+ The output as a list of strings.
+
+
+
+
+ The time for execution.
+
+
+
+
+ The root macro operation.
+
+
+
+
+ Creates a new builder object that executes a given macro script.
+
+ A list of strings representing the macro.
+ The InputInterpreter to be used.
+
+
+
+ Creates a new builder object that executes a given macro script.
+
+ A list of strings representing the macro.
+ The InputInterpreter to be used.
+
+
+
+ Gets a list of strings representing the output.
+
+
+
+
+ Gets the execution time of the last script computation.
+
+
+
+
+ Gets the decimal value last computed by the macrobuilder.
+
+
+
+ Runs this macro.
+
+
+ Executes the asynchronous operation.
+ The input.
+ The callback.
+
+
+ Executes the asynchronous threading work operation.
+ The input.
+ .
+
+
+ Macro asynchronous delegate.
+ The input.
+ .
+
+
+
+ Represents the operation types supported by a scripted macro.
+
+
+
+
+ Represents a conditional block.
+
+
+
+
+ Represents a conditional else block.
+
+
+
+
+ Represents a complete conditional block.
+
+
+
+
+ A while block.
+
+
+
+
+ A for block.
+
+
+
+
+ A function declaration.
+
+
+
+
+ An echo statement.
+
+
+
+
+ A say statement.
+
+
+
+
+ A display statement.
+
+
+
+
+ A statement to execute.
+
+
+
+
+ A string to display.
+
+
+
+
+ An unknown or malformed block.
+
+
+
+
+ An operation object that executes a specified action.
+
+
+
+
+ The type of operation represented by the operation.
+
+
+
+
+ The collection of children nodes that belong to the operation.
+
+
+
+
+ A list of the necesary input to execute the operation.
+
+
+
+
+ Creates a new macro operation node.
+
+ The type of operation the node represents.
+
+
+
+ Gets or sets the children nodes of the operation.
+
+
+
+
+ Gets or sets the input for the operation.
+
+
+
+
+ Gets or sets the operation type for this operation.
+
+
+
+
+ Represents the data types supported in a variable.
+
+
+
+
+ Decimal
+
+
+
+
+ Equation
+
+
+
+
+ Array
+
+
+
+
+ Unknown
+
+
+
+
+ No type associated
+
+
+
+
+ An object that contains information about a variable.
+
+
+
+
+ The type of variable.
+
+
+
+
+ The value of the variable.
+
+
+
+
+ Creates an empty variable.
+
+
+
+
+ Gets or sets an object representing the variable's value.
+
+
+
+
+ Gets or sets the type of the variable.
+
+
+
+
diff --git a/CS-MIC/csmic/CSMICTests/bin/Release/CSMICTests.dll b/CS-MIC/csmic/CSMICTests/bin/Release/CSMICTests.dll
new file mode 100644
index 0000000..129f752
Binary files /dev/null and b/CS-MIC/csmic/CSMICTests/bin/Release/CSMICTests.dll differ
diff --git a/CS-MIC/csmic/CSMICTests/bin/Release/CSMICTests.pdb b/CS-MIC/csmic/CSMICTests/bin/Release/CSMICTests.pdb
new file mode 100644
index 0000000..03f947d
Binary files /dev/null and b/CS-MIC/csmic/CSMICTests/bin/Release/CSMICTests.pdb differ
diff --git a/CS-MIC/csmic/CSMICTests/bin/Release/Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll b/CS-MIC/csmic/CSMICTests/bin/Release/Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
new file mode 100644
index 0000000..eb92aa1
Binary files /dev/null and b/CS-MIC/csmic/CSMICTests/bin/Release/Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll differ
diff --git a/CS-MIC/csmic/CSMICTests/bin/Release/csmic.dll b/CS-MIC/csmic/CSMICTests/bin/Release/csmic.dll
new file mode 100644
index 0000000..038b768
Binary files /dev/null and b/CS-MIC/csmic/CSMICTests/bin/Release/csmic.dll differ
diff --git a/CS-MIC/csmic/CSMICTests/bin/Release/csmic.pdb b/CS-MIC/csmic/CSMICTests/bin/Release/csmic.pdb
new file mode 100644
index 0000000..b0b1ab5
Binary files /dev/null and b/CS-MIC/csmic/CSMICTests/bin/Release/csmic.pdb differ
diff --git a/CS-MIC/csmic/CSMICTests/obj/Debug/CSMICTests.csproj.CopyComplete b/CS-MIC/csmic/CSMICTests/obj/Debug/CSMICTests.csproj.CopyComplete
new file mode 100644
index 0000000..e69de29
diff --git a/CS-MIC/csmic/CSMICTests/obj/Debug/CSMICTests.csproj.CoreCompileInputs.cache b/CS-MIC/csmic/CSMICTests/obj/Debug/CSMICTests.csproj.CoreCompileInputs.cache
new file mode 100644
index 0000000..51e51b2
--- /dev/null
+++ b/CS-MIC/csmic/CSMICTests/obj/Debug/CSMICTests.csproj.CoreCompileInputs.cache
@@ -0,0 +1 @@
+b39ce37174cad74c8729c35da3279f049bebd6ab
diff --git a/CS-MIC/csmic/CSMICTests/obj/Debug/CSMICTests.csproj.FileListAbsolute.txt b/CS-MIC/csmic/CSMICTests/obj/Debug/CSMICTests.csproj.FileListAbsolute.txt
new file mode 100644
index 0000000..aa80486
--- /dev/null
+++ b/CS-MIC/csmic/CSMICTests/obj/Debug/CSMICTests.csproj.FileListAbsolute.txt
@@ -0,0 +1,11 @@
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\CSMICTests\obj\Debug\CSMICTests.csprojAssemblyReference.cache
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\CSMICTests\bin\Debug\CSMICTests.dll
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\CSMICTests\bin\Debug\CSMICTests.pdb
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\CSMICTests\bin\Debug\csmic.dll
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\CSMICTests\bin\Debug\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\CSMICTests\bin\Debug\csmic.pdb
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\CSMICTests\bin\Debug\csmic.xml
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\CSMICTests\obj\Debug\CSMICTests.csproj.CoreCompileInputs.cache
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\CSMICTests\obj\Debug\CSMICTests.csproj.CopyComplete
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\CSMICTests\obj\Debug\CSMICTests.dll
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\CSMICTests\obj\Debug\CSMICTests.pdb
diff --git a/CS-MIC/csmic/CSMICTests/obj/Debug/CSMICTests.csprojAssemblyReference.cache b/CS-MIC/csmic/CSMICTests/obj/Debug/CSMICTests.csprojAssemblyReference.cache
new file mode 100644
index 0000000..95c7266
Binary files /dev/null and b/CS-MIC/csmic/CSMICTests/obj/Debug/CSMICTests.csprojAssemblyReference.cache differ
diff --git a/CS-MIC/csmic/CSMICTests/obj/Debug/CSMICTests.dll b/CS-MIC/csmic/CSMICTests/obj/Debug/CSMICTests.dll
new file mode 100644
index 0000000..63b6cc2
Binary files /dev/null and b/CS-MIC/csmic/CSMICTests/obj/Debug/CSMICTests.dll differ
diff --git a/CS-MIC/csmic/CSMICTests/obj/Debug/CSMICTests.pdb b/CS-MIC/csmic/CSMICTests/obj/Debug/CSMICTests.pdb
new file mode 100644
index 0000000..0cc07cf
Binary files /dev/null and b/CS-MIC/csmic/CSMICTests/obj/Debug/CSMICTests.pdb differ
diff --git a/CS-MIC/csmic/CSMICTests/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/CS-MIC/csmic/CSMICTests/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
new file mode 100644
index 0000000..ea54693
Binary files /dev/null and b/CS-MIC/csmic/CSMICTests/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ
diff --git a/CS-MIC/csmic/CSMICTests/obj/Debug/build.force b/CS-MIC/csmic/CSMICTests/obj/Debug/build.force
new file mode 100644
index 0000000..e69de29
diff --git a/CS-MIC/csmic/CSMICTests/obj/Debug/csmic_Accessor.dll b/CS-MIC/csmic/CSMICTests/obj/Debug/csmic_Accessor.dll
new file mode 100644
index 0000000..3ff9fd6
Binary files /dev/null and b/CS-MIC/csmic/CSMICTests/obj/Debug/csmic_Accessor.dll differ
diff --git a/CS-MIC/csmic/CSMICTests/obj/Debug/csmic_Accessor.pdb b/CS-MIC/csmic/CSMICTests/obj/Debug/csmic_Accessor.pdb
new file mode 100644
index 0000000..3c96b5c
Binary files /dev/null and b/CS-MIC/csmic/CSMICTests/obj/Debug/csmic_Accessor.pdb differ
diff --git a/CS-MIC/csmic/CSMICTests/obj/Release/CSMICTests.csproj.CopyComplete b/CS-MIC/csmic/CSMICTests/obj/Release/CSMICTests.csproj.CopyComplete
new file mode 100644
index 0000000..e69de29
diff --git a/CS-MIC/csmic/CSMICTests/obj/Release/CSMICTests.csproj.CoreCompileInputs.cache b/CS-MIC/csmic/CSMICTests/obj/Release/CSMICTests.csproj.CoreCompileInputs.cache
new file mode 100644
index 0000000..f473ee7
--- /dev/null
+++ b/CS-MIC/csmic/CSMICTests/obj/Release/CSMICTests.csproj.CoreCompileInputs.cache
@@ -0,0 +1 @@
+3994c92a986e4a93798e861e932c7d0764b0348e
diff --git a/CS-MIC/csmic/CSMICTests/obj/Release/CSMICTests.csproj.FileListAbsolute.txt b/CS-MIC/csmic/CSMICTests/obj/Release/CSMICTests.csproj.FileListAbsolute.txt
new file mode 100644
index 0000000..8faeeca
--- /dev/null
+++ b/CS-MIC/csmic/CSMICTests/obj/Release/CSMICTests.csproj.FileListAbsolute.txt
@@ -0,0 +1,10 @@
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\CSMICTests\bin\Release\CSMICTests.dll
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\CSMICTests\bin\Release\CSMICTests.pdb
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\CSMICTests\bin\Release\csmic.dll
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\CSMICTests\bin\Release\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\CSMICTests\bin\Release\csmic.pdb
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\CSMICTests\obj\Release\CSMICTests.csprojAssemblyReference.cache
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\CSMICTests\obj\Release\CSMICTests.csproj.CoreCompileInputs.cache
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\CSMICTests\obj\Release\CSMICTests.csproj.CopyComplete
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\CSMICTests\obj\Release\CSMICTests.dll
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\CSMICTests\obj\Release\CSMICTests.pdb
diff --git a/CS-MIC/csmic/CSMICTests/obj/Release/CSMICTests.csprojAssemblyReference.cache b/CS-MIC/csmic/CSMICTests/obj/Release/CSMICTests.csprojAssemblyReference.cache
new file mode 100644
index 0000000..c2d1876
Binary files /dev/null and b/CS-MIC/csmic/CSMICTests/obj/Release/CSMICTests.csprojAssemblyReference.cache differ
diff --git a/CS-MIC/csmic/CSMICTests/obj/Release/CSMICTests.dll b/CS-MIC/csmic/CSMICTests/obj/Release/CSMICTests.dll
new file mode 100644
index 0000000..129f752
Binary files /dev/null and b/CS-MIC/csmic/CSMICTests/obj/Release/CSMICTests.dll differ
diff --git a/CS-MIC/csmic/CSMICTests/obj/Release/CSMICTests.pdb b/CS-MIC/csmic/CSMICTests/obj/Release/CSMICTests.pdb
new file mode 100644
index 0000000..03f947d
Binary files /dev/null and b/CS-MIC/csmic/CSMICTests/obj/Release/CSMICTests.pdb differ
diff --git a/CS-MIC/csmic/HelpFile/HelpFile.shfbproj b/CS-MIC/csmic/HelpFile/HelpFile.shfbproj
new file mode 100644
index 0000000..5390394
--- /dev/null
+++ b/CS-MIC/csmic/HelpFile/HelpFile.shfbproj
@@ -0,0 +1,87 @@
+
+
+
+
+ Debug
+ AnyCPU
+ 2.0
+ {b60970b9-771a-4ebb-9978-89f55163888f}
+ 1.9.5.0
+
+ HelpFile
+ HelpFile
+ HelpFile
+
+ .\Help\
+ csmic_help
+ en-US
+ HtmlHelp1, Website
+ False
+ .NET Framework 4.0
+ True
+ False
+ False
+ True
+ Standard
+ Blank
+ csmic
+ True
+ VS2010
+ False
+ Guid
+ CS-MIC - C Sharp Math Input Control
+ Please visit the <%3ba href="%3bhttp://cs-mic.com"%3b>%3bofficial site<%3b/a>%3b for more information.
+ Please feel free to provide feedback!
+ jordan%40jordanwages.com
+ Copyright 2012
+ AboveNamespaces
+ Msdn
+ Msdn
+ True
+ True
+ CS-MIC is a .NET library written in C# designed to give developers easy access to expression parsing. For many developers, there is no need to involve complicated settings and formats. With few exposed methods and objects, CS-MIC makes basic expression solving as simple as possible with as little logic required from developers as possible. In fact, one can pull a value with only one line of code.
+ Attributes, ExplicitInterfaceImplementations, InheritedMembers, InheritedFrameworkMembers, Internals, Protected, SealedProtected
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ SAK
+ SAK
+ SAK
+ SAK
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CS-MIC/csmic/HelpFile/HelpFile.shfbproj.vspscc b/CS-MIC/csmic/HelpFile/HelpFile.shfbproj.vspscc
new file mode 100644
index 0000000..feffdec
--- /dev/null
+++ b/CS-MIC/csmic/HelpFile/HelpFile.shfbproj.vspscc
@@ -0,0 +1,10 @@
+""
+{
+"FILE_VERSION" = "9237"
+"ENLISTMENT_CHOICE" = "NEVER"
+"PROJECT_FILE_RELATIVE_PATH" = ""
+"NUMBER_OF_EXCLUDED_FILES" = "0"
+"ORIGINAL_PROJECT_FILE_PATH" = ""
+"NUMBER_OF_NESTED_PROJECTS" = "0"
+"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
+}
diff --git a/CS-MIC/csmic/UpgradeLog.htm b/CS-MIC/csmic/UpgradeLog.htm
new file mode 100644
index 0000000..0e1c2ae
Binary files /dev/null and b/CS-MIC/csmic/UpgradeLog.htm differ
diff --git a/CS-MIC/csmic/csmic.sln b/CS-MIC/csmic/csmic.sln
new file mode 100644
index 0000000..8e22dc5
--- /dev/null
+++ b/CS-MIC/csmic/csmic.sln
@@ -0,0 +1,38 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.27703.2026
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csmic", "csmic\csmic.csproj", "{7BBA4BA2-E885-4D89-8710-F1A609616B7D}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSMICTests", "CSMICTests\CSMICTests.csproj", "{C03AD9DF-630F-4C88-A9D4-8B4B450CCB54}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {7BBA4BA2-E885-4D89-8710-F1A609616B7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {7BBA4BA2-E885-4D89-8710-F1A609616B7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {7BBA4BA2-E885-4D89-8710-F1A609616B7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {7BBA4BA2-E885-4D89-8710-F1A609616B7D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C03AD9DF-630F-4C88-A9D4-8B4B450CCB54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C03AD9DF-630F-4C88-A9D4-8B4B450CCB54}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C03AD9DF-630F-4C88-A9D4-8B4B450CCB54}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C03AD9DF-630F-4C88-A9D4-8B4B450CCB54}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {27D51C21-4BAE-4773-83C2-C565983E8D2D}
+ EndGlobalSection
+ GlobalSection(TestCaseManagementSettings) = postSolution
+ CategoryFile = csmic8.vsmdi
+ EndGlobalSection
+ GlobalSection(SubversionScc) = preSolution
+ Svn-Managed = True
+ Manager = AnkhSVN - Subversion Support for Visual Studio
+ EndGlobalSection
+EndGlobal
diff --git a/CS-MIC/csmic/csmic.vssscc b/CS-MIC/csmic/csmic.vssscc
new file mode 100644
index 0000000..794f014
--- /dev/null
+++ b/CS-MIC/csmic/csmic.vssscc
@@ -0,0 +1,10 @@
+""
+{
+"FILE_VERSION" = "9237"
+"ENLISTMENT_CHOICE" = "NEVER"
+"PROJECT_FILE_RELATIVE_PATH" = ""
+"NUMBER_OF_EXCLUDED_FILES" = "0"
+"ORIGINAL_PROJECT_FILE_PATH" = ""
+"NUMBER_OF_NESTED_PROJECTS" = "0"
+"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROJECT"
+}
diff --git a/CS-MIC/csmic/csmic/CodedFunctionFactory.cs b/CS-MIC/csmic/csmic/CodedFunctionFactory.cs
new file mode 100644
index 0000000..e72ce84
--- /dev/null
+++ b/CS-MIC/csmic/csmic/CodedFunctionFactory.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace csmic
+{
+ /// Coded function factory.
+ ///
+ /// This class generates new coded functions dynamically.
+ ///
+ public static class CodedFunctionFactory
+ {
+ /// Creates a new ICodedFunction interface object that implements the dynamic method described.
+ /// Name of the function.
+ /// Number of expected arguments.
+ /// The method body.
+ /// An ICodedFunction interface object.
+ public static ICodedFunction Create(string functionName, int numExpectedArguments, Func methodBody)
+ {
+ return new GenericCodedFunction(functionName, numExpectedArguments, methodBody);
+ }
+ }
+}
diff --git a/CS-MIC/csmic/csmic/CodedFunctions/CF_Abs.cs b/CS-MIC/csmic/csmic/CodedFunctions/CF_Abs.cs
new file mode 100644
index 0000000..d459f55
--- /dev/null
+++ b/CS-MIC/csmic/csmic/CodedFunctions/CF_Abs.cs
@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace csmic.CodedFunctions
+{
+ ///
+ /// A coded implementation of the absolute value function.
+ ///
+ class CF_Abs : ICodedFunction
+ {
+ #region ICodedFunction Members
+
+ ///
+ /// Expects 1 argument.
+ ///
+ public int NumExpectedArguments
+ {
+ get { return 1; }
+ }
+
+ ///
+ /// The name of the function.
+ ///
+ public string FunctionName
+ {
+ get { return "abs"; }
+ }
+
+ ///
+ /// Executes a code block.
+ ///
+ /// The arguments used in the code block.
+ /// The absolute value of the argument.
+ public decimal Execute(params decimal[] args)
+ {
+ decimal output = 0;
+ if (args.Length == this.NumExpectedArguments)
+ {
+ decimal input = args[0];
+ output = Math.Abs(input);
+ }
+ return output;
+ }
+
+ #endregion
+ }
+}
diff --git a/CS-MIC/csmic/csmic/CodedFunctions/CF_Cos.cs b/CS-MIC/csmic/csmic/CodedFunctions/CF_Cos.cs
new file mode 100644
index 0000000..be0df91
--- /dev/null
+++ b/CS-MIC/csmic/csmic/CodedFunctions/CF_Cos.cs
@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace csmic.CodedFunctions
+{
+ ///
+ /// A coded implementation of the cosine function.
+ ///
+ class CF_Cos : ICodedFunction
+ {
+ #region ICodedFunction Members
+
+ ///
+ /// Expects 1 argument.
+ ///
+ public int NumExpectedArguments
+ {
+ get { return 1; }
+ }
+
+ ///
+ /// The name of the function.
+ ///
+ public string FunctionName
+ {
+ get { return "cos"; }
+ }
+
+ ///
+ /// Executes a code block.
+ ///
+ /// The arguments used in the code block.
+ /// The cosine of the argument.
+ public decimal Execute(params decimal[] args)
+ {
+ decimal output = 0;
+ if (args.Length == this.NumExpectedArguments)
+ {
+ decimal input = args[0];
+ output = (decimal)Math.Cos((double)input);
+ }
+ return output;
+ }
+
+ #endregion
+ }
+}
diff --git a/CS-MIC/csmic/csmic/CodedFunctions/CF_Exp.cs b/CS-MIC/csmic/csmic/CodedFunctions/CF_Exp.cs
new file mode 100644
index 0000000..e4cad95
--- /dev/null
+++ b/CS-MIC/csmic/csmic/CodedFunctions/CF_Exp.cs
@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace csmic.CodedFunctions
+{
+ ///
+ /// A coded implementation of the exponential function based on the constant e.
+ ///
+ class CF_Exp : ICodedFunction
+ {
+ #region ICodedFunction Members
+
+ ///
+ /// Expects 1 argument.
+ ///
+ public int NumExpectedArguments
+ {
+ get { return 1; }
+ }
+
+ ///
+ /// The name of the function.
+ ///
+ public string FunctionName
+ {
+ get { return "exp"; }
+ }
+
+ ///
+ /// Executes a code block.
+ ///
+ /// The arguments used in the code block.
+ /// The constant e raised to the power of the argument.
+ public decimal Execute(params decimal[] args)
+ {
+ decimal output = 0;
+ if (args.Length == this.NumExpectedArguments)
+ {
+ decimal input = args[0];
+ output = (decimal)Math.Exp((double)input);
+ }
+ return output;
+ }
+
+ #endregion
+ }
+}
diff --git a/CS-MIC/csmic/csmic/CodedFunctions/CF_Log.cs b/CS-MIC/csmic/csmic/CodedFunctions/CF_Log.cs
new file mode 100644
index 0000000..c938834
--- /dev/null
+++ b/CS-MIC/csmic/csmic/CodedFunctions/CF_Log.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace csmic.CodedFunctions
+{
+ ///
+ /// A coded implementation of the log function.
+ ///
+ class CF_Log : ICodedFunction
+ {
+ #region ICodedFunction Members
+
+ ///
+ /// Expects 2 arguments.
+ ///
+ public int NumExpectedArguments
+ {
+ get { return 2; }
+ }
+
+ ///
+ /// The name of the function.
+ ///
+ public string FunctionName
+ {
+ get { return "log"; }
+ }
+
+ ///
+ /// Executes a code block.
+ ///
+ /// The arguments used in the code block.
+ /// The log of the first argument to the base of the second argument.
+ public decimal Execute(params decimal[] args)
+ {
+ decimal output = 0;
+ if (args.Length == this.NumExpectedArguments)
+ {
+ decimal input = args[0];
+ decimal logBase = args[1];
+ try
+ {
+ output = (decimal)Math.Log((double)input, (double)logBase);
+ }
+ catch
+ {
+ output = decimal.MinValue;
+ }
+ }
+ return output;
+ }
+
+ #endregion
+ }
+}
diff --git a/CS-MIC/csmic/csmic/CodedFunctions/CF_Precision.cs b/CS-MIC/csmic/csmic/CodedFunctions/CF_Precision.cs
new file mode 100644
index 0000000..b718082
--- /dev/null
+++ b/CS-MIC/csmic/csmic/CodedFunctions/CF_Precision.cs
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace csmic.CodedFunctions
+{
+ ///
+ /// A coded implementation of a precision function.
+ ///
+ class CF_Precision : ICodedFunction
+ {
+ #region ICodedFunction Members
+
+ ///
+ /// Expects 2 arguments.
+ ///
+ public int NumExpectedArguments
+ {
+ get { return 2; }
+ }
+
+ ///
+ /// The name of the function.
+ ///
+ public string FunctionName
+ {
+ get { return "precision"; }
+ }
+
+ ///
+ /// Executes a code block.
+ ///
+ /// The arguments used in the code block.
+ /// The first argument to the precision of the argument.
+ public decimal Execute(params decimal[] args)
+ {
+ decimal output = 0;
+ if (args.Length == this.NumExpectedArguments)
+ {
+ decimal input = args[0];
+ decimal precision = args[1];
+ output = (decimal)Math.Round(input, (int)precision);
+ }
+ return output;
+ }
+
+ #endregion
+ }
+}
diff --git a/CS-MIC/csmic/csmic/CodedFunctions/CF_Round.cs b/CS-MIC/csmic/csmic/CodedFunctions/CF_Round.cs
new file mode 100644
index 0000000..9d88fe5
--- /dev/null
+++ b/CS-MIC/csmic/csmic/CodedFunctions/CF_Round.cs
@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace csmic.CodedFunctions
+{
+ ///
+ /// A coded implementation of a rounded function.
+ ///
+ class CF_Round : ICodedFunction
+ {
+ #region ICodedFunction Members
+
+ ///
+ /// Expects 1 argument.
+ ///
+ public int NumExpectedArguments
+ {
+ get { return 1; }
+ }
+
+ ///
+ /// The name of the function.
+ ///
+ public string FunctionName
+ {
+ get { return "round"; }
+ }
+
+ ///
+ /// Executes a code block.
+ ///
+ /// The arguments used in the code block.
+ /// The rounded argument.
+ public decimal Execute(params decimal[] args)
+ {
+ decimal output = 0;
+ if (args.Length == this.NumExpectedArguments)
+ {
+ decimal input = args[0];
+ output = Math.Round(input);
+ }
+ return output;
+ }
+
+ #endregion
+ }
+}
diff --git a/CS-MIC/csmic/csmic/CodedFunctions/CF_Sin.cs b/CS-MIC/csmic/csmic/CodedFunctions/CF_Sin.cs
new file mode 100644
index 0000000..8b05729
--- /dev/null
+++ b/CS-MIC/csmic/csmic/CodedFunctions/CF_Sin.cs
@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace csmic.CodedFunctions
+{
+ ///
+ /// A coded implementation of the sine function.
+ ///
+ class CF_Sin : ICodedFunction
+ {
+ #region ICodedFunction Members
+
+ ///
+ /// Expects 1 argument.
+ ///
+ public int NumExpectedArguments
+ {
+ get { return 1; }
+ }
+
+ ///
+ /// The name of the function.
+ ///
+ public string FunctionName
+ {
+ get { return "sin"; }
+ }
+
+ ///
+ /// Executes a code block.
+ ///
+ /// The arguments used in the code block.
+ /// The sine of the argument.
+ public decimal Execute(params decimal[] args)
+ {
+ decimal output = 0;
+ if (args.Length == this.NumExpectedArguments)
+ {
+ decimal input = args[0];
+ output = (decimal)Math.Sin((double)input);
+ }
+ return output;
+ }
+
+ #endregion
+ }
+}
diff --git a/CS-MIC/csmic/csmic/CodedFunctions/CF_Sqrt.cs b/CS-MIC/csmic/csmic/CodedFunctions/CF_Sqrt.cs
new file mode 100644
index 0000000..5de4871
--- /dev/null
+++ b/CS-MIC/csmic/csmic/CodedFunctions/CF_Sqrt.cs
@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace csmic.CodedFunctions
+{
+ ///
+ /// A coded implementation of the squre root function.
+ ///
+ class CF_Sqrt : ICodedFunction
+ {
+ #region ICodedFunction Members
+
+ ///
+ /// Expects 1 argument.
+ ///
+ public int NumExpectedArguments
+ {
+ get { return 1; }
+ }
+
+ ///
+ /// The name of the function.
+ ///
+ public string FunctionName
+ {
+ get { return "sqrt"; }
+ }
+
+ ///
+ /// Executes a code block.
+ ///
+ /// The arguments used in the code block.
+ /// The square root of the argument.
+ public decimal Execute(params decimal[] args)
+ {
+ decimal output = 0;
+ if (args.Length == this.NumExpectedArguments)
+ {
+ decimal input = args[0];
+ output = (decimal)Math.Sqrt((double)input);
+ }
+ return output;
+ }
+
+ #endregion
+ }
+}
diff --git a/CS-MIC/csmic/csmic/CodedFunctions/CF_Tan.cs b/CS-MIC/csmic/csmic/CodedFunctions/CF_Tan.cs
new file mode 100644
index 0000000..6527cbe
--- /dev/null
+++ b/CS-MIC/csmic/csmic/CodedFunctions/CF_Tan.cs
@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace csmic.CodedFunctions
+{
+ ///
+ /// A coded implementation of the tangent function.
+ ///
+ class CF_Tan : ICodedFunction
+ {
+ #region ICodedFunction Members
+
+ ///
+ /// Expects 1 argument.
+ ///
+ public int NumExpectedArguments
+ {
+ get { return 1; }
+ }
+
+ ///
+ /// The name of the function.
+ ///
+ public string FunctionName
+ {
+ get { return "tan"; }
+ }
+
+ ///
+ /// Executes a code block.
+ ///
+ /// The arguments used in the code block.
+ /// The tangent of the argument.
+ public decimal Execute(params decimal[] args)
+ {
+ decimal output = 0;
+ if (args.Length == this.NumExpectedArguments)
+ {
+ decimal input = args[0];
+ output = (decimal)Math.Tan((double)input);
+ }
+ return output;
+ }
+
+ #endregion
+ }
+}
diff --git a/CS-MIC/csmic/csmic/Computable/Computable.cs b/CS-MIC/csmic/csmic/Computable/Computable.cs
new file mode 100644
index 0000000..323b9f7
--- /dev/null
+++ b/CS-MIC/csmic/csmic/Computable/Computable.cs
@@ -0,0 +1,182 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace csmic.ComputableEngine
+{
+ /// Computable class.
+ public sealed class Computable
+ {
+ #region Members
+
+ /// The expression to be built.
+ private string expression;
+ /// The interpreter to act as a base.
+ private InputInterpreter interpreter;
+
+ #region Constants
+
+ /// The add symbol.
+ private const string ADD = "+";
+ /// The substract symbol.
+ private const string SUBSTRACT = "-";
+ /// The divide symbol.
+ private const string DIVIDE = "/";
+ /// The multiply symbol.
+ private const string MULTIPLY = "*";
+ /// The modifier symbol.
+ private const string MOD = "%";
+ /// The power symbol.
+ private const string POWER = "^";
+
+ #endregion
+
+ #endregion
+
+ #region Properties
+
+ /// Gets the expression.
+ /// The expression.
+ internal string Expression
+ {
+ get
+ {
+ return this.expression;
+ }
+ }
+
+ #endregion
+
+ #region Constructor
+
+ /// Creates a Computable instance.
+ /// The expression.
+ /// The interpreter.
+ internal Computable(string expression, InputInterpreter interpreter)
+ {
+ this.expression = expression;
+ this.interpreter = interpreter;
+ }
+
+ #endregion
+
+ #region Methods
+
+ /// Resolves the computable as an input interpreter having calculated the input.
+ /// The computable as an input interpreter.
+ public InputInterpreter Resolve()
+ {
+ this.interpreter.Interpret(this.Expression);
+ return this.interpreter;
+ }
+
+ /// Resolve the computer to a type .
+ /// Generic type parameter.
+ /// The selector function.
+ /// .
+ public T ResolveTo(Func selector)
+ {
+ return selector(this.Resolve());
+ }
+
+ /// Form the operation given the operation constant and an argument.
+ /// The operation constant.
+ /// The argument.
+ /// A string with the given operation appended.
+ private string FormOperation(string operation, object argument)
+ {
+ return string.Format("({0} {1} {2})", this.Expression, operation, argument);
+ }
+
+ /// Form the function with the current expression as the first argument, followed by .
+ /// The name of the function.
+ /// The arguments.
+ /// .
+ private string FormFunction(string name, object[] arguments)
+ {
+ return string.Format("{0}({1})", name, string.Join(",", this.Expression, arguments));
+ }
+
+ /// Adds addend.
+ /// The decimal to add.
+ /// A computable class after the addition.
+ public Computable Add(decimal addend)
+ {
+ this.expression = FormOperation(ADD, addend);
+ return this;
+ }
+
+ /// Subtracts the subtrahend.
+ /// The subtrahend.
+ /// A computable class after the subtraction.
+ public Computable Subtract(decimal subtrahend)
+ {
+ this.expression = FormOperation(SUBSTRACT, subtrahend);
+ return this;
+ }
+
+ /// Multiplies the multiplicand.
+ /// The multiplicand.
+ /// A computable class after the mulitplication.
+ public Computable Multiply(decimal multiplicand)
+ {
+ this.expression = FormOperation(MULTIPLY, multiplicand);
+ return this;
+ }
+
+ /// Divides the divisor.
+ /// The divisor.
+ /// A computable class after the divison.
+ public Computable Divide(decimal divisor)
+ {
+ this.expression = FormOperation(DIVIDE, divisor);
+ return this;
+ }
+
+ /// Mods using a given divisor.
+ /// The divisor.
+ /// A computable class after the mod.
+ public Computable Mod(decimal divisor)
+ {
+ this.expression = FormOperation(MOD, divisor);
+ return this;
+ }
+
+ /// Raises to power of the given integer value.
+ /// The power.
+ /// A computable class after the power operation.
+ public Computable RaiseToPower(int power)
+ {
+ this.expression = FormOperation(POWER, power);
+ return this;
+ }
+
+ /// Applies the function with the current expression as the first argument, followed by .
+ /// The name of the function.
+ /// The arguments.
+ /// A computable class after the function is applied.
+ public Computable ApplyFunction(string name, object[] arguments)
+ {
+ this.expression = FormFunction(name, arguments);
+ return this;
+ }
+
+ /// Executes a command for all items in a collection.
+ /// Generic type parameter.
+ /// The items of type .
+ /// The action belonging to type .
+ /// .
+ public Computable ForAll(ICollection items, Func> action)
+ {
+ foreach (T item in items)
+ {
+ action(this)(item);
+ }
+
+ return this;
+ }
+
+ #endregion
+ }
+}
diff --git a/CS-MIC/csmic/csmic/Extensions/CSMICExtension.cs b/CS-MIC/csmic/csmic/Extensions/CSMICExtension.cs
new file mode 100644
index 0000000..c999aa3
--- /dev/null
+++ b/CS-MIC/csmic/csmic/Extensions/CSMICExtension.cs
@@ -0,0 +1,178 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.Concurrent;
+using System.Linq;
+using System.Text;
+
+namespace csmic.Extensions
+{
+ /// CS-MIC extension methods.
+ public static class CSMICExtension
+ {
+ #region String
+
+ /// A string extension method that interprets as input the string that calls it.
+ /// The input to act on.
+ /// The output from the interpretation of the string.
+ public static string Interpret(this string input)
+ {
+ InputInterpreter interpreter = new InputInterpreter();
+ interpreter.Interpret(input);
+ return interpreter.Output;
+ }
+
+ /// A string extension method that executes as macro operation.
+ /// The script to act on.
+ /// The final output of the script.
+ public static string RunAsMacro(this string script)
+ {
+ MacroBuilder macro = new MacroBuilder(script, new InputInterpreter());
+ return macro.FinalOutput;
+ }
+
+ #endregion
+
+ #region IEnumerable
+
+ ///
+ /// A string extension method that interprets as input the string that calls it.
+ ///
+ /// The collection to act on.
+ /// The output from the interpretation of the string.
+ public static IEnumerable Interpret(this IEnumerable collection)
+ {
+ List computed = new List();
+ InputInterpreter interpreter = new InputInterpreter();
+
+ foreach (string input in collection)
+ {
+ interpreter.Interpret(input);
+ computed.Add(interpreter.Output);
+ }
+
+ return computed;
+ }
+
+ ///
+ /// A string extension method that interprets as input the string that calls it.
+ ///
+ /// The collection to act on.
+ /// The action.
+ /// The output from the interpretation of the string.
+ public static IEnumerable Interpret(this IEnumerable collection, Action action)
+ {
+ List computed = new List();
+ InputInterpreter interpreter = new InputInterpreter();
+
+ foreach (string input in collection)
+ {
+ interpreter.Interpret(input);
+ computed.Add(interpreter.Output);
+ action(interpreter);
+ }
+
+ return computed;
+ }
+
+ /// Enumerates input in this collection, returning a selection on the interpreter.
+ /// Generic type parameter.
+ /// The collection to act on.
+ /// The selection.
+ ///
+ /// An enumerator that allows foreach to be used to process interpret< t> in this
+ /// collection.
+ ///
+ public static IEnumerable Interpret(this IEnumerable collection, Func selection)
+ {
+ List computed = new List();
+ InputInterpreter interpreter = new InputInterpreter();
+
+ foreach (string input in collection)
+ {
+ interpreter.Interpret(input);
+ computed.Add(selection(interpreter));
+ }
+
+ return computed;
+ }
+
+ /// A string extension method that executes as macro operation.
+ /// The collection to act on.
+ /// The final output of the script.
+ public static MacroBuilder RunAsMacro(this IEnumerable collection)
+ {
+ return new MacroBuilder(string.Join(Environment.NewLine, collection.ToArray()), new InputInterpreter());
+ }
+
+ #endregion
+
+ #region IEnumerable In Parallel
+
+ /// Enumerates input in parallel in this collection.
+ /// The collection to act on.
+ ///
+ /// An enumerator that allows foreach to be used to process interpret in parallel in this
+ /// collection.
+ ///
+ public static IEnumerable InterpretInParallel(this IEnumerable collection)
+ {
+ ConcurrentBag bag = new ConcurrentBag();
+
+ collection.AsParallel().ForAll(input =>
+ {
+ InputInterpreter interpreter = new InputInterpreter();
+ interpreter.Interpret(input);
+ bag.Add(interpreter);
+ });
+
+ return bag;
+ }
+
+ /// Enumerates input in parallel this collection, returning a selection on the interpreter.
+ /// Generic type parameter.
+ /// The collection to act on.
+ /// The selection.
+ ///
+ /// An enumerator that allows foreach to be used to process interpret in parallel< t> in
+ /// this collection.
+ ///
+ public static IEnumerable InterpretInParallel(this IEnumerable collection, Func selection)
+ {
+ ConcurrentBag bag = new ConcurrentBag();
+
+ collection.AsParallel().ForAll(input =>
+ {
+ InputInterpreter interpreter = new InputInterpreter();
+ interpreter.Interpret(input);
+ bag.Add(selection(interpreter));
+ });
+
+ return bag;
+ }
+
+ #endregion
+
+ #region ParallelQuery
+
+ ///
+ /// A string extension method that interprets as input the strings that calls it in parallel.
+ ///
+ /// The collection to act on.
+ /// The output from the interpretation of the string.
+ public static IEnumerable Interpret(this ParallelQuery collection)
+ {
+ ConcurrentBag bag = new ConcurrentBag();
+
+ collection.ForAll(input =>
+ {
+ InputInterpreter interpreter = new InputInterpreter();
+ interpreter.Interpret(input);
+ bag.Add(interpreter);
+ });
+
+ return bag;
+ }
+
+ #endregion
+ }
+}
diff --git a/CS-MIC/csmic/csmic/GenericCodedFunction.cs b/CS-MIC/csmic/csmic/GenericCodedFunction.cs
new file mode 100644
index 0000000..6e1f12a
--- /dev/null
+++ b/CS-MIC/csmic/csmic/GenericCodedFunction.cs
@@ -0,0 +1,76 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace csmic
+{
+ ///
+ /// A generically coded implementation of the ICodedFunction interface.
+ ///
+ internal class GenericCodedFunction : ICodedFunction
+ {
+ #region Members
+
+ /// Number of expected arguments.
+ private int numExpectedArguments;
+ /// Name of the function.
+ private string functionName;
+ /// The method body.
+ private Func methodBody;
+
+ #endregion
+
+ #region Constructor
+
+ /// Constructor.
+ /// Name of the function.
+ /// Number of expected arguments.
+ /// The method body.
+ internal GenericCodedFunction(string functionName, int numExpectedArguments, Func methodBody)
+ {
+ this.functionName = functionName;
+ this.numExpectedArguments = numExpectedArguments;
+ this.methodBody = methodBody;
+ }
+
+ #endregion
+
+ #region ICodedFunction Members
+
+ /// Gets the number of expected arguments.
+ /// The total number of expected arguments.
+ public int NumExpectedArguments
+ {
+ get
+ {
+ return this.numExpectedArguments;
+ }
+ }
+
+ /// Gets the name of the function.
+ /// The name of the function.
+ public string FunctionName
+ {
+ get
+ {
+ return this.functionName;
+ }
+ }
+
+ /// Executes a code block that computes the value of the function.
+ /// A variable-length parameters list containing arguments.
+ /// The decimal value computed by the function.
+ public decimal Execute(params decimal[] args)
+ {
+ if (this.methodBody != null)
+ {
+ return this.methodBody(args);
+ }
+
+ throw new MissingMethodException(this.GetType().Name, this.functionName);
+ }
+
+ #endregion
+ }
+}
diff --git a/CS-MIC/csmic/csmic/ICodedFunction.cs b/CS-MIC/csmic/csmic/ICodedFunction.cs
new file mode 100644
index 0000000..4b827a4
--- /dev/null
+++ b/CS-MIC/csmic/csmic/ICodedFunction.cs
@@ -0,0 +1,73 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace csmic
+{
+ ///
+ /// Implements a function that is coded in the .Net environment.
+ ///
+ /// This interface is required to implement a method or function
+ /// that can be used by the CS-MIC inputInterpreter. It is worth noting that the
+ /// function's name will be the text that is used in the inputInterpreter as the
+ /// executable text.
+ public interface ICodedFunction
+ {
+ #region Properties
+
+ ///
+ /// Gets the number of expected arguments.
+ ///
+ int NumExpectedArguments { get; }
+ ///
+ /// Gets the name of the function.
+ ///
+ /// The input inputInterpreter will use this function name as
+ /// executable text, expecting an opening and closing parenthesis following
+ /// it.
+ string FunctionName { get; }
+
+ #endregion
+
+ #region Methods
+
+ ///
+ /// Executes a code block that computes the value of the function.
+ ///
+ /// An array of arguments passed to the function.
+ /// The decimal value computed by the function.
+ /// Any code block is valid. Error handling must be done by the
+ /// developer, as the inputInterpreter cannot determine if there is an error.
+ ///
+ /// This example shows how to implement the sine function through the interface's
+ /// Execute() function.
+ ///
+ /// public decimal Execute(params decimal[] args)
+ ///{
+ /// //Set up an output variable.
+ /// decimal output = 0;
+ ///
+ /// //Check to see if the number or arguments recieved
+ /// //is equal to the number of arguments expected.
+ /// if (args.Length == this.NumExpectedArguments)
+ /// {
+ /// //Grab the argument and set a local variable for clarity.
+ /// decimal input = args[0];
+ ///
+ /// //Set the output as a sine of the input.
+ /// output = (decimal)Math.Sin((double)input);
+ /// }
+ ///
+ /// //Return the output. The function will return the sine if the arguments
+ /// //matched what was expected, and will return 0 otherwise. Returning 0 on
+ /// //errors is the standard in CS-MIC.
+ /// return output;
+ ///}
+ ///
+ ///
+ decimal Execute(params decimal[] args);
+
+ #endregion
+ }
+}
diff --git a/CS-MIC/csmic/csmic/InputInterpreter.cs b/CS-MIC/csmic/csmic/InputInterpreter.cs
new file mode 100644
index 0000000..fa07c76
--- /dev/null
+++ b/CS-MIC/csmic/csmic/InputInterpreter.cs
@@ -0,0 +1,502 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Linq;
+using System.Text.RegularExpressions;
+using System.IO;
+using System.Threading;
+using csmic.CodedFunctions;
+using csmic.Interpreter;
+using csmic.ComputableEngine;
+using System.Runtime.Remoting.Messaging;
+
+// namespace: csmic
+//
+// summary: .
+namespace csmic
+{
+ ///
+ /// An interpreter object that reads user input and evaluates the code.
+ ///
+ /// The interpreter does not support exceptions by design. Instead, invalid
+ /// calculations, parameters, etc. will result in a result of zero.
+ ///
+ /// InputInterpreter interpreter = new InputInterpreter();
+ /// interpreter.Interpret("1/0"); // The result will be 0, not an exception.
+ ///
+ ///
+ public class InputInterpreter
+ {
+ #region Members
+
+ ///
+ /// The output generated.
+ ///
+ private string output;
+ ///
+ /// The variables assigned.
+ ///
+ internal Dictionary variables;
+ ///
+ /// The time for execution.
+ ///
+ private TimeSpan executionTime;
+ ///
+ /// The verbose message of the calculation.
+ ///
+ private string message;
+ ///
+ /// The list of coded functions that can be executed.
+ ///
+ private List codedFunctions;
+ ///
+ /// The list of user defined functions that can be executed.
+ ///
+ private List interpretedFunctions;
+ ///
+ /// The private calculated value.
+ ///
+ private decimal calculatedValue;
+
+ #endregion
+
+ #region Constructor
+
+ ///
+ /// Creates a new InputInterpreter.
+ ///
+ public InputInterpreter()
+ {
+ this.output = string.Empty;
+ this.variables = new Dictionary();
+ this.executionTime = new TimeSpan();
+ this.codedFunctions = new List();
+ this.interpretedFunctions = new List();
+ LoadDefaultCodedFunctions();
+ }
+
+ ///
+ /// Creates a new InputInterpreter from an original.
+ ///
+ /// The orginal input interpreter to copy.
+ public InputInterpreter(InputInterpreter original)
+ {
+ this.output = original.output;
+ this.variables = original.variables;
+ this.executionTime = original.executionTime;
+ this.codedFunctions = original.codedFunctions;
+ this.interpretedFunctions = original.interpretedFunctions;
+ }
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// Gets the message that represents the InputInterpreters output.
+ ///
+ public string Output
+ {
+ get
+ {
+ return this.output;
+ }
+ }
+
+ ///
+ /// Gets the verbose message that is generated with a calculation.
+ ///
+ public string Message
+ {
+ get
+ {
+ return this.message;
+ }
+ }
+
+ ///
+ /// Gets the value of the output as a decimal.
+ ///
+ public decimal Decimal
+ {
+ get
+ {
+ return this.calculatedValue;
+ }
+ }
+
+ ///
+ /// Gets the value of the output cast as an int.
+ ///
+ public int Int
+ {
+ get
+ {
+ return (int)decimal.Round(this.calculatedValue);
+ }
+ }
+
+ ///
+ /// Gets the value of the output cast as a float.
+ ///
+ public float Float
+ {
+ get
+ {
+ return (float)this.calculatedValue;
+ }
+ }
+
+ ///
+ /// Gets the value of the output cast as a double.
+ ///
+ public double Double
+ {
+ get
+ {
+ return (double)this.calculatedValue;
+ }
+ }
+
+ ///
+ /// Gets the value (cast as a long) converted to its binary equivalent.
+ ///
+ public string Binary
+ {
+ get
+ {
+ return Convert.ToString((long)this.calculatedValue, 2).PadLeft(64, '0');
+ }
+ }
+
+ ///
+ /// Gets the execution time of the last calculation.
+ ///
+ public TimeSpan LastExecutionTime
+ {
+ get
+ {
+ return this.executionTime;
+ }
+ }
+
+ ///
+ /// Gets or sets a list of coded functions that the interpreter supports.
+ ///
+ public List CodedFunctions
+ {
+ get
+ {
+ return this.codedFunctions;
+ }
+ set
+ {
+ this.codedFunctions = value;
+ }
+ }
+
+ ///
+ /// Gets or sets a list of user generated interpreted functions that the interpreter supports.
+ ///
+ /// The interpreted functions.
+ public List InterpretedFunctions
+ {
+ get
+ {
+ return this.interpretedFunctions;
+ }
+ set
+ {
+ this.interpretedFunctions = value;
+ }
+ }
+
+ /// Gets the variables.
+ /// The variables.
+ public Dictionary Variables
+ {
+ get
+ {
+ return this.variables;
+ }
+ set
+ {
+ this.variables = value;
+ }
+ }
+
+ #endregion
+
+ #region Public Methods
+
+ ///
+ /// Interprets and executes given input.
+ ///
+ /// The input to interpret and execute.
+ public void Interpret(string input)
+ {
+ if (string.IsNullOrEmpty(input))
+ {
+ return;
+ }
+
+ DateTime timeStart = DateTime.Now;
+ this.message = string.Empty;
+
+ UTF8Encoding encoder = new UTF8Encoding();
+ Parser p = new Parser(new Scanner(new MemoryStream(encoder.GetBytes(input))));
+ p.Interpreter = this;
+ try
+ {
+ p.Parse();
+ this.calculatedValue = p.CalculatedValue;
+ if (p.errors.count > 0)
+ {
+ ProduceOutput(this.calculatedValue, p.errors.errMsgFormat);
+ }
+ }
+ catch (Exception e)
+ {
+ this.calculatedValue = 0;
+ ProduceOutput(this.calculatedValue, e.Message);
+ }
+
+ DateTime timeEnd = DateTime.Now;
+ this.executionTime = timeEnd - timeStart;
+ }
+
+ ///
+ /// Computes an expression and returns the result as a decimal.
+ ///
+ /// The expression to be calculated.
+ /// The value that was computed.
+ public decimal ComputeExpression(string expression)
+ {
+ this.Interpret(expression);
+ return this.calculatedValue;
+ }
+
+ ///
+ /// Assigns a decimal value to a variable.
+ ///
+ /// The name of the variable.
+ /// The value of the variable.
+ /// True if the variable was set, false otherwise.
+ internal bool Assign(string name, decimal value)
+ {
+ Variable v = new Variable();
+ v.Type = VariableType.Decimal;
+ v.Value = value;
+
+ if (!this.variables.ContainsKey(name))
+ {
+ this.variables.Add(name, v);
+ }
+ else
+ {
+ this.variables[name] = v;
+ }
+
+ return true;
+ }
+
+ ///
+ /// Assigns a decimal value to a variable.
+ ///
+ /// The name of the variable.
+ /// The expression of the variable.
+ /// True if the variable was set, false otherwise.
+ internal bool Assign(string name, string expression)
+ {
+ Variable v = new Variable();
+ v.Type = VariableType.Equation;
+ v.Value = expression;
+
+ if (!this.variables.ContainsKey(name))
+ {
+ this.variables.Add(name, v);
+ }
+ else
+ {
+ this.variables[name] = v;
+ }
+
+ return true;
+ }
+
+ ///
+ /// Assigns a decimal value to a variable.
+ ///
+ /// The name of the variable.
+ /// The values of the variable.
+ /// True if the variable was set, false otherwise.
+ internal bool Assign(string name, decimal[] values)
+ {
+ Variable v = new Variable();
+ v.Type = VariableType.Array;
+ v.Value = values;
+
+ if (!this.variables.ContainsKey(name))
+ {
+ this.variables.Add(name, v);
+ }
+ else
+ {
+ this.variables[name] = v;
+ }
+
+ return true;
+ }
+
+ ///
+ /// Executes a function stored in the interpreter.
+ ///
+ /// The name of the function to execute.
+ /// The arguments to pass to the function.
+ /// The value computed from the function execution.
+ internal decimal ExecuteFunction(string name, decimal[] args)
+ {
+ foreach (ICodedFunction codedFunction in this.codedFunctions)
+ {
+ if (codedFunction.FunctionName == name)
+ {
+ return codedFunction.Execute(args);
+ }
+ }
+
+ foreach (InterpretedFunction interpretedFunction in this.interpretedFunctions)
+ {
+ if (interpretedFunction.Name == name)
+ {
+ string answer = interpretedFunction.Compute(args);
+ decimal parsed = 0;
+ if (decimal.TryParse(answer, out parsed))
+ {
+ return parsed;
+ }
+ }
+ }
+
+ return 0;
+ }
+
+ #endregion
+
+ #region Private Methods
+
+ ///
+ /// Loads the default coded functions supported by the interpreter.
+ ///
+ private void LoadDefaultCodedFunctions()
+ {
+ this.codedFunctions.Add(new CF_Sin());
+ this.codedFunctions.Add(new CF_Cos());
+ this.codedFunctions.Add(new CF_Tan());
+ this.codedFunctions.Add(new CF_Round());
+ this.codedFunctions.Add(new CF_Sqrt());
+ this.codedFunctions.Add(new CF_Abs());
+ this.codedFunctions.Add(new CF_Exp());
+ this.codedFunctions.Add(new CF_Log());
+ this.codedFunctions.Add(new CF_Precision());
+ }
+
+ ///
+ /// Produces output given a single object.
+ ///
+ /// The object representing the output.
+ internal void ProduceOutput(object output)
+ {
+ if (output is bool)
+ {
+ bool o = (bool)output;
+ if (o)
+ {
+ this.calculatedValue = 1;
+ }
+ else
+ {
+ this.calculatedValue = 0;
+ }
+ }
+ this.output = string.Format("{0}", output);
+ }
+
+ ///
+ /// Produces output given an object and a message.
+ ///
+ /// The object representing the output.
+ /// The message to be displayed with the output.
+ private void ProduceOutput(object output, string message)
+ {
+ if (!string.IsNullOrEmpty(message))
+ {
+ this.output = string.Format("{0}", output);
+ this.message = message;
+ }
+ else
+ {
+ ProduceOutput(output);
+ this.message = string.Empty;
+ }
+ }
+
+ #endregion
+
+ #region Asynchronous
+
+ /// Interpret an input asynchronously.
+ /// The input to interpret and execute.
+ /// The callback.
+ public void InterpretAsync(string input, Action callback)
+ {
+ InterpretAsyncDelegate del = new InterpretAsyncDelegate(InterpretAsyncThreadingWork);
+ del.BeginInvoke(input, (result) =>
+ {
+ AsyncResult returned = result as AsyncResult;
+ if (returned != null)
+ {
+ InterpretAsyncDelegate end = returned.AsyncDelegate as InterpretAsyncDelegate;
+ if (end != null)
+ {
+ InputInterpreter returnValue = end.EndInvoke(result);
+ callback(returnValue);
+ }
+ }
+ }, null);
+ }
+
+ /// Interpret asynchronous threading work.
+ /// The input to interpret and execute.
+ private InputInterpreter InterpretAsyncThreadingWork(string input)
+ {
+ Interpret(input);
+ return this;
+ }
+
+ /// Interpret asynchronous delegate.
+ /// The input.
+ /// .
+ private delegate InputInterpreter InterpretAsyncDelegate(string input);
+
+ #endregion
+
+ #region Computable
+
+ /// Converts this object to a computable.
+ /// This object as a Computable.
+ public Computable ToComputable()
+ {
+ return new Computable(this.Decimal.ToString(), this);
+ }
+
+ /// Treats the current object as a computable and performs an action in that context.
+ /// The action to execute as a computable object.
+ /// This object as a Computable, after the given action.
+ public Computable AsComputable(Func action)
+ {
+ return action(this.ToComputable());
+ }
+
+ #endregion
+ }
+}
diff --git a/CS-MIC/csmic/csmic/InterpretedFunction.cs b/CS-MIC/csmic/csmic/InterpretedFunction.cs
new file mode 100644
index 0000000..70c29d6
--- /dev/null
+++ b/CS-MIC/csmic/csmic/InterpretedFunction.cs
@@ -0,0 +1,151 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace csmic
+{
+ ///
+ /// Represents a user defined function that can be executed by the interpreter.
+ ///
+ public class InterpretedFunction
+ {
+ #region Members
+
+ ///
+ /// The name of the function.
+ ///
+ private string name;
+ ///
+ /// The number of expected arguments.
+ ///
+ private int numExpectedArguments;
+ ///
+ /// The set of instructions to be passed to the internal inputInterpreter.
+ ///
+ private MacroOperation script;
+ ///
+ /// A set of arguments used in computation of the function.
+ ///
+ private InterpretedFunctionArgument[] arguments;
+ ///
+ /// The internal macro builder used for computation.
+ ///
+ private MacroBuilder macroFunction;
+ ///
+ /// The internal input inputInterpreter that macro builder will use for computation.
+ ///
+ private InputInterpreter interpreter;
+
+ #endregion
+
+ #region Constructor
+
+ ///
+ /// Creates a new interpreted function.
+ ///
+ /// The name of the fuction.
+ /// The node to be used in computation.
+ /// A set of argument names to be used in computation.
+ internal InterpretedFunction(string name, MacroOperation script, params string[] args)
+ {
+ this.name = name;
+ this.script = script;
+ this.macroFunction = null;
+ this.arguments = new InterpretedFunctionArgument[args.Length];
+ this.interpreter = new InputInterpreter();
+ this.numExpectedArguments = args.Length;
+
+ for (int i = 0; i < args.Length; i++)
+ {
+ this.arguments[i] = new InterpretedFunctionArgument(args[i], 0);
+ }
+ }
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// Gets the name of the function.
+ ///
+ public string Name
+ {
+ get
+ {
+ return this.name;
+ }
+ }
+
+ ///
+ /// Gets the number of expected arguments for the function.
+ ///
+ public int NumExpectedArguments
+ {
+ get
+ {
+ return this.numExpectedArguments;
+ }
+ }
+
+ #endregion
+
+ #region Public Methods
+
+ ///
+ /// Computes the value of the function.
+ ///
+ /// The arguments used for computation.
+ /// The decimal value computed by the function.
+ public string Compute(params decimal[] args)
+ {
+ if (args.Length != this.numExpectedArguments)
+ {
+ return "0";
+ }
+
+ if (args.Length == this.arguments.Length)
+ {
+ for (int i = 0; i < args.Length; i++)
+ {
+ this.arguments[i].Value = args[i];
+ }
+ }
+
+ foreach (InterpretedFunctionArgument argument in this.arguments)
+ {
+ this.interpreter.Interpret(string.Format("{0} :: {1}", argument.Name, argument.Value));
+ }
+
+ this.macroFunction = new MacroBuilder(this.script, this.interpreter);
+
+ return this.macroFunction.FinalOutput;
+ }
+
+ #endregion
+
+ ///
+ /// Because a function's internal pattern may be different, we must manually check to see if the function
+ /// names are the same.
+ ///
+ /// The object to test.
+ /// True if the functions are the same.
+ public override bool Equals(object obj)
+ {
+ InterpretedFunction fun = obj as InterpretedFunction;
+ if(fun != null)
+ {
+ return fun.name == this.name;
+ }
+
+ return false;
+ }
+
+ /// Serves as a hash function for a particular type.
+ /// A hash code for the current .
+ public override int GetHashCode()
+ {
+ return this.script.GetHashCode() & this.name.GetHashCode();
+ }
+ }
+}
diff --git a/CS-MIC/csmic/csmic/InterpretedFunctionArgument.cs b/CS-MIC/csmic/csmic/InterpretedFunctionArgument.cs
new file mode 100644
index 0000000..2338b6e
--- /dev/null
+++ b/CS-MIC/csmic/csmic/InterpretedFunctionArgument.cs
@@ -0,0 +1,84 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace csmic
+{
+ ///
+ /// Represents an argument made in an interpreted function.
+ ///
+ public class InterpretedFunctionArgument
+ {
+ #region Members
+
+ ///
+ /// The name of the argument.
+ ///
+ private string name;
+ ///
+ /// The value of the argument.
+ ///
+ private decimal value;
+
+ #endregion
+
+ #region Constructors
+
+ ///
+ /// Creates a new interpreted function argument.
+ ///
+ public InterpretedFunctionArgument()
+ {
+ this.name = string.Empty;
+ this.value = 0;
+ }
+
+ ///
+ /// Creates a new interpreted function argument.
+ ///
+ /// The name of the argument in the interpreted function.
+ /// The value of the argument to use in the interpreted function.
+ public InterpretedFunctionArgument(string name, decimal value)
+ {
+ this.name = name;
+ this.value = value;
+ }
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// Gets or sets the name of the argument.
+ ///
+ public string Name
+ {
+ get
+ {
+ return this.name;
+ }
+ set
+ {
+ this.name = value;
+ }
+ }
+
+ ///
+ /// Gets or sets the value of the argument.
+ ///
+ public decimal Value
+ {
+ get
+ {
+ return this.value;
+ }
+ set
+ {
+ this.value = value;
+ }
+ }
+
+ #endregion
+ }
+}
diff --git a/CS-MIC/csmic/csmic/InterpreterParser/CSMIC.atg b/CS-MIC/csmic/csmic/InterpreterParser/CSMIC.atg
new file mode 100644
index 0000000..eb741c0
--- /dev/null
+++ b/CS-MIC/csmic/csmic/InterpreterParser/CSMIC.atg
@@ -0,0 +1,369 @@
+using csmic;
+using System.Text;
+using System.Collections.Generic;
+
+COMPILER CSMIC
+
+/*
+*
+* Class Structures
+*
+*/
+
+private decimal calcValue = 0;
+private string stringValue = string.Empty;
+
+public decimal CalculatedValue
+{
+ get
+ {
+ return this.calcValue;
+ }
+ set
+ {
+ this.calcValue = value;
+ }
+}
+
+private InputInterpreter interpreter = null;
+
+public InputInterpreter Interpreter
+{
+ get
+ {
+ return this.interpreter;
+ }
+ set
+ {
+ this.interpreter = value;
+ }
+}
+
+bool IsFunctionCall()
+{
+ scanner.ResetPeek();
+ Token next = scanner.Peek();
+ if (next.kind == _LPAREN && la.kind == _identifier)
+ return true;
+ return false;
+}
+
+bool IsCompare()
+{
+ scanner.ResetPeek();
+ Token next = scanner.Peek();
+ if (next.kind == _COMPARER)
+ return true;
+ return false;
+}
+
+bool IsAssignment()
+{
+ scanner.ResetPeek();
+ Token next = scanner.Peek();
+ if (next.val == "::" || next.val == ":=" || next.val == "->")
+ return true;
+ return false;
+}
+
+bool IsArrayCall()
+{
+ scanner.ResetPeek();
+ Token next = scanner.Peek();
+ if(next.val == "[")
+ return true;
+ return false;
+}
+
+CHARACTERS
+
+ UpperLetter = 'A'..'Z'.
+ LowerLetter = 'a'..'z'.
+ letter = UpperLetter + LowerLetter.
+ digit = "0123456789" .
+ cr = '\r' .
+ lf = '\n' .
+ tab = '\t' .
+ PM = "+-" .
+ NoQuote = ANY - '\"' .
+
+TOKENS
+
+ identifier = letter { letter | digit}.
+ sign = PM .
+ binary = ( '0' | '1' ) { '0' | '1' } ('B' | 'b') .
+ hex = "0x" ( digit | ('A' | 'B' | 'C' | 'D' | 'E' |'F') | ('a' | 'b' | 'c' | 'd' | 'e' |'f') ) { digit | ('A' | 'B' | 'C' | 'D' | 'E' |'F') | ('a' | 'b' | 'c' | 'd' | 'e' |'f') } .
+ number = digit { digit }['.' {digit}] [('E'|'e')['+'|'-'] digit {digit}] .
+ string = "\"" { NoQuote } "\"" .
+ LPAREN = '(' .
+ RPAREN = ')' .
+ COMPARER = "==" | "<" | ">" | "<=" | ">=" .
+
+IGNORE cr + tab
+
+/*
+ * Parser specification
+ *
+ */
+
+PRODUCTIONS
+
+CSMIC (. decimal r = 0;
+ string s = string.Empty;
+ decimal[] a = new decimal[0];
+ bool success = true;
+ if(this.interpreter == null)
+ {
+ return;
+ }
+ .)
+=
+ IF(IsCompare())
+ Comparison (. this.calcValue = (success == true) ? 1 : 0; this.interpreter.ProduceOutput(success); .)
+ |
+ IF(IsAssignment())
+ Assignment (. this.calcValue = r; .)
+ |
+ Expression (. this.calcValue = r; this.interpreter.ProduceOutput(r); .)
+ |
+ String (. this.stringValue = s; this.interpreter.ProduceOutput(s); .)
+.
+
+String
+=
+ string (. s = t.val; .)
+
+.
+
+Expression
+=
+ (. decimal r1; .)
+Term
+{
+ '+' Term (. r += r1; .)
+|
+ '-' Term (. r -= r1; .)
+}
+.
+
+Term (. decimal r1; .)
+=
+ Factor
+ {
+ '*'
+ Factor (. r *= r1; .)
+|
+ '/'
+ Factor (. r /= r1; .)
+|
+ '%' Term (. r %= r1; .)
+}
+.
+
+Factor (. decimal r1; .)
+=
+ Value
+ {
+ '^'
+ Expression (. r = Convert.ToDecimal(Math.Pow(Convert.ToDouble(r), Convert.ToDouble(r1))); .)
+ }
+.
+
+Value (. r = 0;
+ decimal r1 = 0;
+ string fn;
+ int sign = 1;.)
+=
+
+ [
+ "+"
+ |
+ "-" (. sign = -1; .)
+ ]
+(
+ IF(IsFunctionCall())
+ Function (. r = sign * r; .)
+|
+ IF(IsArrayCall())
+ ArrayCall (. r = sign * r; .)
+|
+ identifier (. if(this.interpreter.variables.ContainsKey(t.val))
+ {
+ Variable v = this.interpreter.variables[t.val];
+ if(v.Type == VariableType.Equation)
+ {
+ InputInterpreter i = new InputInterpreter(this.interpreter);
+ i.Interpret(v.Value.ToString());
+ r = i.Decimal;
+ }
+ else if(v.Type == VariableType.Decimal)
+ {
+ r = Convert.ToDecimal(v.Value);
+ }
+ else
+ {
+ r = 0;
+ }
+ }
+ .)
+|
+ number (. r = sign * Convert.ToDecimal (t.val); .)
+|
+ hex (. string expression = t.val.Remove(0,2);
+ try
+ {
+ decimal value = Convert.ToDecimal(Convert.ToInt64(expression, 16));
+ r = sign * value;
+ }
+ catch
+ {
+ r = 0;
+ }
+ .)
+|
+ binary (. string expression = t.val.Remove(t.val.Length - 1);
+ try
+ {
+ decimal value = Convert.ToDecimal(Convert.ToInt64(expression, 2));
+ r = sign * value;
+ }
+ catch
+ {
+ r = 0;
+ }
+ .)
+|
+ '('
+ Expression
+ ')' (. r = sign * r; .)
+)
+.
+
+ArrayL
+=
+'['
+CommaList
+']'
+.
+
+ArrayCall (. string ident = string.Empty; r = 0; decimal pos = 0; .)
+=
+identifier (. ident = t.val; .)
+'['
+ Expression (. int i = 0;
+ try
+ {
+ i = Convert.ToInt32(pos);
+ if(this.interpreter.variables.ContainsKey(ident))
+ {
+ decimal[] values = this.interpreter.variables[ident].Value as decimal[];
+ if(values != null)
+ {
+ r = values[i];
+ }
+ }
+ }
+ catch
+ {
+ }
+ .)
+']'
+.
+
+CommaList (. List list = new List(); decimal r = 0; .)
+=
+Expression (. list.Add(r); d = list.ToArray(); .)
+{
+ ','
+ Expression (. list.Add(r); d = list.ToArray(); .)
+}
+.
+
+Assignment (.
+ string identifier = string.Empty;
+ string expression = string.Empty;
+ decimal[] d = new decimal[0];
+ r = 0;
+ .)
+=
+identifier (. identifier = t.val; .)
+(
+ (
+ "::"
+ Expression (. this.interpreter.Assign(identifier, r); .)
+ (. this.interpreter.ProduceOutput(r); .)
+ )
+ |
+ (
+ ":="
+ AnyExpression (. this.interpreter.Assign(identifier, expression); .)
+ (. this.interpreter.ProduceOutput(expression); .)
+ )
+ |
+ (
+ "->"
+ ArrayL (. this.interpreter.Assign(identifier, d); r = 0; .)
+ (.
+ StringBuilder builder = new StringBuilder();
+ foreach(decimal dec in d)
+ {
+ builder.Append("," + dec.ToString());
+ }
+ builder.Remove(0,1);
+ this.interpreter.ProduceOutput(builder.ToString());
+ .)
+ )
+)
+.
+
+Function (.
+ string functionName = string.Empty;
+ decimal[] d = new decimal[0];
+ .)
+=
+identifier (. functionName = t.val; .)
+'('
+CommaList
+')' (. r = this.interpreter.ExecuteFunction(functionName, d); .)
+.
+
+Comparison (.
+ decimal firstValue = 0;
+ decimal secondValue = 0;
+ string compareType = string.Empty;
+ .)
+=
+Expression
+COMPARER (. compareType = t.val; .)
+Expression (.
+ switch(compareType)
+ {
+ case "==":
+ result = (firstValue == secondValue);
+ break;
+ case ">":
+ result = (firstValue > secondValue);
+ break;
+ case "<":
+ result = (firstValue < secondValue);
+ break;
+ case ">=":
+ result = (firstValue >= secondValue);
+ break;
+ case "<=":
+ result = (firstValue <= secondValue);
+ break;
+ default:
+ result = false;
+ break;
+ }
+ .)
+.
+
+AnyExpression (. value = string.Empty; StringBuilder builder = new StringBuilder(); .)
+=
+ANY (. builder.Append(t.val); .) { ANY (. builder.Append(t.val); .) } (. value = builder.ToString(); .)
+.
+
+
+END CSMIC.
\ No newline at end of file
diff --git a/CS-MIC/csmic/csmic/InterpreterParser/Parser.cs b/CS-MIC/csmic/csmic/InterpreterParser/Parser.cs
new file mode 100644
index 0000000..5e3e549
--- /dev/null
+++ b/CS-MIC/csmic/csmic/InterpreterParser/Parser.cs
@@ -0,0 +1,530 @@
+using csmic;
+using System.Text;
+using System.Collections.Generic;
+
+
+
+using System;
+
+namespace csmic.Interpreter {
+
+
+
+public class Parser {
+ public const int _EOF = 0;
+ public const int _identifier = 1;
+ public const int _sign = 2;
+ public const int _binary = 3;
+ public const int _hex = 4;
+ public const int _number = 5;
+ public const int _string = 6;
+ public const int _LPAREN = 7;
+ public const int _RPAREN = 8;
+ public const int _COMPARER = 9;
+ public const int maxT = 22;
+
+ const bool _T = true;
+ const bool _x = false;
+ const int minErrDist = 2;
+
+ public Scanner scanner;
+ public Errors errors;
+
+ public Token t; // last recognized token
+ public Token la; // lookahead token
+ int errDist = minErrDist;
+
+private decimal calcValue = 0;
+private string stringValue = string.Empty;
+
+public decimal CalculatedValue
+{
+ get
+ {
+ return this.calcValue;
+ }
+ set
+ {
+ this.calcValue = value;
+ }
+}
+
+private InputInterpreter interpreter = null;
+
+public InputInterpreter Interpreter
+{
+ get
+ {
+ return this.interpreter;
+ }
+ set
+ {
+ this.interpreter = value;
+ }
+}
+
+bool IsFunctionCall()
+{
+ scanner.ResetPeek();
+ Token next = scanner.Peek();
+ if (next.kind == _LPAREN && la.kind == _identifier)
+ return true;
+ return false;
+}
+
+bool IsCompare()
+{
+ scanner.ResetPeek();
+ Token next = scanner.Peek();
+ if (next.kind == _COMPARER)
+ return true;
+ return false;
+}
+
+bool IsAssignment()
+{
+ scanner.ResetPeek();
+ Token next = scanner.Peek();
+ if (next.val == "::" || next.val == ":=" || next.val == "->")
+ return true;
+ return false;
+}
+
+bool IsArrayCall()
+{
+ scanner.ResetPeek();
+ Token next = scanner.Peek();
+ if(next.val == "[")
+ return true;
+ return false;
+}
+
+
+
+ public Parser(Scanner scanner) {
+ this.scanner = scanner;
+ errors = new Errors();
+ }
+
+ void SynErr (int n) {
+ if (errDist >= minErrDist) errors.SynErr(la.line, la.col, n);
+ errDist = 0;
+ }
+
+ public void SemErr (string msg) {
+ if (errDist >= minErrDist) errors.SemErr(t.line, t.col, msg);
+ errDist = 0;
+ }
+
+ void Get () {
+ for (;;) {
+ t = la;
+ la = scanner.Scan();
+ if (la.kind <= maxT) { ++errDist; break; }
+
+ la = t;
+ }
+ }
+
+ void Expect (int n) {
+ if (la.kind==n) Get(); else { SynErr(n); }
+ }
+
+ bool StartOf (int s) {
+ return set[s, la.kind];
+ }
+
+ void ExpectWeak (int n, int follow) {
+ if (la.kind == n) Get();
+ else {
+ SynErr(n);
+ while (!StartOf(follow)) Get();
+ }
+ }
+
+
+ bool WeakSeparator(int n, int syFol, int repFol) {
+ int kind = la.kind;
+ if (kind == n) {Get(); return true;}
+ else if (StartOf(repFol)) {return false;}
+ else {
+ SynErr(n);
+ while (!(set[syFol, kind] || set[repFol, kind] || set[0, kind])) {
+ Get();
+ kind = la.kind;
+ }
+ return StartOf(syFol);
+ }
+ }
+
+
+ void CSMIC() {
+ decimal r = 0;
+ string s = string.Empty;
+ decimal[] a = new decimal[0];
+ bool success = true;
+ if(this.interpreter == null)
+ {
+ return;
+ }
+
+ if (IsCompare()) {
+ Comparison(out success);
+ this.calcValue = (success == true) ? 1 : 0; this.interpreter.ProduceOutput(success);
+ } else if (IsAssignment()) {
+ Assignment(out r);
+ this.calcValue = r;
+ } else if (StartOf(1)) {
+ Expression(out r);
+ this.calcValue = r; this.interpreter.ProduceOutput(r);
+ } else if (la.kind == 6) {
+ String(out s);
+ this.stringValue = s; this.interpreter.ProduceOutput(s);
+ } else SynErr(23);
+ }
+
+ void Comparison(out bool result) {
+ decimal firstValue = 0;
+ decimal secondValue = 0;
+ string compareType = string.Empty;
+
+ Expression(out firstValue);
+ Expect(9);
+ compareType = t.val;
+ Expression(out secondValue);
+ switch(compareType)
+ {
+ case "==":
+ result = (firstValue == secondValue);
+ break;
+ case ">":
+ result = (firstValue > secondValue);
+ break;
+ case "<":
+ result = (firstValue < secondValue);
+ break;
+ case ">=":
+ result = (firstValue >= secondValue);
+ break;
+ case "<=":
+ result = (firstValue <= secondValue);
+ break;
+ default:
+ result = false;
+ break;
+ }
+
+ }
+
+ void Assignment(out decimal r) {
+ string identifier = string.Empty;
+ string expression = string.Empty;
+ decimal[] d = new decimal[0];
+ r = 0;
+
+ Expect(1);
+ identifier = t.val;
+ if (la.kind == 19) {
+ Get();
+ Expression(out r);
+ this.interpreter.Assign(identifier, r);
+ this.interpreter.ProduceOutput(r);
+ } else if (la.kind == 20) {
+ Get();
+ AnyExpression(out expression);
+ this.interpreter.Assign(identifier, expression);
+ this.interpreter.ProduceOutput(expression);
+ } else if (la.kind == 21) {
+ Get();
+ ArrayL(out d);
+ this.interpreter.Assign(identifier, d); r = 0;
+ StringBuilder builder = new StringBuilder();
+ foreach(decimal dec in d)
+ {
+ builder.Append("," + dec.ToString());
+ }
+ builder.Remove(0,1);
+ this.interpreter.ProduceOutput(builder.ToString());
+
+ } else SynErr(24);
+ }
+
+ void Expression(out decimal r) {
+ decimal r1;
+ Term(out r);
+ while (la.kind == 10 || la.kind == 11) {
+ if (la.kind == 10) {
+ Get();
+ Term(out r1);
+ r += r1;
+ } else {
+ Get();
+ Term(out r1);
+ r -= r1;
+ }
+ }
+ }
+
+ void String(out string s) {
+ Expect(6);
+ s = t.val;
+ }
+
+ void Term(out decimal r) {
+ decimal r1;
+ Factor(out r);
+ while (la.kind == 12 || la.kind == 13 || la.kind == 14) {
+ if (la.kind == 12) {
+ Get();
+ Factor(out r1);
+ r *= r1;
+ } else if (la.kind == 13) {
+ Get();
+ Factor(out r1);
+ r /= r1;
+ } else {
+ Get();
+ Term(out r1);
+ r %= r1;
+ }
+ }
+ }
+
+ void Factor(out decimal r) {
+ decimal r1;
+ Value(out r);
+ while (la.kind == 15) {
+ Get();
+ Expression(out r1);
+ r = Convert.ToDecimal(Math.Pow(Convert.ToDouble(r), Convert.ToDouble(r1)));
+ }
+ }
+
+ void Value(out decimal r) {
+ r = 0;
+ decimal r1 = 0;
+ string fn;
+ int sign = 1;
+ if (la.kind == 10 || la.kind == 11) {
+ if (la.kind == 10) {
+ Get();
+ } else {
+ Get();
+ sign = -1;
+ }
+ }
+ if (IsFunctionCall()) {
+ Function(out r);
+ r = sign * r;
+ } else if (IsArrayCall()) {
+ ArrayCall(out r);
+ r = sign * r;
+ } else if (la.kind == 1) {
+ Get();
+ if(this.interpreter.variables.ContainsKey(t.val))
+ {
+ Variable v = this.interpreter.variables[t.val];
+ if(v.Type == VariableType.Equation)
+ {
+ InputInterpreter i = new InputInterpreter(this.interpreter);
+ i.Interpret(v.Value.ToString());
+ r = i.Decimal;
+ }
+ else if(v.Type == VariableType.Decimal)
+ {
+ r = Convert.ToDecimal(v.Value);
+ }
+ else
+ {
+ r = 0;
+ }
+ }
+
+ } else if (la.kind == 5) {
+ Get();
+ r = sign * Convert.ToDecimal (t.val);
+ } else if (la.kind == 4) {
+ Get();
+ string expression = t.val.Remove(0,2);
+ try
+ {
+ decimal value = Convert.ToDecimal(Convert.ToInt64(expression, 16));
+ r = sign * value;
+ }
+ catch
+ {
+ r = 0;
+ }
+
+ } else if (la.kind == 3) {
+ Get();
+ string expression = t.val.Remove(t.val.Length - 1);
+ try
+ {
+ decimal value = Convert.ToDecimal(Convert.ToInt64(expression, 2));
+ r = sign * value;
+ }
+ catch
+ {
+ r = 0;
+ }
+
+ } else if (la.kind == 7) {
+ Get();
+ Expression(out r);
+ Expect(8);
+ r = sign * r;
+ } else SynErr(25);
+ }
+
+ void Function(out decimal r) {
+ string functionName = string.Empty;
+ decimal[] d = new decimal[0];
+
+ Expect(1);
+ functionName = t.val;
+ Expect(7);
+ CommaList(out d);
+ Expect(8);
+ r = this.interpreter.ExecuteFunction(functionName, d);
+ }
+
+ void ArrayCall(out decimal r) {
+ string ident = string.Empty; r = 0; decimal pos = 0;
+ Expect(1);
+ ident = t.val;
+ Expect(16);
+ Expression(out pos);
+ int i = 0;
+ try
+ {
+ i = Convert.ToInt32(pos);
+ if(this.interpreter.variables.ContainsKey(ident))
+ {
+ decimal[] values = this.interpreter.variables[ident].Value as decimal[];
+ if(values != null)
+ {
+ r = values[i];
+ }
+ }
+ }
+ catch
+ {
+ }
+
+ Expect(17);
+ }
+
+ void ArrayL(out decimal[] d) {
+ Expect(16);
+ CommaList(out d);
+ Expect(17);
+ }
+
+ void CommaList(out decimal[] d) {
+ List list = new List(); decimal r = 0;
+ Expression(out r);
+ list.Add(r); d = list.ToArray();
+ while (la.kind == 18) {
+ Get();
+ Expression(out r);
+ list.Add(r); d = list.ToArray();
+ }
+ }
+
+ void AnyExpression(out string value) {
+ value = string.Empty; StringBuilder builder = new StringBuilder();
+ Get();
+ builder.Append(t.val);
+ while (StartOf(2)) {
+ Get();
+ builder.Append(t.val);
+ }
+ value = builder.ToString();
+ }
+
+
+
+ public void Parse() {
+ la = new Token();
+ la.val = "";
+ Get();
+ CSMIC();
+ Expect(0);
+
+ }
+
+ static readonly bool[,] set = {
+ {_T,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x},
+ {_x,_T,_x,_T, _T,_T,_x,_T, _x,_x,_T,_T, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x},
+ {_x,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_x}
+
+ };
+} // end Parser
+
+
+public class Errors {
+ public int count = 0; // number of errors detected
+ public System.IO.TextWriter errorStream = Console.Out; // error messages go to this stream
+ public string errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text
+
+ public virtual void SynErr (int line, int col, int n) {
+ string s;
+ switch (n) {
+ case 0: s = "EOF expected"; break;
+ case 1: s = "identifier expected"; break;
+ case 2: s = "sign expected"; break;
+ case 3: s = "binary expected"; break;
+ case 4: s = "hex expected"; break;
+ case 5: s = "number expected"; break;
+ case 6: s = "string expected"; break;
+ case 7: s = "LPAREN expected"; break;
+ case 8: s = "RPAREN expected"; break;
+ case 9: s = "COMPARER expected"; break;
+ case 10: s = "\"+\" expected"; break;
+ case 11: s = "\"-\" expected"; break;
+ case 12: s = "\"*\" expected"; break;
+ case 13: s = "\"/\" expected"; break;
+ case 14: s = "\"%\" expected"; break;
+ case 15: s = "\"^\" expected"; break;
+ case 16: s = "\"[\" expected"; break;
+ case 17: s = "\"]\" expected"; break;
+ case 18: s = "\",\" expected"; break;
+ case 19: s = "\"::\" expected"; break;
+ case 20: s = "\":=\" expected"; break;
+ case 21: s = "\"->\" expected"; break;
+ case 22: s = "??? expected"; break;
+ case 23: s = "invalid CSMIC"; break;
+ case 24: s = "invalid Assignment"; break;
+ case 25: s = "invalid Value"; break;
+
+ default: s = "error " + n; break;
+ }
+ errorStream.WriteLine(errMsgFormat, line, col, s);
+ count++;
+ }
+
+ public virtual void SemErr (int line, int col, string s) {
+ errorStream.WriteLine(errMsgFormat, line, col, s);
+ count++;
+ }
+
+ public virtual void SemErr (string s) {
+ errorStream.WriteLine(s);
+ count++;
+ }
+
+ public virtual void Warning (int line, int col, string s) {
+ errorStream.WriteLine(errMsgFormat, line, col, s);
+ }
+
+ public virtual void Warning(string s) {
+ errorStream.WriteLine(s);
+ }
+} // Errors
+
+
+public class FatalError: Exception {
+ public FatalError(string m): base(m) {}
+}
+}
\ No newline at end of file
diff --git a/CS-MIC/csmic/csmic/InterpreterParser/Parser.cs.old b/CS-MIC/csmic/csmic/InterpreterParser/Parser.cs.old
new file mode 100644
index 0000000..0c45f1e
--- /dev/null
+++ b/CS-MIC/csmic/csmic/InterpreterParser/Parser.cs.old
@@ -0,0 +1,530 @@
+using csmic;
+using System.Text;
+using System.Collections.Generic;
+
+
+
+using System;
+
+namespace csmic.Interpreter {
+
+
+
+public class Parser {
+ public const int _EOF = 0;
+ public const int _identifier = 1;
+ public const int _sign = 2;
+ public const int _binary = 3;
+ public const int _hex = 4;
+ public const int _number = 5;
+ public const int _string = 6;
+ public const int _LPAREN = 7;
+ public const int _RPAREN = 8;
+ public const int _COMPARER = 9;
+ public const int maxT = 22;
+
+ const bool _T = true;
+ const bool _x = false;
+ const int minErrDist = 2;
+
+ public Scanner scanner;
+ public Errors errors;
+
+ public Token t; // last recognized token
+ public Token la; // lookahead token
+ int errDist = minErrDist;
+
+private decimal calcValue = 0;
+private string stringValue = string.Empty;
+
+public decimal CalculatedValue
+{
+ get
+ {
+ return this.calcValue;
+ }
+ set
+ {
+ this.calcValue = value;
+ }
+}
+
+private InputInterpreter interpreter = null;
+
+public InputInterpreter Interpreter
+{
+ get
+ {
+ return this.interpreter;
+ }
+ set
+ {
+ this.interpreter = value;
+ }
+}
+
+bool IsFunctionCall()
+{
+ scanner.ResetPeek();
+ Token next = scanner.Peek();
+ if (next.kind == _LPAREN && la.kind == _identifier)
+ return true;
+ return false;
+}
+
+bool IsCompare()
+{
+ scanner.ResetPeek();
+ Token next = scanner.Peek();
+ if (next.kind == _COMPARER)
+ return true;
+ return false;
+}
+
+bool IsAssignment()
+{
+ scanner.ResetPeek();
+ Token next = scanner.Peek();
+ if (next.val == "::" || next.val == ":=" || next.val == "->")
+ return true;
+ return false;
+}
+
+bool IsArrayCall()
+{
+ scanner.ResetPeek();
+ Token next = scanner.Peek();
+ if(next.val == "[")
+ return true;
+ return false;
+}
+
+
+
+ public Parser(Scanner scanner) {
+ this.scanner = scanner;
+ errors = new Errors();
+ }
+
+ void SynErr (int n) {
+ if (errDist >= minErrDist) errors.SynErr(la.line, la.col, n);
+ errDist = 0;
+ }
+
+ public void SemErr (string msg) {
+ if (errDist >= minErrDist) errors.SemErr(t.line, t.col, msg);
+ errDist = 0;
+ }
+
+ void Get () {
+ for (;;) {
+ t = la;
+ la = scanner.Scan();
+ if (la.kind <= maxT) { ++errDist; break; }
+
+ la = t;
+ }
+ }
+
+ void Expect (int n) {
+ if (la.kind==n) Get(); else { SynErr(n); }
+ }
+
+ bool StartOf (int s) {
+ return set[s, la.kind];
+ }
+
+ void ExpectWeak (int n, int follow) {
+ if (la.kind == n) Get();
+ else {
+ SynErr(n);
+ while (!StartOf(follow)) Get();
+ }
+ }
+
+
+ bool WeakSeparator(int n, int syFol, int repFol) {
+ int kind = la.kind;
+ if (kind == n) {Get(); return true;}
+ else if (StartOf(repFol)) {return false;}
+ else {
+ SynErr(n);
+ while (!(set[syFol, kind] || set[repFol, kind] || set[0, kind])) {
+ Get();
+ kind = la.kind;
+ }
+ return StartOf(syFol);
+ }
+ }
+
+
+ void CSMIC() {
+ decimal r = 0;
+ string s = string.Empty;
+ decimal[] a = new decimal[0];
+ bool success = true;
+ if(this.interpreter == null)
+ {
+ return;
+ }
+
+ if (IsCompare()) {
+ Comparison(out success);
+ this.calcValue = (success == true) ? 1 : 0; this.interpreter.ProduceOutput(success);
+ } else if (IsAssignment()) {
+ Assignment(out r);
+ this.calcValue = r;
+ } else if (StartOf(1)) {
+ Expression(out r);
+ this.calcValue = r; this.interpreter.ProduceOutput(r);
+ } else if (la.kind == 6) {
+ String(out s);
+ this.stringValue = s; this.interpreter.ProduceOutput(s);
+ } else SynErr(23);
+ }
+
+ void Comparison(out bool result) {
+ decimal firstValue = 0;
+ decimal secondValue = 0;
+ string compareType = string.Empty;
+
+ Expression(out firstValue);
+ Expect(9);
+ compareType = t.val;
+ Expression(out secondValue);
+ switch(compareType)
+ {
+ case "==":
+ result = (firstValue == secondValue);
+ break;
+ case ">":
+ result = (firstValue > secondValue);
+ break;
+ case "<":
+ result = (firstValue < secondValue);
+ break;
+ case ">=":
+ result = (firstValue >= secondValue);
+ break;
+ case "<=":
+ result = (firstValue <= secondValue);
+ break;
+ default:
+ result = false;
+ break;
+ }
+
+ }
+
+ void Assignment(out decimal r) {
+ string identifier = string.Empty;
+ string expression = string.Empty;
+ decimal[] d = new decimal[0];
+ r = 0;
+
+ Expect(1);
+ identifier = t.val;
+ if (la.kind == 19) {
+ Get();
+ Expression(out r);
+ this.interpreter.Assign(identifier, r);
+ this.interpreter.ProduceOutput(r);
+ } else if (la.kind == 20) {
+ Get();
+ AnyExpression(out expression);
+ this.interpreter.Assign(identifier, expression);
+ this.interpreter.ProduceOutput(expression);
+ } else if (la.kind == 21) {
+ Get();
+ ArrayL(out d);
+ this.interpreter.Assign(identifier, d); r = 0;
+ StringBuilder builder = new StringBuilder();
+ foreach(decimal dec in d)
+ {
+ builder.Append("," + dec.ToString());
+ }
+ builder.Remove(0,1);
+ this.interpreter.ProduceOutput(builder.ToString());
+
+ } else SynErr(24);
+ }
+
+ void Expression(out decimal r) {
+ decimal r1;
+ Term(out r);
+ while (la.kind == 10 || la.kind == 11) {
+ if (la.kind == 10) {
+ Get();
+ Term(out r1);
+ r += r1;
+ } else {
+ Get();
+ Term(out r1);
+ r -= r1;
+ }
+ }
+ }
+
+ void String(out string s) {
+ Expect(6);
+ s = t.val;
+ }
+
+ void Term(out decimal r) {
+ decimal r1;
+ Factor(out r);
+ while (la.kind == 12 || la.kind == 13 || la.kind == 14) {
+ if (la.kind == 12) {
+ Get();
+ Factor(out r1);
+ r *= r1;
+ } else if (la.kind == 13) {
+ Get();
+ Factor(out r1);
+ r /= r1;
+ } else {
+ Get();
+ Term(out r1);
+ r %= r1;
+ }
+ }
+ }
+
+ void Factor(out decimal r) {
+ decimal r1;
+ Value(out r);
+ while (la.kind == 15) {
+ Get();
+ Expression(out r1);
+ r = Convert.ToDecimal(Math.Pow(Convert.ToDouble(r), Convert.ToDouble(r1)));
+ }
+ }
+
+ void Value(out decimal r) {
+ r = 0;
+ decimal r1 = 0;
+ string fn;
+ int sign = 1;
+ if (la.kind == 10 || la.kind == 11) {
+ if (la.kind == 10) {
+ Get();
+ } else {
+ Get();
+ sign = -1;
+ }
+ }
+ if (IsFunctionCall()) {
+ Function(out r);
+ r = sign * r;
+ } else if (IsArrayCall()) {
+ ArrayCall(out r);
+ r = sign * r;
+ } else if (la.kind == 1) {
+ Get();
+ if(this.interpreter.variables.ContainsKey(t.val))
+ {
+ Variable v = this.interpreter.variables[t.val];
+ if(v.Type == VariableType.Equation)
+ {
+ InputInterpreter i = new InputInterpreter(this.interpreter);
+ i.Interpret(v.Value.ToString());
+ r = i.Decimal;
+ }
+ else if(v.Type == VariableType.Decimal)
+ {
+ r = Convert.ToDecimal(v.Value);
+ }
+ else
+ {
+ r = 0;
+ }
+ }
+
+ } else if (la.kind == 5) {
+ Get();
+ r = sign * Convert.ToDecimal (t.val);
+ } else if (la.kind == 4) {
+ Get();
+ string expression = t.val.Remove(0,2);
+ try
+ {
+ decimal value = Convert.ToDecimal(Convert.ToInt64(expression, 16));
+ r = sign * value;
+ }
+ catch
+ {
+ r = 0;
+ }
+
+ } else if (la.kind == 3) {
+ Get();
+ string expression = t.val.Remove(t.val.Length - 1);
+ try
+ {
+ decimal value = Convert.ToDecimal(Convert.ToInt64(expression, 2));
+ r = sign * value;
+ }
+ catch
+ {
+ r = 0;
+ }
+
+ } else if (la.kind == 7) {
+ Get();
+ Expression(out r);
+ Expect(8);
+ r = sign * r;
+ } else SynErr(25);
+ }
+
+ void Function(out decimal r) {
+ string functionName = string.Empty;
+ decimal[] d = new decimal[0];
+
+ Expect(1);
+ functionName = t.val;
+ Expect(7);
+ CommaList(out d);
+ Expect(8);
+ r = this.interpreter.ExecuteFunction(functionName, d);
+ }
+
+ void ArrayCall(out decimal r) {
+ string ident = string.Empty; r = 0; decimal pos = 0;
+ Expect(1);
+ ident = t.val;
+ Expect(16);
+ Expression(out pos);
+ int i = 0;
+ try
+ {
+ i = Convert.ToInt32(pos);
+ if(this.interpreter.variables.ContainsKey(ident))
+ {
+ decimal[] values = this.interpreter.variables[ident].Value as decimal[];
+ if(values != null)
+ {
+ r = values[i];
+ }
+ }
+ }
+ catch
+ {
+ }
+
+ Expect(17);
+ }
+
+ void ArrayL(out decimal[] d) {
+ Expect(16);
+ CommaList(out d);
+ Expect(17);
+ }
+
+ void CommaList(out decimal[] d) {
+ List list = new List(); decimal r = 0;
+ Expression(out r);
+ list.Add(r); d = list.ToArray();
+ while (la.kind == 18) {
+ Get();
+ Expression(out r);
+ list.Add(r); d = list.ToArray();
+ }
+ }
+
+ void AnyExpression(out string value) {
+ value = string.Empty; StringBuilder builder = new StringBuilder();
+ Get();
+ builder.Append(t.val);
+ while (StartOf(2)) {
+ Get();
+ builder.Append(t.val);
+ }
+ value = builder.ToString();
+ }
+
+
+
+ public void Parse() {
+ la = new Token();
+ la.val = "";
+ Get();
+ CSMIC();
+ Expect(0);
+
+ }
+
+ static readonly bool[,] set = {
+ {_T,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x},
+ {_x,_T,_x,_T, _T,_T,_x,_T, _x,_x,_T,_T, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x},
+ {_x,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_x}
+
+ };
+} // end Parser
+
+
+public class Errors {
+ public int count = 0; // number of errors detected
+ public System.IO.TextWriter errorStream = Console.Out; // error messages go to this stream
+ public string errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text
+
+ public virtual void SynErr (int line, int col, int n) {
+ string s;
+ switch (n) {
+ case 0: s = "EOF expected"; break;
+ case 1: s = "identifier expected"; break;
+ case 2: s = "sign expected"; break;
+ case 3: s = "binary expected"; break;
+ case 4: s = "hex expected"; break;
+ case 5: s = "number expected"; break;
+ case 6: s = "string expected"; break;
+ case 7: s = "LPAREN expected"; break;
+ case 8: s = "RPAREN expected"; break;
+ case 9: s = "COMPARER expected"; break;
+ case 10: s = "\"+\" expected"; break;
+ case 11: s = "\"-\" expected"; break;
+ case 12: s = "\"*\" expected"; break;
+ case 13: s = "\"/\" expected"; break;
+ case 14: s = "\"%\" expected"; break;
+ case 15: s = "\"^\" expected"; break;
+ case 16: s = "\"[\" expected"; break;
+ case 17: s = "\"]\" expected"; break;
+ case 18: s = "\",\" expected"; break;
+ case 19: s = "\"::\" expected"; break;
+ case 20: s = "\":=\" expected"; break;
+ case 21: s = "\"->\" expected"; break;
+ case 22: s = "??? expected"; break;
+ case 23: s = "invalid CSMIC"; break;
+ case 24: s = "invalid Assignment"; break;
+ case 25: s = "invalid Value"; break;
+
+ default: s = "error " + n; break;
+ }
+ errorStream.WriteLine(errMsgFormat, line, col, s);
+ count++;
+ }
+
+ public virtual void SemErr (int line, int col, string s) {
+ errorStream.WriteLine(errMsgFormat, line, col, s);
+ count++;
+ }
+
+ public virtual void SemErr (string s) {
+ errorStream.WriteLine(s);
+ count++;
+ }
+
+ public virtual void Warning (int line, int col, string s) {
+ errorStream.WriteLine(errMsgFormat, line, col, s);
+ }
+
+ public virtual void Warning(string s) {
+ errorStream.WriteLine(s);
+ }
+} // Errors
+
+
+public class FatalError: Exception {
+ public FatalError(string m): base(m) {}
+}
+}
\ No newline at end of file
diff --git a/src/Core/cocor/Parser.frame b/CS-MIC/csmic/csmic/InterpreterParser/Parser.frame
similarity index 96%
rename from src/Core/cocor/Parser.frame
rename to CS-MIC/csmic/csmic/InterpreterParser/Parser.frame
index 6878147..85e022f 100644
--- a/src/Core/cocor/Parser.frame
+++ b/CS-MIC/csmic/csmic/InterpreterParser/Parser.frame
@@ -1,156 +1,156 @@
-/*----------------------------------------------------------------------
-Compiler Generator Coco/R,
-Copyright (c) 1990, 2004 Hanspeter Moessenboeck, University of Linz
-extended by M. Loeberbauer & A. Woess, Univ. of Linz
-with improvements by Pat Terry, Rhodes University
-
-This program is free software; you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation; either version 2, or (at your option) any
-later version.
-
-This program is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License along
-with this program; if not, write to the Free Software Foundation, Inc.,
-59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-As an exception, it is allowed to write an extension of Coco/R that is
-used as a plugin in non-free software.
-
-If not otherwise stated, any source code generated by Coco/R (other than
-Coco/R itself) does not fall under the GNU General Public License.
-----------------------------------------------------------------------*/
--->begin
-using System;
-
--->namespace
-
-public class Parser {
--->constants
- const bool _T = true;
- const bool _x = false;
- const int minErrDist = 2;
-
- public Scanner scanner;
- public Errors errors;
-
- public Token t; // last recognized token
- public Token la; // lookahead token
- int errDist = minErrDist;
-
--->declarations
-
- public Parser(Scanner scanner) {
- this.scanner = scanner;
- errors = new Errors();
- }
-
- void SynErr (int n) {
- if (errDist >= minErrDist) errors.SynErr(la.line, la.col, n);
- errDist = 0;
- }
-
- public void SemErr (string msg) {
- if (errDist >= minErrDist) errors.SemErr(t.line, t.col, msg);
- errDist = 0;
- }
-
- void Get () {
- for (;;) {
- t = la;
- la = scanner.Scan();
- if (la.kind <= maxT) { ++errDist; break; }
--->pragmas
- la = t;
- }
- }
-
- void Expect (int n) {
- if (la.kind==n) Get(); else { SynErr(n); }
- }
-
- bool StartOf (int s) {
- return set[s, la.kind];
- }
-
- void ExpectWeak (int n, int follow) {
- if (la.kind == n) Get();
- else {
- SynErr(n);
- while (!StartOf(follow)) Get();
- }
- }
-
-
- bool WeakSeparator(int n, int syFol, int repFol) {
- int kind = la.kind;
- if (kind == n) {Get(); return true;}
- else if (StartOf(repFol)) {return false;}
- else {
- SynErr(n);
- while (!(set[syFol, kind] || set[repFol, kind] || set[0, kind])) {
- Get();
- kind = la.kind;
- }
- return StartOf(syFol);
- }
- }
-
-
--->productions
-
- public void Parse() {
- la = new Token();
- la.val = "";
- Get();
--->parseRoot
- }
-
- static readonly bool[,] set = {
--->initialization
- };
-} // end Parser
-
-
-public class Errors {
- public int count = 0; // number of errors detected
- public System.IO.TextWriter errorStream = Console.Out; // error messages go to this stream
- public string errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text
-
- public virtual void SynErr (int line, int col, int n) {
- string s;
- switch (n) {
--->errors
- default: s = "error " + n; break;
- }
- errorStream.WriteLine(errMsgFormat, line, col, s);
- count++;
- }
-
- public virtual void SemErr (int line, int col, string s) {
- errorStream.WriteLine(errMsgFormat, line, col, s);
- count++;
- }
-
- public virtual void SemErr (string s) {
- errorStream.WriteLine(s);
- count++;
- }
-
- public virtual void Warning (int line, int col, string s) {
- errorStream.WriteLine(errMsgFormat, line, col, s);
- }
-
- public virtual void Warning(string s) {
- errorStream.WriteLine(s);
- }
-} // Errors
-
-
-public class FatalError: Exception {
- public FatalError(string m): base(m) {}
-}
+/*----------------------------------------------------------------------
+Compiler Generator Coco/R,
+Copyright (c) 1990, 2004 Hanspeter Moessenboeck, University of Linz
+extended by M. Loeberbauer & A. Woess, Univ. of Linz
+with improvements by Pat Terry, Rhodes University
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+As an exception, it is allowed to write an extension of Coco/R that is
+used as a plugin in non-free software.
+
+If not otherwise stated, any source code generated by Coco/R (other than
+Coco/R itself) does not fall under the GNU General Public License.
+----------------------------------------------------------------------*/
+-->begin
+using System;
+
+-->namespace
+
+public class Parser {
+-->constants
+ const bool _T = true;
+ const bool _x = false;
+ const int minErrDist = 2;
+
+ public Scanner scanner;
+ public Errors errors;
+
+ public Token t; // last recognized token
+ public Token la; // lookahead token
+ int errDist = minErrDist;
+
+-->declarations
+
+ public Parser(Scanner scanner) {
+ this.scanner = scanner;
+ errors = new Errors();
+ }
+
+ void SynErr (int n) {
+ if (errDist >= minErrDist) errors.SynErr(la.line, la.col, n);
+ errDist = 0;
+ }
+
+ public void SemErr (string msg) {
+ if (errDist >= minErrDist) errors.SemErr(t.line, t.col, msg);
+ errDist = 0;
+ }
+
+ void Get () {
+ for (;;) {
+ t = la;
+ la = scanner.Scan();
+ if (la.kind <= maxT) { ++errDist; break; }
+-->pragmas
+ la = t;
+ }
+ }
+
+ void Expect (int n) {
+ if (la.kind==n) Get(); else { SynErr(n); }
+ }
+
+ bool StartOf (int s) {
+ return set[s, la.kind];
+ }
+
+ void ExpectWeak (int n, int follow) {
+ if (la.kind == n) Get();
+ else {
+ SynErr(n);
+ while (!StartOf(follow)) Get();
+ }
+ }
+
+
+ bool WeakSeparator(int n, int syFol, int repFol) {
+ int kind = la.kind;
+ if (kind == n) {Get(); return true;}
+ else if (StartOf(repFol)) {return false;}
+ else {
+ SynErr(n);
+ while (!(set[syFol, kind] || set[repFol, kind] || set[0, kind])) {
+ Get();
+ kind = la.kind;
+ }
+ return StartOf(syFol);
+ }
+ }
+
+
+-->productions
+
+ public void Parse() {
+ la = new Token();
+ la.val = "";
+ Get();
+-->parseRoot
+ }
+
+ static readonly bool[,] set = {
+-->initialization
+ };
+} // end Parser
+
+
+public class Errors {
+ public int count = 0; // number of errors detected
+ public System.IO.TextWriter errorStream = Console.Out; // error messages go to this stream
+ public string errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text
+
+ public virtual void SynErr (int line, int col, int n) {
+ string s;
+ switch (n) {
+-->errors
+ default: s = "error " + n; break;
+ }
+ errorStream.WriteLine(errMsgFormat, line, col, s);
+ count++;
+ }
+
+ public virtual void SemErr (int line, int col, string s) {
+ errorStream.WriteLine(errMsgFormat, line, col, s);
+ count++;
+ }
+
+ public virtual void SemErr (string s) {
+ errorStream.WriteLine(s);
+ count++;
+ }
+
+ public virtual void Warning (int line, int col, string s) {
+ errorStream.WriteLine(errMsgFormat, line, col, s);
+ }
+
+ public virtual void Warning(string s) {
+ errorStream.WriteLine(s);
+ }
+} // Errors
+
+
+public class FatalError: Exception {
+ public FatalError(string m): base(m) {}
+}
diff --git a/CS-MIC/csmic/csmic/InterpreterParser/Scanner.cs b/CS-MIC/csmic/csmic/InterpreterParser/Scanner.cs
new file mode 100644
index 0000000..abecef8
--- /dev/null
+++ b/CS-MIC/csmic/csmic/InterpreterParser/Scanner.cs
@@ -0,0 +1,489 @@
+
+using System;
+using System.IO;
+using System.Collections;
+
+namespace csmic.Interpreter {
+
+public class Token {
+ public int kind; // token kind
+ public int pos; // token position in bytes in the source text (starting at 0)
+ public int charPos; // token position in characters in the source text (starting at 0)
+ public int col; // token column (starting at 1)
+ public int line; // token line (starting at 1)
+ public string val; // token value
+ public Token next; // ML 2005-03-11 Tokens are kept in linked list
+}
+
+//-----------------------------------------------------------------------------------
+// Buffer
+//-----------------------------------------------------------------------------------
+public class Buffer {
+ // This Buffer supports the following cases:
+ // 1) seekable stream (file)
+ // a) whole stream in buffer
+ // b) part of stream in buffer
+ // 2) non seekable stream (network, console)
+
+ public const int EOF = char.MaxValue + 1;
+ const int MIN_BUFFER_LENGTH = 1024; // 1KB
+ const int MAX_BUFFER_LENGTH = MIN_BUFFER_LENGTH * 64; // 64KB
+ byte[] buf; // input buffer
+ int bufStart; // position of first byte in buffer relative to input stream
+ int bufLen; // length of buffer
+ int fileLen; // length of input stream (may change if the stream is no file)
+ int bufPos; // current position in buffer
+ Stream stream; // input stream (seekable)
+ bool isUserStream; // was the stream opened by the user?
+
+ public Buffer (Stream s, bool isUserStream) {
+ stream = s; this.isUserStream = isUserStream;
+
+ if (stream.CanSeek) {
+ fileLen = (int) stream.Length;
+ bufLen = Math.Min(fileLen, MAX_BUFFER_LENGTH);
+ bufStart = Int32.MaxValue; // nothing in the buffer so far
+ } else {
+ fileLen = bufLen = bufStart = 0;
+ }
+
+ buf = new byte[(bufLen>0) ? bufLen : MIN_BUFFER_LENGTH];
+ if (fileLen > 0) Pos = 0; // setup buffer to position 0 (start)
+ else bufPos = 0; // index 0 is already after the file, thus Pos = 0 is invalid
+ if (bufLen == fileLen && stream.CanSeek) Close();
+ }
+
+ protected Buffer(Buffer b) { // called in UTF8Buffer constructor
+ buf = b.buf;
+ bufStart = b.bufStart;
+ bufLen = b.bufLen;
+ fileLen = b.fileLen;
+ bufPos = b.bufPos;
+ stream = b.stream;
+ // keep destructor from closing the stream
+ b.stream = null;
+ isUserStream = b.isUserStream;
+ }
+
+ ~Buffer() { Close(); }
+
+ protected void Close() {
+ if (!isUserStream && stream != null) {
+ stream.Close();
+ stream = null;
+ }
+ }
+
+ public virtual int Read () {
+ if (bufPos < bufLen) {
+ return buf[bufPos++];
+ } else if (Pos < fileLen) {
+ Pos = Pos; // shift buffer start to Pos
+ return buf[bufPos++];
+ } else if (stream != null && !stream.CanSeek && ReadNextStreamChunk() > 0) {
+ return buf[bufPos++];
+ } else {
+ return EOF;
+ }
+ }
+
+ public int Peek () {
+ int curPos = Pos;
+ int ch = Read();
+ Pos = curPos;
+ return ch;
+ }
+
+ // beg .. begin, zero-based, inclusive, in byte
+ // end .. end, zero-based, exclusive, in byte
+ public string GetString (int beg, int end) {
+ int len = 0;
+ char[] buf = new char[end - beg];
+ int oldPos = Pos;
+ Pos = beg;
+ while (Pos < end) buf[len++] = (char) Read();
+ Pos = oldPos;
+ return new String(buf, 0, len);
+ }
+
+ public int Pos {
+ get { return bufPos + bufStart; }
+ set {
+ if (value >= fileLen && stream != null && !stream.CanSeek) {
+ // Wanted position is after buffer and the stream
+ // is not seek-able e.g. network or console,
+ // thus we have to read the stream manually till
+ // the wanted position is in sight.
+ while (value >= fileLen && ReadNextStreamChunk() > 0);
+ }
+
+ if (value < 0 || value > fileLen) {
+ throw new FatalError("buffer out of bounds access, position: " + value);
+ }
+
+ if (value >= bufStart && value < bufStart + bufLen) { // already in buffer
+ bufPos = value - bufStart;
+ } else if (stream != null) { // must be swapped in
+ stream.Seek(value, SeekOrigin.Begin);
+ bufLen = stream.Read(buf, 0, buf.Length);
+ bufStart = value; bufPos = 0;
+ } else {
+ // set the position to the end of the file, Pos will return fileLen.
+ bufPos = fileLen - bufStart;
+ }
+ }
+ }
+
+ // Read the next chunk of bytes from the stream, increases the buffer
+ // if needed and updates the fields fileLen and bufLen.
+ // Returns the number of bytes read.
+ private int ReadNextStreamChunk() {
+ int free = buf.Length - bufLen;
+ if (free == 0) {
+ // in the case of a growing input stream
+ // we can neither seek in the stream, nor can we
+ // foresee the maximum length, thus we must adapt
+ // the buffer size on demand.
+ byte[] newBuf = new byte[bufLen * 2];
+ Array.Copy(buf, newBuf, bufLen);
+ buf = newBuf;
+ free = bufLen;
+ }
+ int read = stream.Read(buf, bufLen, free);
+ if (read > 0) {
+ fileLen = bufLen = (bufLen + read);
+ return read;
+ }
+ // end of stream reached
+ return 0;
+ }
+}
+
+//-----------------------------------------------------------------------------------
+// UTF8Buffer
+//-----------------------------------------------------------------------------------
+public class UTF8Buffer: Buffer {
+ public UTF8Buffer(Buffer b): base(b) {}
+
+ public override int Read() {
+ int ch;
+ do {
+ ch = base.Read();
+ // until we find a utf8 start (0xxxxxxx or 11xxxxxx)
+ } while ((ch >= 128) && ((ch & 0xC0) != 0xC0) && (ch != EOF));
+ if (ch < 128 || ch == EOF) {
+ // nothing to do, first 127 chars are the same in ascii and utf8
+ // 0xxxxxxx or end of file character
+ } else if ((ch & 0xF0) == 0xF0) {
+ // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
+ int c1 = ch & 0x07; ch = base.Read();
+ int c2 = ch & 0x3F; ch = base.Read();
+ int c3 = ch & 0x3F; ch = base.Read();
+ int c4 = ch & 0x3F;
+ ch = (((((c1 << 6) | c2) << 6) | c3) << 6) | c4;
+ } else if ((ch & 0xE0) == 0xE0) {
+ // 1110xxxx 10xxxxxx 10xxxxxx
+ int c1 = ch & 0x0F; ch = base.Read();
+ int c2 = ch & 0x3F; ch = base.Read();
+ int c3 = ch & 0x3F;
+ ch = (((c1 << 6) | c2) << 6) | c3;
+ } else if ((ch & 0xC0) == 0xC0) {
+ // 110xxxxx 10xxxxxx
+ int c1 = ch & 0x1F; ch = base.Read();
+ int c2 = ch & 0x3F;
+ ch = (c1 << 6) | c2;
+ }
+ return ch;
+ }
+}
+
+//-----------------------------------------------------------------------------------
+// Scanner
+//-----------------------------------------------------------------------------------
+public class Scanner {
+ const char EOL = '\n';
+ const int eofSym = 0; /* pdt */
+ const int maxT = 22;
+ const int noSym = 22;
+
+
+ public Buffer buffer; // scanner buffer
+
+ Token t; // current token
+ int ch; // current input character
+ int pos; // byte position of current character
+ int charPos; // position by unicode characters starting with 0
+ int col; // column number of current character
+ int line; // line number of current character
+ int oldEols; // EOLs that appeared in a comment;
+ static readonly Hashtable start; // maps first token character to start state
+
+ Token tokens; // list of tokens already peeked (first token is a dummy)
+ Token pt; // current peek token
+
+ char[] tval = new char[128]; // text of current token
+ int tlen; // length of current token
+
+ static Scanner() {
+ start = new Hashtable(128);
+ for (int i = 65; i <= 90; ++i) start[i] = 1;
+ for (int i = 97; i <= 122; ++i) start[i] = 1;
+ start[43] = 2;
+ for (int i = 50; i <= 57; ++i) start[i] = 6;
+ start[48] = 17;
+ start[49] = 18;
+ start[34] = 11;
+ start[40] = 13;
+ start[41] = 14;
+ start[61] = 15;
+ start[60] = 19;
+ start[62] = 20;
+ start[42] = 21;
+ start[47] = 22;
+ start[37] = 23;
+ start[94] = 24;
+ start[91] = 25;
+ start[93] = 26;
+ start[44] = 27;
+ start[58] = 31;
+ start[45] = 32;
+ start[Buffer.EOF] = -1;
+
+ }
+
+ public Scanner (string fileName) {
+ try {
+ Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
+ buffer = new Buffer(stream, false);
+ Init();
+ } catch (IOException) {
+ throw new FatalError("Cannot open file " + fileName);
+ }
+ }
+
+ public Scanner (Stream s) {
+ buffer = new Buffer(s, true);
+ Init();
+ }
+
+ void Init() {
+ pos = -1; line = 1; col = 0; charPos = -1;
+ oldEols = 0;
+ NextCh();
+ if (ch == 0xEF) { // check optional byte order mark for UTF-8
+ NextCh(); int ch1 = ch;
+ NextCh(); int ch2 = ch;
+ if (ch1 != 0xBB || ch2 != 0xBF) {
+ throw new FatalError(String.Format("illegal byte order mark: EF {0,2:X} {1,2:X}", ch1, ch2));
+ }
+ buffer = new UTF8Buffer(buffer); col = 0; charPos = -1;
+ NextCh();
+ }
+ pt = tokens = new Token(); // first token is a dummy
+ }
+
+ void NextCh() {
+ if (oldEols > 0) { ch = EOL; oldEols--; }
+ else {
+ pos = buffer.Pos;
+ // buffer reads unicode chars, if UTF8 has been detected
+ ch = buffer.Read(); col++; charPos++;
+ // replace isolated '\r' by '\n' in order to make
+ // eol handling uniform across Windows, Unix and Mac
+ if (ch == '\r' && buffer.Peek() != '\n') ch = EOL;
+ if (ch == EOL) { line++; col = 0; }
+ }
+
+ }
+
+ void AddCh() {
+ if (tlen >= tval.Length) {
+ char[] newBuf = new char[2 * tval.Length];
+ Array.Copy(tval, 0, newBuf, 0, tval.Length);
+ tval = newBuf;
+ }
+ if (ch != Buffer.EOF) {
+ tval[tlen++] = (char) ch;
+ NextCh();
+ }
+ }
+
+
+
+
+ void CheckLiteral() {
+ switch (t.val) {
+ case "+": t.kind = 10; break;
+ case "-": t.kind = 11; break;
+ default: break;
+ }
+ }
+
+ Token NextToken() {
+ while (ch == ' ' ||
+ ch == 9 || ch == 13
+ ) NextCh();
+
+ int recKind = noSym;
+ int recEnd = pos;
+ t = new Token();
+ t.pos = pos; t.col = col; t.line = line; t.charPos = charPos;
+ int state;
+ if (start.ContainsKey(ch)) { state = (int) start[ch]; }
+ else { state = 0; }
+ tlen = 0; AddCh();
+
+ switch (state) {
+ case -1: { t.kind = eofSym; break; } // NextCh already done
+ case 0: {
+ if (recKind != noSym) {
+ tlen = recEnd - t.pos;
+ SetScannerBehindT();
+ }
+ t.kind = recKind; break;
+ } // NextCh already done
+ case 1:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;}
+ else {t.kind = 1; break;}
+ case 2:
+ {t.kind = 2; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 3:
+ {t.kind = 3; break;}
+ case 4:
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 5;}
+ else {goto case 0;}
+ case 5:
+ recEnd = pos; recKind = 4;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 5;}
+ else {t.kind = 4; break;}
+ case 6:
+ recEnd = pos; recKind = 5;
+ if (ch >= '0' && ch <= '9') {AddCh(); goto case 6;}
+ else if (ch == 'E' || ch == 'e') {AddCh(); goto case 7;}
+ else if (ch == '.') {AddCh(); goto case 10;}
+ else {t.kind = 5; break;}
+ case 7:
+ if (ch >= '0' && ch <= '9') {AddCh(); goto case 9;}
+ else if (ch == '+' || ch == '-') {AddCh(); goto case 8;}
+ else {goto case 0;}
+ case 8:
+ if (ch >= '0' && ch <= '9') {AddCh(); goto case 9;}
+ else {goto case 0;}
+ case 9:
+ recEnd = pos; recKind = 5;
+ if (ch >= '0' && ch <= '9') {AddCh(); goto case 9;}
+ else {t.kind = 5; break;}
+ case 10:
+ recEnd = pos; recKind = 5;
+ if (ch >= '0' && ch <= '9') {AddCh(); goto case 10;}
+ else if (ch == 'E' || ch == 'e') {AddCh(); goto case 7;}
+ else {t.kind = 5; break;}
+ case 11:
+ if (ch <= '!' || ch >= '#' && ch <= 65535) {AddCh(); goto case 11;}
+ else if (ch == '"') {AddCh(); goto case 12;}
+ else {goto case 0;}
+ case 12:
+ {t.kind = 6; break;}
+ case 13:
+ {t.kind = 7; break;}
+ case 14:
+ {t.kind = 8; break;}
+ case 15:
+ if (ch == '=') {AddCh(); goto case 16;}
+ else {goto case 0;}
+ case 16:
+ {t.kind = 9; break;}
+ case 17:
+ recEnd = pos; recKind = 5;
+ if (ch >= '2' && ch <= '9') {AddCh(); goto case 6;}
+ else if (ch == 'B' || ch == 'b') {AddCh(); goto case 3;}
+ else if (ch >= '0' && ch <= '1') {AddCh(); goto case 18;}
+ else if (ch == 'x') {AddCh(); goto case 4;}
+ else if (ch == 'E' || ch == 'e') {AddCh(); goto case 7;}
+ else if (ch == '.') {AddCh(); goto case 10;}
+ else {t.kind = 5; break;}
+ case 18:
+ recEnd = pos; recKind = 5;
+ if (ch >= '2' && ch <= '9') {AddCh(); goto case 6;}
+ else if (ch == 'B' || ch == 'b') {AddCh(); goto case 3;}
+ else if (ch >= '0' && ch <= '1') {AddCh(); goto case 18;}
+ else if (ch == 'E' || ch == 'e') {AddCh(); goto case 7;}
+ else if (ch == '.') {AddCh(); goto case 10;}
+ else {t.kind = 5; break;}
+ case 19:
+ recEnd = pos; recKind = 9;
+ if (ch == '=') {AddCh(); goto case 16;}
+ else {t.kind = 9; break;}
+ case 20:
+ recEnd = pos; recKind = 9;
+ if (ch == '=') {AddCh(); goto case 16;}
+ else {t.kind = 9; break;}
+ case 21:
+ {t.kind = 12; break;}
+ case 22:
+ {t.kind = 13; break;}
+ case 23:
+ {t.kind = 14; break;}
+ case 24:
+ {t.kind = 15; break;}
+ case 25:
+ {t.kind = 16; break;}
+ case 26:
+ {t.kind = 17; break;}
+ case 27:
+ {t.kind = 18; break;}
+ case 28:
+ {t.kind = 19; break;}
+ case 29:
+ {t.kind = 20; break;}
+ case 30:
+ {t.kind = 21; break;}
+ case 31:
+ if (ch == ':') {AddCh(); goto case 28;}
+ else if (ch == '=') {AddCh(); goto case 29;}
+ else {goto case 0;}
+ case 32:
+ recEnd = pos; recKind = 2;
+ if (ch == '>') {AddCh(); goto case 30;}
+ else {t.kind = 2; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+
+ }
+ t.val = new String(tval, 0, tlen);
+ return t;
+ }
+
+ private void SetScannerBehindT() {
+ buffer.Pos = t.pos;
+ NextCh();
+ line = t.line; col = t.col; charPos = t.charPos;
+ for (int i = 0; i < tlen; i++) NextCh();
+ }
+
+ // get the next token (possibly a token already seen during peeking)
+ public Token Scan () {
+ if (tokens.next == null) {
+ return NextToken();
+ } else {
+ pt = tokens = tokens.next;
+ return tokens;
+ }
+ }
+
+ // peek for the next token, ignore pragmas
+ public Token Peek () {
+ do {
+ if (pt.next == null) {
+ pt.next = NextToken();
+ }
+ pt = pt.next;
+ } while (pt.kind > maxT); // skip pragmas
+
+ return pt;
+ }
+
+ // make sure that peeking starts at the current scan position
+ public void ResetPeek () { pt = tokens; }
+
+} // end Scanner
+}
\ No newline at end of file
diff --git a/CS-MIC/csmic/csmic/InterpreterParser/Scanner.cs.old b/CS-MIC/csmic/csmic/InterpreterParser/Scanner.cs.old
new file mode 100644
index 0000000..8c97818
--- /dev/null
+++ b/CS-MIC/csmic/csmic/InterpreterParser/Scanner.cs.old
@@ -0,0 +1,489 @@
+
+using System;
+using System.IO;
+using System.Collections;
+
+namespace csmic.Interpreter {
+
+public class Token {
+ public int kind; // token kind
+ public int pos; // token position in bytes in the source text (starting at 0)
+ public int charPos; // token position in characters in the source text (starting at 0)
+ public int col; // token column (starting at 1)
+ public int line; // token line (starting at 1)
+ public string val; // token value
+ public Token next; // ML 2005-03-11 Tokens are kept in linked list
+}
+
+//-----------------------------------------------------------------------------------
+// Buffer
+//-----------------------------------------------------------------------------------
+public class Buffer {
+ // This Buffer supports the following cases:
+ // 1) seekable stream (file)
+ // a) whole stream in buffer
+ // b) part of stream in buffer
+ // 2) non seekable stream (network, console)
+
+ public const int EOF = char.MaxValue + 1;
+ const int MIN_BUFFER_LENGTH = 1024; // 1KB
+ const int MAX_BUFFER_LENGTH = MIN_BUFFER_LENGTH * 64; // 64KB
+ byte[] buf; // input buffer
+ int bufStart; // position of first byte in buffer relative to input stream
+ int bufLen; // length of buffer
+ int fileLen; // length of input stream (may change if the stream is no file)
+ int bufPos; // current position in buffer
+ Stream stream; // input stream (seekable)
+ bool isUserStream; // was the stream opened by the user?
+
+ public Buffer (Stream s, bool isUserStream) {
+ stream = s; this.isUserStream = isUserStream;
+
+ if (stream.CanSeek) {
+ fileLen = (int) stream.Length;
+ bufLen = Math.Min(fileLen, MAX_BUFFER_LENGTH);
+ bufStart = Int32.MaxValue; // nothing in the buffer so far
+ } else {
+ fileLen = bufLen = bufStart = 0;
+ }
+
+ buf = new byte[(bufLen>0) ? bufLen : MIN_BUFFER_LENGTH];
+ if (fileLen > 0) Pos = 0; // setup buffer to position 0 (start)
+ else bufPos = 0; // index 0 is already after the file, thus Pos = 0 is invalid
+ if (bufLen == fileLen && stream.CanSeek) Close();
+ }
+
+ protected Buffer(Buffer b) { // called in UTF8Buffer constructor
+ buf = b.buf;
+ bufStart = b.bufStart;
+ bufLen = b.bufLen;
+ fileLen = b.fileLen;
+ bufPos = b.bufPos;
+ stream = b.stream;
+ // keep destructor from closing the stream
+ b.stream = null;
+ isUserStream = b.isUserStream;
+ }
+
+ ~Buffer() { Close(); }
+
+ protected void Close() {
+ if (!isUserStream && stream != null) {
+ stream.Close();
+ stream = null;
+ }
+ }
+
+ public virtual int Read () {
+ if (bufPos < bufLen) {
+ return buf[bufPos++];
+ } else if (Pos < fileLen) {
+ Pos = Pos; // shift buffer start to Pos
+ return buf[bufPos++];
+ } else if (stream != null && !stream.CanSeek && ReadNextStreamChunk() > 0) {
+ return buf[bufPos++];
+ } else {
+ return EOF;
+ }
+ }
+
+ public int Peek () {
+ int curPos = Pos;
+ int ch = Read();
+ Pos = curPos;
+ return ch;
+ }
+
+ // beg .. begin, zero-based, inclusive, in byte
+ // end .. end, zero-based, exclusive, in byte
+ public string GetString (int beg, int end) {
+ int len = 0;
+ char[] buf = new char[end - beg];
+ int oldPos = Pos;
+ Pos = beg;
+ while (Pos < end) buf[len++] = (char) Read();
+ Pos = oldPos;
+ return new String(buf, 0, len);
+ }
+
+ public int Pos {
+ get { return bufPos + bufStart; }
+ set {
+ if (value >= fileLen && stream != null && !stream.CanSeek) {
+ // Wanted position is after buffer and the stream
+ // is not seek-able e.g. network or console,
+ // thus we have to read the stream manually till
+ // the wanted position is in sight.
+ while (value >= fileLen && ReadNextStreamChunk() > 0);
+ }
+
+ if (value < 0 || value > fileLen) {
+ throw new FatalError("buffer out of bounds access, position: " + value);
+ }
+
+ if (value >= bufStart && value < bufStart + bufLen) { // already in buffer
+ bufPos = value - bufStart;
+ } else if (stream != null) { // must be swapped in
+ stream.Seek(value, SeekOrigin.Begin);
+ bufLen = stream.Read(buf, 0, buf.Length);
+ bufStart = value; bufPos = 0;
+ } else {
+ // set the position to the end of the file, Pos will return fileLen.
+ bufPos = fileLen - bufStart;
+ }
+ }
+ }
+
+ // Read the next chunk of bytes from the stream, increases the buffer
+ // if needed and updates the fields fileLen and bufLen.
+ // Returns the number of bytes read.
+ private int ReadNextStreamChunk() {
+ int free = buf.Length - bufLen;
+ if (free == 0) {
+ // in the case of a growing input stream
+ // we can neither seek in the stream, nor can we
+ // foresee the maximum length, thus we must adapt
+ // the buffer size on demand.
+ byte[] newBuf = new byte[bufLen * 2];
+ Array.Copy(buf, newBuf, bufLen);
+ buf = newBuf;
+ free = bufLen;
+ }
+ int read = stream.Read(buf, bufLen, free);
+ if (read > 0) {
+ fileLen = bufLen = (bufLen + read);
+ return read;
+ }
+ // end of stream reached
+ return 0;
+ }
+}
+
+//-----------------------------------------------------------------------------------
+// UTF8Buffer
+//-----------------------------------------------------------------------------------
+public class UTF8Buffer: Buffer {
+ public UTF8Buffer(Buffer b): base(b) {}
+
+ public override int Read() {
+ int ch;
+ do {
+ ch = base.Read();
+ // until we find a utf8 start (0xxxxxxx or 11xxxxxx)
+ } while ((ch >= 128) && ((ch & 0xC0) != 0xC0) && (ch != EOF));
+ if (ch < 128 || ch == EOF) {
+ // nothing to do, first 127 chars are the same in ascii and utf8
+ // 0xxxxxxx or end of file character
+ } else if ((ch & 0xF0) == 0xF0) {
+ // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
+ int c1 = ch & 0x07; ch = base.Read();
+ int c2 = ch & 0x3F; ch = base.Read();
+ int c3 = ch & 0x3F; ch = base.Read();
+ int c4 = ch & 0x3F;
+ ch = (((((c1 << 6) | c2) << 6) | c3) << 6) | c4;
+ } else if ((ch & 0xE0) == 0xE0) {
+ // 1110xxxx 10xxxxxx 10xxxxxx
+ int c1 = ch & 0x0F; ch = base.Read();
+ int c2 = ch & 0x3F; ch = base.Read();
+ int c3 = ch & 0x3F;
+ ch = (((c1 << 6) | c2) << 6) | c3;
+ } else if ((ch & 0xC0) == 0xC0) {
+ // 110xxxxx 10xxxxxx
+ int c1 = ch & 0x1F; ch = base.Read();
+ int c2 = ch & 0x3F;
+ ch = (c1 << 6) | c2;
+ }
+ return ch;
+ }
+}
+
+//-----------------------------------------------------------------------------------
+// Scanner
+//-----------------------------------------------------------------------------------
+public class Scanner {
+ const char EOL = '\n';
+ const int eofSym = 0; /* pdt */
+ const int maxT = 22;
+ const int noSym = 22;
+
+
+ public Buffer buffer; // scanner buffer
+
+ Token t; // current token
+ int ch; // current input character
+ int pos; // byte position of current character
+ int charPos; // position by unicode characters starting with 0
+ int col; // column number of current character
+ int line; // line number of current character
+ int oldEols; // EOLs that appeared in a comment;
+ static readonly Hashtable start; // maps first token character to start state
+
+ Token tokens; // list of tokens already peeked (first token is a dummy)
+ Token pt; // current peek token
+
+ char[] tval = new char[128]; // text of current token
+ int tlen; // length of current token
+
+ static Scanner() {
+ start = new Hashtable(128);
+ for (int i = 65; i <= 90; ++i) start[i] = 1;
+ for (int i = 97; i <= 122; ++i) start[i] = 1;
+ start[43] = 2;
+ for (int i = 50; i <= 57; ++i) start[i] = 6;
+ start[48] = 17;
+ start[49] = 18;
+ start[34] = 11;
+ start[40] = 13;
+ start[41] = 14;
+ start[61] = 15;
+ start[60] = 19;
+ start[62] = 20;
+ start[42] = 21;
+ start[47] = 22;
+ start[37] = 23;
+ start[94] = 24;
+ start[91] = 25;
+ start[93] = 26;
+ start[44] = 27;
+ start[58] = 31;
+ start[45] = 32;
+ start[Buffer.EOF] = -1;
+
+ }
+
+ public Scanner (string fileName) {
+ try {
+ Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
+ buffer = new Buffer(stream, false);
+ Init();
+ } catch (IOException) {
+ throw new FatalError("Cannot open file " + fileName);
+ }
+ }
+
+ public Scanner (Stream s) {
+ buffer = new Buffer(s, true);
+ Init();
+ }
+
+ void Init() {
+ pos = -1; line = 1; col = 0; charPos = -1;
+ oldEols = 0;
+ NextCh();
+ if (ch == 0xEF) { // check optional byte order mark for UTF-8
+ NextCh(); int ch1 = ch;
+ NextCh(); int ch2 = ch;
+ if (ch1 != 0xBB || ch2 != 0xBF) {
+ throw new FatalError(String.Format("illegal byte order mark: EF {0,2:X} {1,2:X}", ch1, ch2));
+ }
+ buffer = new UTF8Buffer(buffer); col = 0; charPos = -1;
+ NextCh();
+ }
+ pt = tokens = new Token(); // first token is a dummy
+ }
+
+ void NextCh() {
+ if (oldEols > 0) { ch = EOL; oldEols--; }
+ else {
+ pos = buffer.Pos;
+ // buffer reads unicode chars, if UTF8 has been detected
+ ch = buffer.Read(); col++; charPos++;
+ // replace isolated '\r' by '\n' in order to make
+ // eol handling uniform across Windows, Unix and Mac
+ if (ch == '\r' && buffer.Peek() != '\n') ch = EOL;
+ if (ch == EOL) { line++; col = 0; }
+ }
+
+ }
+
+ void AddCh() {
+ if (tlen >= tval.Length) {
+ char[] newBuf = new char[2 * tval.Length];
+ Array.Copy(tval, 0, newBuf, 0, tval.Length);
+ tval = newBuf;
+ }
+ if (ch != Buffer.EOF) {
+ tval[tlen++] = (char) ch;
+ NextCh();
+ }
+ }
+
+
+
+
+ void CheckLiteral() {
+ switch (t.val) {
+ case "+": t.kind = 10; break;
+ case "-": t.kind = 11; break;
+ default: break;
+ }
+ }
+
+ Token NextToken() {
+ while (ch == ' ' ||
+ ch == 9 || ch == 13
+ ) NextCh();
+
+ int recKind = noSym;
+ int recEnd = pos;
+ t = new Token();
+ t.pos = pos; t.col = col; t.line = line; t.charPos = charPos;
+ int state;
+ if (start.ContainsKey(ch)) { state = (int) start[ch]; }
+ else { state = 0; }
+ tlen = 0; AddCh();
+
+ switch (state) {
+ case -1: { t.kind = eofSym; break; } // NextCh already done
+ case 0: {
+ if (recKind != noSym) {
+ tlen = recEnd - t.pos;
+ SetScannerBehindT();
+ }
+ t.kind = recKind; break;
+ } // NextCh already done
+ case 1:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;}
+ else {t.kind = 1; break;}
+ case 2:
+ {t.kind = 2; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 3:
+ {t.kind = 3; break;}
+ case 4:
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 5;}
+ else {goto case 0;}
+ case 5:
+ recEnd = pos; recKind = 4;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 5;}
+ else {t.kind = 4; break;}
+ case 6:
+ recEnd = pos; recKind = 5;
+ if (ch >= '0' && ch <= '9') {AddCh(); goto case 6;}
+ else if (ch == 'E' || ch == 'e') {AddCh(); goto case 7;}
+ else if (ch == '.') {AddCh(); goto case 10;}
+ else {t.kind = 5; break;}
+ case 7:
+ if (ch >= '0' && ch <= '9') {AddCh(); goto case 9;}
+ else if (ch == '+' || ch == '-') {AddCh(); goto case 8;}
+ else {goto case 0;}
+ case 8:
+ if (ch >= '0' && ch <= '9') {AddCh(); goto case 9;}
+ else {goto case 0;}
+ case 9:
+ recEnd = pos; recKind = 5;
+ if (ch >= '0' && ch <= '9') {AddCh(); goto case 9;}
+ else {t.kind = 5; break;}
+ case 10:
+ recEnd = pos; recKind = 5;
+ if (ch >= '0' && ch <= '9') {AddCh(); goto case 10;}
+ else if (ch == 'E' || ch == 'e') {AddCh(); goto case 7;}
+ else {t.kind = 5; break;}
+ case 11:
+ if (ch <= '!' || ch >= '#' && ch <= 65535) {AddCh(); goto case 11;}
+ else if (ch == '"') {AddCh(); goto case 12;}
+ else {goto case 0;}
+ case 12:
+ {t.kind = 6; break;}
+ case 13:
+ {t.kind = 7; break;}
+ case 14:
+ {t.kind = 8; break;}
+ case 15:
+ if (ch == '=') {AddCh(); goto case 16;}
+ else {goto case 0;}
+ case 16:
+ {t.kind = 9; break;}
+ case 17:
+ recEnd = pos; recKind = 5;
+ if (ch >= '2' && ch <= '9') {AddCh(); goto case 6;}
+ else if (ch == 'B' || ch == 'b') {AddCh(); goto case 3;}
+ else if (ch >= '0' && ch <= '1') {AddCh(); goto case 18;}
+ else if (ch == 'x') {AddCh(); goto case 4;}
+ else if (ch == 'E' || ch == 'e') {AddCh(); goto case 7;}
+ else if (ch == '.') {AddCh(); goto case 10;}
+ else {t.kind = 5; break;}
+ case 18:
+ recEnd = pos; recKind = 5;
+ if (ch >= '2' && ch <= '9') {AddCh(); goto case 6;}
+ else if (ch == 'B' || ch == 'b') {AddCh(); goto case 3;}
+ else if (ch >= '0' && ch <= '1') {AddCh(); goto case 18;}
+ else if (ch == 'E' || ch == 'e') {AddCh(); goto case 7;}
+ else if (ch == '.') {AddCh(); goto case 10;}
+ else {t.kind = 5; break;}
+ case 19:
+ recEnd = pos; recKind = 9;
+ if (ch == '=') {AddCh(); goto case 16;}
+ else {t.kind = 9; break;}
+ case 20:
+ recEnd = pos; recKind = 9;
+ if (ch == '=') {AddCh(); goto case 16;}
+ else {t.kind = 9; break;}
+ case 21:
+ {t.kind = 12; break;}
+ case 22:
+ {t.kind = 13; break;}
+ case 23:
+ {t.kind = 14; break;}
+ case 24:
+ {t.kind = 15; break;}
+ case 25:
+ {t.kind = 16; break;}
+ case 26:
+ {t.kind = 17; break;}
+ case 27:
+ {t.kind = 18; break;}
+ case 28:
+ {t.kind = 19; break;}
+ case 29:
+ {t.kind = 20; break;}
+ case 30:
+ {t.kind = 21; break;}
+ case 31:
+ if (ch == ':') {AddCh(); goto case 28;}
+ else if (ch == '=') {AddCh(); goto case 29;}
+ else {goto case 0;}
+ case 32:
+ recEnd = pos; recKind = 2;
+ if (ch == '>') {AddCh(); goto case 30;}
+ else {t.kind = 2; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+
+ }
+ t.val = new String(tval, 0, tlen);
+ return t;
+ }
+
+ private void SetScannerBehindT() {
+ buffer.Pos = t.pos;
+ NextCh();
+ line = t.line; col = t.col; charPos = t.charPos;
+ for (int i = 0; i < tlen; i++) NextCh();
+ }
+
+ // get the next token (possibly a token already seen during peeking)
+ public Token Scan () {
+ if (tokens.next == null) {
+ return NextToken();
+ } else {
+ pt = tokens = tokens.next;
+ return tokens;
+ }
+ }
+
+ // peek for the next token, ignore pragmas
+ public Token Peek () {
+ do {
+ if (pt.next == null) {
+ pt.next = NextToken();
+ }
+ pt = pt.next;
+ } while (pt.kind > maxT); // skip pragmas
+
+ return pt;
+ }
+
+ // make sure that peeking starts at the current scan position
+ public void ResetPeek () { pt = tokens; }
+
+} // end Scanner
+}
\ No newline at end of file
diff --git a/src/Core/cocor/Scanner.frame b/CS-MIC/csmic/csmic/InterpreterParser/Scanner.frame
similarity index 96%
rename from src/Core/cocor/Scanner.frame
rename to CS-MIC/csmic/csmic/InterpreterParser/Scanner.frame
index 9ccf06b..abac75d 100644
--- a/src/Core/cocor/Scanner.frame
+++ b/CS-MIC/csmic/csmic/InterpreterParser/Scanner.frame
@@ -1,381 +1,381 @@
-/*----------------------------------------------------------------------
-Compiler Generator Coco/R,
-Copyright (c) 1990, 2004 Hanspeter Moessenboeck, University of Linz
-extended by M. Loeberbauer & A. Woess, Univ. of Linz
-with improvements by Pat Terry, Rhodes University
-
-This program is free software; you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation; either version 2, or (at your option) any
-later version.
-
-This program is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License along
-with this program; if not, write to the Free Software Foundation, Inc.,
-59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-As an exception, it is allowed to write an extension of Coco/R that is
-used as a plugin in non-free software.
-
-If not otherwise stated, any source code generated by Coco/R (other than
-Coco/R itself) does not fall under the GNU General Public License.
------------------------------------------------------------------------*/
--->begin
-using System;
-using System.IO;
-using System.Collections;
-
--->namespace
-
-public class Token {
- public int kind; // token kind
- public int pos; // token position in bytes in the source text (starting at 0)
- public int charPos; // token position in characters in the source text (starting at 0)
- public int col; // token column (starting at 1)
- public int line; // token line (starting at 1)
- public string val; // token value
- public Token next; // ML 2005-03-11 Tokens are kept in linked list
-}
-
-//-----------------------------------------------------------------------------------
-// Buffer
-//-----------------------------------------------------------------------------------
-public class Buffer {
- // This Buffer supports the following cases:
- // 1) seekable stream (file)
- // a) whole stream in buffer
- // b) part of stream in buffer
- // 2) non seekable stream (network, console)
-
- public const int EOF = char.MaxValue + 1;
- const int MIN_BUFFER_LENGTH = 1024; // 1KB
- const int MAX_BUFFER_LENGTH = MIN_BUFFER_LENGTH * 64; // 64KB
- byte[] buf; // input buffer
- int bufStart; // position of first byte in buffer relative to input stream
- int bufLen; // length of buffer
- int fileLen; // length of input stream (may change if the stream is no file)
- int bufPos; // current position in buffer
- Stream stream; // input stream (seekable)
- bool isUserStream; // was the stream opened by the user?
-
- public Buffer (Stream s, bool isUserStream) {
- stream = s; this.isUserStream = isUserStream;
-
- if (stream.CanSeek) {
- fileLen = (int) stream.Length;
- bufLen = Math.Min(fileLen, MAX_BUFFER_LENGTH);
- bufStart = Int32.MaxValue; // nothing in the buffer so far
- } else {
- fileLen = bufLen = bufStart = 0;
- }
-
- buf = new byte[(bufLen>0) ? bufLen : MIN_BUFFER_LENGTH];
- if (fileLen > 0) Pos = 0; // setup buffer to position 0 (start)
- else bufPos = 0; // index 0 is already after the file, thus Pos = 0 is invalid
- if (bufLen == fileLen && stream.CanSeek) Close();
- }
-
- protected Buffer(Buffer b) { // called in UTF8Buffer constructor
- buf = b.buf;
- bufStart = b.bufStart;
- bufLen = b.bufLen;
- fileLen = b.fileLen;
- bufPos = b.bufPos;
- stream = b.stream;
- // keep destructor from closing the stream
- b.stream = null;
- isUserStream = b.isUserStream;
- }
-
- ~Buffer() { Close(); }
-
- protected void Close() {
- if (!isUserStream && stream != null) {
- stream.Close();
- stream = null;
- }
- }
-
- public virtual int Read () {
- if (bufPos < bufLen) {
- return buf[bufPos++];
- } else if (Pos < fileLen) {
- Pos = Pos; // shift buffer start to Pos
- return buf[bufPos++];
- } else if (stream != null && !stream.CanSeek && ReadNextStreamChunk() > 0) {
- return buf[bufPos++];
- } else {
- return EOF;
- }
- }
-
- public int Peek () {
- int curPos = Pos;
- int ch = Read();
- Pos = curPos;
- return ch;
- }
-
- // beg .. begin, zero-based, inclusive, in byte
- // end .. end, zero-based, exclusive, in byte
- public string GetString (int beg, int end) {
- int len = 0;
- char[] buf = new char[end - beg];
- int oldPos = Pos;
- Pos = beg;
- while (Pos < end) buf[len++] = (char) Read();
- Pos = oldPos;
- return new String(buf, 0, len);
- }
-
- public int Pos {
- get { return bufPos + bufStart; }
- set {
- if (value >= fileLen && stream != null && !stream.CanSeek) {
- // Wanted position is after buffer and the stream
- // is not seek-able e.g. network or console,
- // thus we have to read the stream manually till
- // the wanted position is in sight.
- while (value >= fileLen && ReadNextStreamChunk() > 0);
- }
-
- if (value < 0 || value > fileLen) {
- throw new FatalError("buffer out of bounds access, position: " + value);
- }
-
- if (value >= bufStart && value < bufStart + bufLen) { // already in buffer
- bufPos = value - bufStart;
- } else if (stream != null) { // must be swapped in
- stream.Seek(value, SeekOrigin.Begin);
- bufLen = stream.Read(buf, 0, buf.Length);
- bufStart = value; bufPos = 0;
- } else {
- // set the position to the end of the file, Pos will return fileLen.
- bufPos = fileLen - bufStart;
- }
- }
- }
-
- // Read the next chunk of bytes from the stream, increases the buffer
- // if needed and updates the fields fileLen and bufLen.
- // Returns the number of bytes read.
- private int ReadNextStreamChunk() {
- int free = buf.Length - bufLen;
- if (free == 0) {
- // in the case of a growing input stream
- // we can neither seek in the stream, nor can we
- // foresee the maximum length, thus we must adapt
- // the buffer size on demand.
- byte[] newBuf = new byte[bufLen * 2];
- Array.Copy(buf, newBuf, bufLen);
- buf = newBuf;
- free = bufLen;
- }
- int read = stream.Read(buf, bufLen, free);
- if (read > 0) {
- fileLen = bufLen = (bufLen + read);
- return read;
- }
- // end of stream reached
- return 0;
- }
-}
-
-//-----------------------------------------------------------------------------------
-// UTF8Buffer
-//-----------------------------------------------------------------------------------
-public class UTF8Buffer: Buffer {
- public UTF8Buffer(Buffer b): base(b) {}
-
- public override int Read() {
- int ch;
- do {
- ch = base.Read();
- // until we find a utf8 start (0xxxxxxx or 11xxxxxx)
- } while ((ch >= 128) && ((ch & 0xC0) != 0xC0) && (ch != EOF));
- if (ch < 128 || ch == EOF) {
- // nothing to do, first 127 chars are the same in ascii and utf8
- // 0xxxxxxx or end of file character
- } else if ((ch & 0xF0) == 0xF0) {
- // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
- int c1 = ch & 0x07; ch = base.Read();
- int c2 = ch & 0x3F; ch = base.Read();
- int c3 = ch & 0x3F; ch = base.Read();
- int c4 = ch & 0x3F;
- ch = (((((c1 << 6) | c2) << 6) | c3) << 6) | c4;
- } else if ((ch & 0xE0) == 0xE0) {
- // 1110xxxx 10xxxxxx 10xxxxxx
- int c1 = ch & 0x0F; ch = base.Read();
- int c2 = ch & 0x3F; ch = base.Read();
- int c3 = ch & 0x3F;
- ch = (((c1 << 6) | c2) << 6) | c3;
- } else if ((ch & 0xC0) == 0xC0) {
- // 110xxxxx 10xxxxxx
- int c1 = ch & 0x1F; ch = base.Read();
- int c2 = ch & 0x3F;
- ch = (c1 << 6) | c2;
- }
- return ch;
- }
-}
-
-//-----------------------------------------------------------------------------------
-// Scanner
-//-----------------------------------------------------------------------------------
-public class Scanner {
- const char EOL = '\n';
- const int eofSym = 0; /* pdt */
--->declarations
-
- public Buffer buffer; // scanner buffer
-
- Token t; // current token
- int ch; // current input character
- int pos; // byte position of current character
- int charPos; // position by unicode characters starting with 0
- int col; // column number of current character
- int line; // line number of current character
- int oldEols; // EOLs that appeared in a comment;
- static readonly Hashtable start; // maps first token character to start state
-
- Token tokens; // list of tokens already peeked (first token is a dummy)
- Token pt; // current peek token
-
- char[] tval = new char[128]; // text of current token
- int tlen; // length of current token
-
- static Scanner() {
- start = new Hashtable(128);
--->initialization
- }
-
- public Scanner (string fileName) {
- try {
- Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
- buffer = new Buffer(stream, false);
- Init();
- } catch (IOException) {
- throw new FatalError("Cannot open file " + fileName);
- }
- }
-
- public Scanner (Stream s) {
- buffer = new Buffer(s, true);
- Init();
- }
-
- void Init() {
- pos = -1; line = 1; col = 0; charPos = -1;
- oldEols = 0;
- NextCh();
- if (ch == 0xEF) { // check optional byte order mark for UTF-8
- NextCh(); int ch1 = ch;
- NextCh(); int ch2 = ch;
- if (ch1 != 0xBB || ch2 != 0xBF) {
- throw new FatalError(String.Format("illegal byte order mark: EF {0,2:X} {1,2:X}", ch1, ch2));
- }
- buffer = new UTF8Buffer(buffer); col = 0; charPos = -1;
- NextCh();
- }
- pt = tokens = new Token(); // first token is a dummy
- }
-
- void NextCh() {
- if (oldEols > 0) { ch = EOL; oldEols--; }
- else {
- pos = buffer.Pos;
- // buffer reads unicode chars, if UTF8 has been detected
- ch = buffer.Read(); col++; charPos++;
- // replace isolated '\r' by '\n' in order to make
- // eol handling uniform across Windows, Unix and Mac
- if (ch == '\r' && buffer.Peek() != '\n') ch = EOL;
- if (ch == EOL) { line++; col = 0; }
- }
--->casing1
- }
-
- void AddCh() {
- if (tlen >= tval.Length) {
- char[] newBuf = new char[2 * tval.Length];
- Array.Copy(tval, 0, newBuf, 0, tval.Length);
- tval = newBuf;
- }
- if (ch != Buffer.EOF) {
--->casing2
- NextCh();
- }
- }
-
-
--->comments
-
- void CheckLiteral() {
--->literals
- }
-
- Token NextToken() {
- while (ch == ' ' ||
--->scan1
- ) NextCh();
--->scan2
- int recKind = noSym;
- int recEnd = pos;
- t = new Token();
- t.pos = pos; t.col = col; t.line = line; t.charPos = charPos;
- int state;
- if (start.ContainsKey(ch)) { state = (int) start[ch]; }
- else { state = 0; }
- tlen = 0; AddCh();
-
- switch (state) {
- case -1: { t.kind = eofSym; break; } // NextCh already done
- case 0: {
- if (recKind != noSym) {
- tlen = recEnd - t.pos;
- SetScannerBehindT();
- }
- t.kind = recKind; break;
- } // NextCh already done
--->scan3
- }
- t.val = new String(tval, 0, tlen);
- return t;
- }
-
- private void SetScannerBehindT() {
- buffer.Pos = t.pos;
- NextCh();
- line = t.line; col = t.col; charPos = t.charPos;
- for (int i = 0; i < tlen; i++) NextCh();
- }
-
- // get the next token (possibly a token already seen during peeking)
- public Token Scan () {
- if (tokens.next == null) {
- return NextToken();
- } else {
- pt = tokens = tokens.next;
- return tokens;
- }
- }
-
- // peek for the next token, ignore pragmas
- public Token Peek () {
- do {
- if (pt.next == null) {
- pt.next = NextToken();
- }
- pt = pt.next;
- } while (pt.kind > maxT); // skip pragmas
-
- return pt;
- }
-
- // make sure that peeking starts at the current scan position
- public void ResetPeek () { pt = tokens; }
-
-} // end Scanner
+/*----------------------------------------------------------------------
+Compiler Generator Coco/R,
+Copyright (c) 1990, 2004 Hanspeter Moessenboeck, University of Linz
+extended by M. Loeberbauer & A. Woess, Univ. of Linz
+with improvements by Pat Terry, Rhodes University
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+As an exception, it is allowed to write an extension of Coco/R that is
+used as a plugin in non-free software.
+
+If not otherwise stated, any source code generated by Coco/R (other than
+Coco/R itself) does not fall under the GNU General Public License.
+-----------------------------------------------------------------------*/
+-->begin
+using System;
+using System.IO;
+using System.Collections;
+
+-->namespace
+
+public class Token {
+ public int kind; // token kind
+ public int pos; // token position in bytes in the source text (starting at 0)
+ public int charPos; // token position in characters in the source text (starting at 0)
+ public int col; // token column (starting at 1)
+ public int line; // token line (starting at 1)
+ public string val; // token value
+ public Token next; // ML 2005-03-11 Tokens are kept in linked list
+}
+
+//-----------------------------------------------------------------------------------
+// Buffer
+//-----------------------------------------------------------------------------------
+public class Buffer {
+ // This Buffer supports the following cases:
+ // 1) seekable stream (file)
+ // a) whole stream in buffer
+ // b) part of stream in buffer
+ // 2) non seekable stream (network, console)
+
+ public const int EOF = char.MaxValue + 1;
+ const int MIN_BUFFER_LENGTH = 1024; // 1KB
+ const int MAX_BUFFER_LENGTH = MIN_BUFFER_LENGTH * 64; // 64KB
+ byte[] buf; // input buffer
+ int bufStart; // position of first byte in buffer relative to input stream
+ int bufLen; // length of buffer
+ int fileLen; // length of input stream (may change if the stream is no file)
+ int bufPos; // current position in buffer
+ Stream stream; // input stream (seekable)
+ bool isUserStream; // was the stream opened by the user?
+
+ public Buffer (Stream s, bool isUserStream) {
+ stream = s; this.isUserStream = isUserStream;
+
+ if (stream.CanSeek) {
+ fileLen = (int) stream.Length;
+ bufLen = Math.Min(fileLen, MAX_BUFFER_LENGTH);
+ bufStart = Int32.MaxValue; // nothing in the buffer so far
+ } else {
+ fileLen = bufLen = bufStart = 0;
+ }
+
+ buf = new byte[(bufLen>0) ? bufLen : MIN_BUFFER_LENGTH];
+ if (fileLen > 0) Pos = 0; // setup buffer to position 0 (start)
+ else bufPos = 0; // index 0 is already after the file, thus Pos = 0 is invalid
+ if (bufLen == fileLen && stream.CanSeek) Close();
+ }
+
+ protected Buffer(Buffer b) { // called in UTF8Buffer constructor
+ buf = b.buf;
+ bufStart = b.bufStart;
+ bufLen = b.bufLen;
+ fileLen = b.fileLen;
+ bufPos = b.bufPos;
+ stream = b.stream;
+ // keep destructor from closing the stream
+ b.stream = null;
+ isUserStream = b.isUserStream;
+ }
+
+ ~Buffer() { Close(); }
+
+ protected void Close() {
+ if (!isUserStream && stream != null) {
+ stream.Close();
+ stream = null;
+ }
+ }
+
+ public virtual int Read () {
+ if (bufPos < bufLen) {
+ return buf[bufPos++];
+ } else if (Pos < fileLen) {
+ Pos = Pos; // shift buffer start to Pos
+ return buf[bufPos++];
+ } else if (stream != null && !stream.CanSeek && ReadNextStreamChunk() > 0) {
+ return buf[bufPos++];
+ } else {
+ return EOF;
+ }
+ }
+
+ public int Peek () {
+ int curPos = Pos;
+ int ch = Read();
+ Pos = curPos;
+ return ch;
+ }
+
+ // beg .. begin, zero-based, inclusive, in byte
+ // end .. end, zero-based, exclusive, in byte
+ public string GetString (int beg, int end) {
+ int len = 0;
+ char[] buf = new char[end - beg];
+ int oldPos = Pos;
+ Pos = beg;
+ while (Pos < end) buf[len++] = (char) Read();
+ Pos = oldPos;
+ return new String(buf, 0, len);
+ }
+
+ public int Pos {
+ get { return bufPos + bufStart; }
+ set {
+ if (value >= fileLen && stream != null && !stream.CanSeek) {
+ // Wanted position is after buffer and the stream
+ // is not seek-able e.g. network or console,
+ // thus we have to read the stream manually till
+ // the wanted position is in sight.
+ while (value >= fileLen && ReadNextStreamChunk() > 0);
+ }
+
+ if (value < 0 || value > fileLen) {
+ throw new FatalError("buffer out of bounds access, position: " + value);
+ }
+
+ if (value >= bufStart && value < bufStart + bufLen) { // already in buffer
+ bufPos = value - bufStart;
+ } else if (stream != null) { // must be swapped in
+ stream.Seek(value, SeekOrigin.Begin);
+ bufLen = stream.Read(buf, 0, buf.Length);
+ bufStart = value; bufPos = 0;
+ } else {
+ // set the position to the end of the file, Pos will return fileLen.
+ bufPos = fileLen - bufStart;
+ }
+ }
+ }
+
+ // Read the next chunk of bytes from the stream, increases the buffer
+ // if needed and updates the fields fileLen and bufLen.
+ // Returns the number of bytes read.
+ private int ReadNextStreamChunk() {
+ int free = buf.Length - bufLen;
+ if (free == 0) {
+ // in the case of a growing input stream
+ // we can neither seek in the stream, nor can we
+ // foresee the maximum length, thus we must adapt
+ // the buffer size on demand.
+ byte[] newBuf = new byte[bufLen * 2];
+ Array.Copy(buf, newBuf, bufLen);
+ buf = newBuf;
+ free = bufLen;
+ }
+ int read = stream.Read(buf, bufLen, free);
+ if (read > 0) {
+ fileLen = bufLen = (bufLen + read);
+ return read;
+ }
+ // end of stream reached
+ return 0;
+ }
+}
+
+//-----------------------------------------------------------------------------------
+// UTF8Buffer
+//-----------------------------------------------------------------------------------
+public class UTF8Buffer: Buffer {
+ public UTF8Buffer(Buffer b): base(b) {}
+
+ public override int Read() {
+ int ch;
+ do {
+ ch = base.Read();
+ // until we find a utf8 start (0xxxxxxx or 11xxxxxx)
+ } while ((ch >= 128) && ((ch & 0xC0) != 0xC0) && (ch != EOF));
+ if (ch < 128 || ch == EOF) {
+ // nothing to do, first 127 chars are the same in ascii and utf8
+ // 0xxxxxxx or end of file character
+ } else if ((ch & 0xF0) == 0xF0) {
+ // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
+ int c1 = ch & 0x07; ch = base.Read();
+ int c2 = ch & 0x3F; ch = base.Read();
+ int c3 = ch & 0x3F; ch = base.Read();
+ int c4 = ch & 0x3F;
+ ch = (((((c1 << 6) | c2) << 6) | c3) << 6) | c4;
+ } else if ((ch & 0xE0) == 0xE0) {
+ // 1110xxxx 10xxxxxx 10xxxxxx
+ int c1 = ch & 0x0F; ch = base.Read();
+ int c2 = ch & 0x3F; ch = base.Read();
+ int c3 = ch & 0x3F;
+ ch = (((c1 << 6) | c2) << 6) | c3;
+ } else if ((ch & 0xC0) == 0xC0) {
+ // 110xxxxx 10xxxxxx
+ int c1 = ch & 0x1F; ch = base.Read();
+ int c2 = ch & 0x3F;
+ ch = (c1 << 6) | c2;
+ }
+ return ch;
+ }
+}
+
+//-----------------------------------------------------------------------------------
+// Scanner
+//-----------------------------------------------------------------------------------
+public class Scanner {
+ const char EOL = '\n';
+ const int eofSym = 0; /* pdt */
+-->declarations
+
+ public Buffer buffer; // scanner buffer
+
+ Token t; // current token
+ int ch; // current input character
+ int pos; // byte position of current character
+ int charPos; // position by unicode characters starting with 0
+ int col; // column number of current character
+ int line; // line number of current character
+ int oldEols; // EOLs that appeared in a comment;
+ static readonly Hashtable start; // maps first token character to start state
+
+ Token tokens; // list of tokens already peeked (first token is a dummy)
+ Token pt; // current peek token
+
+ char[] tval = new char[128]; // text of current token
+ int tlen; // length of current token
+
+ static Scanner() {
+ start = new Hashtable(128);
+-->initialization
+ }
+
+ public Scanner (string fileName) {
+ try {
+ Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
+ buffer = new Buffer(stream, false);
+ Init();
+ } catch (IOException) {
+ throw new FatalError("Cannot open file " + fileName);
+ }
+ }
+
+ public Scanner (Stream s) {
+ buffer = new Buffer(s, true);
+ Init();
+ }
+
+ void Init() {
+ pos = -1; line = 1; col = 0; charPos = -1;
+ oldEols = 0;
+ NextCh();
+ if (ch == 0xEF) { // check optional byte order mark for UTF-8
+ NextCh(); int ch1 = ch;
+ NextCh(); int ch2 = ch;
+ if (ch1 != 0xBB || ch2 != 0xBF) {
+ throw new FatalError(String.Format("illegal byte order mark: EF {0,2:X} {1,2:X}", ch1, ch2));
+ }
+ buffer = new UTF8Buffer(buffer); col = 0; charPos = -1;
+ NextCh();
+ }
+ pt = tokens = new Token(); // first token is a dummy
+ }
+
+ void NextCh() {
+ if (oldEols > 0) { ch = EOL; oldEols--; }
+ else {
+ pos = buffer.Pos;
+ // buffer reads unicode chars, if UTF8 has been detected
+ ch = buffer.Read(); col++; charPos++;
+ // replace isolated '\r' by '\n' in order to make
+ // eol handling uniform across Windows, Unix and Mac
+ if (ch == '\r' && buffer.Peek() != '\n') ch = EOL;
+ if (ch == EOL) { line++; col = 0; }
+ }
+-->casing1
+ }
+
+ void AddCh() {
+ if (tlen >= tval.Length) {
+ char[] newBuf = new char[2 * tval.Length];
+ Array.Copy(tval, 0, newBuf, 0, tval.Length);
+ tval = newBuf;
+ }
+ if (ch != Buffer.EOF) {
+-->casing2
+ NextCh();
+ }
+ }
+
+
+-->comments
+
+ void CheckLiteral() {
+-->literals
+ }
+
+ Token NextToken() {
+ while (ch == ' ' ||
+-->scan1
+ ) NextCh();
+-->scan2
+ int recKind = noSym;
+ int recEnd = pos;
+ t = new Token();
+ t.pos = pos; t.col = col; t.line = line; t.charPos = charPos;
+ int state;
+ if (start.ContainsKey(ch)) { state = (int) start[ch]; }
+ else { state = 0; }
+ tlen = 0; AddCh();
+
+ switch (state) {
+ case -1: { t.kind = eofSym; break; } // NextCh already done
+ case 0: {
+ if (recKind != noSym) {
+ tlen = recEnd - t.pos;
+ SetScannerBehindT();
+ }
+ t.kind = recKind; break;
+ } // NextCh already done
+-->scan3
+ }
+ t.val = new String(tval, 0, tlen);
+ return t;
+ }
+
+ private void SetScannerBehindT() {
+ buffer.Pos = t.pos;
+ NextCh();
+ line = t.line; col = t.col; charPos = t.charPos;
+ for (int i = 0; i < tlen; i++) NextCh();
+ }
+
+ // get the next token (possibly a token already seen during peeking)
+ public Token Scan () {
+ if (tokens.next == null) {
+ return NextToken();
+ } else {
+ pt = tokens = tokens.next;
+ return tokens;
+ }
+ }
+
+ // peek for the next token, ignore pragmas
+ public Token Peek () {
+ do {
+ if (pt.next == null) {
+ pt.next = NextToken();
+ }
+ pt = pt.next;
+ } while (pt.kind > maxT); // skip pragmas
+
+ return pt;
+ }
+
+ // make sure that peeking starts at the current scan position
+ public void ResetPeek () { pt = tokens; }
+
+} // end Scanner
diff --git a/CS-MIC/csmic/csmic/MacroBuilder.cs b/CS-MIC/csmic/csmic/MacroBuilder.cs
new file mode 100644
index 0000000..dad631c
--- /dev/null
+++ b/CS-MIC/csmic/csmic/MacroBuilder.cs
@@ -0,0 +1,337 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.IO;
+using System.Threading;
+using csmic.Scripting;
+using System.Runtime.Remoting.Messaging;
+
+namespace csmic
+{
+ ///
+ /// A builder object that executes macro scripts.
+ ///
+ public class MacroBuilder
+ {
+ #region Members
+
+ ///
+ /// The input inputInterpreter.
+ ///
+ private InputInterpreter interpreter;
+ /// The script to run as a macro.
+ private string script;
+ ///
+ /// The output as a list of strings.
+ ///
+ private List output;
+ ///
+ /// The time for execution.
+ ///
+ private TimeSpan executionTime;
+ ///
+ /// The root macro operation.
+ ///
+ private MacroOperation rootOperation;
+
+ #endregion
+
+ #region Constructor
+
+ ///
+ /// Creates a new builder object that executes a given macro script.
+ ///
+ /// A list of strings representing the macro.
+ /// The InputInterpreter to be used.
+ public MacroBuilder(string script, InputInterpreter inputInterpreter)
+ {
+ this.output = new List();
+ this.executionTime = new TimeSpan();
+
+ this.script = script;
+ this.interpreter = inputInterpreter;
+ }
+
+ ///
+ /// Creates a new builder object that executes a given macro script.
+ ///
+ /// A list of strings representing the macro.
+ /// The InputInterpreter to be used.
+ internal MacroBuilder(MacroOperation script, InputInterpreter inputInterpreter)
+ {
+ this.output = new List();
+ this.executionTime = new TimeSpan();
+ DateTime timeStart = DateTime.Now;
+
+ this.interpreter = inputInterpreter;
+
+ this.rootOperation = script;
+
+ ExecuteOperation(this.rootOperation);
+
+ DateTime timeEnd = DateTime.Now;
+ this.executionTime = timeEnd - timeStart;
+ }
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// Gets a list of strings representing the output.
+ ///
+ public List Output
+ {
+ get
+ {
+ return this.output;
+ }
+ }
+
+ ///
+ /// Gets the execution time of the last script computation.
+ ///
+ public TimeSpan LastExecutionTime
+ {
+ get
+ {
+ return this.executionTime;
+ }
+ }
+
+ ///
+ /// Gets the decimal value last computed by the macrobuilder.
+ ///
+ public string FinalOutput
+ {
+ get
+ {
+ return this.interpreter.Output;
+ }
+ }
+
+ #endregion
+
+ #region Public Methods
+
+ /// Runs this macro.
+ public void Run()
+ {
+ DateTime timeStart = DateTime.Now;
+
+ ASCIIEncoding encoder = new ASCIIEncoding();
+ Parser p = new Parser(new Scanner(new MemoryStream(encoder.GetBytes(this.script))));
+ p.Parse();
+
+ this.rootOperation = p.Root;
+
+ ExecuteOperation(p.Root);
+
+ DateTime timeEnd = DateTime.Now;
+ this.executionTime = timeEnd - timeStart;
+ }
+
+ #endregion
+
+ #region Private Methods
+
+ private void ExecuteOperation(MacroOperation operation)
+ {
+ switch (operation.OperationType)
+ {
+ case OperationType.If:
+ if (operation.Input.Count == 1)
+ {
+ this.interpreter.Interpret(operation.Input[0]);
+ if (this.interpreter.Decimal == 1)
+ {
+ foreach (MacroOperation op in operation.Children)
+ {
+ ExecuteOperation(op);
+ }
+ }
+ }
+ break;
+ case OperationType.Else:
+ foreach (MacroOperation op in operation.Children)
+ {
+ ExecuteOperation(op);
+ }
+ break;
+ case OperationType.IfElse:
+ if (operation.Children.Count == 2 && operation.Children[0].Input.Count == 1)
+ {
+ MacroOperation ifOp = operation.Children[0];
+ MacroOperation elseOp = operation.Children[1];
+ this.interpreter.Interpret(ifOp.Input[0]);
+ if (this.interpreter.Decimal == 1)
+ {
+ foreach (MacroOperation op in ifOp.Children)
+ {
+ ExecuteOperation(op);
+ }
+ }
+ else
+ {
+ foreach (MacroOperation op in elseOp.Children)
+ {
+ ExecuteOperation(op);
+ }
+ }
+ }
+ break;
+ case OperationType.While:
+ if (operation.Input.Count == 1)
+ {
+ this.interpreter.Interpret(operation.Input[0]);
+ while (this.interpreter.Decimal == 1)
+ {
+ foreach (MacroOperation op in operation.Children)
+ {
+ ExecuteOperation(op);
+ }
+ this.interpreter.Interpret(operation.Input[0]);
+ }
+ }
+ break;
+ case OperationType.For:
+ if (operation.Input.Count == 3)
+ {
+ this.interpreter.Interpret(operation.Input[0]);
+ this.interpreter.Interpret(operation.Input[1]);
+ int loopCount = this.interpreter.Int;
+ while (this.interpreter.Int == 1)
+ {
+ foreach (MacroOperation op in operation.Children)
+ {
+ ExecuteOperation(op);
+ }
+ this.interpreter.Interpret(operation.Input[2]);
+ this.interpreter.Interpret(operation.Input[1]);
+ }
+ }
+ break;
+ case OperationType.FunctionDeclaration:
+ if (operation.Input.Count > 1)
+ {
+ string name = operation.Input[0];
+ operation.Input.RemoveAt(0);
+ StringBuilder builder = new StringBuilder();
+ operation.OperationType = OperationType.Unknown;
+ InterpretedFunction function = new InterpretedFunction(name, operation, operation.Input.ToArray());
+ if (this.interpreter.InterpretedFunctions.Contains(function))
+ {
+ this.interpreter.InterpretedFunctions[this.interpreter.InterpretedFunctions.IndexOf(function)] = function;
+ }
+ else
+ {
+ this.interpreter.InterpretedFunctions.Add(function);
+ }
+ }
+ break;
+ case OperationType.Echo:
+ if (operation.Children.Count == 1)
+ {
+ MacroOperation op = operation.Children[0];
+ if (op.OperationType == OperationType.Statement)
+ {
+ this.interpreter.Interpret(op.Input[0]);
+ this.output.Add(this.interpreter.Output);
+ }
+ }
+ break;
+ case OperationType.Say:
+ if (operation.Input.Count == 1)
+ {
+ this.output.Add(operation.Input[0]);
+ }
+ break;
+ case OperationType.Display:
+ StringBuilder sb = new StringBuilder();
+ foreach (MacroOperation op in operation.Children)
+ {
+ if (op.OperationType == OperationType.Statement)
+ {
+ if (op.Input.Count == 1)
+ {
+ this.interpreter.Interpret(op.Input[0]);
+ sb.Append(this.interpreter.Output);
+ }
+ }
+ else if (op.OperationType == OperationType.String)
+ {
+ if (op.Input.Count == 1)
+ {
+ sb.Append(op.Input[0]);
+ }
+ }
+ }
+ this.output.Add(sb.ToString());
+ break;
+ case OperationType.Statement:
+ if (operation.Input.Count == 1)
+ {
+ this.interpreter.Interpret(operation.Input[0]);
+ }
+ break;
+ case OperationType.String:
+ //Should not reach this state.
+ break;
+ case OperationType.Unknown:
+ if (operation.Children.Count > 0)
+ {
+ foreach (MacroOperation op in operation.Children)
+ {
+ ExecuteOperation(op);
+ }
+ }
+ break;
+ default:
+ //CRAP.
+ break;
+ }
+ }
+
+ #endregion
+
+ #region Asynchronous
+
+ /// Executes the asynchronous operation.
+ /// The input.
+ /// The callback.
+ public void RunAsync(string input, Action callback)
+ {
+ MacroAsyncDelegate del = new MacroAsyncDelegate(RunAsyncThreadingWork);
+ del.BeginInvoke(input, (result) =>
+ {
+ AsyncResult returned = result as AsyncResult;
+ if (returned != null)
+ {
+ MacroAsyncDelegate end = returned.AsyncDelegate as MacroAsyncDelegate;
+ if (end != null)
+ {
+ MacroBuilder returnValue = end.EndInvoke(result);
+ callback(returnValue);
+ }
+ }
+ }, null);
+ }
+
+ /// Executes the asynchronous threading work operation.
+ /// The input.
+ /// .
+ private MacroBuilder RunAsyncThreadingWork(string input)
+ {
+ Run();
+ return this;
+ }
+
+ /// Macro asynchronous delegate.
+ /// The input.
+ /// .
+ private delegate MacroBuilder MacroAsyncDelegate(string input);
+
+ #endregion
+ }
+}
diff --git a/CS-MIC/csmic/csmic/MacroOperation.cs b/CS-MIC/csmic/csmic/MacroOperation.cs
new file mode 100644
index 0000000..4e448e7
--- /dev/null
+++ b/CS-MIC/csmic/csmic/MacroOperation.cs
@@ -0,0 +1,149 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace csmic
+{
+ ///
+ /// Represents the operation types supported by a scripted macro.
+ ///
+ internal enum OperationType
+ {
+ ///
+ /// Represents a conditional block.
+ ///
+ If,
+ ///
+ /// Represents a conditional else block.
+ ///
+ Else,
+ ///
+ /// Represents a complete conditional block.
+ ///
+ IfElse,
+ ///
+ /// A while block.
+ ///
+ While,
+ ///
+ /// A for block.
+ ///
+ For,
+ ///
+ /// A function declaration.
+ ///
+ FunctionDeclaration,
+ ///
+ /// An echo statement.
+ ///
+ Echo,
+ ///
+ /// A say statement.
+ ///
+ Say,
+ ///
+ /// A display statement.
+ ///
+ Display,
+ ///
+ /// A statement to execute.
+ ///
+ Statement,
+ ///
+ /// A string to display.
+ ///
+ String,
+ ///
+ /// An unknown or malformed block.
+ ///
+ Unknown
+ }
+
+ ///
+ /// An operation object that executes a specified action.
+ ///
+ internal class MacroOperation
+ {
+ #region Members
+
+ ///
+ /// The type of operation represented by the operation.
+ ///
+ private OperationType operationType;
+ ///
+ /// The collection of children nodes that belong to the operation.
+ ///
+ private List children;
+ ///
+ /// A list of the necesary input to execute the operation.
+ ///
+ private List input;
+
+ #endregion
+
+ #region Constructor
+
+ ///
+ /// Creates a new macro operation node.
+ ///
+ /// The type of operation the node represents.
+ public MacroOperation(OperationType operationType)
+ {
+ this.operationType = operationType;
+ this.children = new List();
+ this.input = new List();
+ }
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// Gets or sets the children nodes of the operation.
+ ///
+ public List Children
+ {
+ get
+ {
+ return this.children;
+ }
+ set
+ {
+ this.children = value;
+ }
+ }
+
+ ///
+ /// Gets or sets the input for the operation.
+ ///
+ public List Input
+ {
+ get
+ {
+ return this.input;
+ }
+ set
+ {
+ this.input = value;
+ }
+ }
+
+ ///
+ /// Gets or sets the operation type for this operation.
+ ///
+ public OperationType OperationType
+ {
+ get
+ {
+ return this.operationType;
+ }
+ set
+ {
+ this.operationType = value;
+ }
+ }
+
+ #endregion
+ }
+}
diff --git a/CS-MIC/csmic/csmic/ScriptParser/Parser.cs b/CS-MIC/csmic/csmic/ScriptParser/Parser.cs
new file mode 100644
index 0000000..1906973
--- /dev/null
+++ b/CS-MIC/csmic/csmic/ScriptParser/Parser.cs
@@ -0,0 +1,794 @@
+using csmic;
+using System.Text;
+using System.Collections.Generic;
+
+
+
+using System;
+
+namespace csmic.Scripting {
+
+
+
+public class Parser {
+ public const int _EOF = 0;
+ public const int _identifier = 1;
+ public const int _sign = 2;
+ public const int _binary = 3;
+ public const int _hex = 4;
+ public const int _number = 5;
+ public const int _newline = 6;
+ public const int _string = 7;
+ public const int _LPAREN = 8;
+ public const int _RPAREN = 9;
+ public const int _COMPARER = 10;
+ public const int maxT = 34;
+
+ const bool _T = true;
+ const bool _x = false;
+ const int minErrDist = 2;
+
+ public Scanner scanner;
+ public Errors errors;
+
+ public Token t; // last recognized token
+ public Token la; // lookahead token
+ int errDist = minErrDist;
+
+private MacroOperation root = new MacroOperation(OperationType.Unknown);
+
+internal MacroOperation Root
+{
+ get
+ {
+ return this.root;
+ }
+ set
+ {
+ this.root = value;
+ }
+}
+
+bool IsFunctionCall()
+{
+ scanner.ResetPeek();
+ Token next = scanner.Peek();
+ if (next.kind == _LPAREN && la.kind == _identifier)
+ return true;
+ return false;
+}
+
+bool IsCompare()
+{
+ scanner.ResetPeek();
+ Token next = scanner.Peek();
+ if (next.kind == _COMPARER)
+ return true;
+ return false;
+}
+
+bool IsAssignment()
+{
+ scanner.ResetPeek();
+ Token next = scanner.Peek();
+ if (next.val == "::" || next.val == ":=" || next.val == "->")
+ return true;
+ return false;
+}
+
+bool IsArrayCall()
+{
+ scanner.ResetPeek();
+ Token next = scanner.Peek();
+ if(next.val == "[")
+ return true;
+ return false;
+}
+
+
+
+ public Parser(Scanner scanner) {
+ this.scanner = scanner;
+ errors = new Errors();
+ }
+
+ void SynErr (int n) {
+ if (errDist >= minErrDist) errors.SynErr(la.line, la.col, n);
+ errDist = 0;
+ }
+
+ public void SemErr (string msg) {
+ if (errDist >= minErrDist) errors.SemErr(t.line, t.col, msg);
+ errDist = 0;
+ }
+
+ void Get () {
+ for (;;) {
+ t = la;
+ la = scanner.Scan();
+ if (la.kind <= maxT) { ++errDist; break; }
+
+ la = t;
+ }
+ }
+
+ void Expect (int n) {
+ if (la.kind==n) Get(); else { SynErr(n); }
+ }
+
+ bool StartOf (int s) {
+ return set[s, la.kind];
+ }
+
+ void ExpectWeak (int n, int follow) {
+ if (la.kind == n) Get();
+ else {
+ SynErr(n);
+ while (!StartOf(follow)) Get();
+ }
+ }
+
+
+ bool WeakSeparator(int n, int syFol, int repFol) {
+ int kind = la.kind;
+ if (kind == n) {Get(); return true;}
+ else if (StartOf(repFol)) {return false;}
+ else {
+ SynErr(n);
+ while (!(set[syFol, kind] || set[repFol, kind] || set[0, kind])) {
+ Get();
+ kind = la.kind;
+ }
+ return StartOf(syFol);
+ }
+ }
+
+
+ void SCRIPT() {
+ string statement = string.Empty;
+ while (StartOf(1)) {
+ switch (la.kind) {
+ case 1: case 3: case 4: case 5: case 8: case 22: case 23: {
+ Statement(out statement);
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ this.root.Children.Add(operation);
+
+ break;
+ }
+ case 11: {
+ IfBlock(ref this.root);
+ break;
+ }
+ case 15: {
+ WhileBlock(ref this.root);
+ break;
+ }
+ case 18: {
+ FunctionDeclaration(ref this.root);
+ break;
+ }
+ case 19: {
+ EchoStatement(ref this.root);
+ break;
+ }
+ case 20: {
+ SayStatement(ref this.root);
+ break;
+ }
+ case 21: {
+ DisplayStatement(ref this.root);
+ break;
+ }
+ case 16: {
+ ForBlock(ref this.root);
+ break;
+ }
+ }
+ }
+ }
+
+ void Statement(out string value) {
+ value = string.Empty;
+ StringBuilder builder = new StringBuilder();
+
+ if (IsAssignment()) {
+ Assignment(ref builder);
+ value = builder.ToString();
+ } else if (StartOf(2)) {
+ Expression(ref builder);
+ value = builder.ToString();
+ } else SynErr(35);
+ }
+
+ void IfBlock(ref MacroOperation parent) {
+ MacroOperation ifBlock = new MacroOperation(OperationType.If);
+ MacroOperation elseBlock = new MacroOperation(OperationType.Else);
+ string ifStatement = string.Empty;
+ string statement = string.Empty;
+ StringBuilder builder = new StringBuilder();
+ bool hasElse = false;
+
+ Expect(11);
+ Expect(8);
+ Comparison(ref builder);
+ ifStatement = builder.ToString(); ifBlock.Input.Add(ifStatement);
+ Expect(9);
+ Expect(12);
+ while (StartOf(3)) {
+ switch (la.kind) {
+ case 1: case 3: case 4: case 5: case 8: case 22: case 23: {
+ Statement(out statement);
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ ifBlock.Children.Add(operation);
+
+ break;
+ }
+ case 11: {
+ IfBlock(ref ifBlock);
+ break;
+ }
+ case 15: {
+ WhileBlock(ref ifBlock);
+ break;
+ }
+ case 19: {
+ EchoStatement(ref ifBlock);
+ break;
+ }
+ case 20: {
+ SayStatement(ref ifBlock);
+ break;
+ }
+ case 21: {
+ DisplayStatement(ref ifBlock);
+ break;
+ }
+ case 16: {
+ ForBlock(ref ifBlock);
+ break;
+ }
+ }
+ }
+ Expect(13);
+ if (la.kind == 14) {
+ Get();
+ hasElse = true;
+ Expect(12);
+ while (StartOf(3)) {
+ switch (la.kind) {
+ case 1: case 3: case 4: case 5: case 8: case 22: case 23: {
+ Statement(out statement);
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ elseBlock.Children.Add(operation);
+
+ break;
+ }
+ case 11: {
+ IfBlock(ref elseBlock);
+ break;
+ }
+ case 15: {
+ WhileBlock(ref elseBlock);
+ break;
+ }
+ case 19: {
+ EchoStatement(ref elseBlock);
+ break;
+ }
+ case 20: {
+ SayStatement(ref elseBlock);
+ break;
+ }
+ case 21: {
+ DisplayStatement(ref elseBlock);
+ break;
+ }
+ case 16: {
+ ForBlock(ref elseBlock);
+ break;
+ }
+ }
+ }
+ Expect(13);
+ }
+ if(hasElse)
+ {
+ MacroOperation ifelse = new MacroOperation(OperationType.IfElse);
+ ifelse.Children.Add(ifBlock);
+ ifelse.Children.Add(elseBlock);
+ parent.Children.Add(ifelse);
+ }
+ else
+ {
+ parent.Children.Add(ifBlock);
+ }
+
+ }
+
+ void WhileBlock(ref MacroOperation parent) {
+ StringBuilder builder = new StringBuilder();
+ MacroOperation whileBlock = new MacroOperation(OperationType.While);
+ string statement = string.Empty;
+
+ Expect(15);
+ Expect(8);
+ Comparison(ref builder);
+ whileBlock.Input.Add(builder.ToString());
+ Expect(9);
+ Expect(12);
+ while (StartOf(3)) {
+ switch (la.kind) {
+ case 1: case 3: case 4: case 5: case 8: case 22: case 23: {
+ Statement(out statement);
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ whileBlock.Children.Add(operation);
+
+ break;
+ }
+ case 11: {
+ IfBlock(ref whileBlock);
+ break;
+ }
+ case 15: {
+ WhileBlock(ref whileBlock);
+ break;
+ }
+ case 19: {
+ EchoStatement(ref whileBlock);
+ break;
+ }
+ case 20: {
+ SayStatement(ref whileBlock);
+ break;
+ }
+ case 21: {
+ DisplayStatement(ref whileBlock);
+ break;
+ }
+ case 16: {
+ ForBlock(ref whileBlock);
+ break;
+ }
+ }
+ }
+ Expect(13);
+ parent.Children.Add(whileBlock);
+
+ }
+
+ void FunctionDeclaration(ref MacroOperation parent) {
+ StringBuilder builder = new StringBuilder();
+ string statement = string.Empty;
+ MacroOperation func = new MacroOperation(OperationType.FunctionDeclaration);
+
+ Expect(18);
+ Expect(8);
+ CommaList(ref builder);
+ string[] args = builder.ToString().Split(','); func.Input.AddRange(args);
+ Expect(9);
+ Expect(12);
+ while (StartOf(3)) {
+ switch (la.kind) {
+ case 1: case 3: case 4: case 5: case 8: case 22: case 23: {
+ Statement(out statement);
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ func.Children.Add(operation);
+
+ break;
+ }
+ case 11: {
+ IfBlock(ref func);
+ break;
+ }
+ case 15: {
+ WhileBlock(ref func);
+ break;
+ }
+ case 19: {
+ EchoStatement(ref func);
+ break;
+ }
+ case 20: {
+ SayStatement(ref func);
+ break;
+ }
+ case 21: {
+ DisplayStatement(ref func);
+ break;
+ }
+ case 16: {
+ ForBlock(ref func);
+ break;
+ }
+ }
+ }
+ Expect(13);
+ parent.Children.Add(func);
+
+ }
+
+ void EchoStatement(ref MacroOperation parent) {
+ StringBuilder builder = new StringBuilder();
+ MacroOperation echoStatement = new MacroOperation(OperationType.Echo);
+ string statement = string.Empty;
+
+ Expect(19);
+ Statement(out statement);
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ echoStatement.Children.Add(operation);
+ parent.Children.Add(echoStatement);
+
+ }
+
+ void SayStatement(ref MacroOperation parent) {
+ StringBuilder builder = new StringBuilder();
+ MacroOperation sayStatement = new MacroOperation(OperationType.Say);
+ string statement = string.Empty;
+
+ Expect(20);
+ Expect(7);
+ statement = t.val.Replace("\"", "");
+ sayStatement.Input.Add(statement);
+ parent.Children.Add(sayStatement);
+
+ }
+
+ void DisplayStatement(ref MacroOperation parent) {
+ StringBuilder builder = new StringBuilder();
+ MacroOperation displayStatement = new MacroOperation(OperationType.Display);
+ string statement = string.Empty;
+
+ Expect(21);
+ if (StartOf(2)) {
+ Statement(out statement);
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ displayStatement.Children.Add(operation);
+
+ } else if (la.kind == 7) {
+ Get();
+ statement = t.val.Replace("\"", "");
+ MacroOperation operation = new MacroOperation(OperationType.String);
+ operation.Input.Add(statement);
+ displayStatement.Children.Add(operation);
+
+ } else SynErr(36);
+ while (la.kind == 17) {
+ Get();
+ if (StartOf(2)) {
+ Statement(out statement);
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ displayStatement.Children.Add(operation);
+
+ } else if (la.kind == 7) {
+ Get();
+ statement = t.val.Replace("\"", "");
+ MacroOperation operation = new MacroOperation(OperationType.String);
+ operation.Input.Add(statement);
+ displayStatement.Children.Add(operation);
+
+ } else SynErr(37);
+ }
+ parent.Children.Add(displayStatement);
+
+ }
+
+ void ForBlock(ref MacroOperation parent) {
+ StringBuilder builder = new StringBuilder();
+ string statement = string.Empty;
+ string statement2 = string.Empty;
+ MacroOperation forBlock = new MacroOperation(OperationType.For);
+
+ Expect(16);
+ Expect(8);
+ Statement(out statement);
+ Expect(17);
+ Comparison(ref builder);
+ Expect(17);
+ Statement(out statement2);
+ forBlock.Input.Add(statement); forBlock.Input.Add(builder.ToString()); forBlock.Input.Add(statement2);
+ Expect(9);
+ Expect(12);
+ while (StartOf(3)) {
+ switch (la.kind) {
+ case 1: case 3: case 4: case 5: case 8: case 22: case 23: {
+ Statement(out statement);
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ forBlock.Children.Add(operation);
+
+ break;
+ }
+ case 11: {
+ IfBlock(ref forBlock);
+ break;
+ }
+ case 15: {
+ WhileBlock(ref forBlock);
+ break;
+ }
+ case 19: {
+ EchoStatement(ref forBlock);
+ break;
+ }
+ case 20: {
+ SayStatement(ref forBlock);
+ break;
+ }
+ case 21: {
+ DisplayStatement(ref forBlock);
+ break;
+ }
+ case 16: {
+ ForBlock(ref forBlock);
+ break;
+ }
+ }
+ }
+ Expect(13);
+ parent.Children.Add(forBlock);
+
+ }
+
+ void Comparison(ref StringBuilder result) {
+ Expression(ref result);
+ Expect(10);
+ result.Append(t.val);
+ Expression(ref result);
+ }
+
+ void CommaList(ref StringBuilder builder) {
+ Expression(ref builder);
+ while (la.kind == 17) {
+ Get();
+ builder.Append(t.val);
+ Expression(ref builder);
+ }
+ }
+
+ void Assignment(ref StringBuilder builder) {
+ Expect(1);
+ builder.Append(t.val);
+ if (la.kind == 30) {
+ Get();
+ builder.Append(t.val);
+ Expression(ref builder);
+ } else if (la.kind == 31) {
+ Get();
+ builder.Append(t.val); string value = string.Empty;
+ AnyExpression(out value);
+ builder.Append(value);
+ Expect(6);
+ } else if (la.kind == 32) {
+ Get();
+ builder.Append(t.val);
+ ArrayL(ref builder);
+ } else SynErr(38);
+ }
+
+ void Expression(ref StringBuilder builder) {
+ Term(ref builder);
+ while (la.kind == 22 || la.kind == 23 || la.kind == 24) {
+ if (la.kind == 22) {
+ Get();
+ builder.Append(t.val);
+ Term(ref builder);
+ } else if (la.kind == 23) {
+ Get();
+ builder.Append(t.val);
+ Term(ref builder);
+ } else {
+ Get();
+ builder.Append(t.val);
+ Term(ref builder);
+ }
+ }
+ }
+
+ void Term(ref StringBuilder builder) {
+ Factor(ref builder);
+ while (la.kind == 25 || la.kind == 26) {
+ if (la.kind == 25) {
+ Get();
+ builder.Append(t.val);
+ Factor(ref builder);
+ } else {
+ Get();
+ builder.Append(t.val);
+ Factor(ref builder);
+ }
+ }
+ }
+
+ void Factor(ref StringBuilder builder) {
+ Value(ref builder);
+ while (la.kind == 27) {
+ Get();
+ builder.Append(t.val);
+ Value(ref builder);
+ }
+ }
+
+ void Value(ref StringBuilder builder) {
+ if (la.kind == 22 || la.kind == 23) {
+ if (la.kind == 22) {
+ Get();
+ builder.Append(t.val);
+ } else {
+ Get();
+ builder.Append(t.val);
+ }
+ }
+ if (IsFunctionCall()) {
+ Function(ref builder);
+ } else if (IsArrayCall()) {
+ ArrayCall(ref builder);
+ } else if (la.kind == 1) {
+ Get();
+ builder.Append(t.val);
+ } else if (la.kind == 5) {
+ Get();
+ builder.Append(t.val);
+ } else if (la.kind == 4) {
+ Get();
+ builder.Append(t.val);
+ } else if (la.kind == 3) {
+ Get();
+ builder.Append(t.val);
+ } else if (la.kind == 8) {
+ Get();
+ builder.Append(t.val);
+ Expression(ref builder);
+ Expect(9);
+ builder.Append(t.val);
+ } else SynErr(39);
+ }
+
+ void Function(ref StringBuilder builder) {
+ Expect(1);
+ builder.Append(t.val);
+ Expect(8);
+ builder.Append(t.val);
+ CommaList(ref builder);
+ Expect(9);
+ builder.Append(t.val);
+ }
+
+ void ArrayCall(ref StringBuilder builder) {
+ Expect(1);
+ builder.Append(t.val);
+ Expect(28);
+ builder.Append(t.val);
+ Expression(ref builder);
+ Expect(29);
+ builder.Append(t.val);
+ }
+
+ void ArrayL(ref StringBuilder builder) {
+ Expect(28);
+ builder.Append(t.val);
+ CommaList(ref builder);
+ Expect(29);
+ builder.Append(t.val);
+ }
+
+ void AnyExpression(out string value) {
+ value = string.Empty; StringBuilder builder = new StringBuilder();
+ Get();
+ builder.Append(t.val);
+ while (StartOf(4)) {
+ Get();
+ builder.Append(t.val);
+ }
+ Expect(33);
+ value = builder.ToString();
+ }
+
+
+
+ public void Parse() {
+ la = new Token();
+ la.val = "";
+ Get();
+ SCRIPT();
+ Expect(0);
+
+ }
+
+ static readonly bool[,] set = {
+ {_T,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x},
+ {_x,_T,_x,_T, _T,_T,_x,_x, _T,_x,_x,_T, _x,_x,_x,_T, _T,_x,_T,_T, _T,_T,_T,_T, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x},
+ {_x,_T,_x,_T, _T,_T,_x,_x, _T,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_T,_T, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x},
+ {_x,_T,_x,_T, _T,_T,_x,_x, _T,_x,_x,_T, _x,_x,_x,_T, _T,_x,_x,_T, _T,_T,_T,_T, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x},
+ {_x,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_x,_T,_x}
+
+ };
+} // end Parser
+
+
+public class Errors {
+ public int count = 0; // number of errors detected
+ public System.IO.TextWriter errorStream = Console.Out; // error messages go to this stream
+ public string errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text
+
+ public virtual void SynErr (int line, int col, int n) {
+ string s;
+ switch (n) {
+ case 0: s = "EOF expected"; break;
+ case 1: s = "identifier expected"; break;
+ case 2: s = "sign expected"; break;
+ case 3: s = "binary expected"; break;
+ case 4: s = "hex expected"; break;
+ case 5: s = "number expected"; break;
+ case 6: s = "newline expected"; break;
+ case 7: s = "string expected"; break;
+ case 8: s = "LPAREN expected"; break;
+ case 9: s = "RPAREN expected"; break;
+ case 10: s = "COMPARER expected"; break;
+ case 11: s = "\"if\" expected"; break;
+ case 12: s = "\"{\" expected"; break;
+ case 13: s = "\"}\" expected"; break;
+ case 14: s = "\"else\" expected"; break;
+ case 15: s = "\"while\" expected"; break;
+ case 16: s = "\"for\" expected"; break;
+ case 17: s = "\",\" expected"; break;
+ case 18: s = "\"function\" expected"; break;
+ case 19: s = "\"echo:\" expected"; break;
+ case 20: s = "\"say:\" expected"; break;
+ case 21: s = "\"display:\" expected"; break;
+ case 22: s = "\"+\" expected"; break;
+ case 23: s = "\"-\" expected"; break;
+ case 24: s = "\"%\" expected"; break;
+ case 25: s = "\"*\" expected"; break;
+ case 26: s = "\"/\" expected"; break;
+ case 27: s = "\"^\" expected"; break;
+ case 28: s = "\"[\" expected"; break;
+ case 29: s = "\"]\" expected"; break;
+ case 30: s = "\"::\" expected"; break;
+ case 31: s = "\":=\" expected"; break;
+ case 32: s = "\"->\" expected"; break;
+ case 33: s = "\"\\n\" expected"; break;
+ case 34: s = "??? expected"; break;
+ case 35: s = "invalid Statement"; break;
+ case 36: s = "invalid DisplayStatement"; break;
+ case 37: s = "invalid DisplayStatement"; break;
+ case 38: s = "invalid Assignment"; break;
+ case 39: s = "invalid Value"; break;
+
+ default: s = "error " + n; break;
+ }
+ errorStream.WriteLine(errMsgFormat, line, col, s);
+ count++;
+ }
+
+ public virtual void SemErr (int line, int col, string s) {
+ errorStream.WriteLine(errMsgFormat, line, col, s);
+ count++;
+ }
+
+ public virtual void SemErr (string s) {
+ errorStream.WriteLine(s);
+ count++;
+ }
+
+ public virtual void Warning (int line, int col, string s) {
+ errorStream.WriteLine(errMsgFormat, line, col, s);
+ }
+
+ public virtual void Warning(string s) {
+ errorStream.WriteLine(s);
+ }
+} // Errors
+
+
+public class FatalError: Exception {
+ public FatalError(string m): base(m) {}
+}
+}
\ No newline at end of file
diff --git a/CS-MIC/csmic/csmic/ScriptParser/Parser.cs.old b/CS-MIC/csmic/csmic/ScriptParser/Parser.cs.old
new file mode 100644
index 0000000..6995c23
--- /dev/null
+++ b/CS-MIC/csmic/csmic/ScriptParser/Parser.cs.old
@@ -0,0 +1,794 @@
+using csmic;
+using System.Text;
+using System.Collections.Generic;
+
+
+
+using System;
+
+namespace csmic.Scripting {
+
+
+
+public class Parser {
+ public const int _EOF = 0;
+ public const int _identifier = 1;
+ public const int _sign = 2;
+ public const int _binary = 3;
+ public const int _hex = 4;
+ public const int _number = 5;
+ public const int _newline = 6;
+ public const int _string = 7;
+ public const int _LPAREN = 8;
+ public const int _RPAREN = 9;
+ public const int _COMPARER = 10;
+ public const int maxT = 34;
+
+ const bool _T = true;
+ const bool _x = false;
+ const int minErrDist = 2;
+
+ public Scanner scanner;
+ public Errors errors;
+
+ public Token t; // last recognized token
+ public Token la; // lookahead token
+ int errDist = minErrDist;
+
+private MacroOperation root = new MacroOperation(OperationType.Unknown);
+
+internal MacroOperation Root
+{
+ get
+ {
+ return this.root;
+ }
+ set
+ {
+ this.root = value;
+ }
+}
+
+bool IsFunctionCall()
+{
+ scanner.ResetPeek();
+ Token next = scanner.Peek();
+ if (next.kind == _LPAREN && la.kind == _identifier)
+ return true;
+ return false;
+}
+
+bool IsCompare()
+{
+ scanner.ResetPeek();
+ Token next = scanner.Peek();
+ if (next.kind == _COMPARER)
+ return true;
+ return false;
+}
+
+bool IsAssignment()
+{
+ scanner.ResetPeek();
+ Token next = scanner.Peek();
+ if (next.val == "::" || next.val == ":=" || next.val == "->")
+ return true;
+ return false;
+}
+
+bool IsArrayCall()
+{
+ scanner.ResetPeek();
+ Token next = scanner.Peek();
+ if(next.val == "[")
+ return true;
+ return false;
+}
+
+
+
+ public Parser(Scanner scanner) {
+ this.scanner = scanner;
+ errors = new Errors();
+ }
+
+ void SynErr (int n) {
+ if (errDist >= minErrDist) errors.SynErr(la.line, la.col, n);
+ errDist = 0;
+ }
+
+ public void SemErr (string msg) {
+ if (errDist >= minErrDist) errors.SemErr(t.line, t.col, msg);
+ errDist = 0;
+ }
+
+ void Get () {
+ for (;;) {
+ t = la;
+ la = scanner.Scan();
+ if (la.kind <= maxT) { ++errDist; break; }
+
+ la = t;
+ }
+ }
+
+ void Expect (int n) {
+ if (la.kind==n) Get(); else { SynErr(n); }
+ }
+
+ bool StartOf (int s) {
+ return set[s, la.kind];
+ }
+
+ void ExpectWeak (int n, int follow) {
+ if (la.kind == n) Get();
+ else {
+ SynErr(n);
+ while (!StartOf(follow)) Get();
+ }
+ }
+
+
+ bool WeakSeparator(int n, int syFol, int repFol) {
+ int kind = la.kind;
+ if (kind == n) {Get(); return true;}
+ else if (StartOf(repFol)) {return false;}
+ else {
+ SynErr(n);
+ while (!(set[syFol, kind] || set[repFol, kind] || set[0, kind])) {
+ Get();
+ kind = la.kind;
+ }
+ return StartOf(syFol);
+ }
+ }
+
+
+ void SCRIPT() {
+ string statement = string.Empty;
+ while (StartOf(1)) {
+ switch (la.kind) {
+ case 1: case 3: case 4: case 5: case 8: case 22: case 23: {
+ Statement(out statement);
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ this.root.Children.Add(operation);
+
+ break;
+ }
+ case 11: {
+ IfBlock(ref this.root);
+ break;
+ }
+ case 15: {
+ WhileBlock(ref this.root);
+ break;
+ }
+ case 18: {
+ FunctionDeclaration(ref this.root);
+ break;
+ }
+ case 19: {
+ EchoStatement(ref this.root);
+ break;
+ }
+ case 20: {
+ SayStatement(ref this.root);
+ break;
+ }
+ case 21: {
+ DisplayStatement(ref this.root);
+ break;
+ }
+ case 16: {
+ ForBlock(ref this.root);
+ break;
+ }
+ }
+ }
+ }
+
+ void Statement(out string value) {
+ value = string.Empty;
+ StringBuilder builder = new StringBuilder();
+
+ if (IsAssignment()) {
+ Assignment(ref builder);
+ value = builder.ToString();
+ } else if (StartOf(2)) {
+ Expression(ref builder);
+ value = builder.ToString();
+ } else SynErr(35);
+ }
+
+ void IfBlock(ref MacroOperation parent) {
+ MacroOperation ifBlock = new MacroOperation(OperationType.If);
+ MacroOperation elseBlock = new MacroOperation(OperationType.Else);
+ string ifStatement = string.Empty;
+ string statement = string.Empty;
+ StringBuilder builder = new StringBuilder();
+ bool hasElse = false;
+
+ Expect(11);
+ Expect(8);
+ Comparison(ref builder);
+ ifStatement = builder.ToString(); ifBlock.Input.Add(ifStatement);
+ Expect(9);
+ Expect(12);
+ while (StartOf(3)) {
+ switch (la.kind) {
+ case 1: case 3: case 4: case 5: case 8: case 22: case 23: {
+ Statement(out statement);
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ ifBlock.Children.Add(operation);
+
+ break;
+ }
+ case 11: {
+ IfBlock(ref ifBlock);
+ break;
+ }
+ case 15: {
+ WhileBlock(ref ifBlock);
+ break;
+ }
+ case 19: {
+ EchoStatement(ref ifBlock);
+ break;
+ }
+ case 20: {
+ SayStatement(ref ifBlock);
+ break;
+ }
+ case 21: {
+ DisplayStatement(ref ifBlock);
+ break;
+ }
+ case 16: {
+ ForBlock(ref ifBlock);
+ break;
+ }
+ }
+ }
+ Expect(13);
+ if (la.kind == 14) {
+ Get();
+ hasElse = true;
+ Expect(12);
+ while (StartOf(3)) {
+ switch (la.kind) {
+ case 1: case 3: case 4: case 5: case 8: case 22: case 23: {
+ Statement(out statement);
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ elseBlock.Children.Add(operation);
+
+ break;
+ }
+ case 11: {
+ IfBlock(ref elseBlock);
+ break;
+ }
+ case 15: {
+ WhileBlock(ref elseBlock);
+ break;
+ }
+ case 19: {
+ EchoStatement(ref elseBlock);
+ break;
+ }
+ case 20: {
+ SayStatement(ref elseBlock);
+ break;
+ }
+ case 21: {
+ DisplayStatement(ref elseBlock);
+ break;
+ }
+ case 16: {
+ ForBlock(ref elseBlock);
+ break;
+ }
+ }
+ }
+ Expect(13);
+ }
+ if(hasElse)
+ {
+ MacroOperation ifelse = new MacroOperation(OperationType.IfElse);
+ ifelse.Children.Add(ifBlock);
+ ifelse.Children.Add(elseBlock);
+ parent.Children.Add(ifelse);
+ }
+ else
+ {
+ parent.Children.Add(ifBlock);
+ }
+
+ }
+
+ void WhileBlock(ref MacroOperation parent) {
+ StringBuilder builder = new StringBuilder();
+ MacroOperation whileBlock = new MacroOperation(OperationType.While);
+ string statement = string.Empty;
+
+ Expect(15);
+ Expect(8);
+ Comparison(ref builder);
+ whileBlock.Input.Add(builder.ToString());
+ Expect(9);
+ Expect(12);
+ while (StartOf(3)) {
+ switch (la.kind) {
+ case 1: case 3: case 4: case 5: case 8: case 22: case 23: {
+ Statement(out statement);
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ whileBlock.Children.Add(operation);
+
+ break;
+ }
+ case 11: {
+ IfBlock(ref whileBlock);
+ break;
+ }
+ case 15: {
+ WhileBlock(ref whileBlock);
+ break;
+ }
+ case 19: {
+ EchoStatement(ref whileBlock);
+ break;
+ }
+ case 20: {
+ SayStatement(ref whileBlock);
+ break;
+ }
+ case 21: {
+ DisplayStatement(ref whileBlock);
+ break;
+ }
+ case 16: {
+ ForBlock(ref whileBlock);
+ break;
+ }
+ }
+ }
+ Expect(13);
+ parent.Children.Add(whileBlock);
+
+ }
+
+ void FunctionDeclaration(ref MacroOperation parent) {
+ StringBuilder builder = new StringBuilder();
+ string statement = string.Empty;
+ MacroOperation func = new MacroOperation(OperationType.FunctionDeclaration);
+
+ Expect(18);
+ Expect(8);
+ CommaList(ref builder);
+ string[] args = builder.ToString().Split(','); func.Input.AddRange(args);
+ Expect(9);
+ Expect(12);
+ while (StartOf(3)) {
+ switch (la.kind) {
+ case 1: case 3: case 4: case 5: case 8: case 22: case 23: {
+ Statement(out statement);
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ func.Children.Add(operation);
+
+ break;
+ }
+ case 11: {
+ IfBlock(ref func);
+ break;
+ }
+ case 15: {
+ WhileBlock(ref func);
+ break;
+ }
+ case 19: {
+ EchoStatement(ref func);
+ break;
+ }
+ case 20: {
+ SayStatement(ref func);
+ break;
+ }
+ case 21: {
+ DisplayStatement(ref func);
+ break;
+ }
+ case 16: {
+ ForBlock(ref func);
+ break;
+ }
+ }
+ }
+ Expect(13);
+ parent.Children.Add(func);
+
+ }
+
+ void EchoStatement(ref MacroOperation parent) {
+ StringBuilder builder = new StringBuilder();
+ MacroOperation echoStatement = new MacroOperation(OperationType.Echo);
+ string statement = string.Empty;
+
+ Expect(19);
+ Statement(out statement);
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ echoStatement.Children.Add(operation);
+ parent.Children.Add(echoStatement);
+
+ }
+
+ void SayStatement(ref MacroOperation parent) {
+ StringBuilder builder = new StringBuilder();
+ MacroOperation sayStatement = new MacroOperation(OperationType.Say);
+ string statement = string.Empty;
+
+ Expect(20);
+ Expect(7);
+ statement = t.val.Replace("\"", "");
+ sayStatement.Input.Add(statement);
+ parent.Children.Add(sayStatement);
+
+ }
+
+ void DisplayStatement(ref MacroOperation parent) {
+ StringBuilder builder = new StringBuilder();
+ MacroOperation displayStatement = new MacroOperation(OperationType.Display);
+ string statement = string.Empty;
+
+ Expect(21);
+ if (StartOf(2)) {
+ Statement(out statement);
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ displayStatement.Children.Add(operation);
+
+ } else if (la.kind == 7) {
+ Get();
+ statement = t.val.Replace("\"", "");
+ MacroOperation operation = new MacroOperation(OperationType.String);
+ operation.Input.Add(statement);
+ displayStatement.Children.Add(operation);
+
+ } else SynErr(36);
+ while (la.kind == 17) {
+ Get();
+ if (StartOf(2)) {
+ Statement(out statement);
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ displayStatement.Children.Add(operation);
+
+ } else if (la.kind == 7) {
+ Get();
+ statement = t.val.Replace("\"", "");
+ MacroOperation operation = new MacroOperation(OperationType.String);
+ operation.Input.Add(statement);
+ displayStatement.Children.Add(operation);
+
+ } else SynErr(37);
+ }
+ parent.Children.Add(displayStatement);
+
+ }
+
+ void ForBlock(ref MacroOperation parent) {
+ StringBuilder builder = new StringBuilder();
+ string statement = string.Empty;
+ string statement2 = string.Empty;
+ MacroOperation forBlock = new MacroOperation(OperationType.For);
+
+ Expect(16);
+ Expect(8);
+ Statement(out statement);
+ Expect(17);
+ Comparison(ref builder);
+ Expect(17);
+ Statement(out statement2);
+ forBlock.Input.Add(statement); forBlock.Input.Add(builder.ToString()); forBlock.Input.Add(statement2);
+ Expect(9);
+ Expect(12);
+ while (StartOf(3)) {
+ switch (la.kind) {
+ case 1: case 3: case 4: case 5: case 8: case 22: case 23: {
+ Statement(out statement);
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ forBlock.Children.Add(operation);
+
+ break;
+ }
+ case 11: {
+ IfBlock(ref forBlock);
+ break;
+ }
+ case 15: {
+ WhileBlock(ref forBlock);
+ break;
+ }
+ case 19: {
+ EchoStatement(ref forBlock);
+ break;
+ }
+ case 20: {
+ SayStatement(ref forBlock);
+ break;
+ }
+ case 21: {
+ DisplayStatement(ref forBlock);
+ break;
+ }
+ case 16: {
+ ForBlock(ref forBlock);
+ break;
+ }
+ }
+ }
+ Expect(13);
+ parent.Children.Add(forBlock);
+
+ }
+
+ void Comparison(ref StringBuilder result) {
+ Expression(ref result);
+ Expect(10);
+ result.Append(t.val);
+ Expression(ref result);
+ }
+
+ void CommaList(ref StringBuilder builder) {
+ Expression(ref builder);
+ while (la.kind == 17) {
+ Get();
+ builder.Append(t.val);
+ Expression(ref builder);
+ }
+ }
+
+ void Assignment(ref StringBuilder builder) {
+ Expect(1);
+ builder.Append(t.val);
+ if (la.kind == 30) {
+ Get();
+ builder.Append(t.val);
+ Expression(ref builder);
+ } else if (la.kind == 31) {
+ Get();
+ builder.Append(t.val); string value = string.Empty;
+ AnyExpression(out value);
+ builder.Append(value);
+ Expect(6);
+ } else if (la.kind == 32) {
+ Get();
+ builder.Append(t.val);
+ ArrayL(ref builder);
+ } else SynErr(38);
+ }
+
+ void Expression(ref StringBuilder builder) {
+ Term(ref builder);
+ while (la.kind == 22 || la.kind == 23 || la.kind == 24) {
+ if (la.kind == 22) {
+ Get();
+ builder.Append(t.val);
+ Term(ref builder);
+ } else if (la.kind == 23) {
+ Get();
+ builder.Append(t.val);
+ Term(ref builder);
+ } else {
+ Get();
+ builder.Append(t.val);
+ Term(ref builder);
+ }
+ }
+ }
+
+ void Term(ref StringBuilder builder) {
+ Factor(ref builder);
+ while (la.kind == 25 || la.kind == 26) {
+ if (la.kind == 25) {
+ Get();
+ builder.Append(t.val);
+ Factor(ref builder);
+ } else {
+ Get();
+ builder.Append(t.val);
+ Factor(ref builder);
+ }
+ }
+ }
+
+ void Factor(ref StringBuilder builder) {
+ Value(ref builder);
+ while (la.kind == 27) {
+ Get();
+ builder.Append(t.val);
+ Value(ref builder);
+ }
+ }
+
+ void Value(ref StringBuilder builder) {
+ if (la.kind == 22 || la.kind == 23) {
+ if (la.kind == 22) {
+ Get();
+ builder.Append(t.val);
+ } else {
+ Get();
+ builder.Append(t.val);
+ }
+ }
+ if (IsFunctionCall()) {
+ Function(ref builder);
+ } else if (IsArrayCall()) {
+ ArrayCall(ref builder);
+ } else if (la.kind == 1) {
+ Get();
+ builder.Append(t.val);
+ } else if (la.kind == 5) {
+ Get();
+ builder.Append(t.val);
+ } else if (la.kind == 4) {
+ Get();
+ builder.Append(t.val);
+ } else if (la.kind == 3) {
+ Get();
+ builder.Append(t.val);
+ } else if (la.kind == 8) {
+ Get();
+ builder.Append(t.val);
+ Expression(ref builder);
+ Expect(9);
+ builder.Append(t.val);
+ } else SynErr(39);
+ }
+
+ void Function(ref StringBuilder builder) {
+ Expect(1);
+ builder.Append(t.val);
+ Expect(8);
+ builder.Append(t.val);
+ CommaList(ref builder);
+ Expect(9);
+ builder.Append(t.val);
+ }
+
+ void ArrayCall(ref StringBuilder builder) {
+ Expect(1);
+ builder.Append(t.val);
+ Expect(28);
+ builder.Append(t.val);
+ Expression(ref builder);
+ Expect(29);
+ builder.Append(t.val);
+ }
+
+ void ArrayL(ref StringBuilder builder) {
+ Expect(28);
+ builder.Append(t.val);
+ CommaList(ref builder);
+ Expect(29);
+ builder.Append(t.val);
+ }
+
+ void AnyExpression(out string value) {
+ value = string.Empty; StringBuilder builder = new StringBuilder();
+ Get();
+ builder.Append(t.val);
+ while (StartOf(4)) {
+ Get();
+ builder.Append(t.val);
+ }
+ Expect(33);
+ value = builder.ToString();
+ }
+
+
+
+ public void Parse() {
+ la = new Token();
+ la.val = "";
+ Get();
+ SCRIPT();
+ Expect(0);
+
+ }
+
+ static readonly bool[,] set = {
+ {_T,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x},
+ {_x,_T,_x,_T, _T,_T,_x,_x, _T,_x,_x,_T, _x,_x,_x,_T, _T,_x,_T,_T, _T,_T,_T,_T, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x},
+ {_x,_T,_x,_T, _T,_T,_x,_x, _T,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_T,_T, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x},
+ {_x,_T,_x,_T, _T,_T,_x,_x, _T,_x,_x,_T, _x,_x,_x,_T, _T,_x,_x,_T, _T,_T,_T,_T, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x},
+ {_x,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_x,_T,_x}
+
+ };
+} // end Parser
+
+
+public class Errors {
+ public int count = 0; // number of errors detected
+ public System.IO.TextWriter errorStream = Console.Out; // error messages go to this stream
+ public string errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text
+
+ public virtual void SynErr (int line, int col, int n) {
+ string s;
+ switch (n) {
+ case 0: s = "EOF expected"; break;
+ case 1: s = "identifier expected"; break;
+ case 2: s = "sign expected"; break;
+ case 3: s = "binary expected"; break;
+ case 4: s = "hex expected"; break;
+ case 5: s = "number expected"; break;
+ case 6: s = "newline expected"; break;
+ case 7: s = "string expected"; break;
+ case 8: s = "LPAREN expected"; break;
+ case 9: s = "RPAREN expected"; break;
+ case 10: s = "COMPARER expected"; break;
+ case 11: s = "\"if\" expected"; break;
+ case 12: s = "\"{\" expected"; break;
+ case 13: s = "\"}\" expected"; break;
+ case 14: s = "\"else\" expected"; break;
+ case 15: s = "\"while\" expected"; break;
+ case 16: s = "\"for\" expected"; break;
+ case 17: s = "\",\" expected"; break;
+ case 18: s = "\"function\" expected"; break;
+ case 19: s = "\"echo:\" expected"; break;
+ case 20: s = "\"say:\" expected"; break;
+ case 21: s = "\"display:\" expected"; break;
+ case 22: s = "\"+\" expected"; break;
+ case 23: s = "\"-\" expected"; break;
+ case 24: s = "\"%\" expected"; break;
+ case 25: s = "\"*\" expected"; break;
+ case 26: s = "\"/\" expected"; break;
+ case 27: s = "\"^\" expected"; break;
+ case 28: s = "\"[\" expected"; break;
+ case 29: s = "\"]\" expected"; break;
+ case 30: s = "\"::\" expected"; break;
+ case 31: s = "\":=\" expected"; break;
+ case 32: s = "\"->\" expected"; break;
+ case 33: s = "\"\\n\" expected"; break;
+ case 34: s = "??? expected"; break;
+ case 35: s = "invalid Statement"; break;
+ case 36: s = "invalid DisplayStatement"; break;
+ case 37: s = "invalid DisplayStatement"; break;
+ case 38: s = "invalid Assignment"; break;
+ case 39: s = "invalid Value"; break;
+
+ default: s = "error " + n; break;
+ }
+ errorStream.WriteLine(errMsgFormat, line, col, s);
+ count++;
+ }
+
+ public virtual void SemErr (int line, int col, string s) {
+ errorStream.WriteLine(errMsgFormat, line, col, s);
+ count++;
+ }
+
+ public virtual void SemErr (string s) {
+ errorStream.WriteLine(s);
+ count++;
+ }
+
+ public virtual void Warning (int line, int col, string s) {
+ errorStream.WriteLine(errMsgFormat, line, col, s);
+ }
+
+ public virtual void Warning(string s) {
+ errorStream.WriteLine(s);
+ }
+} // Errors
+
+
+public class FatalError: Exception {
+ public FatalError(string m): base(m) {}
+}
+}
\ No newline at end of file
diff --git a/CS-MIC/csmic/csmic/ScriptParser/Parser.frame b/CS-MIC/csmic/csmic/ScriptParser/Parser.frame
new file mode 100644
index 0000000..85e022f
--- /dev/null
+++ b/CS-MIC/csmic/csmic/ScriptParser/Parser.frame
@@ -0,0 +1,156 @@
+/*----------------------------------------------------------------------
+Compiler Generator Coco/R,
+Copyright (c) 1990, 2004 Hanspeter Moessenboeck, University of Linz
+extended by M. Loeberbauer & A. Woess, Univ. of Linz
+with improvements by Pat Terry, Rhodes University
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+As an exception, it is allowed to write an extension of Coco/R that is
+used as a plugin in non-free software.
+
+If not otherwise stated, any source code generated by Coco/R (other than
+Coco/R itself) does not fall under the GNU General Public License.
+----------------------------------------------------------------------*/
+-->begin
+using System;
+
+-->namespace
+
+public class Parser {
+-->constants
+ const bool _T = true;
+ const bool _x = false;
+ const int minErrDist = 2;
+
+ public Scanner scanner;
+ public Errors errors;
+
+ public Token t; // last recognized token
+ public Token la; // lookahead token
+ int errDist = minErrDist;
+
+-->declarations
+
+ public Parser(Scanner scanner) {
+ this.scanner = scanner;
+ errors = new Errors();
+ }
+
+ void SynErr (int n) {
+ if (errDist >= minErrDist) errors.SynErr(la.line, la.col, n);
+ errDist = 0;
+ }
+
+ public void SemErr (string msg) {
+ if (errDist >= minErrDist) errors.SemErr(t.line, t.col, msg);
+ errDist = 0;
+ }
+
+ void Get () {
+ for (;;) {
+ t = la;
+ la = scanner.Scan();
+ if (la.kind <= maxT) { ++errDist; break; }
+-->pragmas
+ la = t;
+ }
+ }
+
+ void Expect (int n) {
+ if (la.kind==n) Get(); else { SynErr(n); }
+ }
+
+ bool StartOf (int s) {
+ return set[s, la.kind];
+ }
+
+ void ExpectWeak (int n, int follow) {
+ if (la.kind == n) Get();
+ else {
+ SynErr(n);
+ while (!StartOf(follow)) Get();
+ }
+ }
+
+
+ bool WeakSeparator(int n, int syFol, int repFol) {
+ int kind = la.kind;
+ if (kind == n) {Get(); return true;}
+ else if (StartOf(repFol)) {return false;}
+ else {
+ SynErr(n);
+ while (!(set[syFol, kind] || set[repFol, kind] || set[0, kind])) {
+ Get();
+ kind = la.kind;
+ }
+ return StartOf(syFol);
+ }
+ }
+
+
+-->productions
+
+ public void Parse() {
+ la = new Token();
+ la.val = "";
+ Get();
+-->parseRoot
+ }
+
+ static readonly bool[,] set = {
+-->initialization
+ };
+} // end Parser
+
+
+public class Errors {
+ public int count = 0; // number of errors detected
+ public System.IO.TextWriter errorStream = Console.Out; // error messages go to this stream
+ public string errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text
+
+ public virtual void SynErr (int line, int col, int n) {
+ string s;
+ switch (n) {
+-->errors
+ default: s = "error " + n; break;
+ }
+ errorStream.WriteLine(errMsgFormat, line, col, s);
+ count++;
+ }
+
+ public virtual void SemErr (int line, int col, string s) {
+ errorStream.WriteLine(errMsgFormat, line, col, s);
+ count++;
+ }
+
+ public virtual void SemErr (string s) {
+ errorStream.WriteLine(s);
+ count++;
+ }
+
+ public virtual void Warning (int line, int col, string s) {
+ errorStream.WriteLine(errMsgFormat, line, col, s);
+ }
+
+ public virtual void Warning(string s) {
+ errorStream.WriteLine(s);
+ }
+} // Errors
+
+
+public class FatalError: Exception {
+ public FatalError(string m): base(m) {}
+}
diff --git a/CS-MIC/csmic/csmic/ScriptParser/Scanner.cs b/CS-MIC/csmic/csmic/ScriptParser/Scanner.cs
new file mode 100644
index 0000000..5d86fec
--- /dev/null
+++ b/CS-MIC/csmic/csmic/ScriptParser/Scanner.cs
@@ -0,0 +1,635 @@
+
+using System;
+using System.IO;
+using System.Collections;
+
+namespace csmic.Scripting {
+
+public class Token {
+ public int kind; // token kind
+ public int pos; // token position in bytes in the source text (starting at 0)
+ public int charPos; // token position in characters in the source text (starting at 0)
+ public int col; // token column (starting at 1)
+ public int line; // token line (starting at 1)
+ public string val; // token value
+ public Token next; // ML 2005-03-11 Tokens are kept in linked list
+}
+
+//-----------------------------------------------------------------------------------
+// Buffer
+//-----------------------------------------------------------------------------------
+public class Buffer {
+ // This Buffer supports the following cases:
+ // 1) seekable stream (file)
+ // a) whole stream in buffer
+ // b) part of stream in buffer
+ // 2) non seekable stream (network, console)
+
+ public const int EOF = char.MaxValue + 1;
+ const int MIN_BUFFER_LENGTH = 1024; // 1KB
+ const int MAX_BUFFER_LENGTH = MIN_BUFFER_LENGTH * 64; // 64KB
+ byte[] buf; // input buffer
+ int bufStart; // position of first byte in buffer relative to input stream
+ int bufLen; // length of buffer
+ int fileLen; // length of input stream (may change if the stream is no file)
+ int bufPos; // current position in buffer
+ Stream stream; // input stream (seekable)
+ bool isUserStream; // was the stream opened by the user?
+
+ public Buffer (Stream s, bool isUserStream) {
+ stream = s; this.isUserStream = isUserStream;
+
+ if (stream.CanSeek) {
+ fileLen = (int) stream.Length;
+ bufLen = Math.Min(fileLen, MAX_BUFFER_LENGTH);
+ bufStart = Int32.MaxValue; // nothing in the buffer so far
+ } else {
+ fileLen = bufLen = bufStart = 0;
+ }
+
+ buf = new byte[(bufLen>0) ? bufLen : MIN_BUFFER_LENGTH];
+ if (fileLen > 0) Pos = 0; // setup buffer to position 0 (start)
+ else bufPos = 0; // index 0 is already after the file, thus Pos = 0 is invalid
+ if (bufLen == fileLen && stream.CanSeek) Close();
+ }
+
+ protected Buffer(Buffer b) { // called in UTF8Buffer constructor
+ buf = b.buf;
+ bufStart = b.bufStart;
+ bufLen = b.bufLen;
+ fileLen = b.fileLen;
+ bufPos = b.bufPos;
+ stream = b.stream;
+ // keep destructor from closing the stream
+ b.stream = null;
+ isUserStream = b.isUserStream;
+ }
+
+ ~Buffer() { Close(); }
+
+ protected void Close() {
+ if (!isUserStream && stream != null) {
+ stream.Close();
+ stream = null;
+ }
+ }
+
+ public virtual int Read () {
+ if (bufPos < bufLen) {
+ return buf[bufPos++];
+ } else if (Pos < fileLen) {
+ Pos = Pos; // shift buffer start to Pos
+ return buf[bufPos++];
+ } else if (stream != null && !stream.CanSeek && ReadNextStreamChunk() > 0) {
+ return buf[bufPos++];
+ } else {
+ return EOF;
+ }
+ }
+
+ public int Peek () {
+ int curPos = Pos;
+ int ch = Read();
+ Pos = curPos;
+ return ch;
+ }
+
+ // beg .. begin, zero-based, inclusive, in byte
+ // end .. end, zero-based, exclusive, in byte
+ public string GetString (int beg, int end) {
+ int len = 0;
+ char[] buf = new char[end - beg];
+ int oldPos = Pos;
+ Pos = beg;
+ while (Pos < end) buf[len++] = (char) Read();
+ Pos = oldPos;
+ return new String(buf, 0, len);
+ }
+
+ public int Pos {
+ get { return bufPos + bufStart; }
+ set {
+ if (value >= fileLen && stream != null && !stream.CanSeek) {
+ // Wanted position is after buffer and the stream
+ // is not seek-able e.g. network or console,
+ // thus we have to read the stream manually till
+ // the wanted position is in sight.
+ while (value >= fileLen && ReadNextStreamChunk() > 0);
+ }
+
+ if (value < 0 || value > fileLen) {
+ throw new FatalError("buffer out of bounds access, position: " + value);
+ }
+
+ if (value >= bufStart && value < bufStart + bufLen) { // already in buffer
+ bufPos = value - bufStart;
+ } else if (stream != null) { // must be swapped in
+ stream.Seek(value, SeekOrigin.Begin);
+ bufLen = stream.Read(buf, 0, buf.Length);
+ bufStart = value; bufPos = 0;
+ } else {
+ // set the position to the end of the file, Pos will return fileLen.
+ bufPos = fileLen - bufStart;
+ }
+ }
+ }
+
+ // Read the next chunk of bytes from the stream, increases the buffer
+ // if needed and updates the fields fileLen and bufLen.
+ // Returns the number of bytes read.
+ private int ReadNextStreamChunk() {
+ int free = buf.Length - bufLen;
+ if (free == 0) {
+ // in the case of a growing input stream
+ // we can neither seek in the stream, nor can we
+ // foresee the maximum length, thus we must adapt
+ // the buffer size on demand.
+ byte[] newBuf = new byte[bufLen * 2];
+ Array.Copy(buf, newBuf, bufLen);
+ buf = newBuf;
+ free = bufLen;
+ }
+ int read = stream.Read(buf, bufLen, free);
+ if (read > 0) {
+ fileLen = bufLen = (bufLen + read);
+ return read;
+ }
+ // end of stream reached
+ return 0;
+ }
+}
+
+//-----------------------------------------------------------------------------------
+// UTF8Buffer
+//-----------------------------------------------------------------------------------
+public class UTF8Buffer: Buffer {
+ public UTF8Buffer(Buffer b): base(b) {}
+
+ public override int Read() {
+ int ch;
+ do {
+ ch = base.Read();
+ // until we find a utf8 start (0xxxxxxx or 11xxxxxx)
+ } while ((ch >= 128) && ((ch & 0xC0) != 0xC0) && (ch != EOF));
+ if (ch < 128 || ch == EOF) {
+ // nothing to do, first 127 chars are the same in ascii and utf8
+ // 0xxxxxxx or end of file character
+ } else if ((ch & 0xF0) == 0xF0) {
+ // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
+ int c1 = ch & 0x07; ch = base.Read();
+ int c2 = ch & 0x3F; ch = base.Read();
+ int c3 = ch & 0x3F; ch = base.Read();
+ int c4 = ch & 0x3F;
+ ch = (((((c1 << 6) | c2) << 6) | c3) << 6) | c4;
+ } else if ((ch & 0xE0) == 0xE0) {
+ // 1110xxxx 10xxxxxx 10xxxxxx
+ int c1 = ch & 0x0F; ch = base.Read();
+ int c2 = ch & 0x3F; ch = base.Read();
+ int c3 = ch & 0x3F;
+ ch = (((c1 << 6) | c2) << 6) | c3;
+ } else if ((ch & 0xC0) == 0xC0) {
+ // 110xxxxx 10xxxxxx
+ int c1 = ch & 0x1F; ch = base.Read();
+ int c2 = ch & 0x3F;
+ ch = (c1 << 6) | c2;
+ }
+ return ch;
+ }
+}
+
+//-----------------------------------------------------------------------------------
+// Scanner
+//-----------------------------------------------------------------------------------
+public class Scanner {
+ const char EOL = '\n';
+ const int eofSym = 0; /* pdt */
+ const int maxT = 34;
+ const int noSym = 34;
+
+
+ public Buffer buffer; // scanner buffer
+
+ Token t; // current token
+ int ch; // current input character
+ int pos; // byte position of current character
+ int charPos; // position by unicode characters starting with 0
+ int col; // column number of current character
+ int line; // line number of current character
+ int oldEols; // EOLs that appeared in a comment;
+ static readonly Hashtable start; // maps first token character to start state
+
+ Token tokens; // list of tokens already peeked (first token is a dummy)
+ Token pt; // current peek token
+
+ char[] tval = new char[128]; // text of current token
+ int tlen; // length of current token
+
+ static Scanner() {
+ start = new Hashtable(128);
+ for (int i = 65; i <= 90; ++i) start[i] = 1;
+ for (int i = 97; i <= 99; ++i) start[i] = 1;
+ for (int i = 102; i <= 114; ++i) start[i] = 1;
+ for (int i = 116; i <= 122; ++i) start[i] = 1;
+ start[43] = 2;
+ for (int i = 50; i <= 57; ++i) start[i] = 6;
+ for (int i = 10; i <= 10; ++i) start[i] = 12;
+ for (int i = 13; i <= 13; ++i) start[i] = 11;
+ start[48] = 19;
+ start[49] = 20;
+ start[34] = 13;
+ start[40] = 15;
+ start[41] = 16;
+ start[61] = 17;
+ start[60] = 21;
+ start[62] = 22;
+ start[123] = 23;
+ start[125] = 24;
+ start[44] = 25;
+ start[101] = 38;
+ start[115] = 39;
+ start[100] = 40;
+ start[37] = 29;
+ start[42] = 30;
+ start[47] = 31;
+ start[94] = 32;
+ start[91] = 33;
+ start[93] = 34;
+ start[58] = 41;
+ start[45] = 42;
+ start[Buffer.EOF] = -1;
+
+ }
+
+ public Scanner (string fileName) {
+ try {
+ Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
+ buffer = new Buffer(stream, false);
+ Init();
+ } catch (IOException) {
+ throw new FatalError("Cannot open file " + fileName);
+ }
+ }
+
+ public Scanner (Stream s) {
+ buffer = new Buffer(s, true);
+ Init();
+ }
+
+ void Init() {
+ pos = -1; line = 1; col = 0; charPos = -1;
+ oldEols = 0;
+ NextCh();
+ if (ch == 0xEF) { // check optional byte order mark for UTF-8
+ NextCh(); int ch1 = ch;
+ NextCh(); int ch2 = ch;
+ if (ch1 != 0xBB || ch2 != 0xBF) {
+ throw new FatalError(String.Format("illegal byte order mark: EF {0,2:X} {1,2:X}", ch1, ch2));
+ }
+ buffer = new UTF8Buffer(buffer); col = 0; charPos = -1;
+ NextCh();
+ }
+ pt = tokens = new Token(); // first token is a dummy
+ }
+
+ void NextCh() {
+ if (oldEols > 0) { ch = EOL; oldEols--; }
+ else {
+ pos = buffer.Pos;
+ // buffer reads unicode chars, if UTF8 has been detected
+ ch = buffer.Read(); col++; charPos++;
+ // replace isolated '\r' by '\n' in order to make
+ // eol handling uniform across Windows, Unix and Mac
+ if (ch == '\r' && buffer.Peek() != '\n') ch = EOL;
+ if (ch == EOL) { line++; col = 0; }
+ }
+
+ }
+
+ void AddCh() {
+ if (tlen >= tval.Length) {
+ char[] newBuf = new char[2 * tval.Length];
+ Array.Copy(tval, 0, newBuf, 0, tval.Length);
+ tval = newBuf;
+ }
+ if (ch != Buffer.EOF) {
+ tval[tlen++] = (char) ch;
+ NextCh();
+ }
+ }
+
+
+
+ bool Comment0() {
+ int level = 1, pos0 = pos, line0 = line, col0 = col, charPos0 = charPos;
+ NextCh();
+ if (ch == '/') {
+ NextCh();
+ for(;;) {
+ if (ch == 10) {
+ level--;
+ if (level == 0) { oldEols = line - line0; NextCh(); return true; }
+ NextCh();
+ } else if (ch == Buffer.EOF) return false;
+ else NextCh();
+ }
+ } else {
+ buffer.Pos = pos0; NextCh(); line = line0; col = col0; charPos = charPos0;
+ }
+ return false;
+ }
+
+ bool Comment1() {
+ int level = 1, pos0 = pos, line0 = line, col0 = col, charPos0 = charPos;
+ NextCh();
+ if (ch == '*') {
+ NextCh();
+ for(;;) {
+ if (ch == '*') {
+ NextCh();
+ if (ch == '/') {
+ level--;
+ if (level == 0) { oldEols = line - line0; NextCh(); return true; }
+ NextCh();
+ }
+ } else if (ch == '/') {
+ NextCh();
+ if (ch == '*') {
+ level++; NextCh();
+ }
+ } else if (ch == Buffer.EOF) return false;
+ else NextCh();
+ }
+ } else {
+ buffer.Pos = pos0; NextCh(); line = line0; col = col0; charPos = charPos0;
+ }
+ return false;
+ }
+
+
+ void CheckLiteral() {
+ switch (t.val) {
+ case "if": t.kind = 11; break;
+ case "else": t.kind = 14; break;
+ case "while": t.kind = 15; break;
+ case "for": t.kind = 16; break;
+ case "function": t.kind = 18; break;
+ case "+": t.kind = 22; break;
+ case "-": t.kind = 23; break;
+ case "\n": t.kind = 33; break;
+ default: break;
+ }
+ }
+
+ Token NextToken() {
+ while (ch == ' ' ||
+ ch >= 9 && ch <= 10 || ch == 13
+ ) NextCh();
+ if (ch == '/' && Comment0() ||ch == '/' && Comment1()) return NextToken();
+ int recKind = noSym;
+ int recEnd = pos;
+ t = new Token();
+ t.pos = pos; t.col = col; t.line = line; t.charPos = charPos;
+ int state;
+ if (start.ContainsKey(ch)) { state = (int) start[ch]; }
+ else { state = 0; }
+ tlen = 0; AddCh();
+
+ switch (state) {
+ case -1: { t.kind = eofSym; break; } // NextCh already done
+ case 0: {
+ if (recKind != noSym) {
+ tlen = recEnd - t.pos;
+ SetScannerBehindT();
+ }
+ t.kind = recKind; break;
+ } // NextCh already done
+ case 1:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 2:
+ {t.kind = 2; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 3:
+ {t.kind = 3; break;}
+ case 4:
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 5;}
+ else {goto case 0;}
+ case 5:
+ recEnd = pos; recKind = 4;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 5;}
+ else {t.kind = 4; break;}
+ case 6:
+ recEnd = pos; recKind = 5;
+ if (ch >= '0' && ch <= '9') {AddCh(); goto case 6;}
+ else if (ch == 'E' || ch == 'e') {AddCh(); goto case 7;}
+ else if (ch == '.') {AddCh(); goto case 10;}
+ else {t.kind = 5; break;}
+ case 7:
+ if (ch >= '0' && ch <= '9') {AddCh(); goto case 9;}
+ else if (ch == '+' || ch == '-') {AddCh(); goto case 8;}
+ else {goto case 0;}
+ case 8:
+ if (ch >= '0' && ch <= '9') {AddCh(); goto case 9;}
+ else {goto case 0;}
+ case 9:
+ recEnd = pos; recKind = 5;
+ if (ch >= '0' && ch <= '9') {AddCh(); goto case 9;}
+ else {t.kind = 5; break;}
+ case 10:
+ recEnd = pos; recKind = 5;
+ if (ch >= '0' && ch <= '9') {AddCh(); goto case 10;}
+ else if (ch == 'E' || ch == 'e') {AddCh(); goto case 7;}
+ else {t.kind = 5; break;}
+ case 11:
+ if (ch == 10) {AddCh(); goto case 12;}
+ else {goto case 0;}
+ case 12:
+ {t.kind = 6; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 13:
+ if (ch <= '!' || ch >= '#' && ch <= 65535) {AddCh(); goto case 13;}
+ else if (ch == '"') {AddCh(); goto case 14;}
+ else {goto case 0;}
+ case 14:
+ {t.kind = 7; break;}
+ case 15:
+ {t.kind = 8; break;}
+ case 16:
+ {t.kind = 9; break;}
+ case 17:
+ if (ch == '=') {AddCh(); goto case 18;}
+ else {goto case 0;}
+ case 18:
+ {t.kind = 10; break;}
+ case 19:
+ recEnd = pos; recKind = 5;
+ if (ch >= '2' && ch <= '9') {AddCh(); goto case 6;}
+ else if (ch == 'B' || ch == 'b') {AddCh(); goto case 3;}
+ else if (ch >= '0' && ch <= '1') {AddCh(); goto case 20;}
+ else if (ch == 'x') {AddCh(); goto case 4;}
+ else if (ch == 'E' || ch == 'e') {AddCh(); goto case 7;}
+ else if (ch == '.') {AddCh(); goto case 10;}
+ else {t.kind = 5; break;}
+ case 20:
+ recEnd = pos; recKind = 5;
+ if (ch >= '2' && ch <= '9') {AddCh(); goto case 6;}
+ else if (ch == 'B' || ch == 'b') {AddCh(); goto case 3;}
+ else if (ch >= '0' && ch <= '1') {AddCh(); goto case 20;}
+ else if (ch == 'E' || ch == 'e') {AddCh(); goto case 7;}
+ else if (ch == '.') {AddCh(); goto case 10;}
+ else {t.kind = 5; break;}
+ case 21:
+ recEnd = pos; recKind = 10;
+ if (ch == '=') {AddCh(); goto case 18;}
+ else {t.kind = 10; break;}
+ case 22:
+ recEnd = pos; recKind = 10;
+ if (ch == '=') {AddCh(); goto case 18;}
+ else {t.kind = 10; break;}
+ case 23:
+ {t.kind = 12; break;}
+ case 24:
+ {t.kind = 13; break;}
+ case 25:
+ {t.kind = 17; break;}
+ case 26:
+ {t.kind = 19; break;}
+ case 27:
+ {t.kind = 20; break;}
+ case 28:
+ {t.kind = 21; break;}
+ case 29:
+ {t.kind = 24; break;}
+ case 30:
+ {t.kind = 25; break;}
+ case 31:
+ {t.kind = 26; break;}
+ case 32:
+ {t.kind = 27; break;}
+ case 33:
+ {t.kind = 28; break;}
+ case 34:
+ {t.kind = 29; break;}
+ case 35:
+ {t.kind = 30; break;}
+ case 36:
+ {t.kind = 31; break;}
+ case 37:
+ {t.kind = 32; break;}
+ case 38:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'b' || ch >= 'd' && ch <= 'z') {AddCh(); goto case 1;}
+ else if (ch == 'c') {AddCh(); goto case 43;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 39:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'b' && ch <= 'z') {AddCh(); goto case 1;}
+ else if (ch == 'a') {AddCh(); goto case 44;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 40:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'h' || ch >= 'j' && ch <= 'z') {AddCh(); goto case 1;}
+ else if (ch == 'i') {AddCh(); goto case 45;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 41:
+ if (ch == ':') {AddCh(); goto case 35;}
+ else if (ch == '=') {AddCh(); goto case 36;}
+ else {goto case 0;}
+ case 42:
+ recEnd = pos; recKind = 2;
+ if (ch == '>') {AddCh(); goto case 37;}
+ else {t.kind = 2; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 43:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'g' || ch >= 'i' && ch <= 'z') {AddCh(); goto case 1;}
+ else if (ch == 'h') {AddCh(); goto case 46;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 44:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'x' || ch == 'z') {AddCh(); goto case 1;}
+ else if (ch == 'y') {AddCh(); goto case 47;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 45:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'r' || ch >= 't' && ch <= 'z') {AddCh(); goto case 1;}
+ else if (ch == 's') {AddCh(); goto case 48;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 46:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'n' || ch >= 'p' && ch <= 'z') {AddCh(); goto case 1;}
+ else if (ch == 'o') {AddCh(); goto case 49;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 47:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;}
+ else if (ch == ':') {AddCh(); goto case 27;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 48:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'o' || ch >= 'q' && ch <= 'z') {AddCh(); goto case 1;}
+ else if (ch == 'p') {AddCh(); goto case 50;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 49:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;}
+ else if (ch == ':') {AddCh(); goto case 26;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 50:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'k' || ch >= 'm' && ch <= 'z') {AddCh(); goto case 1;}
+ else if (ch == 'l') {AddCh(); goto case 51;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 51:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'b' && ch <= 'z') {AddCh(); goto case 1;}
+ else if (ch == 'a') {AddCh(); goto case 52;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 52:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'x' || ch == 'z') {AddCh(); goto case 1;}
+ else if (ch == 'y') {AddCh(); goto case 53;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 53:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;}
+ else if (ch == ':') {AddCh(); goto case 28;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+
+ }
+ t.val = new String(tval, 0, tlen);
+ return t;
+ }
+
+ private void SetScannerBehindT() {
+ buffer.Pos = t.pos;
+ NextCh();
+ line = t.line; col = t.col; charPos = t.charPos;
+ for (int i = 0; i < tlen; i++) NextCh();
+ }
+
+ // get the next token (possibly a token already seen during peeking)
+ public Token Scan () {
+ if (tokens.next == null) {
+ return NextToken();
+ } else {
+ pt = tokens = tokens.next;
+ return tokens;
+ }
+ }
+
+ // peek for the next token, ignore pragmas
+ public Token Peek () {
+ do {
+ if (pt.next == null) {
+ pt.next = NextToken();
+ }
+ pt = pt.next;
+ } while (pt.kind > maxT); // skip pragmas
+
+ return pt;
+ }
+
+ // make sure that peeking starts at the current scan position
+ public void ResetPeek () { pt = tokens; }
+
+} // end Scanner
+}
\ No newline at end of file
diff --git a/CS-MIC/csmic/csmic/ScriptParser/Scanner.cs.old b/CS-MIC/csmic/csmic/ScriptParser/Scanner.cs.old
new file mode 100644
index 0000000..d4290ed
--- /dev/null
+++ b/CS-MIC/csmic/csmic/ScriptParser/Scanner.cs.old
@@ -0,0 +1,635 @@
+
+using System;
+using System.IO;
+using System.Collections;
+
+namespace csmic.Scripting {
+
+public class Token {
+ public int kind; // token kind
+ public int pos; // token position in bytes in the source text (starting at 0)
+ public int charPos; // token position in characters in the source text (starting at 0)
+ public int col; // token column (starting at 1)
+ public int line; // token line (starting at 1)
+ public string val; // token value
+ public Token next; // ML 2005-03-11 Tokens are kept in linked list
+}
+
+//-----------------------------------------------------------------------------------
+// Buffer
+//-----------------------------------------------------------------------------------
+public class Buffer {
+ // This Buffer supports the following cases:
+ // 1) seekable stream (file)
+ // a) whole stream in buffer
+ // b) part of stream in buffer
+ // 2) non seekable stream (network, console)
+
+ public const int EOF = char.MaxValue + 1;
+ const int MIN_BUFFER_LENGTH = 1024; // 1KB
+ const int MAX_BUFFER_LENGTH = MIN_BUFFER_LENGTH * 64; // 64KB
+ byte[] buf; // input buffer
+ int bufStart; // position of first byte in buffer relative to input stream
+ int bufLen; // length of buffer
+ int fileLen; // length of input stream (may change if the stream is no file)
+ int bufPos; // current position in buffer
+ Stream stream; // input stream (seekable)
+ bool isUserStream; // was the stream opened by the user?
+
+ public Buffer (Stream s, bool isUserStream) {
+ stream = s; this.isUserStream = isUserStream;
+
+ if (stream.CanSeek) {
+ fileLen = (int) stream.Length;
+ bufLen = Math.Min(fileLen, MAX_BUFFER_LENGTH);
+ bufStart = Int32.MaxValue; // nothing in the buffer so far
+ } else {
+ fileLen = bufLen = bufStart = 0;
+ }
+
+ buf = new byte[(bufLen>0) ? bufLen : MIN_BUFFER_LENGTH];
+ if (fileLen > 0) Pos = 0; // setup buffer to position 0 (start)
+ else bufPos = 0; // index 0 is already after the file, thus Pos = 0 is invalid
+ if (bufLen == fileLen && stream.CanSeek) Close();
+ }
+
+ protected Buffer(Buffer b) { // called in UTF8Buffer constructor
+ buf = b.buf;
+ bufStart = b.bufStart;
+ bufLen = b.bufLen;
+ fileLen = b.fileLen;
+ bufPos = b.bufPos;
+ stream = b.stream;
+ // keep destructor from closing the stream
+ b.stream = null;
+ isUserStream = b.isUserStream;
+ }
+
+ ~Buffer() { Close(); }
+
+ protected void Close() {
+ if (!isUserStream && stream != null) {
+ stream.Close();
+ stream = null;
+ }
+ }
+
+ public virtual int Read () {
+ if (bufPos < bufLen) {
+ return buf[bufPos++];
+ } else if (Pos < fileLen) {
+ Pos = Pos; // shift buffer start to Pos
+ return buf[bufPos++];
+ } else if (stream != null && !stream.CanSeek && ReadNextStreamChunk() > 0) {
+ return buf[bufPos++];
+ } else {
+ return EOF;
+ }
+ }
+
+ public int Peek () {
+ int curPos = Pos;
+ int ch = Read();
+ Pos = curPos;
+ return ch;
+ }
+
+ // beg .. begin, zero-based, inclusive, in byte
+ // end .. end, zero-based, exclusive, in byte
+ public string GetString (int beg, int end) {
+ int len = 0;
+ char[] buf = new char[end - beg];
+ int oldPos = Pos;
+ Pos = beg;
+ while (Pos < end) buf[len++] = (char) Read();
+ Pos = oldPos;
+ return new String(buf, 0, len);
+ }
+
+ public int Pos {
+ get { return bufPos + bufStart; }
+ set {
+ if (value >= fileLen && stream != null && !stream.CanSeek) {
+ // Wanted position is after buffer and the stream
+ // is not seek-able e.g. network or console,
+ // thus we have to read the stream manually till
+ // the wanted position is in sight.
+ while (value >= fileLen && ReadNextStreamChunk() > 0);
+ }
+
+ if (value < 0 || value > fileLen) {
+ throw new FatalError("buffer out of bounds access, position: " + value);
+ }
+
+ if (value >= bufStart && value < bufStart + bufLen) { // already in buffer
+ bufPos = value - bufStart;
+ } else if (stream != null) { // must be swapped in
+ stream.Seek(value, SeekOrigin.Begin);
+ bufLen = stream.Read(buf, 0, buf.Length);
+ bufStart = value; bufPos = 0;
+ } else {
+ // set the position to the end of the file, Pos will return fileLen.
+ bufPos = fileLen - bufStart;
+ }
+ }
+ }
+
+ // Read the next chunk of bytes from the stream, increases the buffer
+ // if needed and updates the fields fileLen and bufLen.
+ // Returns the number of bytes read.
+ private int ReadNextStreamChunk() {
+ int free = buf.Length - bufLen;
+ if (free == 0) {
+ // in the case of a growing input stream
+ // we can neither seek in the stream, nor can we
+ // foresee the maximum length, thus we must adapt
+ // the buffer size on demand.
+ byte[] newBuf = new byte[bufLen * 2];
+ Array.Copy(buf, newBuf, bufLen);
+ buf = newBuf;
+ free = bufLen;
+ }
+ int read = stream.Read(buf, bufLen, free);
+ if (read > 0) {
+ fileLen = bufLen = (bufLen + read);
+ return read;
+ }
+ // end of stream reached
+ return 0;
+ }
+}
+
+//-----------------------------------------------------------------------------------
+// UTF8Buffer
+//-----------------------------------------------------------------------------------
+public class UTF8Buffer: Buffer {
+ public UTF8Buffer(Buffer b): base(b) {}
+
+ public override int Read() {
+ int ch;
+ do {
+ ch = base.Read();
+ // until we find a utf8 start (0xxxxxxx or 11xxxxxx)
+ } while ((ch >= 128) && ((ch & 0xC0) != 0xC0) && (ch != EOF));
+ if (ch < 128 || ch == EOF) {
+ // nothing to do, first 127 chars are the same in ascii and utf8
+ // 0xxxxxxx or end of file character
+ } else if ((ch & 0xF0) == 0xF0) {
+ // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
+ int c1 = ch & 0x07; ch = base.Read();
+ int c2 = ch & 0x3F; ch = base.Read();
+ int c3 = ch & 0x3F; ch = base.Read();
+ int c4 = ch & 0x3F;
+ ch = (((((c1 << 6) | c2) << 6) | c3) << 6) | c4;
+ } else if ((ch & 0xE0) == 0xE0) {
+ // 1110xxxx 10xxxxxx 10xxxxxx
+ int c1 = ch & 0x0F; ch = base.Read();
+ int c2 = ch & 0x3F; ch = base.Read();
+ int c3 = ch & 0x3F;
+ ch = (((c1 << 6) | c2) << 6) | c3;
+ } else if ((ch & 0xC0) == 0xC0) {
+ // 110xxxxx 10xxxxxx
+ int c1 = ch & 0x1F; ch = base.Read();
+ int c2 = ch & 0x3F;
+ ch = (c1 << 6) | c2;
+ }
+ return ch;
+ }
+}
+
+//-----------------------------------------------------------------------------------
+// Scanner
+//-----------------------------------------------------------------------------------
+public class Scanner {
+ const char EOL = '\n';
+ const int eofSym = 0; /* pdt */
+ const int maxT = 34;
+ const int noSym = 34;
+
+
+ public Buffer buffer; // scanner buffer
+
+ Token t; // current token
+ int ch; // current input character
+ int pos; // byte position of current character
+ int charPos; // position by unicode characters starting with 0
+ int col; // column number of current character
+ int line; // line number of current character
+ int oldEols; // EOLs that appeared in a comment;
+ static readonly Hashtable start; // maps first token character to start state
+
+ Token tokens; // list of tokens already peeked (first token is a dummy)
+ Token pt; // current peek token
+
+ char[] tval = new char[128]; // text of current token
+ int tlen; // length of current token
+
+ static Scanner() {
+ start = new Hashtable(128);
+ for (int i = 65; i <= 90; ++i) start[i] = 1;
+ for (int i = 97; i <= 99; ++i) start[i] = 1;
+ for (int i = 102; i <= 114; ++i) start[i] = 1;
+ for (int i = 116; i <= 122; ++i) start[i] = 1;
+ start[43] = 2;
+ for (int i = 50; i <= 57; ++i) start[i] = 6;
+ for (int i = 10; i <= 10; ++i) start[i] = 12;
+ for (int i = 13; i <= 13; ++i) start[i] = 11;
+ start[48] = 19;
+ start[49] = 20;
+ start[34] = 13;
+ start[40] = 15;
+ start[41] = 16;
+ start[61] = 17;
+ start[60] = 21;
+ start[62] = 22;
+ start[123] = 23;
+ start[125] = 24;
+ start[44] = 25;
+ start[101] = 38;
+ start[115] = 39;
+ start[100] = 40;
+ start[37] = 29;
+ start[42] = 30;
+ start[47] = 31;
+ start[94] = 32;
+ start[91] = 33;
+ start[93] = 34;
+ start[58] = 41;
+ start[45] = 42;
+ start[Buffer.EOF] = -1;
+
+ }
+
+ public Scanner (string fileName) {
+ try {
+ Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
+ buffer = new Buffer(stream, false);
+ Init();
+ } catch (IOException) {
+ throw new FatalError("Cannot open file " + fileName);
+ }
+ }
+
+ public Scanner (Stream s) {
+ buffer = new Buffer(s, true);
+ Init();
+ }
+
+ void Init() {
+ pos = -1; line = 1; col = 0; charPos = -1;
+ oldEols = 0;
+ NextCh();
+ if (ch == 0xEF) { // check optional byte order mark for UTF-8
+ NextCh(); int ch1 = ch;
+ NextCh(); int ch2 = ch;
+ if (ch1 != 0xBB || ch2 != 0xBF) {
+ throw new FatalError(String.Format("illegal byte order mark: EF {0,2:X} {1,2:X}", ch1, ch2));
+ }
+ buffer = new UTF8Buffer(buffer); col = 0; charPos = -1;
+ NextCh();
+ }
+ pt = tokens = new Token(); // first token is a dummy
+ }
+
+ void NextCh() {
+ if (oldEols > 0) { ch = EOL; oldEols--; }
+ else {
+ pos = buffer.Pos;
+ // buffer reads unicode chars, if UTF8 has been detected
+ ch = buffer.Read(); col++; charPos++;
+ // replace isolated '\r' by '\n' in order to make
+ // eol handling uniform across Windows, Unix and Mac
+ if (ch == '\r' && buffer.Peek() != '\n') ch = EOL;
+ if (ch == EOL) { line++; col = 0; }
+ }
+
+ }
+
+ void AddCh() {
+ if (tlen >= tval.Length) {
+ char[] newBuf = new char[2 * tval.Length];
+ Array.Copy(tval, 0, newBuf, 0, tval.Length);
+ tval = newBuf;
+ }
+ if (ch != Buffer.EOF) {
+ tval[tlen++] = (char) ch;
+ NextCh();
+ }
+ }
+
+
+
+ bool Comment0() {
+ int level = 1, pos0 = pos, line0 = line, col0 = col, charPos0 = charPos;
+ NextCh();
+ if (ch == '/') {
+ NextCh();
+ for(;;) {
+ if (ch == 10) {
+ level--;
+ if (level == 0) { oldEols = line - line0; NextCh(); return true; }
+ NextCh();
+ } else if (ch == Buffer.EOF) return false;
+ else NextCh();
+ }
+ } else {
+ buffer.Pos = pos0; NextCh(); line = line0; col = col0; charPos = charPos0;
+ }
+ return false;
+ }
+
+ bool Comment1() {
+ int level = 1, pos0 = pos, line0 = line, col0 = col, charPos0 = charPos;
+ NextCh();
+ if (ch == '*') {
+ NextCh();
+ for(;;) {
+ if (ch == '*') {
+ NextCh();
+ if (ch == '/') {
+ level--;
+ if (level == 0) { oldEols = line - line0; NextCh(); return true; }
+ NextCh();
+ }
+ } else if (ch == '/') {
+ NextCh();
+ if (ch == '*') {
+ level++; NextCh();
+ }
+ } else if (ch == Buffer.EOF) return false;
+ else NextCh();
+ }
+ } else {
+ buffer.Pos = pos0; NextCh(); line = line0; col = col0; charPos = charPos0;
+ }
+ return false;
+ }
+
+
+ void CheckLiteral() {
+ switch (t.val) {
+ case "if": t.kind = 11; break;
+ case "else": t.kind = 14; break;
+ case "while": t.kind = 15; break;
+ case "for": t.kind = 16; break;
+ case "function": t.kind = 18; break;
+ case "+": t.kind = 22; break;
+ case "-": t.kind = 23; break;
+ case "\n": t.kind = 33; break;
+ default: break;
+ }
+ }
+
+ Token NextToken() {
+ while (ch == ' ' ||
+ ch >= 9 && ch <= 10 || ch == 13
+ ) NextCh();
+ if (ch == '/' && Comment0() ||ch == '/' && Comment1()) return NextToken();
+ int recKind = noSym;
+ int recEnd = pos;
+ t = new Token();
+ t.pos = pos; t.col = col; t.line = line; t.charPos = charPos;
+ int state;
+ if (start.ContainsKey(ch)) { state = (int) start[ch]; }
+ else { state = 0; }
+ tlen = 0; AddCh();
+
+ switch (state) {
+ case -1: { t.kind = eofSym; break; } // NextCh already done
+ case 0: {
+ if (recKind != noSym) {
+ tlen = recEnd - t.pos;
+ SetScannerBehindT();
+ }
+ t.kind = recKind; break;
+ } // NextCh already done
+ case 1:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 2:
+ {t.kind = 2; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 3:
+ {t.kind = 3; break;}
+ case 4:
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 5;}
+ else {goto case 0;}
+ case 5:
+ recEnd = pos; recKind = 4;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 5;}
+ else {t.kind = 4; break;}
+ case 6:
+ recEnd = pos; recKind = 5;
+ if (ch >= '0' && ch <= '9') {AddCh(); goto case 6;}
+ else if (ch == 'E' || ch == 'e') {AddCh(); goto case 7;}
+ else if (ch == '.') {AddCh(); goto case 10;}
+ else {t.kind = 5; break;}
+ case 7:
+ if (ch >= '0' && ch <= '9') {AddCh(); goto case 9;}
+ else if (ch == '+' || ch == '-') {AddCh(); goto case 8;}
+ else {goto case 0;}
+ case 8:
+ if (ch >= '0' && ch <= '9') {AddCh(); goto case 9;}
+ else {goto case 0;}
+ case 9:
+ recEnd = pos; recKind = 5;
+ if (ch >= '0' && ch <= '9') {AddCh(); goto case 9;}
+ else {t.kind = 5; break;}
+ case 10:
+ recEnd = pos; recKind = 5;
+ if (ch >= '0' && ch <= '9') {AddCh(); goto case 10;}
+ else if (ch == 'E' || ch == 'e') {AddCh(); goto case 7;}
+ else {t.kind = 5; break;}
+ case 11:
+ if (ch == 10) {AddCh(); goto case 12;}
+ else {goto case 0;}
+ case 12:
+ {t.kind = 6; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 13:
+ if (ch <= '!' || ch >= '#' && ch <= 65535) {AddCh(); goto case 13;}
+ else if (ch == '"') {AddCh(); goto case 14;}
+ else {goto case 0;}
+ case 14:
+ {t.kind = 7; break;}
+ case 15:
+ {t.kind = 8; break;}
+ case 16:
+ {t.kind = 9; break;}
+ case 17:
+ if (ch == '=') {AddCh(); goto case 18;}
+ else {goto case 0;}
+ case 18:
+ {t.kind = 10; break;}
+ case 19:
+ recEnd = pos; recKind = 5;
+ if (ch >= '2' && ch <= '9') {AddCh(); goto case 6;}
+ else if (ch == 'B' || ch == 'b') {AddCh(); goto case 3;}
+ else if (ch >= '0' && ch <= '1') {AddCh(); goto case 20;}
+ else if (ch == 'x') {AddCh(); goto case 4;}
+ else if (ch == 'E' || ch == 'e') {AddCh(); goto case 7;}
+ else if (ch == '.') {AddCh(); goto case 10;}
+ else {t.kind = 5; break;}
+ case 20:
+ recEnd = pos; recKind = 5;
+ if (ch >= '2' && ch <= '9') {AddCh(); goto case 6;}
+ else if (ch == 'B' || ch == 'b') {AddCh(); goto case 3;}
+ else if (ch >= '0' && ch <= '1') {AddCh(); goto case 20;}
+ else if (ch == 'E' || ch == 'e') {AddCh(); goto case 7;}
+ else if (ch == '.') {AddCh(); goto case 10;}
+ else {t.kind = 5; break;}
+ case 21:
+ recEnd = pos; recKind = 10;
+ if (ch == '=') {AddCh(); goto case 18;}
+ else {t.kind = 10; break;}
+ case 22:
+ recEnd = pos; recKind = 10;
+ if (ch == '=') {AddCh(); goto case 18;}
+ else {t.kind = 10; break;}
+ case 23:
+ {t.kind = 12; break;}
+ case 24:
+ {t.kind = 13; break;}
+ case 25:
+ {t.kind = 17; break;}
+ case 26:
+ {t.kind = 19; break;}
+ case 27:
+ {t.kind = 20; break;}
+ case 28:
+ {t.kind = 21; break;}
+ case 29:
+ {t.kind = 24; break;}
+ case 30:
+ {t.kind = 25; break;}
+ case 31:
+ {t.kind = 26; break;}
+ case 32:
+ {t.kind = 27; break;}
+ case 33:
+ {t.kind = 28; break;}
+ case 34:
+ {t.kind = 29; break;}
+ case 35:
+ {t.kind = 30; break;}
+ case 36:
+ {t.kind = 31; break;}
+ case 37:
+ {t.kind = 32; break;}
+ case 38:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'b' || ch >= 'd' && ch <= 'z') {AddCh(); goto case 1;}
+ else if (ch == 'c') {AddCh(); goto case 43;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 39:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'b' && ch <= 'z') {AddCh(); goto case 1;}
+ else if (ch == 'a') {AddCh(); goto case 44;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 40:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'h' || ch >= 'j' && ch <= 'z') {AddCh(); goto case 1;}
+ else if (ch == 'i') {AddCh(); goto case 45;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 41:
+ if (ch == ':') {AddCh(); goto case 35;}
+ else if (ch == '=') {AddCh(); goto case 36;}
+ else {goto case 0;}
+ case 42:
+ recEnd = pos; recKind = 2;
+ if (ch == '>') {AddCh(); goto case 37;}
+ else {t.kind = 2; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 43:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'g' || ch >= 'i' && ch <= 'z') {AddCh(); goto case 1;}
+ else if (ch == 'h') {AddCh(); goto case 46;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 44:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'x' || ch == 'z') {AddCh(); goto case 1;}
+ else if (ch == 'y') {AddCh(); goto case 47;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 45:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'r' || ch >= 't' && ch <= 'z') {AddCh(); goto case 1;}
+ else if (ch == 's') {AddCh(); goto case 48;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 46:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'n' || ch >= 'p' && ch <= 'z') {AddCh(); goto case 1;}
+ else if (ch == 'o') {AddCh(); goto case 49;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 47:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;}
+ else if (ch == ':') {AddCh(); goto case 27;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 48:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'o' || ch >= 'q' && ch <= 'z') {AddCh(); goto case 1;}
+ else if (ch == 'p') {AddCh(); goto case 50;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 49:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;}
+ else if (ch == ':') {AddCh(); goto case 26;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 50:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'k' || ch >= 'm' && ch <= 'z') {AddCh(); goto case 1;}
+ else if (ch == 'l') {AddCh(); goto case 51;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 51:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'b' && ch <= 'z') {AddCh(); goto case 1;}
+ else if (ch == 'a') {AddCh(); goto case 52;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 52:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'x' || ch == 'z') {AddCh(); goto case 1;}
+ else if (ch == 'y') {AddCh(); goto case 53;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+ case 53:
+ recEnd = pos; recKind = 1;
+ if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;}
+ else if (ch == ':') {AddCh(); goto case 28;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+
+ }
+ t.val = new String(tval, 0, tlen);
+ return t;
+ }
+
+ private void SetScannerBehindT() {
+ buffer.Pos = t.pos;
+ NextCh();
+ line = t.line; col = t.col; charPos = t.charPos;
+ for (int i = 0; i < tlen; i++) NextCh();
+ }
+
+ // get the next token (possibly a token already seen during peeking)
+ public Token Scan () {
+ if (tokens.next == null) {
+ return NextToken();
+ } else {
+ pt = tokens = tokens.next;
+ return tokens;
+ }
+ }
+
+ // peek for the next token, ignore pragmas
+ public Token Peek () {
+ do {
+ if (pt.next == null) {
+ pt.next = NextToken();
+ }
+ pt = pt.next;
+ } while (pt.kind > maxT); // skip pragmas
+
+ return pt;
+ }
+
+ // make sure that peeking starts at the current scan position
+ public void ResetPeek () { pt = tokens; }
+
+} // end Scanner
+}
\ No newline at end of file
diff --git a/CS-MIC/csmic/csmic/ScriptParser/Scanner.frame b/CS-MIC/csmic/csmic/ScriptParser/Scanner.frame
new file mode 100644
index 0000000..abac75d
--- /dev/null
+++ b/CS-MIC/csmic/csmic/ScriptParser/Scanner.frame
@@ -0,0 +1,381 @@
+/*----------------------------------------------------------------------
+Compiler Generator Coco/R,
+Copyright (c) 1990, 2004 Hanspeter Moessenboeck, University of Linz
+extended by M. Loeberbauer & A. Woess, Univ. of Linz
+with improvements by Pat Terry, Rhodes University
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+As an exception, it is allowed to write an extension of Coco/R that is
+used as a plugin in non-free software.
+
+If not otherwise stated, any source code generated by Coco/R (other than
+Coco/R itself) does not fall under the GNU General Public License.
+-----------------------------------------------------------------------*/
+-->begin
+using System;
+using System.IO;
+using System.Collections;
+
+-->namespace
+
+public class Token {
+ public int kind; // token kind
+ public int pos; // token position in bytes in the source text (starting at 0)
+ public int charPos; // token position in characters in the source text (starting at 0)
+ public int col; // token column (starting at 1)
+ public int line; // token line (starting at 1)
+ public string val; // token value
+ public Token next; // ML 2005-03-11 Tokens are kept in linked list
+}
+
+//-----------------------------------------------------------------------------------
+// Buffer
+//-----------------------------------------------------------------------------------
+public class Buffer {
+ // This Buffer supports the following cases:
+ // 1) seekable stream (file)
+ // a) whole stream in buffer
+ // b) part of stream in buffer
+ // 2) non seekable stream (network, console)
+
+ public const int EOF = char.MaxValue + 1;
+ const int MIN_BUFFER_LENGTH = 1024; // 1KB
+ const int MAX_BUFFER_LENGTH = MIN_BUFFER_LENGTH * 64; // 64KB
+ byte[] buf; // input buffer
+ int bufStart; // position of first byte in buffer relative to input stream
+ int bufLen; // length of buffer
+ int fileLen; // length of input stream (may change if the stream is no file)
+ int bufPos; // current position in buffer
+ Stream stream; // input stream (seekable)
+ bool isUserStream; // was the stream opened by the user?
+
+ public Buffer (Stream s, bool isUserStream) {
+ stream = s; this.isUserStream = isUserStream;
+
+ if (stream.CanSeek) {
+ fileLen = (int) stream.Length;
+ bufLen = Math.Min(fileLen, MAX_BUFFER_LENGTH);
+ bufStart = Int32.MaxValue; // nothing in the buffer so far
+ } else {
+ fileLen = bufLen = bufStart = 0;
+ }
+
+ buf = new byte[(bufLen>0) ? bufLen : MIN_BUFFER_LENGTH];
+ if (fileLen > 0) Pos = 0; // setup buffer to position 0 (start)
+ else bufPos = 0; // index 0 is already after the file, thus Pos = 0 is invalid
+ if (bufLen == fileLen && stream.CanSeek) Close();
+ }
+
+ protected Buffer(Buffer b) { // called in UTF8Buffer constructor
+ buf = b.buf;
+ bufStart = b.bufStart;
+ bufLen = b.bufLen;
+ fileLen = b.fileLen;
+ bufPos = b.bufPos;
+ stream = b.stream;
+ // keep destructor from closing the stream
+ b.stream = null;
+ isUserStream = b.isUserStream;
+ }
+
+ ~Buffer() { Close(); }
+
+ protected void Close() {
+ if (!isUserStream && stream != null) {
+ stream.Close();
+ stream = null;
+ }
+ }
+
+ public virtual int Read () {
+ if (bufPos < bufLen) {
+ return buf[bufPos++];
+ } else if (Pos < fileLen) {
+ Pos = Pos; // shift buffer start to Pos
+ return buf[bufPos++];
+ } else if (stream != null && !stream.CanSeek && ReadNextStreamChunk() > 0) {
+ return buf[bufPos++];
+ } else {
+ return EOF;
+ }
+ }
+
+ public int Peek () {
+ int curPos = Pos;
+ int ch = Read();
+ Pos = curPos;
+ return ch;
+ }
+
+ // beg .. begin, zero-based, inclusive, in byte
+ // end .. end, zero-based, exclusive, in byte
+ public string GetString (int beg, int end) {
+ int len = 0;
+ char[] buf = new char[end - beg];
+ int oldPos = Pos;
+ Pos = beg;
+ while (Pos < end) buf[len++] = (char) Read();
+ Pos = oldPos;
+ return new String(buf, 0, len);
+ }
+
+ public int Pos {
+ get { return bufPos + bufStart; }
+ set {
+ if (value >= fileLen && stream != null && !stream.CanSeek) {
+ // Wanted position is after buffer and the stream
+ // is not seek-able e.g. network or console,
+ // thus we have to read the stream manually till
+ // the wanted position is in sight.
+ while (value >= fileLen && ReadNextStreamChunk() > 0);
+ }
+
+ if (value < 0 || value > fileLen) {
+ throw new FatalError("buffer out of bounds access, position: " + value);
+ }
+
+ if (value >= bufStart && value < bufStart + bufLen) { // already in buffer
+ bufPos = value - bufStart;
+ } else if (stream != null) { // must be swapped in
+ stream.Seek(value, SeekOrigin.Begin);
+ bufLen = stream.Read(buf, 0, buf.Length);
+ bufStart = value; bufPos = 0;
+ } else {
+ // set the position to the end of the file, Pos will return fileLen.
+ bufPos = fileLen - bufStart;
+ }
+ }
+ }
+
+ // Read the next chunk of bytes from the stream, increases the buffer
+ // if needed and updates the fields fileLen and bufLen.
+ // Returns the number of bytes read.
+ private int ReadNextStreamChunk() {
+ int free = buf.Length - bufLen;
+ if (free == 0) {
+ // in the case of a growing input stream
+ // we can neither seek in the stream, nor can we
+ // foresee the maximum length, thus we must adapt
+ // the buffer size on demand.
+ byte[] newBuf = new byte[bufLen * 2];
+ Array.Copy(buf, newBuf, bufLen);
+ buf = newBuf;
+ free = bufLen;
+ }
+ int read = stream.Read(buf, bufLen, free);
+ if (read > 0) {
+ fileLen = bufLen = (bufLen + read);
+ return read;
+ }
+ // end of stream reached
+ return 0;
+ }
+}
+
+//-----------------------------------------------------------------------------------
+// UTF8Buffer
+//-----------------------------------------------------------------------------------
+public class UTF8Buffer: Buffer {
+ public UTF8Buffer(Buffer b): base(b) {}
+
+ public override int Read() {
+ int ch;
+ do {
+ ch = base.Read();
+ // until we find a utf8 start (0xxxxxxx or 11xxxxxx)
+ } while ((ch >= 128) && ((ch & 0xC0) != 0xC0) && (ch != EOF));
+ if (ch < 128 || ch == EOF) {
+ // nothing to do, first 127 chars are the same in ascii and utf8
+ // 0xxxxxxx or end of file character
+ } else if ((ch & 0xF0) == 0xF0) {
+ // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
+ int c1 = ch & 0x07; ch = base.Read();
+ int c2 = ch & 0x3F; ch = base.Read();
+ int c3 = ch & 0x3F; ch = base.Read();
+ int c4 = ch & 0x3F;
+ ch = (((((c1 << 6) | c2) << 6) | c3) << 6) | c4;
+ } else if ((ch & 0xE0) == 0xE0) {
+ // 1110xxxx 10xxxxxx 10xxxxxx
+ int c1 = ch & 0x0F; ch = base.Read();
+ int c2 = ch & 0x3F; ch = base.Read();
+ int c3 = ch & 0x3F;
+ ch = (((c1 << 6) | c2) << 6) | c3;
+ } else if ((ch & 0xC0) == 0xC0) {
+ // 110xxxxx 10xxxxxx
+ int c1 = ch & 0x1F; ch = base.Read();
+ int c2 = ch & 0x3F;
+ ch = (c1 << 6) | c2;
+ }
+ return ch;
+ }
+}
+
+//-----------------------------------------------------------------------------------
+// Scanner
+//-----------------------------------------------------------------------------------
+public class Scanner {
+ const char EOL = '\n';
+ const int eofSym = 0; /* pdt */
+-->declarations
+
+ public Buffer buffer; // scanner buffer
+
+ Token t; // current token
+ int ch; // current input character
+ int pos; // byte position of current character
+ int charPos; // position by unicode characters starting with 0
+ int col; // column number of current character
+ int line; // line number of current character
+ int oldEols; // EOLs that appeared in a comment;
+ static readonly Hashtable start; // maps first token character to start state
+
+ Token tokens; // list of tokens already peeked (first token is a dummy)
+ Token pt; // current peek token
+
+ char[] tval = new char[128]; // text of current token
+ int tlen; // length of current token
+
+ static Scanner() {
+ start = new Hashtable(128);
+-->initialization
+ }
+
+ public Scanner (string fileName) {
+ try {
+ Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
+ buffer = new Buffer(stream, false);
+ Init();
+ } catch (IOException) {
+ throw new FatalError("Cannot open file " + fileName);
+ }
+ }
+
+ public Scanner (Stream s) {
+ buffer = new Buffer(s, true);
+ Init();
+ }
+
+ void Init() {
+ pos = -1; line = 1; col = 0; charPos = -1;
+ oldEols = 0;
+ NextCh();
+ if (ch == 0xEF) { // check optional byte order mark for UTF-8
+ NextCh(); int ch1 = ch;
+ NextCh(); int ch2 = ch;
+ if (ch1 != 0xBB || ch2 != 0xBF) {
+ throw new FatalError(String.Format("illegal byte order mark: EF {0,2:X} {1,2:X}", ch1, ch2));
+ }
+ buffer = new UTF8Buffer(buffer); col = 0; charPos = -1;
+ NextCh();
+ }
+ pt = tokens = new Token(); // first token is a dummy
+ }
+
+ void NextCh() {
+ if (oldEols > 0) { ch = EOL; oldEols--; }
+ else {
+ pos = buffer.Pos;
+ // buffer reads unicode chars, if UTF8 has been detected
+ ch = buffer.Read(); col++; charPos++;
+ // replace isolated '\r' by '\n' in order to make
+ // eol handling uniform across Windows, Unix and Mac
+ if (ch == '\r' && buffer.Peek() != '\n') ch = EOL;
+ if (ch == EOL) { line++; col = 0; }
+ }
+-->casing1
+ }
+
+ void AddCh() {
+ if (tlen >= tval.Length) {
+ char[] newBuf = new char[2 * tval.Length];
+ Array.Copy(tval, 0, newBuf, 0, tval.Length);
+ tval = newBuf;
+ }
+ if (ch != Buffer.EOF) {
+-->casing2
+ NextCh();
+ }
+ }
+
+
+-->comments
+
+ void CheckLiteral() {
+-->literals
+ }
+
+ Token NextToken() {
+ while (ch == ' ' ||
+-->scan1
+ ) NextCh();
+-->scan2
+ int recKind = noSym;
+ int recEnd = pos;
+ t = new Token();
+ t.pos = pos; t.col = col; t.line = line; t.charPos = charPos;
+ int state;
+ if (start.ContainsKey(ch)) { state = (int) start[ch]; }
+ else { state = 0; }
+ tlen = 0; AddCh();
+
+ switch (state) {
+ case -1: { t.kind = eofSym; break; } // NextCh already done
+ case 0: {
+ if (recKind != noSym) {
+ tlen = recEnd - t.pos;
+ SetScannerBehindT();
+ }
+ t.kind = recKind; break;
+ } // NextCh already done
+-->scan3
+ }
+ t.val = new String(tval, 0, tlen);
+ return t;
+ }
+
+ private void SetScannerBehindT() {
+ buffer.Pos = t.pos;
+ NextCh();
+ line = t.line; col = t.col; charPos = t.charPos;
+ for (int i = 0; i < tlen; i++) NextCh();
+ }
+
+ // get the next token (possibly a token already seen during peeking)
+ public Token Scan () {
+ if (tokens.next == null) {
+ return NextToken();
+ } else {
+ pt = tokens = tokens.next;
+ return tokens;
+ }
+ }
+
+ // peek for the next token, ignore pragmas
+ public Token Peek () {
+ do {
+ if (pt.next == null) {
+ pt.next = NextToken();
+ }
+ pt = pt.next;
+ } while (pt.kind > maxT); // skip pragmas
+
+ return pt;
+ }
+
+ // make sure that peeking starts at the current scan position
+ public void ResetPeek () { pt = tokens; }
+
+} // end Scanner
diff --git a/CS-MIC/csmic/csmic/ScriptParser/Scripting.atg b/CS-MIC/csmic/csmic/ScriptParser/Scripting.atg
new file mode 100644
index 0000000..0a5f90d
--- /dev/null
+++ b/CS-MIC/csmic/csmic/ScriptParser/Scripting.atg
@@ -0,0 +1,525 @@
+using csmic;
+using System.Text;
+using System.Collections.Generic;
+
+COMPILER SCRIPT
+
+/*
+*
+* Class Structures
+*
+*/
+
+private MacroOperation root = new MacroOperation(OperationType.Unknown);
+
+internal MacroOperation Root
+{
+ get
+ {
+ return this.root;
+ }
+ set
+ {
+ this.root = value;
+ }
+}
+
+bool IsFunctionCall()
+{
+ scanner.ResetPeek();
+ Token next = scanner.Peek();
+ if (next.kind == _LPAREN && la.kind == _identifier)
+ return true;
+ return false;
+}
+
+bool IsCompare()
+{
+ scanner.ResetPeek();
+ Token next = scanner.Peek();
+ if (next.kind == _COMPARER)
+ return true;
+ return false;
+}
+
+bool IsAssignment()
+{
+ scanner.ResetPeek();
+ Token next = scanner.Peek();
+ if (next.val == "::" || next.val == ":=" || next.val == "->")
+ return true;
+ return false;
+}
+
+bool IsArrayCall()
+{
+ scanner.ResetPeek();
+ Token next = scanner.Peek();
+ if(next.val == "[")
+ return true;
+ return false;
+}
+
+CHARACTERS
+
+ UpperLetter = 'A'..'Z'.
+ LowerLetter = 'a'..'z'.
+ letter = UpperLetter + LowerLetter.
+ NoQuote = ANY - '\"' .
+ digit = "0123456789" .
+ cr = '\r' .
+ lf = '\n' .
+ tab = '\t' .
+ PM = "+-" .
+
+TOKENS
+
+ identifier = letter { letter | digit }.
+ sign = PM .
+ binary = ( '0' | '1' ) { '0' | '1' } ('B' | 'b') .
+ hex = "0x" ( digit | ('A' | 'B' | 'C' | 'D' | 'E' |'F') | ('a' | 'b' | 'c' | 'd' | 'e' |'f') ) { digit | ('A' | 'B' | 'C' | 'D' | 'E' |'F') | ('a' | 'b' | 'c' | 'd' | 'e' |'f') } .
+ number = digit { digit }['.' {digit}] [('E'|'e')['+'|'-'] digit {digit}] .
+ newline = [cr] lf .
+ string = "\"" { NoQuote } "\"" .
+ LPAREN = '(' .
+ RPAREN = ')' .
+ COMPARER = "==" | "<" | ">" | "<=" | ">=" .
+
+ COMMENTS FROM "/*" TO "*/" NESTED
+ COMMENTS FROM "//" TO lf
+
+IGNORE cr + lf + tab
+
+/*
+ * Parser specification
+ *
+ */
+
+PRODUCTIONS
+
+SCRIPT (. string statement = string.Empty; .)
+=
+ {
+ Statement (.
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ this.root.Children.Add(operation);
+ .)
+ |
+ IfBlock[
+ |
+ WhileBlock][
+ |
+ FunctionDeclaration][
+ |
+ EchoStatement][
+ |
+ SayStatement][
+ |
+ DisplayStatement][
+ |
+ ForBlock][
+ }
+.
+
+IfBlock][ (.
+ MacroOperation ifBlock = new MacroOperation(OperationType.If);
+ MacroOperation elseBlock = new MacroOperation(OperationType.Else);
+ string ifStatement = string.Empty;
+ string statement = string.Empty;
+ StringBuilder builder = new StringBuilder();
+ bool hasElse = false;
+ .)
+=
+ "if"
+ LPAREN
+ Comparison][ (. ifStatement = builder.ToString(); ifBlock.Input.Add(ifStatement); .)
+ RPAREN
+ '{'
+ {
+ Statement (.
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ ifBlock.Children.Add(operation);
+ .)
+ |
+ IfBlock][
+ |
+ WhileBlock][
+ |
+ EchoStatement][
+ |
+ SayStatement][
+ |
+ DisplayStatement][
+ |
+ ForBlock][
+ }
+ '}'
+ [
+ "else" (. hasElse = true; .)
+ '{'
+ {
+ Statement (.
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ elseBlock.Children.Add(operation);
+ .)
+ |
+ IfBlock][
+ |
+ WhileBlock][
+ |
+ EchoStatement][
+ |
+ SayStatement][
+ |
+ DisplayStatement][
+ |
+ ForBlock][
+ }
+ '}'
+ ]
+ (.
+ if(hasElse)
+ {
+ MacroOperation ifelse = new MacroOperation(OperationType.IfElse);
+ ifelse.Children.Add(ifBlock);
+ ifelse.Children.Add(elseBlock);
+ parent.Children.Add(ifelse);
+ }
+ else
+ {
+ parent.Children.Add(ifBlock);
+ }
+ .)
+.
+
+
+
+WhileBlock][ (.
+ StringBuilder builder = new StringBuilder();
+ MacroOperation whileBlock = new MacroOperation(OperationType.While);
+ string statement = string.Empty;
+ .)
+=
+ "while"
+ LPAREN
+ Comparison][ (. whileBlock.Input.Add(builder.ToString()); .)
+ RPAREN
+ '{'
+ {
+ Statement (.
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ whileBlock.Children.Add(operation);
+ .)
+ |
+ IfBlock][
+ |
+ WhileBlock][
+ |
+ EchoStatement][
+ |
+ SayStatement][
+ |
+ DisplayStatement][
+ |
+ ForBlock][
+ }
+ '}'
+ (.
+ parent.Children.Add(whileBlock);
+ .)
+.
+
+ForBlock][ (.
+ StringBuilder builder = new StringBuilder();
+ string statement = string.Empty;
+ string statement2 = string.Empty;
+ MacroOperation forBlock = new MacroOperation(OperationType.For);
+ .)
+=
+ "for"
+ LPAREN
+ Statement
+ ','
+ Comparison][
+ ','
+ Statement (. forBlock.Input.Add(statement); forBlock.Input.Add(builder.ToString()); forBlock.Input.Add(statement2); .)
+ RPAREN
+ '{'
+ {
+ Statement (.
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ forBlock.Children.Add(operation);
+ .)
+ |
+ IfBlock][
+ |
+ WhileBlock][
+ |
+ EchoStatement][
+ |
+ SayStatement][
+ |
+ DisplayStatement][
+ |
+ ForBlock][
+ }
+ '}'
+ (.
+ parent.Children.Add(forBlock);
+ .)
+.
+
+FunctionDeclaration][ (.
+ StringBuilder builder = new StringBuilder();
+ string statement = string.Empty;
+ MacroOperation func = new MacroOperation(OperationType.FunctionDeclaration);
+ .)
+=
+ "function"
+ LPAREN
+ CommaList][ (. string[] args = builder.ToString().Split(','); func.Input.AddRange(args); .)
+ RPAREN
+ '{'
+ {
+ Statement (.
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ func.Children.Add(operation);
+ .)
+ |
+ IfBlock][
+ |
+ WhileBlock][
+ |
+ EchoStatement][
+ |
+ SayStatement][
+ |
+ DisplayStatement][
+ |
+ ForBlock][
+ }
+ '}'
+ (.
+ parent.Children.Add(func);
+ .)
+.
+
+EchoStatement][ (.
+ StringBuilder builder = new StringBuilder();
+ MacroOperation echoStatement = new MacroOperation(OperationType.Echo);
+ string statement = string.Empty;
+ .)
+=
+ "echo:"
+ Statement (.
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ echoStatement.Children.Add(operation);
+ parent.Children.Add(echoStatement);
+ .)
+.
+
+SayStatement][ (.
+ StringBuilder builder = new StringBuilder();
+ MacroOperation sayStatement = new MacroOperation(OperationType.Say);
+ string statement = string.Empty;
+ .)
+=
+ "say:"
+ string (.
+ statement = t.val.Replace("\"", "");
+ sayStatement.Input.Add(statement);
+ parent.Children.Add(sayStatement);
+ .)
+.
+
+DisplayStatement][ (.
+ StringBuilder builder = new StringBuilder();
+ MacroOperation displayStatement = new MacroOperation(OperationType.Display);
+ string statement = string.Empty;
+ .)
+=
+ "display:"
+ (
+ Statement (.
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ displayStatement.Children.Add(operation);
+ .)
+ |
+ string (.
+ statement = t.val.Replace("\"", "");
+ MacroOperation operation = new MacroOperation(OperationType.String);
+ operation.Input.Add(statement);
+ displayStatement.Children.Add(operation);
+ .)
+ )
+ {
+ ','
+ (
+ Statement (.
+ MacroOperation operation = new MacroOperation(OperationType.Statement);
+ operation.Input.Add(statement);
+ displayStatement.Children.Add(operation);
+ .)
+ |
+ string (.
+ statement = t.val.Replace("\"", "");
+ MacroOperation operation = new MacroOperation(OperationType.String);
+ operation.Input.Add(statement);
+ displayStatement.Children.Add(operation);
+ .)
+ )
+ }
+ (.
+ parent.Children.Add(displayStatement);
+ .)
+.
+
+Statement (.
+ value = string.Empty;
+ StringBuilder builder = new StringBuilder();
+ .)
+=
+ IF(IsAssignment())
+ Assignment][ (. value = builder.ToString(); .)
+ |
+ Expression][ (. value = builder.ToString(); .)
+.
+
+Expression][
+=
+Term][
+{
+ '+' (. builder.Append(t.val); .) Term][
+|
+ '-' (. builder.Append(t.val); .) Term][
+|
+ '%' (. builder.Append(t.val); .) Term][
+}
+.
+
+Term][
+=
+ Factor][
+ {
+ '*' (. builder.Append(t.val); .)
+ Factor][
+|
+ '/' (. builder.Append(t.val); .)
+ Factor][
+}
+.
+
+Factor][
+=
+ Value][
+ {
+ '^' (. builder.Append(t.val); .)
+ Value][
+ }
+.
+
+Value][
+=
+
+ [
+ "+" (. builder.Append(t.val); .)
+ |
+ "-" (. builder.Append(t.val); .)
+ ]
+(
+ IF(IsFunctionCall())
+ Function][
+|
+ IF(IsArrayCall())
+ ArrayCall][
+|
+ identifier (. builder.Append(t.val); .)
+|
+ number (. builder.Append(t.val); .)
+|
+ hex (. builder.Append(t.val); .)
+|
+ binary (. builder.Append(t.val); .)
+|
+ '(' (. builder.Append(t.val); .)
+ Expression][
+ ')' (. builder.Append(t.val); .)
+)
+.
+
+ArrayL][
+=
+'[' (. builder.Append(t.val); .)
+CommaList][
+']' (. builder.Append(t.val); .)
+.
+
+CommaList][
+=
+Expression][
+{
+ ',' (. builder.Append(t.val); .)
+ Expression][
+}
+.
+
+Assignment][
+=
+identifier (. builder.Append(t.val); .)
+(
+ (
+ "::" (. builder.Append(t.val); .)
+ Expression][
+ )
+ |
+ (
+ ":=" (. builder.Append(t.val); string value = string.Empty; .)
+ AnyExpression (. builder.Append(value); .)
+ newline
+ )
+ |
+ (
+ "->" (. builder.Append(t.val); .)
+ ArrayL][
+ )
+)
+.
+
+Function][
+=
+identifier (. builder.Append(t.val); .)
+'(' (. builder.Append(t.val); .)
+CommaList][
+')' (. builder.Append(t.val); .)
+.
+
+ArrayCall][
+=
+identifier (. builder.Append(t.val); .)
+'[' (. builder.Append(t.val); .)
+ Expression][
+']' (. builder.Append(t.val); .)
+.
+
+Comparison][
+=
+Expression][
+COMPARER (. result.Append(t.val); .)
+Expression][
+.
+
+AnyExpression (. value = string.Empty; StringBuilder builder = new StringBuilder(); .)
+=
+ANY (. builder.Append(t.val); .) { ANY (. builder.Append(t.val); .) } '\n' (. value = builder.ToString(); .)
+.
+
+
+END SCRIPT.
\ No newline at end of file
diff --git a/CS-MIC/csmic/csmic/Variable.cs b/CS-MIC/csmic/csmic/Variable.cs
new file mode 100644
index 0000000..4fb9a3e
--- /dev/null
+++ b/CS-MIC/csmic/csmic/Variable.cs
@@ -0,0 +1,100 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace csmic
+{
+ ///
+ /// Represents the data types supported in a variable.
+ ///
+ public enum VariableType
+ {
+ ///
+ /// Decimal
+ ///
+ Decimal,
+ ///
+ /// Equation
+ ///
+ Equation,
+ ///
+ /// Array
+ ///
+ Array,
+ ///
+ /// Unknown
+ ///
+ Unknown,
+ ///
+ /// No type associated
+ ///
+ None
+ }
+
+ ///
+ /// An object that contains information about a variable.
+ ///
+ public class Variable
+ {
+ #region Members
+
+ ///
+ /// The type of variable.
+ ///
+ private VariableType type;
+ ///
+ /// The value of the variable.
+ ///
+ private object value;
+
+ #endregion
+
+ #region Constructor
+
+ ///
+ /// Creates an empty variable.
+ ///
+ public Variable()
+ {
+ this.type = VariableType.None;
+ this.value = null;
+ }
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// Gets or sets an object representing the variable's value.
+ ///
+ public object Value
+ {
+ get
+ {
+ return this.value;
+ }
+ set
+ {
+ this.value = value;
+ }
+ }
+
+ ///
+ /// Gets or sets the type of the variable.
+ ///
+ public VariableType Type
+ {
+ get
+ {
+ return this.type;
+ }
+ set
+ {
+ this.type = value;
+ }
+ }
+
+ #endregion
+ }
+}
diff --git a/CS-MIC/csmic/csmic/bin/Debug/csmic.1.1.4.nupkg b/CS-MIC/csmic/csmic/bin/Debug/csmic.1.1.4.nupkg
new file mode 100644
index 0000000..881606c
Binary files /dev/null and b/CS-MIC/csmic/csmic/bin/Debug/csmic.1.1.4.nupkg differ
diff --git a/CS-MIC/csmic/csmic/bin/Debug/csmic.XML b/CS-MIC/csmic/csmic/bin/Debug/csmic.XML
new file mode 100644
index 0000000..b170882
--- /dev/null
+++ b/CS-MIC/csmic/csmic/bin/Debug/csmic.XML
@@ -0,0 +1,1028 @@
+
+
+
+ csmic
+
+
+
+ Coded function factory.
+
+ This class generates new coded functions dynamically.
+
+
+
+ Creates a new ICodedFunction interface object that implements the dynamic method described.
+ Name of the function.
+ Number of expected arguments.
+ The method body.
+ An ICodedFunction interface object.
+
+
+
+ A coded implementation of the absolute value function.
+
+
+
+
+ Expects 1 argument.
+
+
+
+
+ The name of the function.
+
+
+
+
+ Executes a code block.
+
+ The arguments used in the code block.
+ The absolute value of the argument.
+
+
+
+ A coded implementation of the exponential function based on the constant e.
+
+
+
+
+ Expects 1 argument.
+
+
+
+
+ The name of the function.
+
+
+
+
+ Executes a code block.
+
+ The arguments used in the code block.
+ The constant e raised to the power of the argument.
+
+
+
+ A coded implementation of the log function.
+
+
+
+
+ Expects 2 arguments.
+
+
+
+
+ The name of the function.
+
+
+
+
+ Executes a code block.
+
+ The arguments used in the code block.
+ The log of the first argument to the base of the second argument.
+
+
+
+ A coded implementation of a precision function.
+
+
+
+
+ Expects 2 arguments.
+
+
+
+
+ The name of the function.
+
+
+
+
+ Executes a code block.
+
+ The arguments used in the code block.
+ The first argument to the precision of the argument.
+
+
+
+ A coded implementation of the squre root function.
+
+
+
+
+ Expects 1 argument.
+
+
+
+
+ The name of the function.
+
+
+
+
+ Executes a code block.
+
+ The arguments used in the code block.
+ The square root of the argument.
+
+
+
+ A coded implementation of the cosine function.
+
+
+
+
+ Expects 1 argument.
+
+
+
+
+ The name of the function.
+
+
+
+
+ Executes a code block.
+
+ The arguments used in the code block.
+ The cosine of the argument.
+
+
+
+ A coded implementation of a rounded function.
+
+
+
+
+ Expects 1 argument.
+
+
+
+
+ The name of the function.
+
+
+
+
+ Executes a code block.
+
+ The arguments used in the code block.
+ The rounded argument.
+
+
+
+ A coded implementation of the sine function.
+
+
+
+
+ Expects 1 argument.
+
+
+
+
+ The name of the function.
+
+
+
+
+ Executes a code block.
+
+ The arguments used in the code block.
+ The sine of the argument.
+
+
+
+ A coded implementation of the tangent function.
+
+
+
+
+ Expects 1 argument.
+
+
+
+
+ The name of the function.
+
+
+
+
+ Executes a code block.
+
+ The arguments used in the code block.
+ The tangent of the argument.
+
+
+ Computable class.
+
+
+ The expression to be built.
+
+
+ The interpreter to act as a base.
+
+
+ The add symbol.
+
+
+ The substract symbol.
+
+
+ The divide symbol.
+
+
+ The multiply symbol.
+
+
+ The modifier symbol.
+
+
+ The power symbol.
+
+
+ Gets the expression.
+ The expression.
+
+
+ Creates a Computable instance.
+ The expression.
+ The interpreter.
+
+
+ Resolves the computable as an input interpreter having calculated the input.
+ The computable as an input interpreter.
+
+
+ Resolve the computer to a type .
+ Generic type parameter.
+ The selector function.
+ .
+
+
+ Form the operation given the operation constant and an argument.
+ The operation constant.
+ The argument.
+ A string with the given operation appended.
+
+
+ Form the function with the current expression as the first argument, followed by .
+ The name of the function.
+ The arguments.
+ .
+
+
+ Adds addend.
+ The decimal to add.
+ A computable class after the addition.
+
+
+ Subtracts the subtrahend.
+ The subtrahend.
+ A computable class after the subtraction.
+
+
+ Multiplies the multiplicand.
+ The multiplicand.
+ A computable class after the mulitplication.
+
+
+ Divides the divisor.
+ The divisor.
+ A computable class after the divison.
+
+
+ Mods using a given divisor.
+ The divisor.
+ A computable class after the mod.
+
+
+ Raises to power of the given integer value.
+ The power.
+ A computable class after the power operation.
+
+
+ Applies the function with the current expression as the first argument, followed by .
+ The name of the function.
+ The arguments.
+ A computable class after the function is applied.
+
+
+ Executes a command for all items in a collection.
+ Generic type parameter.
+ The items of type .
+ The action belonging to type .
+ .
+
+
+ CS-MIC extension methods.
+
+
+ A string extension method that interprets as input the string that calls it.
+ The input to act on.
+ The output from the interpretation of the string.
+
+
+ A string extension method that executes as macro operation.
+ The script to act on.
+ The final output of the script.
+
+
+
+ A string extension method that interprets as input the string that calls it.
+
+ The collection to act on.
+ The output from the interpretation of the string.
+
+
+
+ A string extension method that interprets as input the string that calls it.
+
+ The collection to act on.
+ The action.
+ The output from the interpretation of the string.
+
+
+ Enumerates input in this collection, returning a selection on the interpreter.
+ Generic type parameter.
+ The collection to act on.
+ The selection.
+
+ An enumerator that allows foreach to be used to process interpret< t> in this
+ collection.
+
+
+
+ A string extension method that executes as macro operation.
+ The collection to act on.
+ The final output of the script.
+
+
+ Enumerates input in parallel in this collection.
+ The collection to act on.
+
+ An enumerator that allows foreach to be used to process interpret in parallel in this
+ collection.
+
+
+
+ Enumerates input in parallel this collection, returning a selection on the interpreter.
+ Generic type parameter.
+ The collection to act on.
+ The selection.
+
+ An enumerator that allows foreach to be used to process interpret in parallel< t> in
+ this collection.
+
+
+
+
+ A string extension method that interprets as input the strings that calls it in parallel.
+
+ The collection to act on.
+ The output from the interpretation of the string.
+
+
+
+ A generically coded implementation of the ICodedFunction interface.
+
+
+
+ Number of expected arguments.
+
+
+ Name of the function.
+
+
+ The method body.
+
+
+ Constructor.
+ Name of the function.
+ Number of expected arguments.
+ The method body.
+
+
+ Gets the number of expected arguments.
+ The total number of expected arguments.
+
+
+ Gets the name of the function.
+ The name of the function.
+
+
+ Executes a code block that computes the value of the function.
+ A variable-length parameters list containing arguments.
+ The decimal value computed by the function.
+
+
+
+ Implements a function that is coded in the .Net environment.
+
+ This interface is required to implement a method or function
+ that can be used by the CS-MIC inputInterpreter. It is worth noting that the
+ function's name will be the text that is used in the inputInterpreter as the
+ executable text.
+
+
+
+ Gets the number of expected arguments.
+
+
+
+
+ Gets the name of the function.
+
+ The input inputInterpreter will use this function name as
+ executable text, expecting an opening and closing parenthesis following
+ it.
+
+
+
+ Executes a code block that computes the value of the function.
+
+ An array of arguments passed to the function.
+ The decimal value computed by the function.
+ Any code block is valid. Error handling must be done by the
+ developer, as the inputInterpreter cannot determine if there is an error.
+
+ This example shows how to implement the sine function through the interface's
+ Execute() function.
+ ]
+ public decimal Execute(params decimal[] args)
+ {
+ //Set up an output variable.
+ decimal output = 0;
+
+ //Check to see if the number or arguments recieved
+ //is equal to the number of arguments expected.
+ if (args.Length == this.NumExpectedArguments)
+ {
+ //Grab the argument and set a local variable for clarity.
+ decimal input = args[0];
+
+ //Set the output as a sine of the input.
+ output = (decimal)Math.Sin((double)input);
+ }
+
+ //Return the output. The function will return the sine if the arguments
+ //matched what was expected, and will return 0 otherwise. Returning 0 on
+ //errors is the standard in CS-MIC.
+ return output;
+ }
+
+
+
+
+
+ An interpreter object that reads user input and evaluates the code.
+
+ The interpreter does not support exceptions by design. Instead, invalid
+ calculations, parameters, etc. will result in a result of zero.
+
+ InputInterpreter interpreter = new InputInterpreter();
+ interpreter.Interpret("1/0"); // The result will be 0, not an exception.
+
+
+
+
+
+ The output generated.
+
+
+
+
+ The variables assigned.
+
+
+
+
+ The time for execution.
+
+
+
+
+ The verbose message of the calculation.
+
+
+
+
+ The list of coded functions that can be executed.
+
+
+
+
+ The list of user defined functions that can be executed.
+
+
+
+
+ The private calculated value.
+
+
+
+
+ Creates a new InputInterpreter.
+
+
+
+
+ Creates a new InputInterpreter from an original.
+
+ The orginal input interpreter to copy.
+
+
+
+ Gets the message that represents the InputInterpreters output.
+
+
+
+
+ Gets the verbose message that is generated with a calculation.
+
+
+
+
+ Gets the value of the output as a decimal.
+
+
+
+
+ Gets the value of the output cast as an int.
+
+
+
+
+ Gets the value of the output cast as a float.
+
+
+
+
+ Gets the value of the output cast as a double.
+
+
+
+
+ Gets the value (cast as a long) converted to its binary equivalent.
+
+
+
+
+ Gets the execution time of the last calculation.
+
+
+
+
+ Gets or sets a list of coded functions that the interpreter supports.
+
+
+
+
+ Gets or sets a list of user generated interpreted functions that the interpreter supports.
+
+ The interpreted functions.
+
+
+ Gets the variables.
+ The variables.
+
+
+
+ Interprets and executes given input.
+
+ The input to interpret and execute.
+
+
+
+ Computes an expression and returns the result as a decimal.
+
+ The expression to be calculated.
+ The value that was computed.
+
+
+
+ Assigns a decimal value to a variable.
+
+ The name of the variable.
+ The value of the variable.
+ True if the variable was set, false otherwise.
+
+
+
+ Assigns a decimal value to a variable.
+
+ The name of the variable.
+ The expression of the variable.
+ True if the variable was set, false otherwise.
+
+
+
+ Assigns a decimal value to a variable.
+
+ The name of the variable.
+ The values of the variable.
+ True if the variable was set, false otherwise.
+
+
+
+ Executes a function stored in the interpreter.
+
+ The name of the function to execute.
+ The arguments to pass to the function.
+ The value computed from the function execution.
+
+
+
+ Loads the default coded functions supported by the interpreter.
+
+
+
+
+ Produces output given a single object.
+
+ The object representing the output.
+
+
+
+ Produces output given an object and a message.
+
+ The object representing the output.
+ The message to be displayed with the output.
+
+
+ Interpret an input asynchronously.
+ The input to interpret and execute.
+ The callback.
+
+
+ Interpret asynchronous threading work.
+ The input to interpret and execute.
+
+
+ Interpret asynchronous delegate.
+ The input.
+ .
+
+
+ Converts this object to a computable.
+ This object as a Computable.
+
+
+ Treats the current object as a computable and performs an action in that context.
+ The action to execute as a computable object.
+ This object as a Computable, after the given action.
+
+
+
+ Represents a user defined function that can be executed by the interpreter.
+
+
+
+
+ The name of the function.
+
+
+
+
+ The number of expected arguments.
+
+
+
+
+ The set of instructions to be passed to the internal inputInterpreter.
+
+
+
+
+ A set of arguments used in computation of the function.
+
+
+
+
+ The internal macro builder used for computation.
+
+
+
+
+ The internal input inputInterpreter that macro builder will use for computation.
+
+
+
+
+ Creates a new interpreted function.
+
+ The name of the fuction.
+ The node to be used in computation.
+ A set of argument names to be used in computation.
+
+
+
+ Gets the name of the function.
+
+
+
+
+ Gets the number of expected arguments for the function.
+
+
+
+
+ Computes the value of the function.
+
+ The arguments used for computation.
+ The decimal value computed by the function.
+
+
+
+ Because a function's internal pattern may be different, we must manually check to see if the function
+ names are the same.
+
+ The object to test.
+ True if the functions are the same.
+
+
+ Serves as a hash function for a particular type.
+ A hash code for the current .
+
+
+
+ Represents an argument made in an interpreted function.
+
+
+
+
+ The name of the argument.
+
+
+
+
+ The value of the argument.
+
+
+
+
+ Creates a new interpreted function argument.
+
+
+
+
+ Creates a new interpreted function argument.
+
+ The name of the argument in the interpreted function.
+ The value of the argument to use in the interpreted function.
+
+
+
+ Gets or sets the name of the argument.
+
+
+
+
+ Gets or sets the value of the argument.
+
+
+
+
+ A builder object that executes macro scripts.
+
+
+
+
+ The input inputInterpreter.
+
+
+
+ The script to run as a macro.
+
+
+
+ The output as a list of strings.
+
+
+
+
+ The time for execution.
+
+
+
+
+ The root macro operation.
+
+
+
+
+ Creates a new builder object that executes a given macro script.
+
+ A list of strings representing the macro.
+ The InputInterpreter to be used.
+
+
+
+ Creates a new builder object that executes a given macro script.
+
+ A list of strings representing the macro.
+ The InputInterpreter to be used.
+
+
+
+ Gets a list of strings representing the output.
+
+
+
+
+ Gets the execution time of the last script computation.
+
+
+
+
+ Gets the decimal value last computed by the macrobuilder.
+
+
+
+ Runs this macro.
+
+
+ Executes the asynchronous operation.
+ The input.
+ The callback.
+
+
+ Executes the asynchronous threading work operation.
+ The input.
+ .
+
+
+ Macro asynchronous delegate.
+ The input.
+ .
+
+
+
+ Represents the operation types supported by a scripted macro.
+
+
+
+
+ Represents a conditional block.
+
+
+
+
+ Represents a conditional else block.
+
+
+
+
+ Represents a complete conditional block.
+
+
+
+
+ A while block.
+
+
+
+
+ A for block.
+
+
+
+
+ A function declaration.
+
+
+
+
+ An echo statement.
+
+
+
+
+ A say statement.
+
+
+
+
+ A display statement.
+
+
+
+
+ A statement to execute.
+
+
+
+
+ A string to display.
+
+
+
+
+ An unknown or malformed block.
+
+
+
+
+ An operation object that executes a specified action.
+
+
+
+
+ The type of operation represented by the operation.
+
+
+
+
+ The collection of children nodes that belong to the operation.
+
+
+
+
+ A list of the necesary input to execute the operation.
+
+
+
+
+ Creates a new macro operation node.
+
+ The type of operation the node represents.
+
+
+
+ Gets or sets the children nodes of the operation.
+
+
+
+
+ Gets or sets the input for the operation.
+
+
+
+
+ Gets or sets the operation type for this operation.
+
+
+
+
+ Represents the data types supported in a variable.
+
+
+
+
+ Decimal
+
+
+
+
+ Equation
+
+
+
+
+ Array
+
+
+
+
+ Unknown
+
+
+
+
+ No type associated
+
+
+
+
+ An object that contains information about a variable.
+
+
+
+
+ The type of variable.
+
+
+
+
+ The value of the variable.
+
+
+
+
+ Creates an empty variable.
+
+
+
+
+ Gets or sets an object representing the variable's value.
+
+
+
+
+ Gets or sets the type of the variable.
+
+
+
+
diff --git a/CS-MIC/csmic/csmic/bin/Debug/csmic.dll b/CS-MIC/csmic/csmic/bin/Debug/csmic.dll
new file mode 100644
index 0000000..f707ec3
Binary files /dev/null and b/CS-MIC/csmic/csmic/bin/Debug/csmic.dll differ
diff --git a/CS-MIC/csmic/csmic/bin/Debug/csmic.pdb b/CS-MIC/csmic/csmic/bin/Debug/csmic.pdb
new file mode 100644
index 0000000..6a42ea8
Binary files /dev/null and b/CS-MIC/csmic/csmic/bin/Debug/csmic.pdb differ
diff --git a/CS-MIC/csmic/csmic/bin/Debug/net40/csmic.dll b/CS-MIC/csmic/csmic/bin/Debug/net40/csmic.dll
new file mode 100644
index 0000000..c8b3096
Binary files /dev/null and b/CS-MIC/csmic/csmic/bin/Debug/net40/csmic.dll differ
diff --git a/CS-MIC/csmic/csmic/bin/Debug/net40/csmic.pdb b/CS-MIC/csmic/csmic/bin/Debug/net40/csmic.pdb
new file mode 100644
index 0000000..dd92763
Binary files /dev/null and b/CS-MIC/csmic/csmic/bin/Debug/net40/csmic.pdb differ
diff --git a/CS-MIC/csmic/csmic/bin/Release/csmic.1.1.4.nupkg b/CS-MIC/csmic/csmic/bin/Release/csmic.1.1.4.nupkg
new file mode 100644
index 0000000..1a8c40e
Binary files /dev/null and b/CS-MIC/csmic/csmic/bin/Release/csmic.1.1.4.nupkg differ
diff --git a/CS-MIC/csmic/csmic/bin/Release/net40/csmic.dll b/CS-MIC/csmic/csmic/bin/Release/net40/csmic.dll
new file mode 100644
index 0000000..038b768
Binary files /dev/null and b/CS-MIC/csmic/csmic/bin/Release/net40/csmic.dll differ
diff --git a/CS-MIC/csmic/csmic/bin/Release/net40/csmic.pdb b/CS-MIC/csmic/csmic/bin/Release/net40/csmic.pdb
new file mode 100644
index 0000000..b0b1ab5
Binary files /dev/null and b/CS-MIC/csmic/csmic/bin/Release/net40/csmic.pdb differ
diff --git a/CS-MIC/csmic/csmic/coco.exe b/CS-MIC/csmic/csmic/coco.exe
new file mode 100644
index 0000000..6822fa6
Binary files /dev/null and b/CS-MIC/csmic/csmic/coco.exe differ
diff --git a/CS-MIC/csmic/csmic/csmic.csproj b/CS-MIC/csmic/csmic/csmic.csproj
new file mode 100644
index 0000000..67d0899
--- /dev/null
+++ b/CS-MIC/csmic/csmic/csmic.csproj
@@ -0,0 +1,23 @@
+
+
+ net40
+ 1.1.4
+ Jordan Wages
+ None
+ CS-MIC
+ true
+ false
+ Copyright © 2012
+ https://github.com/wagesj45/cs-mic/blob/master/LICENSE
+ http://cs-mic.com/
+ https://github.com/wagesj45/cs-mic
+ A .NET component for easy access to parsing simple math and scripting.
+ math parsing scripting
+
+
+
+
+
+
+
+
diff --git a/CS-MIC/csmic/csmic/csmic.csproj.vspscc b/CS-MIC/csmic/csmic/csmic.csproj.vspscc
new file mode 100644
index 0000000..feffdec
--- /dev/null
+++ b/CS-MIC/csmic/csmic/csmic.csproj.vspscc
@@ -0,0 +1,10 @@
+""
+{
+"FILE_VERSION" = "9237"
+"ENLISTMENT_CHOICE" = "NEVER"
+"PROJECT_FILE_RELATIVE_PATH" = ""
+"NUMBER_OF_EXCLUDED_FILES" = "0"
+"ORIGINAL_PROJECT_FILE_PATH" = ""
+"NUMBER_OF_NESTED_PROJECTS" = "0"
+"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
+}
diff --git a/CS-MIC/csmic/csmic/csmic_open.snk b/CS-MIC/csmic/csmic/csmic_open.snk
new file mode 100644
index 0000000..4524054
Binary files /dev/null and b/CS-MIC/csmic/csmic/csmic_open.snk differ
diff --git a/CS-MIC/csmic/csmic/obj/Debug/DesignTimeResolveAssemblyReferences.cache b/CS-MIC/csmic/csmic/obj/Debug/DesignTimeResolveAssemblyReferences.cache
new file mode 100644
index 0000000..28e76ca
Binary files /dev/null and b/CS-MIC/csmic/csmic/obj/Debug/DesignTimeResolveAssemblyReferences.cache differ
diff --git a/CS-MIC/csmic/csmic/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/CS-MIC/csmic/csmic/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
new file mode 100644
index 0000000..80d1f9f
Binary files /dev/null and b/CS-MIC/csmic/csmic/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ
diff --git a/CS-MIC/csmic/csmic/obj/Debug/csmic.1.1.4.nuspec b/CS-MIC/csmic/csmic/obj/Debug/csmic.1.1.4.nuspec
new file mode 100644
index 0000000..2deed10
--- /dev/null
+++ b/CS-MIC/csmic/csmic/obj/Debug/csmic.1.1.4.nuspec
@@ -0,0 +1,22 @@
+
+
+
+ csmic
+ 1.1.4
+ Jordan Wages
+ Jordan Wages
+ false
+ https://github.com/wagesj45/cs-mic/blob/master/LICENSE
+ http://cs-mic.com/
+ A .NET component for easy access to parsing simple math and scripting.
+ Copyright © 2012
+ math parsing scripting
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CS-MIC/csmic/csmic/obj/Debug/csmic.csproj.CoreCompileInputs.cache b/CS-MIC/csmic/csmic/obj/Debug/csmic.csproj.CoreCompileInputs.cache
new file mode 100644
index 0000000..6d52104
--- /dev/null
+++ b/CS-MIC/csmic/csmic/obj/Debug/csmic.csproj.CoreCompileInputs.cache
@@ -0,0 +1 @@
+5775a073493428828d0febeeaa7c8078a54e5d15
diff --git a/CS-MIC/csmic/csmic/obj/Debug/csmic.csproj.FileListAbsolute.txt b/CS-MIC/csmic/csmic/obj/Debug/csmic.csproj.FileListAbsolute.txt
new file mode 100644
index 0000000..0286e20
--- /dev/null
+++ b/CS-MIC/csmic/csmic/obj/Debug/csmic.csproj.FileListAbsolute.txt
@@ -0,0 +1,6 @@
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\csmic\bin\Debug\csmic.XML
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\csmic\bin\Debug\csmic.dll
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\csmic\bin\Debug\csmic.pdb
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\csmic\obj\Debug\csmic.csproj.CoreCompileInputs.cache
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\csmic\obj\Debug\csmic.dll
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\csmic\obj\Debug\csmic.pdb
diff --git a/CS-MIC/csmic/csmic/obj/Debug/csmic.csprojAssemblyReference.cache b/CS-MIC/csmic/csmic/obj/Debug/csmic.csprojAssemblyReference.cache
new file mode 100644
index 0000000..af5abcb
Binary files /dev/null and b/CS-MIC/csmic/csmic/obj/Debug/csmic.csprojAssemblyReference.cache differ
diff --git a/CS-MIC/csmic/csmic/obj/Debug/csmic.dll b/CS-MIC/csmic/csmic/obj/Debug/csmic.dll
new file mode 100644
index 0000000..f707ec3
Binary files /dev/null and b/CS-MIC/csmic/csmic/obj/Debug/csmic.dll differ
diff --git a/CS-MIC/csmic/csmic/obj/Debug/csmic.pdb b/CS-MIC/csmic/csmic/obj/Debug/csmic.pdb
new file mode 100644
index 0000000..6a42ea8
Binary files /dev/null and b/CS-MIC/csmic/csmic/obj/Debug/csmic.pdb differ
diff --git a/CS-MIC/csmic/csmic/obj/Debug/net40/csmic.AssemblyInfo.cs b/CS-MIC/csmic/csmic/obj/Debug/net40/csmic.AssemblyInfo.cs
new file mode 100644
index 0000000..da70e05
--- /dev/null
+++ b/CS-MIC/csmic/csmic/obj/Debug/net40/csmic.AssemblyInfo.cs
@@ -0,0 +1,25 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+using System;
+using System.Reflection;
+
+[assembly: System.Reflection.AssemblyCompanyAttribute("None")]
+[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
+[assembly: System.Reflection.AssemblyCopyrightAttribute("Copyright © 2012")]
+[assembly: System.Reflection.AssemblyDescriptionAttribute("A .NET component for easy access to parsing simple math and scripting.")]
+[assembly: System.Reflection.AssemblyFileVersionAttribute("1.1.4.0")]
+[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.1.4")]
+[assembly: System.Reflection.AssemblyProductAttribute("CS-MIC")]
+[assembly: System.Reflection.AssemblyTitleAttribute("csmic")]
+[assembly: System.Reflection.AssemblyVersionAttribute("1.1.4.0")]
+
+// Generated by the MSBuild WriteCodeFragment class.
+
diff --git a/CS-MIC/csmic/csmic/obj/Debug/net40/csmic.AssemblyInfoInputs.cache b/CS-MIC/csmic/csmic/obj/Debug/net40/csmic.AssemblyInfoInputs.cache
new file mode 100644
index 0000000..4b2a50b
--- /dev/null
+++ b/CS-MIC/csmic/csmic/obj/Debug/net40/csmic.AssemblyInfoInputs.cache
@@ -0,0 +1 @@
+0ea9b979dda5a9e32efff5e2f55623df53fb1778
diff --git a/CS-MIC/csmic/csmic/obj/Debug/net40/csmic.csproj.CoreCompileInputs.cache b/CS-MIC/csmic/csmic/obj/Debug/net40/csmic.csproj.CoreCompileInputs.cache
new file mode 100644
index 0000000..fca1ddd
--- /dev/null
+++ b/CS-MIC/csmic/csmic/obj/Debug/net40/csmic.csproj.CoreCompileInputs.cache
@@ -0,0 +1 @@
+a5e8f94baf8d8768320eb6d870d6fe889b53b39f
diff --git a/CS-MIC/csmic/csmic/obj/Debug/net40/csmic.csproj.FileListAbsolute.txt b/CS-MIC/csmic/csmic/obj/Debug/net40/csmic.csproj.FileListAbsolute.txt
new file mode 100644
index 0000000..729e9a8
--- /dev/null
+++ b/CS-MIC/csmic/csmic/obj/Debug/net40/csmic.csproj.FileListAbsolute.txt
@@ -0,0 +1,8 @@
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\csmic\obj\Debug\net40\csmic.csprojAssemblyReference.cache
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\csmic\obj\Debug\net40\csmic.csproj.CoreCompileInputs.cache
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\csmic\obj\Debug\net40\csmic.AssemblyInfoInputs.cache
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\csmic\obj\Debug\net40\csmic.AssemblyInfo.cs
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\csmic\bin\Debug\net40\csmic.dll
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\csmic\bin\Debug\net40\csmic.pdb
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\csmic\obj\Debug\net40\csmic.dll
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\csmic\obj\Debug\net40\csmic.pdb
diff --git a/CS-MIC/csmic/csmic/obj/Debug/net40/csmic.csprojAssemblyReference.cache b/CS-MIC/csmic/csmic/obj/Debug/net40/csmic.csprojAssemblyReference.cache
new file mode 100644
index 0000000..0944e8c
Binary files /dev/null and b/CS-MIC/csmic/csmic/obj/Debug/net40/csmic.csprojAssemblyReference.cache differ
diff --git a/CS-MIC/csmic/csmic/obj/Debug/net40/csmic.dll b/CS-MIC/csmic/csmic/obj/Debug/net40/csmic.dll
new file mode 100644
index 0000000..c8b3096
Binary files /dev/null and b/CS-MIC/csmic/csmic/obj/Debug/net40/csmic.dll differ
diff --git a/CS-MIC/csmic/csmic/obj/Debug/net40/csmic.pdb b/CS-MIC/csmic/csmic/obj/Debug/net40/csmic.pdb
new file mode 100644
index 0000000..dd92763
Binary files /dev/null and b/CS-MIC/csmic/csmic/obj/Debug/net40/csmic.pdb differ
diff --git a/CS-MIC/csmic/csmic/obj/Debug/net46/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs b/CS-MIC/csmic/csmic/obj/Debug/net46/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
new file mode 100644
index 0000000..e69de29
diff --git a/CS-MIC/csmic/csmic/obj/Debug/net46/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs b/CS-MIC/csmic/csmic/obj/Debug/net46/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
new file mode 100644
index 0000000..e69de29
diff --git a/CS-MIC/csmic/csmic/obj/Debug/net46/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs b/CS-MIC/csmic/csmic/obj/Debug/net46/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
new file mode 100644
index 0000000..e69de29
diff --git a/CS-MIC/csmic/csmic/obj/Debug/net46/csmic.AssemblyInfo.cs b/CS-MIC/csmic/csmic/obj/Debug/net46/csmic.AssemblyInfo.cs
new file mode 100644
index 0000000..2572a2e
--- /dev/null
+++ b/CS-MIC/csmic/csmic/obj/Debug/net46/csmic.AssemblyInfo.cs
@@ -0,0 +1,23 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+using System;
+using System.Reflection;
+
+[assembly: System.Reflection.AssemblyCompanyAttribute("csmic")]
+[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
+[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
+[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
+[assembly: System.Reflection.AssemblyProductAttribute("csmic")]
+[assembly: System.Reflection.AssemblyTitleAttribute("csmic")]
+[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
+
+// Generated by the MSBuild WriteCodeFragment class.
+
diff --git a/CS-MIC/csmic/csmic/obj/Debug/net46/csmic.AssemblyInfoInputs.cache b/CS-MIC/csmic/csmic/obj/Debug/net46/csmic.AssemblyInfoInputs.cache
new file mode 100644
index 0000000..952fd2b
--- /dev/null
+++ b/CS-MIC/csmic/csmic/obj/Debug/net46/csmic.AssemblyInfoInputs.cache
@@ -0,0 +1 @@
+c9f038d5c3969ac143c7288bb74ddd78a58b070a
diff --git a/CS-MIC/csmic/csmic/obj/Debug/net46/csmic.csproj.CoreCompileInputs.cache b/CS-MIC/csmic/csmic/obj/Debug/net46/csmic.csproj.CoreCompileInputs.cache
new file mode 100644
index 0000000..ce41294
--- /dev/null
+++ b/CS-MIC/csmic/csmic/obj/Debug/net46/csmic.csproj.CoreCompileInputs.cache
@@ -0,0 +1 @@
+f925bdaaece993086be5b4f2ac93432cb385fcbe
diff --git a/CS-MIC/csmic/csmic/obj/Debug/net46/csmic.csprojAssemblyReference.cache b/CS-MIC/csmic/csmic/obj/Debug/net46/csmic.csprojAssemblyReference.cache
new file mode 100644
index 0000000..add48df
Binary files /dev/null and b/CS-MIC/csmic/csmic/obj/Debug/net46/csmic.csprojAssemblyReference.cache differ
diff --git a/CS-MIC/csmic/csmic/obj/Release/csmic.1.1.4.nuspec b/CS-MIC/csmic/csmic/obj/Release/csmic.1.1.4.nuspec
new file mode 100644
index 0000000..4213247
--- /dev/null
+++ b/CS-MIC/csmic/csmic/obj/Release/csmic.1.1.4.nuspec
@@ -0,0 +1,22 @@
+
+
+
+ csmic
+ 1.1.4
+ Jordan Wages
+ Jordan Wages
+ false
+ https://github.com/wagesj45/cs-mic/blob/master/LICENSE
+ http://cs-mic.com/
+ A .NET component for easy access to parsing simple math and scripting.
+ Copyright © 2012
+ math parsing scripting
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CS-MIC/csmic/csmic/obj/Release/net40/csmic.AssemblyInfo.cs b/CS-MIC/csmic/csmic/obj/Release/net40/csmic.AssemblyInfo.cs
new file mode 100644
index 0000000..cbad0c9
--- /dev/null
+++ b/CS-MIC/csmic/csmic/obj/Release/net40/csmic.AssemblyInfo.cs
@@ -0,0 +1,25 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+using System;
+using System.Reflection;
+
+[assembly: System.Reflection.AssemblyCompanyAttribute("None")]
+[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
+[assembly: System.Reflection.AssemblyCopyrightAttribute("Copyright © 2012")]
+[assembly: System.Reflection.AssemblyDescriptionAttribute("A .NET component for easy access to parsing simple math and scripting.")]
+[assembly: System.Reflection.AssemblyFileVersionAttribute("1.1.4.0")]
+[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.1.4")]
+[assembly: System.Reflection.AssemblyProductAttribute("CS-MIC")]
+[assembly: System.Reflection.AssemblyTitleAttribute("csmic")]
+[assembly: System.Reflection.AssemblyVersionAttribute("1.1.4.0")]
+
+// Generated by the MSBuild WriteCodeFragment class.
+
diff --git a/CS-MIC/csmic/csmic/obj/Release/net40/csmic.AssemblyInfoInputs.cache b/CS-MIC/csmic/csmic/obj/Release/net40/csmic.AssemblyInfoInputs.cache
new file mode 100644
index 0000000..b138ad9
--- /dev/null
+++ b/CS-MIC/csmic/csmic/obj/Release/net40/csmic.AssemblyInfoInputs.cache
@@ -0,0 +1 @@
+b9c3515eed0a5638d6a5b8c4e0d7bb5f37b7c757
diff --git a/CS-MIC/csmic/csmic/obj/Release/net40/csmic.csproj.CoreCompileInputs.cache b/CS-MIC/csmic/csmic/obj/Release/net40/csmic.csproj.CoreCompileInputs.cache
new file mode 100644
index 0000000..fca1ddd
--- /dev/null
+++ b/CS-MIC/csmic/csmic/obj/Release/net40/csmic.csproj.CoreCompileInputs.cache
@@ -0,0 +1 @@
+a5e8f94baf8d8768320eb6d870d6fe889b53b39f
diff --git a/CS-MIC/csmic/csmic/obj/Release/net40/csmic.csproj.FileListAbsolute.txt b/CS-MIC/csmic/csmic/obj/Release/net40/csmic.csproj.FileListAbsolute.txt
new file mode 100644
index 0000000..4801eac
--- /dev/null
+++ b/CS-MIC/csmic/csmic/obj/Release/net40/csmic.csproj.FileListAbsolute.txt
@@ -0,0 +1,7 @@
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\csmic\bin\Release\net40\csmic.dll
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\csmic\bin\Release\net40\csmic.pdb
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\csmic\obj\Release\net40\csmic.csproj.CoreCompileInputs.cache
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\csmic\obj\Release\net40\csmic.AssemblyInfoInputs.cache
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\csmic\obj\Release\net40\csmic.AssemblyInfo.cs
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\csmic\obj\Release\net40\csmic.dll
+C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\csmic\obj\Release\net40\csmic.pdb
diff --git a/CS-MIC/csmic/csmic/obj/Release/net40/csmic.dll b/CS-MIC/csmic/csmic/obj/Release/net40/csmic.dll
new file mode 100644
index 0000000..038b768
Binary files /dev/null and b/CS-MIC/csmic/csmic/obj/Release/net40/csmic.dll differ
diff --git a/CS-MIC/csmic/csmic/obj/Release/net40/csmic.pdb b/CS-MIC/csmic/csmic/obj/Release/net40/csmic.pdb
new file mode 100644
index 0000000..b0b1ab5
Binary files /dev/null and b/CS-MIC/csmic/csmic/obj/Release/net40/csmic.pdb differ
diff --git a/CS-MIC/csmic/csmic/obj/csmic.csproj.nuget.cache b/CS-MIC/csmic/csmic/obj/csmic.csproj.nuget.cache
new file mode 100644
index 0000000..597ccad
--- /dev/null
+++ b/CS-MIC/csmic/csmic/obj/csmic.csproj.nuget.cache
@@ -0,0 +1,5 @@
+{
+ "version": 1,
+ "dgSpecHash": "no1TIMbiu1fAXDTJGQ+TSDr5uOTLrmXNFCHSDYCotG8EIO5hC54bP1rMUbPWN+A9Fd4WjYcTSheJw73W11vQ6Q==",
+ "success": true
+}
\ No newline at end of file
diff --git a/CS-MIC/csmic/csmic/obj/csmic.csproj.nuget.g.props b/CS-MIC/csmic/csmic/obj/csmic.csproj.nuget.g.props
new file mode 100644
index 0000000..df5bafa
--- /dev/null
+++ b/CS-MIC/csmic/csmic/obj/csmic.csproj.nuget.g.props
@@ -0,0 +1,15 @@
+
+
+
+ True
+ NuGet
+ C:\Users\wages\Documents\GitHub\cs-mic\CS-MIC\csmic\csmic\obj\project.assets.json
+ $(UserProfile)\.nuget\packages\
+ C:\Users\wages\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder
+ PackageReference
+ 4.7.0
+
+
+ $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
+
+
\ No newline at end of file
diff --git a/CS-MIC/csmic/csmic/obj/csmic.csproj.nuget.g.targets b/CS-MIC/csmic/csmic/obj/csmic.csproj.nuget.g.targets
new file mode 100644
index 0000000..53cfaa1
--- /dev/null
+++ b/CS-MIC/csmic/csmic/obj/csmic.csproj.nuget.g.targets
@@ -0,0 +1,6 @@
+
+
+
+ $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
+
+
\ No newline at end of file
diff --git a/CS-MIC/csmic/csmic/obj/project.assets.json b/CS-MIC/csmic/csmic/obj/project.assets.json
new file mode 100644
index 0000000..971c66c
--- /dev/null
+++ b/CS-MIC/csmic/csmic/obj/project.assets.json
@@ -0,0 +1,52 @@
+{
+ "version": 3,
+ "targets": {
+ ".NETFramework,Version=v4.0": {}
+ },
+ "libraries": {},
+ "projectFileDependencyGroups": {
+ ".NETFramework,Version=v4.0": []
+ },
+ "packageFolders": {
+ "C:\\Users\\wages\\.nuget\\packages\\": {},
+ "C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder": {}
+ },
+ "project": {
+ "version": "1.1.4",
+ "restore": {
+ "projectUniqueName": "C:\\Users\\wages\\Documents\\GitHub\\cs-mic\\CS-MIC\\csmic\\csmic\\csmic.csproj",
+ "projectName": "csmic",
+ "projectPath": "C:\\Users\\wages\\Documents\\GitHub\\cs-mic\\CS-MIC\\csmic\\csmic\\csmic.csproj",
+ "packagesPath": "C:\\Users\\wages\\.nuget\\packages\\",
+ "outputPath": "C:\\Users\\wages\\Documents\\GitHub\\cs-mic\\CS-MIC\\csmic\\csmic\\obj\\",
+ "projectStyle": "PackageReference",
+ "fallbackFolders": [
+ "C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder"
+ ],
+ "configFilePaths": [
+ "C:\\Users\\wages\\AppData\\Roaming\\NuGet\\NuGet.Config",
+ "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
+ ],
+ "originalTargetFrameworks": [
+ "net40"
+ ],
+ "sources": {
+ "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
+ "https://api.nuget.org/v3/index.json": {}
+ },
+ "frameworks": {
+ "net40": {
+ "projectReferences": {}
+ }
+ },
+ "warningProperties": {
+ "warnAsError": [
+ "NU1605"
+ ]
+ }
+ },
+ "frameworks": {
+ "net40": {}
+ }
+ }
+}
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..8000a6f
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,504 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+ When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library. It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random
+ Hacker.
+
+ , 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
diff --git a/README.md b/README.md
index ed2bfdd..1e48d95 100644
--- a/README.md
+++ b/README.md
@@ -1,54 +1,261 @@
-## Design Philosophy
+# cs-mic
+CS-MIC is a .NET library written in C# designed to give developers easy access to expression parsing. For many developers, there is no need to involve complicated settings and formats. With few exposed methods and objects, CS-MIC makes basic expression solving as simple as possible with as little logic required from developers as possible. In fact, one can pull a value with only one line of code.
-CS‑MIC is a small, embeddable expression interpreter designed primarily for UI scenarios where a user types flexible input (e.g., 2+2+someVar) but the host application needs a validated, deterministic numeric value. The library focuses on predictable evaluation, strong validation and extensibility through developer‑supplied variables and coded functions.
+***
-Goals
+## Installation
-- Numeric‑first: Expressions evaluate to a numeric result the host can trust.
-- Predictable semantics: No implicit coercions or surprising operator behavior.
-- Embeddable: Tiny surface area, easy to host inside C# applications.
-- Extensible: Developers inject variables and ICodedFunction implementations.
-- Clear errors: Friendly, actionable diagnostics for invalid input.
+CS-MIC is available as a package on [nuget.org](/https://nuget.org/packages/csmic) for ease and convenience. You can follow the instructions listed on the package site, or use the nuget package manager to search the nuget repository for cs-mic and install it from there.
-Core Principles
+## Usage
-- Determinism: The same input with the same variables/functions yields the same numeric output.
-- Minimalism: Keep the grammar and runtime small; add features only when they reinforce the numeric‑first mission.
-- Type clarity: Values carry explicit types; operators enforce type rules rather than auto‑converting.
-- Safe composition: Functions are pure from the interpreter’s perspective; side effects are the host’s responsibility.
+CS-MIC follows a few basic rules when interpreting user input, but should prove to be fairly straightforward for most developers. While CS-MIC tries to ensure that the order of operations as far as it knows them (parentheses – powers, multiplication, division – addition, subtraction), there may be instances where formatting fails. If this should be noticed, please [report it](https://github.com/wagesj45/cs-mic/issues).
-### Strings: Arguments‑Only, Numeric‑First
+
+### Expression Parsing
-CS‑MIC’s v2 scope treats strings as helpers for functions, not as first‑class expression values. This preserves the “numeric guarantee” while enabling rich, domain‑specific function usage.
+#### Operands
-- Where strings are allowed: As literals in function argument lists (e.g., myFunc("key", 42)).
-- Where strings are not allowed: As standalone primaries, in arithmetic (e.g., "a" + 1), or in comparisons; string variables are out of scope for v2.
-- Function contract: ICodedFunction implementations may accept string arguments and should return a numeric result when the function’s value is used in an expression.
-- Grammar posture: The grammar recognizes quoted string tokens; the parser accepts them only in function argument positions.
-- Operator semantics: No string operators or concatenation; no implicit conversions from string to number.
-- Errors: If a string is used outside an argument position or produced where a number is required, the interpreter emits a clear type error (e.g., "strings are only valid as function arguments").
+`+` - Addition
-Rationale
+`–` - Subtraction
-- Preserves the primary mission: turn flexible user input into a validated numeric value.
-- Keeps complexity low by avoiding general string semantics (concatenation, ordering, variables, etc.).
-- Maximizes developer power: functions can receive text payloads (formats, keys, expressions) and return numbers, leveraging CS‑MIC for parsing, validation and invocation.
+`*` - Multiplication
-Developer Guidance
+`/` - Division
-- Implementing ICodedFunction: Inspect FunctionArgument.Value.Type to branch on expected input. If a string is required, validate and produce a numeric FunctionValue.
-- Argument metadata: Optionally use ExpectedArguments to document names and intended types for better diagnostics.
-- Error messaging: Prefer precise, actionable messages (e.g., "arg 'pattern' must be a string").
+`^` - Raise to a power
-Example
+`%` - Modulus
-// Pseudocode / sketch
-// myFunc("HEX", 0xFF) → 255
-// myFunc("BIN", 1010b) → 10
-// sumWithLabel("groupA", 1, 2, 3) → 6 (label used for logging/selection)
+#### Tokens
-Future Directions (Non‑Goals for v2)
+`::` - Assign a numeric value to a variable.
-- First‑class strings: Allow strings as values, variables, or return types in general expressions (would require defining operators and comparisons).
-- Verbatim/opaque arguments: Special argument modes for embedding mini‑DSLs (higher parser complexity).
-- Value tagging: Optional metadata (e.g., OriginalLiteral) attached to FunctionValue for advanced scenarios.
+`:=` - Assign an equation to a variable.
+
+`->` - Assigns a comma delimited array of numbers to an array variable.
+
+#### Comparison
+
+`==` - Returns ‘True’ if two values are equal to each other.
+
+`>` - Returns ‘True’ if a value is greater than another value.
+
+`<` - Returns ‘True’ if a value is less than another value.
+
+`>=` - Returns ‘True’ if a value is greater than or equal to another value.
+
+`<=` - Returns ‘True’ if a value is greater than or equal to another value.
+
+
+#### Base Conversion
+
+* Decimal
+ * All numbers are interpreted as decimal by default.
+* Binary
+ * Binary numbers are succeeded by a B, non case sensative.
+* Hexadecimal
+ * Hexadecimal numbers are preceded by 0x, non case sensative.
+
+#### Example Input and Output
+
+**Input**|**Output**
+:-----:|:-----:
+`5 + 5` | `10`
+`5 * 2` | `10`
+`1 + 2 * 3` | `7`
+`(1 + 2) * 3` | `9`
+`5 / 2` | `2.5`
+`5 / 0` | `Attempted to divide by zero.`
+`2 ^ 32` | `4294967296`
+`x :: 4` | `4`
+`x :: 6 + 4` | `10`
+`y := 2^x` | `(2^x)`
+
+### Scripting
+
+#### Rules
+
+* Any valid expression can be computed.
+* All computation counts towards the script’s history. This means that once a variable is set inside a script, the variable will remain set until execution of the script is complete.
+* Only one command can be executed per line. No token is required to end the command.
+* Every code block must be opened and closed with a bracket ( { } ). The only exception is the main code block.
+
+#### Loops
+
+`while` - Executes a code block as long as a given condition evaluates to true.
+
+```
+while(bool expression)
+{
+ CODE BLOCK
+}
+```
+
+`for` - After executing an initial condition, a code block is executed while a condition is met. A final statement is executed at the end of each iteration.
+
+```
+for(* expression, bool condition, * expression)
+{
+ CODE BLOCK
+}
+```
+
+#### Conditionals
+
+`if` - Executes a code block if a given condition evaluates to true. An optional else block can follow the if block for execution if the statement evaluates as false.
+
+```
+if(bool expression)
+{
+ CODE BLOCK
+}
+else
+{
+ CODE BLOCK
+}
+```
+
+#### Functions
+
+`echo` - Displays the output from the proceding expression.
+
+```
+echo: expression
+```
+
+`say` - Displays a string.
+
+```
+say: “string”
+```
+
+`display` - Combines strings and expressions to a single line in the output stack.
+
+```
+display: “string”, 12 * 2, “string”, sin(12)
+```
+
+`function` - Creates a new function with a given name, and any number of expected arguments.
+
+```
+function(newFunction, anyArgumentName)
+{
+ sin(anyArgumentName) + cos(anyArgumentName)
+}
+```
+
+#### Comments
+
+* Block Tokens
+ * Starting token: /*
+ * Ending token: */
+ *Any line falling between block comment tokens will be ignored by the macro builder at execution time.
+* Line Tokens
+ * //
+ * Any line starting with the line token will be ignored by the macro builder at execution time.
+
+
+**Example Script**
+
+```
+say: “Fibonacci Sequence”
+temp :: 1
+y :: 1
+echo: y
+for(x :: 1, x < 11, x :: temp + y)
+{
+ echo: x
+ temp :: y
+ y :: x
+}
+x :: 1
+say: “While Loop”
+while(x < 10)
+{
+ if(x == 5)
+ {
+ display: “The condition ‘x == 5’ has been met. x = “, x, “.”
+ }
+ else
+ {
+ echo: sin(x)
+ }
+ x :: x + 1
+}
+```
+
+**Example Script Output**
+```
+Fibonacci Sequence
+1
+1
+2
+3
+5
+8
+13
+21
+34
+55
+89
+While Loop
+0.841470984807897
+0.909297426825682
+0.141120008059867
+-0.756802495307928
+The condition ‘x == 5’ has been met. x = 5.
+-0.279415498198926
+0.656986598718789
+0.989358246623382
+0.412118485241757
+```
+
+## Built In Functions
+
+The following is a list of the internally recognized functions in CS-MIC:
+
+`sin(double expression)`
+
+Returns the sine value of a given `expression`.
+
+`cos(double expression)`
+
+Returns the cosine value of a given `expression`.
+
+`tan(double expression)`
+
+Returns the tangent value of a given `expression`.
+
+`round(double expression)`
+
+Rounds an `expression` to the nearest whole number.
+
+`sqrt(double expression)`
+
+Returns the square root of an `expression`.
+
+`abs(double expression)`
+
+Returns the absolute value of a given `expression`.
+
+`exp(double expression)`
+
+Returns the constant e raised to a given power.
+
+`log(double expression1, double expression2)`
+
+Returns the log of `expression1` to the base of `expression2`
+
+`precision(double expression1, int expression2)`
+
+Returns the value of `expression1` to a given precision. For example, `precision(12.3456789, 4)` will return `12.3456`.
+
+
+## Donations
+
+[](https://support.jordanwages.com?project=2)
+
+If you would like to donate to the development of **cs-mic**, please direct you donation to my [patron page](https://support.jordanwages.com) (powered by Stripe) or directly via my [PayPal.Me](https://www.paypal.me/wagesj45) page. You can also donate Ethereum [to my wallet](https://etherscan.io/address/0x917f3d67e2a7ec8884d241118ee829af57cc4afd).
+
diff --git a/src/.config/dotnet-tools.json b/src/.config/dotnet-tools.json
deleted file mode 100644
index ef58252..0000000
--- a/src/.config/dotnet-tools.json
+++ /dev/null
@@ -1,13 +0,0 @@
-{
- "version": 1,
- "isRoot": true,
- "tools": {
- "cocor": {
- "version": "2014.12.25",
- "commands": [
- "coco"
- ],
- "rollForward": false
- }
- }
-}
\ No newline at end of file
diff --git a/src/Core/CsMic.Core.csproj b/src/Core/CsMic.Core.csproj
deleted file mode 100644
index 7daac77..0000000
--- a/src/Core/CsMic.Core.csproj
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
- net9.0
- CSMic
- enable
- enable
- False
- CSMic.Core
- 2.0.0-beta-01
- CSMic
-
-
-
-
-
-
-
-
-
diff --git a/src/Core/FunctionArgument.cs b/src/Core/FunctionArgument.cs
deleted file mode 100644
index 80b5d6f..0000000
--- a/src/Core/FunctionArgument.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace CSMic
-{
- public class FunctionArgument
- {
- public string Name { get; set; }
- public FunctionValue Value { get; set; }
-
- public FunctionArgument(string name, FunctionValue fv)
- {
- this.Name = name;
- this.Value = fv;
- }
- }
-}
diff --git a/src/Core/FunctionValue.cs b/src/Core/FunctionValue.cs
deleted file mode 100644
index e40a5dc..0000000
--- a/src/Core/FunctionValue.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-using CSMic;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace CSMic
-{
- public class FunctionValue
- {
- public FunctionValueType Type { get; set; }
- public object? Value { get; set; }
-
- public static readonly FunctionValue TRUE = new FunctionValue(FunctionValueType.Numeric, 1m);
- public static readonly FunctionValue FALSE = new FunctionValue(FunctionValueType.Numeric, 0m);
- public static readonly FunctionValue NONE = new FunctionValue(FunctionValueType.None, null);
- public static readonly FunctionValue NUMBER = new FunctionValue(FunctionValueType.Numeric, 0m);
- public static readonly FunctionValue STRING = new FunctionValue(FunctionValueType.String, string.Empty);
- public static readonly FunctionValue ZERO = new FunctionValue(FunctionValueType.Numeric, 0m);
-
- public FunctionValue()
- {
- this.Type = FunctionValueType.None;
- this.Value = null;
- }
-
- public FunctionValue(FunctionValueType type, object? value)
- {
- this.Type = type;
- this.Value = value;
- }
- }
-}
diff --git a/src/Core/FunctionValueType.cs b/src/Core/FunctionValueType.cs
deleted file mode 100644
index 5649c92..0000000
--- a/src/Core/FunctionValueType.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace CSMic
-{
- public enum FunctionValueType
- {
- None,
- Numeric,
- String
- }
-}
diff --git a/src/Core/ICodedFunction.cs b/src/Core/ICodedFunction.cs
deleted file mode 100644
index d81e7d8..0000000
--- a/src/Core/ICodedFunction.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace CSMic
-{
- public interface ICodedFunction
- {
- #region Properties
-
- string Name { get; }
- IEnumerable ExpectedArguments { get; }
- FunctionValue ReturnValue { get; }
-
- #endregion
-
- #region Methods
-
- FunctionValue Execute(params FunctionArgument[] args);
-
- #endregion
- }
-}
diff --git a/src/Core/InputInterpreter.cs b/src/Core/InputInterpreter.cs
deleted file mode 100644
index c9c31c1..0000000
--- a/src/Core/InputInterpreter.cs
+++ /dev/null
@@ -1,201 +0,0 @@
-using System.Runtime.CompilerServices;
-using System.Text;
-using System.IO;
-
-namespace CSMic
-{
- public class InputInterpreter
- {
- #region Members
-
- private decimal numericValue = 0;
- private string stringValue = string.Empty;
- private TimeSpan lastExecutionTime = TimeSpan.Zero;
-
- // Variable stores
- private readonly Dictionary numericVariables;
- private readonly Dictionary numericArrayVariables;
- private readonly Dictionary expressionVariables;
-
- // Function registry
- private readonly Dictionary functions;
-
- #endregion
-
- #region Constructors
-
- public InputInterpreter()
- {
- numericVariables = new Dictionary(StringComparer.Ordinal);
- numericArrayVariables = new Dictionary(StringComparer.Ordinal);
- expressionVariables = new Dictionary(StringComparer.Ordinal);
- functions = new Dictionary(StringComparer.Ordinal);
- }
-
- // Internal constructor to create a child interpreter that shares stores
- internal InputInterpreter(InputInterpreter parent)
- {
- this.numericVariables = parent.numericVariables;
- this.numericArrayVariables = parent.numericArrayVariables;
- this.expressionVariables = parent.expressionVariables;
- this.functions = parent.functions;
- }
-
- #endregion
-
- #region Properties
-
- public decimal NumericValue => numericValue;
- public string StringValue => stringValue;
-
- public TimeSpan LastExecutionTime => lastExecutionTime;
-
- #endregion
-
- #region Output Plumbing
-
- internal void ProduceOutput(decimal numericValue, string stringValue)
- {
- this.numericValue = numericValue;
- this.stringValue = stringValue;
- }
-
- internal void ProduceOutput(FunctionValue functionValue)
- {
- switch (functionValue.Type)
- {
- case FunctionValueType.Numeric:
- decimal numericValue = Convert.ToDecimal(functionValue.Value);
- ProduceOutput(numericValue, string.Empty);
- break;
- case FunctionValueType.String:
- if (functionValue.Value is string s)
- ProduceOutput(0, s);
- else
- ProduceOutput(0, string.Empty);
- break;
- case FunctionValueType.None:
- default:
- ProduceOutput(0, string.Empty);
- break;
- }
- }
-
- #endregion
-
- #region Variable APIs
-
- internal bool TryGetNumeric(string name, out decimal value)
- => numericVariables.TryGetValue(name, out value);
-
- internal bool TryGetNumericArray(string name, out decimal[] values)
- => numericArrayVariables.TryGetValue(name, out values!);
-
- internal bool TryGetExpression(string name, out string expr)
- => expressionVariables.TryGetValue(name, out expr!);
-
- internal void AssignNumeric(string name, decimal value)
- {
- numericVariables[name] = value;
- // Remove conflicting bindings
- expressionVariables.Remove(name);
- }
-
- internal void AssignNumericArray(string name, decimal[] values)
- {
- numericArrayVariables[name] = values;
- }
-
- internal void AssignExpression(string name, string expressionText)
- {
- expressionVariables[name] = expressionText;
- // Remove conflicting numeric value
- numericVariables.Remove(name);
- }
-
- #endregion
-
- #region Expression Evaluation
-
- internal FunctionValue EvaluateExpression(string expressionText)
- {
- // Create a child interpreter sharing stores, so ProduceOutput doesn't affect parent state
- var child = new InputInterpreter(this);
- using var ms = new MemoryStream(Encoding.UTF8.GetBytes(expressionText));
- var scanner = new CSMic.Interpreter.Scanner(ms);
- var parser = new CSMic.Interpreter.Parser(scanner)
- {
- Interpreter = child
- };
- parser.Parse();
- return parser.Result;
- }
-
- // Primary developer-facing API: interpret input and return numeric result
- public decimal Interpret(string input)
- {
- DateTime start = DateTime.Now;
- try
- {
- using var ms = new MemoryStream(Encoding.UTF8.GetBytes(input ?? string.Empty));
- var scanner = new CSMic.Interpreter.Scanner(ms);
- var parser = new CSMic.Interpreter.Parser(scanner)
- {
- Interpreter = this
- };
- parser.Parse();
-
- if (parser.errors.count > 0)
- {
- // Soft error: set numeric to 0 and report a parse error message
- ProduceOutput(0m, parser.errors.errMsgFormat);
- }
- else
- {
- ProduceOutput(parser.Result);
- }
- }
- catch (Exception ex)
- {
- // Soft error: never throw, capture message
- ProduceOutput(0m, ex.Message);
- }
- finally
- {
- DateTime end = DateTime.Now;
- lastExecutionTime = end - start;
- }
-
- return this.numericValue;
- }
-
- #endregion
-
- #region Functions
-
- public void RegisterFunction(ICodedFunction function)
- {
- functions[function.Name] = function;
- }
-
- internal FunctionValue ExecuteFunction(string name, params FunctionArgument[] args)
- {
- if (functions.TryGetValue(name, out var fn))
- {
- try
- {
- return fn.Execute(args);
- }
- catch (Exception ex)
- {
- // Surface function errors to the interpreter's message channel
- ProduceOutput(0m, ex.Message);
- return new FunctionValue(FunctionValueType.None, null);
- }
- }
- return new FunctionValue(FunctionValueType.None, null);
- }
-
- #endregion
- }
-}
diff --git a/src/Core/NuGetPublish.targets b/src/Core/NuGetPublish.targets
deleted file mode 100644
index dfe580a..0000000
--- a/src/Core/NuGetPublish.targets
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
diff --git a/src/Core/Variable.cs b/src/Core/Variable.cs
deleted file mode 100644
index 434daa1..0000000
--- a/src/Core/Variable.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace CSMic
-{
- public class Variable
- {
- #region Members
-
- private VariableType type;
-
- private string name;
-
- private object value;
-
- #endregion
-
- #region Constructor
-
- public Variable()
- {
- this.type = VariableType.None;
- this.value = string.Empty;
- }
-
- #endregion
- }
-}
diff --git a/src/Core/VariableType.cs b/src/Core/VariableType.cs
deleted file mode 100644
index ada5056..0000000
--- a/src/Core/VariableType.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace CSMic
-{
- public enum VariableType
- {
- None,
- Numeric,
- NumericArray,
- Expression,
- }
-}
diff --git a/src/Core/cocor/Interpreter.atg b/src/Core/cocor/Interpreter.atg
deleted file mode 100644
index 2a641ba..0000000
--- a/src/Core/cocor/Interpreter.atg
+++ /dev/null
@@ -1,353 +0,0 @@
-using System;
-using System.Globalization;
-using System.Text;
-using System.Collections.Generic;
-using CSMic;
-
-COMPILER INTERPRETER
-
-/*
- * Class structures and helpers
- */
-
-private FunctionValue functionValue = new FunctionValue();
-
-public FunctionValue Result
-{
- get { return this.functionValue; }
- set { this.functionValue = value; }
-}
-
-private InputInterpreter interpreter = null;
-
-public InputInterpreter Interpreter
-{
- get { return this.interpreter; }
- set { this.interpreter = value; }
-}
-
-bool IsFunctionCall()
-{
- scanner.ResetPeek();
- Token next = scanner.Peek();
- if (next.kind == _LPAREN && la.kind == _identifier) return true;
- return false;
-}
-
-bool IsCompare()
-{
- scanner.ResetPeek();
- Token next = scanner.Peek();
- if (next.kind == _COMPARER) return true;
- return false;
-}
-
-bool IsAssignment()
-{
- scanner.ResetPeek();
- Token next = scanner.Peek();
- if (next.val == "::" || next.val == ":=" || next.val == "->") return true;
- return false;
-}
-
-bool IsArrayCall()
-{
- scanner.ResetPeek();
- Token next = scanner.Peek();
- if (next.val == "[") return true;
- return false;
-}
-
-/*
- * Character sets and tokens
- */
-
-CHARACTERS
-
- UpperLetter = 'A'..'Z'.
- LowerLetter = 'a'..'z'.
- letter = UpperLetter + LowerLetter.
- digit = "0123456789" .
- cr = '\r' .
- lf = '\n' .
- tab = '\t' .
- PM = "+-" .
- NoQuote = ANY - '\"' .
-
-TOKENS
-
- identifier = letter { letter | digit}.
- sign = PM .
- binary = ( '0' | '1' ) { '0' | '1' } ('B' | 'b') .
- hex = "0x" ( digit | ('A' | 'B' | 'C' | 'D' | 'E' |'F') | ('a' | 'b' | 'c' | 'd' | 'e' |'f') ) { digit | ('A' | 'B' | 'C' | 'D' | 'E' |'F') | ('a' | 'b' | 'c' | 'd' | 'e' |'f') } .
- number = digit { digit }['.' {digit}] [('E'|'e')['+'|'-'] digit {digit}] .
- string = "\"" { NoQuote } "\"" .
- LPAREN = '(' .
- RPAREN = ')' .
- COMPARER = "==" | "<" | ">" | "<=" | ">=" .
-
-IGNORE cr + tab
-
-/*
- * Grammar
- */
-
-PRODUCTIONS
-
-INTERPRETER (.
- FunctionValue fv = new FunctionValue();
- bool success = true;
- decimal r = 0;
- if (this.interpreter == null) { return; }
- .)
-=
- IF(IsCompare())
- Comparison
- (. this.functionValue = (success == true) ? FunctionValue.TRUE : FunctionValue.FALSE;
- this.interpreter.ProduceOutput(this.functionValue);
- .)
- |
- IF(IsAssignment())
- Assignment
- (. this.functionValue = new FunctionValue(FunctionValueType.Numeric, r);
- this.interpreter.ProduceOutput(this.functionValue);
- .)
- |
- Expression
- (. this.functionValue = new FunctionValue(FunctionValueType.Numeric, r);
- this.interpreter.ProduceOutput(this.functionValue);
- .)
-.
-
-Expression
-=
- (. decimal r1 = 0; r = 0; .)
- Term
- { '+' Term (. r += r1; .)
- | '-' Term (. r -= r1; .)
- }
-.
-
-Term
-=
- (. decimal r1 = 0; r = 0; .)
- Factor
- { '*' Factor (. r *= r1; .)
- | '/' Factor (. r /= r1; .)
- | '%' Term (. r %= r1; .)
- }
-.
-
-Factor
-=
- (. decimal r1 = 0; .)
- Value
- { '^' Expression
- (. r = Convert.ToDecimal(Math.Pow(Convert.ToDouble(r), Convert.ToDouble(r1))); .)
- }
-.
-
-Value (.
- r = 0; decimal r1 = 0; int signum = 1;
- FunctionValue fvr = new FunctionValue();
- string ident = string.Empty;
- .)
-=
- [ '+' | '-' (. signum = -1; .) ]
- (
- IF(IsFunctionCall())
- Function
- (.
- if (fvr.Type == FunctionValueType.Numeric && fvr.Value != null)
- {
- try { r = signum * Convert.ToDecimal(fvr.Value); }
- catch { SemErr("function returned non-numeric"); r = 0; }
- }
- else
- {
- SemErr("function returned a string; number required");
- r = 0;
- }
- .)
- |
- IF(IsArrayCall())
- ArrayCall (. r = signum * r; .)
- |
- identifier
- (.
- ident = t.val;
- decimal temp = 0;
- string expr = string.Empty;
- bool ok = false;
- // Prefer numeric binding
- try
- {
- // runtime method expected
- ok = this.interpreter.TryGetNumeric(ident, out temp);
- }
- catch { ok = false; }
- if (ok)
- {
- r = signum * temp;
- }
- else
- {
- // Check expression binding
- try
- {
- if (this.interpreter.TryGetExpression(ident, out expr))
- {
- FunctionValue eval = this.interpreter.EvaluateExpression(expr);
- if (eval.Type == FunctionValueType.Numeric && eval.Value != null)
- {
- r = signum * Convert.ToDecimal(eval.Value);
- }
- else
- {
- SemErr("expression variable did not evaluate to a number");
- r = 0;
- }
- }
- else
- {
- SemErr("variable '" + ident + "' is not numeric");
- r = 0;
- }
- }
- catch { SemErr("error evaluating expression variable"); r = 0; }
- }
- .)
- |
- number (. r = signum * decimal.Parse(t.val, NumberStyles.Float); .)
- |
- hex (. string hx = t.val.Remove(0,2);
- try { r = signum * Convert.ToDecimal(Convert.ToInt64(hx, 16)); }
- catch { r = 0; }
- .)
- |
- binary (. string bx = t.val.Remove(t.val.Length - 1);
- try { r = signum * Convert.ToDecimal(Convert.ToInt64(bx, 2)); }
- catch { r = 0; }
- .)
- |
- '(' Expression ')'
- (. r = signum * r; .)
- )
-.
-
-ArrayL
-=
- (. List list = new List(); decimal r = 0; d = new decimal[0]; .)
- '['
- Expression (. list.Add(r); d = list.ToArray(); .)
- { ',' Expression (. list.Add(r); d = list.ToArray(); .) }
- ']'
-.
-
-ArrayCall (. string ident = string.Empty; r = 0; decimal pos = 0; .)
-=
- identifier (. ident = t.val; .)
- '['
- Expression
- (.
- try
- {
- int i = Convert.ToInt32(pos);
- decimal[] values;
- if (this.interpreter.TryGetNumericArray(ident, out values))
- {
- if (i >= 0 && i < values.Length) { r = values[i]; }
- else { SemErr("array index out of range"); r = 0; }
- }
- else
- {
- SemErr("variable '" + ident + "' is not a numeric array");
- r = 0;
- }
- }
- catch { SemErr("invalid array index"); r = 0; }
- .)
- ']'
-.
-
-Assignment
- (. string identifier = string.Empty; string expression = string.Empty; decimal[] d = new decimal[0]; r = 0; .)
-=
- identifier (. identifier = t.val; .)
- (
- (
- "::"
- Expression
- (. this.interpreter.AssignNumeric(identifier, r); .)
- )
- |
- (
- ":="
- AnyExpression
- (. this.interpreter.AssignExpression(identifier, expression); r = 0; .)
- )
- |
- (
- "->"
- ArrayL
- (. this.interpreter.AssignNumericArray(identifier, d); r = 0; .)
- )
- )
-.
-
-// Function call with mixed arguments (numeric expressions and strings)
-Function
- (. string functionName = string.Empty; FunctionArgument[] args = new FunctionArgument[0]; r = new FunctionValue(); .)
-=
- identifier (. functionName = t.val; .)
- '('
- ArgList
- ')'
- (. r = this.interpreter.ExecuteFunction(functionName, args); .)
-.
-
-ArgList
- (. List list = new List(); FunctionArgument a = new FunctionArgument(string.Empty, new FunctionValue()); args = new FunctionArgument[0]; .)
-=
- [
- Arg (. list.Add(a); args = list.ToArray(); .)
- { ',' Arg (. list.Add(a); args = list.ToArray(); .) }
- ]
-.
-
-Arg
- (. arg = new FunctionArgument(string.Empty, new FunctionValue()); decimal r = 0; string s = string.Empty; .)
-=
- (
- string (. s = t.val.Substring(1, t.val.Length - 2); arg = new FunctionArgument(string.Empty, new FunctionValue(FunctionValueType.String, s)); .)
- |
- Expression (. arg = new FunctionArgument(string.Empty, new FunctionValue(FunctionValueType.Numeric, r)); .)
- )
-.
-
-Comparison