├── .gitignore ├── AutomataKey.snk ├── BUILD_NOTES.txt ├── Core.sln ├── Main.sln ├── Matches.playlist ├── README.md ├── license.md ├── packages ├── README.txt └── repositories.config └── src ├── Automata.Tests ├── Automata.Tests.csproj ├── AutomataCompilationTests.cs ├── AutomataKey.snk ├── BREXTests.cs ├── BVAlgebraTests.cs ├── CharSetSolverTests.cs ├── CharSetTests.cs ├── CodeGenTests.cs ├── ConditionalDerivativeTests.cs ├── ContextFreeGrammarTests.cs ├── CountingAutomatonTests.cs ├── CountingSetTests.cs ├── CsAlgebraTests.cs ├── DecisionTreeTests.cs ├── DeterminizationTests.cs ├── EditDistanceTest.cs ├── FiniteAutomataTests.cs ├── HashSetSolverTests.cs ├── LikePatternTests.cs ├── MinimizationTests.cs ├── MiscRegexConversionTests.cs ├── MiscStringOperationTests.cs ├── Properties │ └── AssemblyInfo.cs ├── RegexAutomatonTests.cs ├── RegexExtensionMethodTests.cs ├── RegexToSMTTests.cs ├── RexTests.cs ├── SCCTest.cs ├── SampleRegexes.cs ├── Samples │ ├── Simpl.txt │ ├── grammar-sql.txt │ ├── input.txt │ ├── input_tiny.txt │ ├── matcher_test_set.txt │ ├── regex_tiny.txt │ ├── regexes.txt │ └── regexesWithoutAnchors.txt ├── SequenceTests.cs ├── SerializationTests.cs ├── SpecialRegexTests.cs ├── StateDistinguisherTests.cs ├── SymbolicRegexTests.cs ├── ThreeAutomataTest.cs ├── UTF8EncodingTests.cs └── UtilitiesTests.cs ├── Automata.Z3.Tests ├── Automata.Z3.Tests.csproj ├── FiniteAutomataTests.cs ├── Properties │ └── AssemblyInfo.cs ├── RankedAlphabetTests.cs ├── STTests.cs ├── SampleRegexes.cs ├── TreeTransducerTests.cs ├── UnitTest1.cs ├── UnitTest2.cs └── packages.config ├── Automata.Z3 ├── Automata.Z3.csproj ├── AutomataKey.snk ├── BooleanAlgebraZ3.cs ├── Internal │ ├── DeclaredFuncDecls.cs │ ├── Escape.cs │ ├── LibraryProvider.cs │ ├── TermPrettyPrinter.cs │ ├── TreeInfo.cs │ └── Z3Solver.cs ├── Partition.cs ├── Properties │ └── AssemblyInfo.cs ├── RankedAlphabet.cs ├── TreeRule.cs ├── TreeTheory.cs ├── TreeTransducer.cs ├── ValueTerm.cs ├── Z3Provider.cs └── packages.config ├── Automata ├── Automata.csproj ├── AutomataException.cs ├── AutomataKey.snk ├── Automaton.cs ├── AutomatonSerializer.cs ├── BDD.cs ├── BDDAlgebra.cs ├── BREX.cs ├── BREXManager.cs ├── BV.cs ├── BasicCountingSet.cs ├── BigInt.cs ├── BooleanAlgebras │ ├── BV128Algebra.cs │ ├── BV64Algebra.cs │ ├── BVAlgebra.cs │ ├── CartesianAlgebra.cs │ ├── DisjointUnionAlgebra.cs │ ├── FiniteSetAlgebra.cs │ └── TrivialBooleanAlgebra.cs ├── CharSetSolver.cs ├── CharacterEncoding.cs ├── Chooser.cs ├── ConditionalDerivative.cs ├── ConsList.cs ├── CountingAutomaton.cs ├── CountingSetAutomaton.cs ├── CsAlgebra.cs ├── DirectedGraphs │ ├── DgmlWriter.cs │ └── DotWriter.cs ├── Generated │ ├── IgnoreCaseRelation.cs │ └── UnicodeCategoryRanges.cs ├── Grammars │ ├── ContextFreeGrammar.cs │ ├── GrammarParser.cs │ ├── GrammarSymbol.cs │ ├── Nonterminal.cs │ ├── Production.cs │ └── Terminal.cs ├── Interfaces │ ├── IAcceptor.cs │ ├── IAutomaton.cs │ ├── IBooleanAlgebra.cs │ ├── ICharAlgebra.cs │ ├── IContext.cs │ ├── ICounter.cs │ ├── ICountingSet.cs │ ├── IDeterministicFiniteTransducer.cs │ ├── ILibrary.cs │ ├── IMatcher.cs │ ├── INameProvider.cs │ ├── IPrettyPrinter.cs │ ├── IRegexConverter.cs │ ├── ISolver.cs │ ├── ITransducer.cs │ └── IValue.cs ├── Internal │ ├── AutomataAlgebra.cs │ ├── CharRangeSolver.cs │ ├── ComparablePair.cs │ ├── EditDistance.cs │ ├── ExtendedAction.cs │ ├── ExtendedAutomaton.cs │ ├── ExtendedMove.cs │ ├── GraphAlgorithms.cs │ ├── HashSetSolver.cs │ ├── IntSet.cs │ ├── IteBag.cs │ ├── Maybe.cs │ ├── PartitionRefinement.cs │ ├── PushdownAutomaton.cs │ ├── PushdownMove.cs │ ├── RegexToSMTConverter.cs │ ├── STbComposer.cs │ ├── STbSimplifier.cs │ ├── STbSimulator.cs │ ├── SpecialCharacters.cs │ ├── StateDistinguisher.cs │ ├── StringUtility.cs │ ├── ThreeAutomaton.cs │ ├── UnicodeCategoryTheory.cs │ ├── UnicodeCategoryTheoryProviders.cs │ └── UnionFindHopKarp.cs ├── IntervalSet.cs ├── MintermGenerator.cs ├── Move.cs ├── OUT.Gppg │ ├── LexLocationInFile.cs │ └── ShiftReduceParser.cs ├── OrderedSet.cs ├── PredicateTrie.cs ├── Properties │ └── AssemblyInfo.cs ├── RegexAutomaton │ ├── DecisionTree.cs │ └── RegexAutomaton.cs ├── RegexExtensionMethods.cs ├── RegexParser │ ├── RegexBoyerMoore.cs │ ├── RegexCharClass.cs │ ├── RegexCode.cs │ ├── RegexFCD.cs │ ├── RegexNode.cs │ ├── RegexParser.cs │ ├── RegexReplacement.cs │ ├── RegexTree.cs │ └── SR.cs ├── RegexToAutomatonBuilder.cs ├── RegexToAutomatonConverter.cs ├── Rex │ ├── RexEngine.cs │ └── RexSettings.cs ├── Rule.cs ├── SFA.cs ├── ST.cs ├── STBuilder.cs ├── STb.cs ├── STbFromRegexBuilder.cs ├── Sequence.cs ├── SymbolicRegexBuilder.cs ├── SymbolicRegexMatcher.cs ├── SymbolicRegexNode.cs ├── SymbolicRegexSampler.cs ├── Templates │ ├── AutomataTextTemplate.cs │ ├── AutomataTextTemplate.tt │ ├── AutomatonMovesTextTemplate.cs │ ├── AutomatonMovesTextTemplate.tt │ ├── AutomatonTextTemplate.cs │ └── AutomatonTextTemplate.tt ├── Utilities │ ├── AutomataCSharpCompiler.cs │ ├── CommandLineParser.cs │ ├── CppCodeGenerator.cs │ ├── HelperPredicates.cs │ ├── HighTimer.cs │ ├── IgnoreCaseRelationGenerator.cs │ ├── IgnoreCaseTransformer.cs │ ├── RegexToRangeAutomatonSerializer.cs │ ├── UTF8Encoding.cs │ ├── UnicodeCategoryRangesGenerator.cs │ └── VectorizedIndexOf.cs └── packages.config ├── Bek.Tests ├── AutomataKey.snk ├── Bek.Tests.csproj ├── Bek2Tests.cs ├── BexTests.cs ├── GeneratedCodeSamples │ ├── AST.cs │ ├── CssEncodeFlat.cs │ ├── DecodeDigitPairs.cs │ ├── GeneratedSamples.cs │ ├── HtmlDecodeA.cs │ ├── HtmlDecodeS.cs │ ├── HtmlEncode.cs │ ├── HtmlEncodeStrict.cs │ ├── HtmlEncode_B.cs │ ├── HtmlEncode_F.cs │ ├── ST.cs │ └── UTF8EncodeFlat.cs ├── MiscQueries.cs ├── Neq1Tests.cs ├── Properties │ └── AssemblyInfo.cs ├── STbTests.cs ├── Samples │ ├── Bek │ │ ├── Base64decode.bek │ │ ├── Base64encode.bek │ │ ├── BitsBug.bek │ │ ├── CssEncode.bek │ │ ├── CssEncode4.bek │ │ ├── CssEncode5.bek │ │ ├── DecodeDigitPairs.bek │ │ ├── HtmlDecode.bek │ │ ├── UTF8Decode.bek │ │ ├── UTF8Encode.bek │ │ ├── decode.bek │ │ ├── escapeBrackets.bek │ │ ├── escapeString.bek │ │ ├── identity.bek │ │ ├── test3.bek │ │ └── test3b.bek │ └── Bex │ │ ├── Base64Encode.bek │ │ ├── HtmlDecode.bek │ │ ├── a2b.bek │ │ ├── base16decode.bek │ │ ├── base16encode.bek │ │ └── encode_decode.bek ├── bek_master.html └── packages.config ├── Bek ├── App.config ├── AutomataKey.snk ├── Bek.csproj ├── Frontend │ ├── AST.cs │ ├── BekParser.cs │ ├── Meta.cs │ ├── ParserImpl │ │ ├── bek.g │ │ ├── bekLexer.cs │ │ ├── bekParser.cs │ │ └── generateBekParser.bat │ ├── Symtab.cs │ └── TreeOps │ │ ├── TagChecker.cs │ │ ├── Tags.cs │ │ ├── TreeInfo.cs │ │ ├── Visitors.cs │ │ └── Walkers.cs ├── Model │ ├── Converter.cs │ └── Converters │ │ ├── ABekProg.cs │ │ ├── AIterExpr.cs │ │ ├── AStrExpr.cs │ │ ├── AValueExpr.cs │ │ ├── IterInfo.cs │ │ └── Z3 │ │ ├── BekPgm2STb.cs │ │ ├── BekProg.cs │ │ ├── IterExpr.cs │ │ ├── IterExpr2STb.cs │ │ ├── StrExpr.cs │ │ └── ValueExpr.cs ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── Query │ ├── AST.cs │ ├── Meta.cs │ └── ParserImpl │ │ ├── generateQueryParser.bat │ │ ├── query.g │ │ ├── queryLexer.cs │ │ └── queryParser.cs └── packages.config ├── CounterAutomata ├── App.config ├── AutomataKey.snk ├── CA.cs ├── CounterAutomata.csproj ├── Program.cs ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── Experimentation ├── App.config ├── AutomataKey.snk ├── Experimentation.csproj ├── NFA │ ├── NFAUtil.cs │ ├── RandomNFAExperiment.cs │ ├── RegexExperiment.cs │ ├── TimbukNFAParser.cs │ └── VerificationNFAExperiment.cs ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── STA │ ├── FastExperiment.cs │ ├── GenerateTAs.cs │ ├── LargeAlphabetExperiment.cs │ ├── ParsingUtil.cs │ ├── RecognizerGenerator.cs │ ├── TestMinLoris.cs │ ├── TimbukExperiment.cs │ └── Util.cs └── packages.config ├── Experiments ├── App.config ├── Experiments.csproj ├── HtmlEncode │ └── Test.cs ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── Trie │ └── Test.cs └── packages.config ├── Fast.Tests ├── Fast.Tests.csproj ├── FastSamples │ ├── aaa.fast │ ├── apply.fast │ ├── bodytree.fast │ ├── complement.fast │ ├── compose.fast │ ├── compose1.fast │ ├── constants.fast │ ├── cycletree.fast │ ├── deforestation.fast │ ├── domain.fast │ ├── equivalence.fast │ ├── exforslides.fast │ ├── functions.fast │ ├── htmlSanitizer.fast │ ├── intersect.fast │ ├── lists.fast │ ├── minimization.fast │ ├── nondet.fast │ ├── nondetcs.fast │ ├── operators.fast │ ├── preimage.fast │ ├── recognizers.fast │ ├── restrict.fast │ ├── sample.fast │ ├── shiftchars.fast │ ├── trees.fast │ ├── typechecking.fast │ ├── union.fast │ └── witness.fast ├── FastTests.cs ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── Fast ├── AST.cs ├── AutomataKey.snk ├── CsharpGenerator.cs ├── Fast.csproj ├── FastAssertException.cs ├── FastException.cs ├── FastGen.cs ├── FastLog.cs ├── FastParseException.cs ├── FastPgmParser.cs ├── FastProvider.cs ├── Parser.cs ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── TransducersGenerator.cs ├── packages.config └── parser │ ├── fast.lex │ ├── fast.lex.cs │ ├── fast.y │ ├── fast.y.cs │ └── genparser.bat ├── MSO.Eval ├── App.config ├── GenRandomMSO.cs ├── LTLMSO.cs ├── LargeMinterm.cs ├── MSO.Eval.csproj ├── MSOPopl14.cs ├── Program.cs ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── MSO.Tests ├── MSO.Tests.csproj ├── MSOZ3Test.cs ├── MonaTests.cs ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── MSO ├── AutomataKey.snk ├── BasicAutomata.cs ├── Cons.cs ├── MSO.GetAutomaton.cs ├── MSO.SubstituteVariables.cs ├── MSO.cs ├── MSO.csproj ├── MSOAlgebra.cs ├── Mona │ ├── AST.cs │ ├── MapStack.cs │ ├── MonaParseException.cs │ ├── MonaParser.cs │ ├── Program.ToMSO.cs │ ├── genparser.bat │ ├── mona.lex │ ├── mona.lex.cs │ ├── mona.y │ └── mona.y.cs ├── Properties │ └── AssemblyInfo.cs ├── Variable.cs └── packages.config └── RegenerateUnicodeTables ├── App.config ├── AutomataKey.snk ├── Program.cs ├── Properties └── AssemblyInfo.cs └── RegenerateUnicodeTables.csproj /AutomataKey.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AutomataDotNet/Automata/0242132fdbe9687bea22b7144afa0784d7cd927b/AutomataKey.snk -------------------------------------------------------------------------------- /BUILD_NOTES.txt: -------------------------------------------------------------------------------- 1 | Automata.NET can be built using Visual Studio 2013 from Main.sln. 2 | Build.sln excludes the test projects. 3 | All compiled binaries, except for binaries for test projects, 4 | are placed in the top level bin folder. 5 | 6 | The main projects are: Automata, Automata.Z3, Fast, and Bek 7 | that are accompanied by corresponding unit test projects: 8 | Automata.Tests, Automata.Z3.Tests, Fast.Tests, and Bek.Tests 9 | 10 | All projects are configured to use .NET Framework Version 4.5. 11 | and require at least version 4.0 12 | (due to dependency on System.Numerics.BigInteger) 13 | 14 | The core Automata project (/src/Automata/Automata.csproj) 15 | can be built separately and has no dependencies. 16 | 17 | The Automata.Z3 project depends on Automata and Z3. 18 | Z3 version 4.3.2.0 x86 binary exists as the nuget project with id "z3x86win" 19 | Install nuget from: http://docs.nuget.org/consume/installing-nuget. 20 | When building the solution with Visual Studio 2013 or 2015 the 21 | nuget packages should be installed automatically in the packages folder. 22 | 23 | The Fast (Functional Abstraction of Symbolic Transductions) project 24 | depends on Automata, Automata.Z3, and Z3. 25 | Fast language uses a custom parser that is generated with 26 | Gardens Point Parser Generator version 1.5.0. 27 | The generated fast-parser is standalone, there is no runtime library dependency. 28 | The tool can be downloaded from http://gppg.codeplex.com/downloads/get/378045 29 | in order to regenerate the fast-parser if modifications are made 30 | to the /src/Fast/parser/fast.lex or /src/Fast/parser/fast.y files, 31 | see the file: /src/Fast/parser/genparser.bat for details. 32 | 33 | The Bek project depends on Automata, Automata.Z3, Z3, 34 | and Antlr34 runtime for the bek-parser and query-parser for bek. 35 | Antlr34 is a nuget package that is installed automatically with VS. 36 | The runtime library Antlr3.Runtime.dll of Antlr34 will be istalled in 37 | the folder /packages/Antlr34.3.4.19004.1/lib/. 38 | In order to regenerate the bek-parser or the query-parser if changes are made 39 | to the bek parser source file /src/Bek/Frontend/ParserImpl/bek.g or 40 | the query parser source file /src/Bek/Query/ParserImpl/query.g 41 | see /src/Bek/Frontend/ParserImpl/generateBekParser.bat 42 | and /src/Bek/Query/ParserImpl/generateQueryParser.bat 43 | The bat files assume Antlr34 has been installed in /packages/Antlr34.3.4.19004.1 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /Core.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Automata", "src\Automata\Automata.csproj", "{BC861E29-027D-4AC6-AB24-A7B0CD0FB5E8}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Automata.Tests", "src\Automata.Tests\Automata.Tests.csproj", "{D437274D-5BFD-42FD-BBE5-96C4C0FFBA05}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|x64 = Debug|x64 14 | Release|Any CPU = Release|Any CPU 15 | Release|x64 = Release|x64 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {BC861E29-027D-4AC6-AB24-A7B0CD0FB5E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {BC861E29-027D-4AC6-AB24-A7B0CD0FB5E8}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {BC861E29-027D-4AC6-AB24-A7B0CD0FB5E8}.Debug|x64.ActiveCfg = Debug|x64 21 | {BC861E29-027D-4AC6-AB24-A7B0CD0FB5E8}.Debug|x64.Build.0 = Debug|x64 22 | {BC861E29-027D-4AC6-AB24-A7B0CD0FB5E8}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {BC861E29-027D-4AC6-AB24-A7B0CD0FB5E8}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {BC861E29-027D-4AC6-AB24-A7B0CD0FB5E8}.Release|x64.ActiveCfg = Release|x64 25 | {BC861E29-027D-4AC6-AB24-A7B0CD0FB5E8}.Release|x64.Build.0 = Release|x64 26 | {D437274D-5BFD-42FD-BBE5-96C4C0FFBA05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {D437274D-5BFD-42FD-BBE5-96C4C0FFBA05}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {D437274D-5BFD-42FD-BBE5-96C4C0FFBA05}.Debug|x64.ActiveCfg = Debug|Any CPU 29 | {D437274D-5BFD-42FD-BBE5-96C4C0FFBA05}.Debug|x64.Build.0 = Debug|Any CPU 30 | {D437274D-5BFD-42FD-BBE5-96C4C0FFBA05}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {D437274D-5BFD-42FD-BBE5-96C4C0FFBA05}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {D437274D-5BFD-42FD-BBE5-96C4C0FFBA05}.Release|x64.ActiveCfg = Release|Any CPU 33 | {D437274D-5BFD-42FD-BBE5-96C4C0FFBA05}.Release|x64.Build.0 = Release|Any CPU 34 | EndGlobalSection 35 | GlobalSection(SolutionProperties) = preSolution 36 | HideSolutionNode = FALSE 37 | EndGlobalSection 38 | EndGlobal 39 | -------------------------------------------------------------------------------- /Matches.playlist: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Automata 2 | Automata is a .NET library that provides algorithms for composing and analyzing _regular expressions_, _automata_, and _transducers_. In addition to classical word automata, it also includes algorithms for analysis of _tree automata_ and _tree transducers_. The library covers algorithms over finite alphabets as well as their _symbolic_ counterparts. In symbolic automata concrete characters have been replaced by _character predicates_. Such predicates can range over very large or even _infinite_ alphabets, like integers. Predicates can be supported by an SMT solver as a plugin. 3 | -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | Automata.NET 2 | 3 | Copyright (c) Microsoft Corporation All rights reserved. 4 | 5 | MIT License 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 | -------------------------------------------------------------------------------- /packages/README.txt: -------------------------------------------------------------------------------- 1 | all nuget packages are installed in this folder 2 | -------------------------------------------------------------------------------- /packages/repositories.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/Automata.Tests/AutomataKey.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AutomataDotNet/Automata/0242132fdbe9687bea22b7144afa0784d7cd927b/src/Automata.Tests/AutomataKey.snk -------------------------------------------------------------------------------- /src/Automata.Tests/EditDistanceTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; 6 | using Microsoft.Automata; 7 | 8 | namespace Microsoft.Automata.Tests 9 | { 10 | [TestClass] 11 | public class EditDistanceTest 12 | { 13 | [TestMethod] 14 | public void EDTest1() 15 | { 16 | CharSetSolver solver = new CharSetSolver(); 17 | string a = "aaaaaa"; 18 | 19 | var aut = solver.Convert("^(ab)*$").Determinize().Minimize(); 20 | 21 | int dist; 22 | var output = EditDistance.GetClosestElement(a, aut, solver, out dist); 23 | 24 | Console.WriteLine("string: {0}, distance: {1}", output, dist); 25 | Assert.IsTrue(dist == 3); 26 | 27 | output = EditDistance.GetClosestElement("aba", aut, solver, out dist); 28 | Console.WriteLine("string: {0}, distance: {1}", output, dist); 29 | Assert.IsTrue(dist == 1); 30 | } 31 | 32 | [TestMethod] 33 | public void EDTest2() 34 | { 35 | CharSetSolver solver = new CharSetSolver(); 36 | string a = "aa"; 37 | 38 | var aut = solver.Convert("^(a|b){3}$").Determinize().Minimize(); 39 | 40 | int dist; 41 | var output = EditDistance.GetClosestElement(a, aut, solver, out dist); 42 | 43 | Console.WriteLine("string: {0}, distance: {1}", output, dist); 44 | Assert.IsTrue(dist == 1); 45 | 46 | output = EditDistance.GetClosestElement("bc", aut, solver, out dist); 47 | Console.WriteLine("string: {0}, distance: {1}", output, dist); 48 | Assert.IsTrue(dist == 2); 49 | } 50 | 51 | [TestMethod] 52 | public void EDTestNew() 53 | { 54 | CharSetSolver solver = new CharSetSolver(); 55 | string a = "absabaasd"; 56 | 57 | var aut = solver.Convert("^((ab|b){1,2}cc)*$").Determinize().Minimize(); 58 | 59 | int dist; 60 | var output = EditDistance.GetClosestElement(a, aut, solver, out dist); 61 | 62 | Console.WriteLine("string: {0}, distance: {1}", output, dist); 63 | Assert.IsTrue(dist == 5); 64 | 65 | output = EditDistance.GetClosestElement("aba", aut, solver, out dist); 66 | Console.WriteLine("string: {0}, distance: {1}", output, dist); 67 | Assert.IsTrue(dist == 2); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Automata.Tests/LikePatternTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using Microsoft.Automata; 4 | 5 | namespace Microsoft.Automata.Tests 6 | { 7 | [TestClass] 8 | public class LikePatternTests 9 | { 10 | [TestMethod] 11 | public void TestSampleLikeExpressions() 12 | { 13 | TestCorrectnessOfLike("a","^a$"); 14 | TestCorrectnessOfLike("%a", "a$"); 15 | TestCorrectnessOfLike("a%", "^a"); 16 | TestCorrectnessOfLike("a%b", "^a.*b$"); 17 | TestCorrectnessOfLike("%", ".*"); 18 | TestCorrectnessOfLike("%", ""); 19 | TestCorrectnessOfLike("[a-z]", "^[a-z]$"); 20 | TestCorrectnessOfLike("____", "^.{4}$"); 21 | TestCorrectnessOfLike("a_b_c", "^a.b.c$"); 22 | } 23 | 24 | private static void TestCorrectnessOfLike(string like, string regex) 25 | { 26 | BREXManager bm = new BREXManager(); 27 | var a = bm.MkLike(like); 28 | var A = a.Optimize(); 29 | var b = bm.MkRegex(regex, System.Text.RegularExpressions.RegexOptions.Singleline); 30 | var B = b.Optimize(); 31 | var eq = A.IsEquivalentWith(B); 32 | Assert.IsTrue(eq); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Automata.Tests/MinimizationTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Collections.Generic; 4 | using Microsoft.VisualStudio.TestTools.UnitTesting; 5 | using System.IO; 6 | 7 | using Microsoft.Automata; 8 | 9 | using System.Text.RegularExpressions; 10 | 11 | 12 | namespace Automata.Tests 13 | { 14 | [TestClass] 15 | public class MinimizationTests 16 | { 17 | [TestMethod] 18 | public void TestNFA1() 19 | { 20 | CharSetSolver solver = new CharSetSolver(BitWidth.BV7); 21 | var nfa = Automaton.Create(solver, 0, new int[] { 1 }, new Move[] { new Move(0, 1, solver.True), new Move(0, 2, solver.True), new Move(2, 1, solver.True) }); 22 | var min_nfa = nfa.Minimize(); 23 | nfa.isDeterministic = true; //pretend that nfa is equivalent, causes the deterministic version to be executed that provides the wrong result 24 | var min_nfa_wrong = nfa.Minimize(); 25 | nfa.isDeterministic = false; 26 | min_nfa_wrong.isDeterministic = false; 27 | Assert.IsFalse(min_nfa.IsEquivalentWith(min_nfa_wrong)); 28 | Assert.IsTrue(min_nfa.IsEquivalentWith(nfa)); 29 | } 30 | 31 | [TestMethod] 32 | public void TestNFA2() 33 | { 34 | CharSetSolver solver = new CharSetSolver(BitWidth.BV7); 35 | var a = solver.MkCharConstraint('a'); 36 | var na = solver.MkNot(a); 37 | var nfa = Automaton.Create(solver, 0, new int[] { 1 }, new Move[] { new Move(0, 1, solver.True), new Move(0, 2, solver.True), new Move(2, 1, solver.True), new Move(1, 1, a), new Move(1, 2, na) }); 38 | var min_nfa = nfa.Minimize(); 39 | nfa.isDeterministic = true; //pretend that nfa is equivalent, causes the deterministic version to be executed that provides the wrong result 40 | var min_nfa_wrong = nfa.Minimize(); 41 | nfa.isDeterministic = false; 42 | min_nfa_wrong.isDeterministic = false; 43 | //min_nfa.ShowGraph("min_nfa"); 44 | //min_nfa_wrong.ShowGraph("min_nfa_wrong"); 45 | //min_nfa.Determinize().Minimize().ShowGraph("min_nfa1"); 46 | //nfa.Determinize().Minimize().ShowGraph("dfa"); 47 | //nfa.ShowGraph("nfa"); 48 | //min_nfa_wrong.Determinize().Minimize().ShowGraph("min_nfa2"); 49 | Assert.IsFalse(min_nfa.IsEquivalentWith(min_nfa_wrong)); 50 | Assert.IsTrue(min_nfa.IsEquivalentWith(nfa)); 51 | //concrete witness "abab" distinguishes nfa from min_nfa_wrong 52 | Assert.IsTrue(solver.Convert("^abab$").Intersect(nfa).IsEmpty); 53 | Assert.IsFalse(solver.Convert("^abab$").Intersect(min_nfa_wrong).IsEmpty); 54 | 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Automata.Tests/MiscStringOperationTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using System.Threading; 4 | using System.Globalization; 5 | 6 | namespace Automata.Tests 7 | { 8 | [TestClass] 9 | public class MiscStringOperationTests 10 | { 11 | [TestMethod] 12 | public void TestCultureVariance() 13 | { 14 | Assert.IsTrue("ss".StartsWith("ß", false, CultureInfo.InvariantCulture)); 15 | Assert.IsFalse("ss".StartsWith("ß", StringComparison.Ordinal)); 16 | Assert.IsTrue("ss".StartsWith("ß", false, CultureInfo.CreateSpecificCulture("se"))); 17 | Assert.IsFalse("æ".EndsWith("ae", false, CultureInfo.CreateSpecificCulture("se"))); 18 | Assert.IsTrue("æ".EndsWith("ae", false, CultureInfo.InvariantCulture)); 19 | 20 | var ci = Thread.CurrentThread.CurrentCulture; 21 | Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("se"); 22 | Assert.IsFalse("æ".EndsWith("ae")); 23 | Assert.AreEqual(-1, "æ".IndexOf("ae")); 24 | Thread.CurrentThread.CurrentCulture = ci; 25 | Assert.IsTrue("æ".EndsWith("ae")); 26 | Assert.AreEqual(0, "æ".IndexOf("ae")); 27 | 28 | Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("tr"); 29 | string indigo_tr = "indigo".ToUpper(); 30 | string indigo_tr1 = "indigo".ToUpper(CultureInfo.InvariantCulture); 31 | Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; 32 | string indigo = "indigo".ToUpper(); 33 | Assert.IsFalse(indigo_tr == indigo); 34 | Assert.IsTrue(indigo_tr1 == indigo); 35 | var s = "ß"; 36 | var ss = "ss"; 37 | var SS = "SS"; 38 | Assert.IsTrue(char.IsLower('ß')); 39 | Assert.IsFalse(char.IsUpper('ß')); 40 | Assert.IsTrue(s.StartsWith(ss)); 41 | Assert.IsFalse(s.ToUpper().StartsWith(ss.ToUpper())); 42 | Assert.IsTrue(ss.StartsWith(s)); 43 | Assert.IsFalse(ss.ToUpper().StartsWith(s.ToUpper())); 44 | Assert.IsTrue(ss.ToUpper().StartsWith(SS)); 45 | Assert.IsTrue(s.ToUpper().StartsWith(s)); 46 | var ae = "ae"; 47 | var AE = "AE"; 48 | var A = "Æ"; 49 | var a = "æ"; 50 | Assert.IsTrue(a.ToUpper().StartsWith(A)); 51 | Assert.IsTrue(A.ToLower().StartsWith(a)); 52 | Assert.IsTrue(ae.ToUpper().StartsWith(AE)); 53 | Assert.IsTrue(AE.ToLower().StartsWith(ae)); 54 | Assert.IsTrue(A.ToLower().StartsWith(ae)); 55 | Assert.IsTrue(a.ToUpper().StartsWith(AE)); 56 | Assert.IsFalse(a.ToUpper().StartsWith(AE, StringComparison.Ordinal)); 57 | 58 | Thread.CurrentThread.CurrentCulture = ci; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Automata.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Automata.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Automata.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("2731efec-1529-4f37-8259-8646b08bc8c0")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/Automata.Tests/RegexAutomatonTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Collections.Generic; 4 | using Microsoft.VisualStudio.TestTools.UnitTesting; 5 | 6 | using Microsoft.Automata; 7 | using Microsoft.Automata.BooleanAlgebras; 8 | using System.Text.RegularExpressions; 9 | 10 | namespace Microsoft.Automata.Tests 11 | { 12 | [TestClass] 13 | public class RegexAutomatonTests 14 | { 15 | //[TestMethod] 16 | //public void TestSimpleRegexAutomaton() 17 | //{ 18 | // var regex = new Regex("^a[bB]c$", RegexOptions.Singleline); 19 | // var aut = regex.Compile2(); 20 | // Assert.IsTrue(aut.IsMatch("aBc")); 21 | // Assert.IsTrue(aut.IsMatch("abc")); 22 | // Assert.IsFalse(aut.IsMatch("abC")); 23 | // Assert.IsTrue(aut.SymbolCount == 4); 24 | // Assert.IsTrue(aut.StateCount == 5); 25 | // Assert.IsTrue(aut.FinalSinkState == -1); 26 | // Assert.IsTrue(aut.NonfinalSinkState != -1); 27 | //} 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Automata.Tests/SCCTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; 6 | using Microsoft.Automata; 7 | 8 | namespace Microsoft.Automata.Tests 9 | { 10 | [TestClass] 11 | public class SCCTest 12 | { 13 | [TestMethod] 14 | public void SCCTest1() 15 | { 16 | CharSetSolver solver = new CharSetSolver(); 17 | 18 | var aut = solver.Convert("^a(ab)*$").Determinize().Minimize(); 19 | 20 | var sccs = GraphAlgorithms.GetStronglyConnectedComponents(aut); 21 | List total = new List(); 22 | foreach (var scc in sccs) 23 | { 24 | Console.WriteLine(); 25 | foreach (var st in scc) 26 | { 27 | total.Add(st); 28 | Console.Write(st + ","); 29 | } 30 | } 31 | 32 | Assert.IsTrue(sccs.ToArray().Length == 2); 33 | Assert.IsTrue(total.Count == aut.StateCount); 34 | } 35 | 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Automata.Tests/SampleRegexes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Microsoft.Automata.Tests 8 | { 9 | public static class SampleRegexes 10 | { 11 | public static string[] regexes = new string[] { 12 | @"^\$?(\d{1,3},?(\d{3},?)*\d{3}(\.\d{0,2})?|\d{1,3}(\.\d{0,2})?|\.(\d{1,2})?)\z", 13 | @"^\w+((\-|\+|\.)\w+)*@\w+((\-|\.)\w+)*\.\w+((\-|\.)\w+)*((,|;)\s*\w+((\-|\+|\.)\w+)*@\w+((\-|\.)\w+)*\.\w+((\-|\.)\w+)*)*\z", 14 | @"^([A-Z]{2}|[a-z]{2} \d{2} [A-Z]{1,2}|[a-z]{1,2} \d{1,4})?([A-Z]{3}|[a-z]{3} \d{1,4})?\z", 15 | @"^([A-Z]|[a-z]|[0-9])(((\.|\-)?([A-Z]|[a-z]|[0-9])+)*)@(([A-Z]|[a-z]|[0-9])+)(((\.|\-)?([A-Z]|[a-z]|[0-9])+)*)\. (([A-Z]|[a-z])([A-Z]|[a-z])+)\z", 16 | @"^(\w|\-)+@((\w|\-)+\.)+(\w|\-)+\z", 17 | @"^(\+|\-)?([0-9]*\.?[0-9]+|[0-9]+\.?[0-9]*)((e|E)(\+|\-)?[0-9]+)?\z", 18 | @"^((([A-Z]|[a-z]|[0-9])+[ ]+)|(([A-Z]|[a-z]|[0-9])+\-+)|(([A-Z]|[a-z]|[0-9])+\.+)|(([A-Z]|[a-z]|[0-9])+\++))*([A-Z]|[a-z]|[0-9])+@((\w+\-+)|(\w+\.))*\w{1,63}\.([A-Z]|[a-z]){2,6}\z", 19 | @"^((([A-Z]|[a-z]|[0-9]|\-|\.)+)@(([A-Z]|[a-z]|[0-9]|\-|\.)+)\.(([A-Z]|[a-z]){2,5}){1,25})+(((([A-Z]|[a-z]|[0-9]|\-|\.)+)@(([A-Z]|[a-z]|[0-9]|\-|\.)+)\.(([A-Z]|[a-z]){2,5}){1,25})+)*\z", 20 | @"^((\w+((\-|\+|\.)\w+)*@\w+((\-|\.)\w+)*\.\w+((\-|\.)\w+)*)\s*[,]{0,1}\s*)+\z", 21 | @"^((\w|\d|\-|\.)+)@{1}(((\w|\d|\-){1,67})|((\w|\d|\-)+\.(\w|\d|\-){1,67}))\.((([a-z]|[A-Z]|\d){2,4})(\.([a-z]|A|Z|\d){2})?)\z" 22 | }; 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Automata.Tests/Samples/input.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AutomataDotNet/Automata/0242132fdbe9687bea22b7144afa0784d7cd927b/src/Automata.Tests/Samples/input.txt -------------------------------------------------------------------------------- /src/Automata.Tests/Samples/input_tiny.txt: -------------------------------------------------------------------------------- 1 | aaaaaaaaaxy00000xy0000bbbbbbbbbbbxy111111xcccccccccccc -------------------------------------------------------------------------------- /src/Automata.Tests/Samples/regex_tiny.txt: -------------------------------------------------------------------------------- 1 | xy[0-9]+ -------------------------------------------------------------------------------- /src/Automata.Z3.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Automata.Z3.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Automata.Z3.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("2e25a34b-3b6e-4c7d-8d23-2518275a939d")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/Automata.Z3.Tests/SampleRegexes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Microsoft.Automata.Z3.Tests 8 | { 9 | internal static class SampleRegexes 10 | { 11 | internal static string[] regexes = new string[] { 12 | @"^\w+((\-|\+|\.)\w+)*@\w+((\-|\.)\w+)*\.\w+((\-|\.)\w+)*((,|;)\s*\w+((\-|\+|\.)\w+)*@\w+((\-|\.)\w+)*\.\w+((\-|\.)\w+)*)*\z", 13 | @"^\$?(\d{1,3},?(\d{3},?)*\d{3}(\.\d{0,2})?|\d{1,3}(\.\d{0,2})?|\.(\d{1,2})?)\z", 14 | @"^([A-Z]{2}|[a-z]{2} \d{2} [A-Z]{1,2}|[a-z]{1,2} \d{1,4})?([A-Z]{3}|[a-z]{3} \d{1,4})?\z", 15 | @"^([A-Z]|[a-z]|[0-9])(((\.|\-)?([A-Z]|[a-z]|[0-9])+)*)@(([A-Z]|[a-z]|[0-9])+)(((\.|\-)?([A-Z]|[a-z]|[0-9])+)*)\. (([A-Z]|[a-z])([A-Z]|[a-z])+)\z", 16 | @"^(\w|\-)+@((\w|\-)+\.)+(\w|\-)+\z", 17 | @"^(\+|\-)?([0-9]*\.?[0-9]+|[0-9]+\.?[0-9]*)((e|E)(\+|\-)?[0-9]+)?\z", 18 | @"^((\w|\d|\-|\.)+)@{1}(((\w|\d|\-){1,67})|((\w|\d|\-)+\.(\w|\d|\-){1,67}))\.((([a-z]|[A-Z]|\d){2,4})(\.([a-z]|A|Z|\d){2})?)\z", 19 | @"^((([A-Z]|[a-z]|[0-9])+[ ]+)|(([A-Z]|[a-z]|[0-9])+\-+)|(([A-Z]|[a-z]|[0-9])+\.+)|(([A-Z]|[a-z]|[0-9])+\++))*([A-Z]|[a-z]|[0-9])+@((\w+\-+)|(\w+\.))*\w{1,63}\.([A-Z]|[a-z]){2,6}\z", 20 | @"^((([A-Z]|[a-z]|[0-9]|\-|\.)+)@(([A-Z]|[a-z]|[0-9]|\-|\.)+)\.(([A-Z]|[a-z]){2,5}){1,25})+(((([A-Z]|[a-z]|[0-9]|\-|\.)+)@(([A-Z]|[a-z]|[0-9]|\-|\.)+)\.(([A-Z]|[a-z]){2,5}){1,25})+)*\z", 21 | @"^((\w+((\-|\+|\.)\w+)*@\w+((\-|\.)\w+)*\.\w+((\-|\.)\w+)*)\s*[,]{0,1}\s*)+\z" 22 | }; 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Automata.Z3.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/Automata.Z3/AutomataKey.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AutomataDotNet/Automata/0242132fdbe9687bea22b7144afa0784d7cd927b/src/Automata.Z3/AutomataKey.snk -------------------------------------------------------------------------------- /src/Automata.Z3/Internal/DeclaredFuncDecls.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Microsoft.Z3; 5 | 6 | using Microsoft.Automata; 7 | 8 | namespace Microsoft.Automata.Z3.Internal 9 | { 10 | 11 | internal class DeclaredFuncDecls 12 | { 13 | Dictionary, FuncDecl> funcDecls = new Dictionary, FuncDecl>(); 14 | 15 | internal DeclaredFuncDecls() 16 | { 17 | } 18 | 19 | internal bool TryGetFuncDecl(out FuncDecl funcDecl, string name, params object[] keys) 20 | { 21 | object[] objs = new object[keys.Length + 1]; 22 | objs[0] = name; 23 | Array.Copy(keys, 0, objs, 1, keys.Length); 24 | Sequence s = new Sequence(objs); 25 | 26 | if (funcDecls.TryGetValue(s, out funcDecl)) 27 | return true; 28 | 29 | funcDecl = null; 30 | return false; 31 | } 32 | 33 | internal void AddFuncDecl(FuncDecl funcDecl, string name, params object[] keys) 34 | { 35 | object[] objs = new object[keys.Length + 1]; 36 | objs[0] = name; 37 | Array.Copy(keys, 0, objs, 1, keys.Length); 38 | var s = new Sequence(objs); 39 | funcDecls.Add(new Sequence(objs), funcDecl); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Automata.Z3/Internal/Escape.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Microsoft.Automata.Z3.Internal 7 | { 8 | internal class Escaper 9 | { 10 | #region Escaping strings 11 | /// 12 | /// Make an escaped string from a character 13 | /// 14 | public static string Escape(char c) 15 | { 16 | int code = (int)c; 17 | 18 | if (code > 126) 19 | return ToUnicodeRepr(code); 20 | 21 | if (code <= 32) 22 | return string.Format("\\x{0:X}", code); 23 | 24 | switch (c) 25 | { 26 | case '\\': 27 | return "\\\\"; 28 | case '\0': 29 | return @"\0"; 30 | case '\a': 31 | return @"\a"; 32 | case '\b': 33 | return @"\b"; 34 | case '\t': 35 | return @"\t"; 36 | case '\r': 37 | return @"\r"; 38 | case '\v': 39 | return @"\v"; 40 | case '\f': 41 | return @"\f"; 42 | case '\n': 43 | return @"\n"; 44 | case '\u001B': 45 | return @"\e"; 46 | case '\"': 47 | return "\\\""; 48 | case '\'': 49 | return "\\\'"; 50 | case ' ': 51 | return @"\s"; 52 | default: 53 | return c.ToString(); 54 | } 55 | } 56 | 57 | 58 | public static string EscapeHex(int n) 59 | { 60 | if (0 <= n && n <= 9) 61 | return n.ToString(); 62 | else 63 | return string.Format("0x{0:X}", n); 64 | } 65 | 66 | static string ToUnicodeRepr(int i) 67 | { 68 | string s = string.Format("{0:X}", i); 69 | if (s.Length == 1) 70 | s = "\\u000" + s; 71 | else if (s.Length == 2) 72 | s = "\\u00" + s; 73 | else if (s.Length == 3) 74 | s = "\\u0" + s; 75 | else 76 | s = "\\u" + s; 77 | return s; 78 | } 79 | 80 | /// 81 | /// Make an escaped string from a string 82 | /// 83 | public static string Escape(string s) 84 | { 85 | StringBuilder sb = new StringBuilder(); 86 | sb.Append("\""); 87 | foreach (char c in s) 88 | { 89 | sb.Append(Escape(c)); 90 | } 91 | sb.Append("\""); 92 | return sb.ToString(); 93 | } 94 | #endregion 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/Automata.Z3/Internal/TreeInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Microsoft.Z3; 5 | 6 | namespace Microsoft.Automata.Z3.Internal 7 | { 8 | /// 9 | /// Encapsulates the Z3 declarations related to the algebraic datatype of parse trees 10 | /// 11 | internal class UnrankedTreeInfo 12 | { 13 | public readonly Sort TreeListSort; 14 | public readonly FuncDecl GetNodeLabel, GetNodeSubtrees, MkNode, MkLeaf, GetLeafValue, IsNode, IsLeaf; 15 | public readonly Expr EmptyTreeList; 16 | public readonly FuncDecl GetFirst, GetRest, MkCons, IsEmpty, IsCons; 17 | 18 | public UnrankedTreeInfo(Sort treeListSort, FuncDecl getNodeValue, FuncDecl getSubtrees, FuncDecl mkNode, 19 | FuncDecl mkLeaf, FuncDecl getLeafValue, FuncDecl isNode, FuncDecl isLeaf, 20 | Expr empty, FuncDecl first, FuncDecl rest, 21 | FuncDecl cons, FuncDecl isEmpty, FuncDecl isCons) 22 | { 23 | this.TreeListSort = treeListSort; 24 | this.GetNodeLabel = getNodeValue; 25 | this.GetNodeSubtrees = getSubtrees; 26 | this.MkNode = mkNode; 27 | this.EmptyTreeList = empty; 28 | this.GetFirst = first; 29 | this.GetRest = rest; 30 | this.MkCons = cons; 31 | this.IsEmpty = isEmpty; 32 | this.IsCons = isCons; 33 | this.MkLeaf = mkLeaf; 34 | this.GetLeafValue = getLeafValue; 35 | this.IsNode = isNode; 36 | this.IsLeaf = isLeaf; 37 | } 38 | } 39 | 40 | /// 41 | /// Encapsulates the Z3 declarations related to the algebraic datatype of binary trees without node labels 42 | /// 43 | internal class BinaryTreeInfo 44 | { 45 | public readonly FuncDecl MkTree, MkLeaf, GetLeafValue, IsTree, IsLeaf; 46 | public readonly FuncDecl GetLeft, GetRight; 47 | 48 | public BinaryTreeInfo(FuncDecl mkTree, FuncDecl mkLeaf, 49 | FuncDecl getLeafValue, FuncDecl isTree, FuncDecl isLeaf, 50 | FuncDecl getLeft, FuncDecl getRight) 51 | { 52 | this.MkTree = mkTree; 53 | this.GetLeft = getLeft; 54 | this.GetRight = getRight; 55 | this.MkLeaf = mkLeaf; 56 | this.GetLeafValue = getLeafValue; 57 | this.IsTree = isTree; 58 | this.IsLeaf = isLeaf; 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/Automata.Z3/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Microsoft.Automata.Z3")] 9 | [assembly: AssemblyDescription("Symbolic Automata Analysis Framework Z3 Extension")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft Corporation")] 12 | [assembly: AssemblyProduct("Microsoft.Automata.Z3")] 13 | [assembly: AssemblyCopyright("Copyright (c) Microsoft Corporation. All rights reserved.")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("d8939f4e-137c-499c-9e43-2b90642299a2")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/Automata.Z3/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/Automata/AutomataKey.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AutomataDotNet/Automata/0242132fdbe9687bea22b7144afa0784d7cd927b/src/Automata/AutomataKey.snk -------------------------------------------------------------------------------- /src/Automata/AutomatonSerializer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Microsoft.Automata 4 | { 5 | /// 6 | /// Is used as a base class of automata classes that implement the IAutomaton interface 7 | /// and the INameProvider interface. 8 | /// 9 | public class AutomatonSerializer 10 | { 11 | IAutomaton __aut { get { return (IAutomaton)this; } } 12 | string __name { get { return ((INameProvider)this).Name; } } 13 | public AutomatonSerializer() 14 | { 15 | } 16 | 17 | /// 18 | /// Saves the automaton in .dgml file in the working directory 19 | /// and opens the file in a new process. 20 | /// 21 | public void ShowGraph() 22 | { 23 | Microsoft.Automata.DirectedGraphs.DgmlWriter.ShowGraph(-1, __aut, __name); 24 | } 25 | 26 | /// 27 | /// Saves the automaton in dgml format in .dgml file in the working directory. 28 | /// 29 | public void SaveAsDgml() 30 | { 31 | Microsoft.Automata.DirectedGraphs.DgmlWriter.AutomatonToDgml(-1, __aut, __name); 32 | } 33 | 34 | /// 35 | /// Saves the automaton in dot format in .dot file in the working directory. 36 | /// 37 | public void SaveAsDot() 38 | { 39 | Microsoft.Automata.DirectedGraphs.DotWriter.AutomatonToDot(__aut.DescribeLabel, __aut, __name, __name, DirectedGraphs.DotWriter.RANKDIR.LR, 12, true); 40 | } 41 | 42 | /// 43 | /// Saves the automaton in dot format in the given file in the working directory. 44 | /// 45 | public void SaveAsDot(string file) 46 | { 47 | Microsoft.Automata.DirectedGraphs.DotWriter.AutomatonToDot(__aut.DescribeLabel, __aut, __name, file, DirectedGraphs.DotWriter.RANKDIR.LR, 12, true); 48 | } 49 | 50 | /// 51 | /// Saves the automaton in dgml format in tw. 52 | /// 53 | public void SaveAsDgml(System.IO.TextWriter tw) 54 | { 55 | Microsoft.Automata.DirectedGraphs.DgmlWriter.AutomatonToDgml(-1,__aut,__name, tw); 56 | } 57 | 58 | /// 59 | /// Saves the automaton in dot format in tw. 60 | /// 61 | public void SaveAsDot(System.IO.TextWriter tw) 62 | { 63 | Microsoft.Automata.DirectedGraphs.DotWriter.AutomatonToDot(__aut.DescribeLabel, __aut, __name, tw, DirectedGraphs.DotWriter.RANKDIR.TB, 12, true); 64 | } 65 | 66 | public virtual void ShowGraph(int k) 67 | { 68 | Microsoft.Automata.DirectedGraphs.DgmlWriter.ShowGraph(k, __aut, __name); 69 | } 70 | 71 | public void SaveAsDgml(int k) 72 | { 73 | Microsoft.Automata.DirectedGraphs.DgmlWriter.AutomatonToDgml(k, __aut, __name); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/Automata/BigInt.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Microsoft.Automata 6 | { 7 | /// 8 | /// Nonnegative big integers with restricted functionality. 9 | /// Wraps System.Numerics.BigInteger. 10 | /// 11 | public class BigInt 12 | { 13 | internal static readonly BigInt Zero = new BigInt(System.Numerics.BigInteger.Zero); 14 | internal static readonly BigInt One = new BigInt(System.Numerics.BigInteger.One); 15 | 16 | internal static int NrOfDecimals = 10; //use 10 decimal precision in double 17 | static readonly System.Numerics.BigInteger K_bigint = System.Numerics.BigInteger.Parse("1000000000000"); 18 | static readonly double K_double = (double)System.Numerics.BigInteger.Parse("1000000000000"); 19 | 20 | /// 21 | /// Underlying BigInteger 22 | /// 23 | public System.Numerics.BigInteger biginteger { get; } 24 | 25 | BigInt(System.Numerics.BigInteger n) 26 | { 27 | biginteger = n; 28 | } 29 | 30 | internal BigInt(long m) 31 | { 32 | biginteger = new System.Numerics.BigInteger(m); 33 | } 34 | 35 | internal BigInt(ulong m) 36 | { 37 | biginteger = new System.Numerics.BigInteger((long)m); 38 | } 39 | 40 | internal BigInt Times(BigInt other) 41 | { 42 | return new BigInt(biginteger * other.biginteger); 43 | } 44 | 45 | internal BigInt Plus(BigInt other) 46 | { 47 | return new BigInt(biginteger + other.biginteger); 48 | } 49 | 50 | internal double DivideAsDouble(BigInt divider) 51 | { 52 | double d = (((double)((K_bigint * biginteger) / divider.biginteger)) / K_double); 53 | double d_rounded = Math.Round(d, NrOfDecimals); 54 | return d_rounded; 55 | } 56 | 57 | public override bool Equals(object obj) 58 | { 59 | BigInt b = obj as BigInt; 60 | if (obj == null) 61 | return false; 62 | return biginteger.Equals(b.biginteger); 63 | } 64 | 65 | public override int GetHashCode() 66 | { 67 | return biginteger.GetHashCode(); 68 | } 69 | 70 | public override string ToString() 71 | { 72 | return biginteger.ToString(); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/Automata/CharacterEncoding.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Microsoft.Automata 6 | { 7 | /// 8 | /// Number of bits used in bitvectors. 9 | /// 10 | public enum BitWidth 11 | { 12 | /// 13 | /// 7 bit ASCII encoding 14 | /// 15 | BV7 = 7, 16 | /// 17 | /// 8 bit Extended ASCII encoding 18 | /// 19 | BV8 = 8, 20 | /// 21 | /// 16 bit bit-vector encoding 22 | /// 23 | BV16 = 16, 24 | /// 25 | /// 32 bit bit-vector encoding 26 | /// 27 | BV32 = 32, 28 | ///// 29 | ///// 64 bit bit-vector encoding 30 | ///// 31 | BV64 = 64 32 | } 33 | 34 | /// 35 | /// Provides functionality for character encodings. 36 | /// 37 | public static class CharacterEncodingTool 38 | { 39 | /// 40 | /// Maps ASCII to 7, extended ASCII to 8, and other encodings to 16. 41 | /// Throws AutomataException if IsSpecified(encoding) is false. 42 | /// 43 | /// 44 | /// either 7, 8, or 16 45 | public static int Truncate(BitWidth encoding) 46 | { 47 | switch (encoding) 48 | { 49 | case BitWidth.BV7: return 7; 50 | case BitWidth.BV8: return 8; 51 | case BitWidth.BV16: return 16; 52 | case BitWidth.BV32: return 16; 53 | case BitWidth.BV64: return 16; 54 | default: 55 | throw new AutomataException(AutomataExceptionKind.CharacterEncodingIsUnspecified); 56 | } 57 | } 58 | 59 | /// 60 | /// Returns true iff encoding equals to one of the enums in CharacterEncoding. 61 | /// 62 | public static bool IsSpecified(BitWidth encoding) 63 | { 64 | return (encoding == BitWidth.BV7 || 65 | encoding == BitWidth.BV32 || 66 | encoding == BitWidth.BV8 || 67 | encoding == BitWidth.BV64 || 68 | encoding == BitWidth.BV16); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Automata/Grammars/GrammarSymbol.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | 4 | namespace Microsoft.Automata.Grammars 5 | { 6 | public abstract class GrammarSymbol 7 | { 8 | public abstract string Name { get; } 9 | 10 | public override string ToString() 11 | { 12 | return Name; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Automata/Grammars/Terminal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Microsoft.Automata.Grammars 4 | { 5 | /// 6 | /// terminal symbol 7 | /// 8 | public class Terminal : GrammarSymbol 9 | { 10 | /// 11 | /// the term 12 | /// 13 | public T term; 14 | 15 | /// 16 | /// constructs a terminal 17 | /// 18 | /// given term 19 | /// given name 20 | public Terminal(T term) 21 | { 22 | this.term = term; 23 | } 24 | 25 | string __name = null; 26 | /// 27 | /// name of the terminal 28 | /// 29 | public override string Name 30 | { 31 | get 32 | { 33 | if (__name == null) 34 | { 35 | string s = term.ToString(); 36 | if (s.Length > 0) 37 | { 38 | char first = s[0]; 39 | if (('A' <= first && first <= 'Z') || first == Nonterminal.ReservedNonterminalStart) 40 | __name = "(" + s + ")"; 41 | else 42 | __name = s; 43 | } 44 | else 45 | __name = ""; 46 | } 47 | return __name; 48 | } 49 | } 50 | 51 | /// 52 | public override string ToString() 53 | { 54 | return Name; 55 | } 56 | 57 | public override bool Equals(object obj) 58 | { 59 | var t = obj as Terminal; 60 | if (t == null) 61 | return false; 62 | return t.term.Equals(this.term); 63 | } 64 | 65 | public override int GetHashCode() 66 | { 67 | return term.GetHashCode(); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Automata/Interfaces/IAcceptor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Microsoft.Automata 4 | { 5 | /// 6 | /// Methods for asserting the axiomatic theory and accessing the language acceptor of an SFA or the transduction acceptor of an ST. 7 | /// 8 | /// function declarations, each function declaration has domain and range sorts 9 | /// terms, each term has a fixed sort 10 | /// sorts correspond to different subuniverses of elements 11 | public interface IAcceptor 12 | { 13 | /// 14 | /// The given SMT solver. 15 | /// 16 | IContext Solver { get; } 17 | 18 | /// 19 | /// Assert the theory as an auxiliary background theory to the given SMT solver 20 | /// 21 | void AssertTheory(); 22 | 23 | /// 24 | /// Relation symbol of the language or transduction relation. 25 | /// 26 | FUNC Acceptor { get; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Automata/Interfaces/IAutomaton.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Microsoft.Automata 5 | { 6 | /// 7 | /// For accessing the key components of an automaton. 8 | /// 9 | /// type of labels in moves 10 | public interface IAutomaton : IMinimalAutomaton 11 | { 12 | /// 13 | /// Enumerates all moves of the automaton. 14 | /// 15 | IEnumerable> GetMoves(); 16 | 17 | /// 18 | /// Enumerates all states of the automaton. 19 | /// 20 | IEnumerable GetStates(); 21 | 22 | /// 23 | /// Provides a description of the state for visualization purposes. 24 | /// 25 | string DescribeState(int state); 26 | 27 | /// 28 | /// Provides a description of the label for visualization purposes. 29 | /// 30 | string DescribeLabel(L lab); 31 | 32 | /// 33 | /// Provides a description of the label for visualization purposes. 34 | /// 35 | string DescribeStartLabel(); 36 | } 37 | 38 | /// 39 | /// A minimal incremental subset of IAutomaton needed for certain operations 40 | /// 41 | /// 42 | public interface IMinimalAutomaton 43 | { 44 | /// 45 | /// The initial state of the automaton. 46 | /// 47 | int InitialState { get; } 48 | /// 49 | /// Gets the algebra of the labels. 50 | /// 51 | IBooleanAlgebra Algebra { get; } 52 | /// 53 | /// Returns true iff the state is a final state. 54 | /// 55 | bool IsFinalState(int state); 56 | /// 57 | /// Enumerates all moves of the automaton from the given start state. 58 | /// 59 | IEnumerable> GetMovesFrom(int state); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Automata/Interfaces/ICounter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Microsoft.Automata 8 | { 9 | public interface ICounter 10 | { 11 | int LowerBound { get; } 12 | int UpperBound { get; } 13 | int CounterId { get; } 14 | bool ContainsSubCounter(ICounter counter); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Automata/Interfaces/ICountingSet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Microsoft.Automata 8 | { 9 | /// 10 | /// A bounded set on integers that supports incrementing all elements adding 0 and 1. 11 | /// 12 | public interface ICountingSet 13 | { 14 | /// 15 | /// What the maximum value in the set is allowed to be. 16 | /// 17 | int UpperBound { get; } 18 | 19 | /// 20 | /// True iff the set is empty. 21 | /// 22 | bool IsEmpty { get; } 23 | 24 | /// 25 | /// True iff the set is a singleton set. 26 | /// 27 | bool IsSingleton { get; } 28 | 29 | /// 30 | /// Gets the minimum value in the set. Set must be nonempty. 31 | /// 32 | int Min { get; } 33 | 34 | /// 35 | /// Gets the maximum value in the set. Set must be nonempty. 36 | /// 37 | int Max { get; } 38 | 39 | /// 40 | /// Set the set to the value [0]. 41 | /// 42 | void Set0(); 43 | 44 | /// 45 | /// Set the set to the value [1]. 46 | /// 47 | void Set1(); 48 | 49 | /// 50 | /// Increment all values in the set. 51 | /// If Max becomes greater than UpperBound then remove it. 52 | /// 53 | void Incr(); 54 | 55 | /// 56 | /// Push 0 into the set. 57 | /// 58 | void Push0(); 59 | 60 | /// 61 | /// Empty the set. 62 | /// 63 | void Clear(); 64 | 65 | /// 66 | /// Increment all values in the set and push 0 into the set. 67 | /// If Max becomes greater than UpperBound then remove it. 68 | /// 69 | void IncrPush0(); 70 | 71 | /// 72 | /// Increment all values in the set and push 1 into the set. 73 | /// If Max becomes greater than UpperBound then remove it. 74 | /// 75 | void IncrPush1(); 76 | 77 | /// 78 | /// Increment all values in the set and push 0 and 1 into the set. 79 | /// If Max becomes greater than UpperBound then remove it. 80 | /// 81 | void IncrPush01(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/Automata/Interfaces/IDeterministicFiniteTransducer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Microsoft.Automata 7 | { 8 | /// 9 | /// Deterministic finite state transducer. 10 | /// 11 | public interface IDeterministicFiniteTransducer 12 | { 13 | /// 14 | /// All states. 15 | /// 16 | ICollection Q { get; } 17 | 18 | /// 19 | /// Initial state. 20 | /// 21 | int q0 { get; } 22 | 23 | /// 24 | /// All final states. 25 | /// 26 | ICollection F { get; } 27 | 28 | /// 29 | /// Alphabet. 30 | /// 31 | IEnumerable Sigma { get; } 32 | 33 | /// 34 | /// Transition function. Assumed to be a total function. 35 | /// 36 | /// source state 37 | /// input character (negative value means end of string) 38 | /// target state 39 | int Delta(int state, int c); 40 | 41 | /// 42 | /// Output function. Assumed to be a total function. 43 | /// 44 | /// source state 45 | /// input character (negative value means end of string) 46 | /// output sequence 47 | IEnumerable Psi(int state, int c); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Automata/Interfaces/ILibrary.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Microsoft.Automata 7 | { 8 | public interface ILibrary 9 | { 10 | void DefineFunction(string name, TERM body, params TERM[] vars); 11 | 12 | TERM ApplyFunction(string name, params TERM[] args); 13 | 14 | void GenerateCode(string language, StringBuilder sb); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Automata/Interfaces/INameProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Microsoft.Automata 4 | { 5 | /// 6 | /// Allows to get and set a name as a string. 7 | /// 8 | public interface INameProvider 9 | { 10 | /// 11 | /// Gets and sets a name. 12 | /// 13 | string Name { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Automata/Interfaces/IPrettyPrinter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Microsoft.Automata 4 | { 5 | /// 6 | /// Pretty printer for a given type. 7 | /// 8 | /// element type 9 | public interface IPrettyPrinter 10 | { 11 | /// 12 | /// Returns a string representation of the element t 13 | /// 14 | string PrettyPrint(T t); 15 | 16 | /// 17 | /// Returns a string representation of the element t, uses varLookup for custom variable name lookup. 18 | /// 19 | string PrettyPrint(T t, Func varLookup); 20 | 21 | /// 22 | /// Returns a string representation of the element t, uses varLookup for custom variable name lookup. 23 | /// Uses the form (cond ? t : f) instead of ite(cond,t,f) for printing ite-terms. 24 | /// 25 | string PrettyPrintCS(T t, Func varLookup); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Automata/Interfaces/ISolver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Microsoft.Automata 8 | { 9 | /// 10 | /// Solver interface. Created from IContext. 11 | /// 12 | public interface ISolver 13 | { 14 | /// 15 | /// Push a new logical context. 16 | /// 17 | void Push(); 18 | 19 | /// 20 | /// Pop the current logical context. 21 | /// 22 | void Pop(); 23 | 24 | /// 25 | /// All asserted constraints. 26 | /// 27 | TERM[] Assertions { get; } 28 | 29 | /// 30 | /// Number of asserted constraints. 31 | /// 32 | uint NumAssertions { get; } 33 | 34 | /// 35 | /// Check if the asserted constraints are satisfiable. 36 | /// 37 | bool Check(); 38 | 39 | /// 40 | /// Assert the formula in the solver. 41 | /// 42 | /// 43 | void Assert(TERM constraint); 44 | 45 | /// 46 | /// Check satisfiability of the constraint in the solver without changing the assertions. 47 | /// 48 | bool IsSatisfiable(TERM constraint); 49 | 50 | #region Model generation 51 | 52 | /// 53 | /// If the assertion is satisfiable, returns an interpretation of the terms to be evaluated. 54 | /// The returned dictionary is empty if no terms are listed for evaluation. 55 | /// The assertion may not contain free variables. 56 | /// Returns null iff the assertion is unsatisfiable. 57 | /// 58 | IDictionary> GetModel(TERM assertion, params TERM[] termsToEvaluate); 59 | 60 | /// 61 | /// Find all solutions of an open formula containing exactly one free variable. 62 | /// 63 | IEnumerable> FindAllMembers(TERM openFormula); 64 | 65 | /// 66 | /// Find one solution of an open formula containing exactly one free variable. 67 | /// 68 | /// formula containing exactly one free variable 69 | /// a value satisfying the formula or null if no value was found 70 | IValue FindOneMember(TERM openFormula); 71 | 72 | #endregion 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Automata/Interfaces/ITransducer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Microsoft.Automata 7 | { 8 | /// 9 | /// Extends the IAutomaton interface with transducer specific methods. 10 | /// 11 | public interface ITransducer : IAutomaton 12 | { 13 | /// 14 | /// Returns true iff the label is a final rule. 15 | /// 16 | bool IsFinalRule(RULE rule); 17 | 18 | /// 19 | /// Provides a description of the guard of the rule. 20 | /// 21 | string DescribeGuard(RULE rule); 22 | 23 | /// 24 | /// Returns true iff the guard of the rule is unconditionally true. 25 | /// 26 | bool IsGuardTrue(RULE rule); 27 | 28 | /// 29 | /// Returns the nr of yields of the rule. 30 | /// 31 | int GetYieldsLength(RULE rule); 32 | 33 | /// 34 | /// Provides a description of the yields of the rule. 35 | /// 36 | string DescribeYields(RULE rule); 37 | 38 | /// 39 | /// Provides a description of the update of the rule. 40 | /// 41 | string DescribeUpdate(RULE rule); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Automata/Interfaces/IValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Microsoft.Automata 5 | { 6 | /// 7 | /// Represents a concrete value 8 | /// 9 | public interface IValue 10 | { 11 | /// 12 | /// A ground term. 13 | /// 14 | TERM Value { get; } 15 | 16 | /// 17 | /// Returns true if Value represents a numeral and outputs the numeral in n. 18 | /// Returns false otherwise and sets n to 0. 19 | /// 20 | bool TryGetNumeralValue(out int n); 21 | 22 | /// 23 | /// If Value is a list whose elements are numerals return 24 | /// the corresponding string, otherwise return null. 25 | /// 26 | /// if true, extract numeric values above 65536 to proper UTF-16 code points, otherwise truncate them to single characters ignoring all bits in binary representation in positions 17 and higher 27 | string GetStringValue(bool unicode); 28 | 29 | /// 30 | /// If Value is a list whose elements are numerals gets 31 | /// GetStringValue(false), otherwise return null. 32 | /// 33 | string StringValue { get; } 34 | 35 | /// 36 | /// If the value is a list get the corresponding elements. 37 | /// 38 | List GetList(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Automata/Internal/ComparablePair.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.IO; 5 | 6 | namespace Microsoft.Automata 7 | { 8 | /// 9 | /// Pair of comparable elements 10 | /// 11 | internal class ComparablePair : Tuple, IComparable where S : IComparable where T : IComparable 12 | { 13 | public int CompareTo(object obj) 14 | { 15 | ComparablePair op = obj as ComparablePair; 16 | if (op == null) 17 | return -1; 18 | 19 | var k = Item1.CompareTo(op.Item1); 20 | if (k != 0) 21 | return k; 22 | else 23 | return Item2.CompareTo(op.Item2); 24 | } 25 | 26 | public ComparablePair(S first, T second) 27 | : base(first, second) 28 | { 29 | } 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /src/Automata/Internal/ExtendedAction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.IO; 5 | 6 | namespace Microsoft.Automata 7 | { 8 | /// 9 | /// Represents the action of a move of a Extended Symbolic Finite Transducer (ESFT). 10 | /// 11 | internal class ExtendedAction 12 | { 13 | internal TERM guard; 14 | internal TERM[] yields; 15 | internal int lookahead; 16 | 17 | /// 18 | /// Gets the guard of the rule. 19 | /// 20 | public TERM Guard 21 | { 22 | get { return guard; } 23 | } 24 | 25 | /// 26 | /// Gets the array of yielded outputs, that is the empty array if there are no outputs. 27 | /// 28 | public TERM[] Yields 29 | { 30 | get { return yields; } 31 | } 32 | 33 | /// 34 | /// Gets the lookahead size of the Guard 35 | /// 36 | public int Lookahead 37 | { 38 | get { return lookahead; } 39 | } 40 | 41 | /// 42 | /// Must not be used. 43 | /// 44 | ExtendedAction() { } 45 | 46 | /// 47 | /// Creates a new rule 48 | /// 49 | /// true iff the rule represents a final output 50 | /// predicate over input and registers, or registers only when the rule is a final output 51 | /// output elements yielded by the rule 52 | ExtendedAction(TERM guard, TERM[] yields) 53 | { 54 | this.guard = guard; 55 | this.yields = yields; 56 | } 57 | 58 | internal ExtendedAction(int lookahead, TERM guard, TERM[] yields) 59 | { 60 | this.guard = guard; 61 | this.yields = yields; 62 | this.lookahead = lookahead; 63 | } 64 | 65 | 66 | /// 67 | /// Creates a new rule representing a guarded register update. 68 | /// 69 | /// predicate over input and registers 70 | /// register update 71 | /// (possibly empty) array of output terms yielded by the rule 72 | static public ExtendedAction Mk(TERM guard, params TERM[] yields) 73 | { 74 | return new ExtendedAction(guard, yields); 75 | } 76 | 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Automata/Internal/GraphAlgorithms.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Microsoft.Automata 7 | { 8 | internal class GraphAlgorithms 9 | { 10 | /// 11 | /// Computes the strongly connected components of the automaton 12 | /// 13 | /// 14 | /// 15 | /// 16 | /// 17 | public static IEnumerable> GetStronglyConnectedComponents(Automaton automaton) 18 | { 19 | var output = new List>(); 20 | Tuple, List> dfs = Dfs(automaton.InitialState,automaton); 21 | List startTimes = dfs.Item1; 22 | List endTimes = dfs.Item2; 23 | endTimes.Reverse(); 24 | 25 | HashSet visited = new HashSet(); 26 | foreach(var v in endTimes){ 27 | if(!visited.Contains(v)){ 28 | var start = new List(); 29 | var end = new List(); 30 | Dfs(v,automaton,visited,start,end, true); 31 | var scc = new HashSet(start); 32 | foreach (var s in start) 33 | visited.Add(s); 34 | output.Add(scc); 35 | } 36 | } 37 | return output; 38 | } 39 | 40 | //Updates start times and end times 41 | static Tuple, List> Dfs(int startState, Automaton automaton, bool reverse=false) 42 | { 43 | List startTimes = new List(); 44 | List endTimes = new List(); 45 | Dfs(startState, automaton, new HashSet(), startTimes, endTimes,reverse); 46 | return new Tuple, List>(startTimes, endTimes); 47 | } 48 | 49 | //Updates start times and end times 50 | static void Dfs(int curr, Automaton automaton, HashSet visited, List startTimes, List endTimes, bool reverse = false) 51 | { 52 | if (!visited.Contains(curr)) 53 | { 54 | visited.Add(curr); 55 | startTimes.Add(curr); 56 | if (reverse) 57 | foreach (var move in automaton.GetMovesTo(curr)) 58 | Dfs(move.SourceState, automaton, visited, startTimes, endTimes, reverse); 59 | else 60 | foreach (var move in automaton.GetMovesFrom(curr)) 61 | Dfs(move.TargetState, automaton, visited, startTimes, endTimes, reverse); 62 | endTimes.Add(curr); 63 | } 64 | } 65 | 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Automata/Internal/Maybe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Microsoft.Automata 8 | { 9 | public class Maybe 10 | { 11 | Tuple t; 12 | 13 | public bool IsSomething 14 | { 15 | get { return t.Item1; } 16 | } 17 | 18 | public S Element 19 | { 20 | get { return t.Item2; } 21 | } 22 | 23 | public static readonly Maybe Nothing = 24 | new Maybe(new Tuple(false, default(S))); 25 | 26 | Maybe(Tuple t) 27 | { 28 | this.t = t; 29 | } 30 | 31 | public static Maybe Something(S elem) 32 | { 33 | return new Maybe(new Tuple(true, elem)); 34 | } 35 | 36 | public override bool Equals(object obj) 37 | { 38 | Maybe x = obj as Maybe; 39 | if (x == null) 40 | return false; 41 | return t.Equals(x.t); 42 | } 43 | 44 | public override int GetHashCode() 45 | { 46 | return t.GetHashCode(); 47 | } 48 | 49 | public override string ToString() 50 | { 51 | if (t.Item1) 52 | return t.Item2.ToString(); 53 | else 54 | return "[]"; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Automata/Internal/PushdownMove.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | namespace Microsoft.Automata 5 | { 6 | /// 7 | /// Represents the label of a pushdown automaton move 8 | /// 9 | /// 10 | public class PushdownLabel : Tuple>> 11 | { 12 | public S PopSymbol { get { return Item2.Item1;} } 13 | public Sequence PushSymbols { get { return Item2.Item2; } } 14 | public T Input { get { return Item1; } } 15 | public Tuple> PushAndPop { get { return Item2;} } 16 | 17 | public bool InputIsEpsilon 18 | { 19 | get 20 | { 21 | return object.Equals(Input, default(T)); 22 | } 23 | } 24 | 25 | public PushdownLabel(T label, S pop, params S[] push) : base(label, new Tuple>(pop, new Sequence(push))) 26 | { 27 | } 28 | 29 | public PushdownLabel(S pop, params S[] push) : base(default(T), new Tuple>(pop, new Sequence(push))) 30 | { 31 | } 32 | 33 | public PushdownLabel(T label, Tuple> pp) : base(label, pp) 34 | { 35 | } 36 | 37 | public override string ToString() 38 | { 39 | StringBuilder sb = new StringBuilder(); 40 | sb.Append(object.Equals(Input,default(T)) ? "" : "(" + Input.ToString() + ")"); 41 | sb.Append(string.Format("-{0}", PopSymbol.ToString())); 42 | if (PushSymbols.Length > 0) 43 | { 44 | sb.Append("/"); 45 | if (PushSymbols.Length == 1) 46 | sb.Append(string.Format("+{0}", PushSymbols[0].ToString())); 47 | else 48 | sb.Append(string.Format("+{0}", PushSymbols.ToString())); 49 | } 50 | return sb.ToString(); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Automata/OUT.Gppg/LexLocationInFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace QUT.Gppg 8 | { 9 | /// 10 | /// Lexical location extended with optional file name info. 11 | /// 12 | public class LexLocationInFile : LexLocation, IMerge 13 | { 14 | string file; 15 | /// 16 | /// Default no-arg constructor. 17 | /// 18 | public LexLocationInFile() 19 | : base() 20 | { } 21 | 22 | /// 23 | /// Source file of the location 24 | /// 25 | public string File 26 | { 27 | get 28 | { 29 | return (file == null ? "" : file); 30 | } 31 | } 32 | 33 | public LexLocationInFile(int sl, int sc, int el, int ec, string file) : 34 | base(sl, sc, el, ec) 35 | { this.file = file; } 36 | 37 | public LexLocationInFile Merge(LexLocationInFile last) 38 | { 39 | return new LexLocationInFile(this.StartLine, this.StartColumn, last.EndLine, last.EndColumn, file); 40 | } 41 | 42 | public static LexLocationInFile operator +(LexLocationInFile loc1, LexLocationInFile loc2) 43 | { 44 | return loc1.Merge(loc2); 45 | } 46 | 47 | public override string ToString() 48 | { 49 | return string.Format("{4}({0},{1},{2},{3})", StartLine, StartColumn, EndLine, EndColumn, (file == null ? "" : file)); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Automata/RegexParser/RegexTree.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | 7 | // RegexTree is just a wrapper for a node tree with some 8 | // global information attached. 9 | 10 | namespace System.Text.RegularExpressions { 11 | 12 | using System.Collections; 13 | using System.Collections.Generic; 14 | 15 | // PIETER: made public instead of internal for 16 | // direct access from Automata.Tests 17 | public sealed class RegexTree { 18 | #if SILVERLIGHT 19 | internal RegexTree(RegexNode root, Dictionary caps, Int32[] capnumlist, int captop, Dictionary capnames, String[] capslist, RegexOptions opts) 20 | #else 21 | internal RegexTree(RegexNode root, Hashtable caps, Int32[] capnumlist, int captop, Hashtable capnames, String[] capslist, RegexOptions opts) 22 | #endif 23 | 24 | { 25 | _root = root; 26 | _caps = caps; 27 | _capnumlist = capnumlist; 28 | _capnames = capnames; 29 | _capslist = capslist; 30 | _captop = captop; 31 | _options = opts; 32 | } 33 | 34 | internal RegexNode _root; 35 | #if SILVERLIGHT 36 | internal Dictionary _caps; 37 | #else 38 | internal Hashtable _caps; 39 | #endif 40 | internal Int32[] _capnumlist; 41 | #if SILVERLIGHT 42 | internal Dictionary _capnames; 43 | #else 44 | internal Hashtable _capnames; 45 | #endif 46 | internal String[] _capslist; 47 | internal RegexOptions _options; 48 | internal int _captop; 49 | 50 | #if DBG 51 | internal void Dump() { 52 | _root.Dump(); 53 | } 54 | 55 | internal bool Debug { 56 | get { 57 | return(_options & RegexOptions.Debug) != 0; 58 | } 59 | } 60 | #endif 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Automata/RegexParser/SR.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace System.Text.RegularExpressions 6 | { 7 | static class SR 8 | { 9 | public static string GetString(string s, params object[] o) 10 | { 11 | return s; 12 | } 13 | 14 | public const string ReplacementError = "ReplacementError"; 15 | public const string UnexpectedOpcode = "UnexpectedOpcode"; 16 | public const string TooManyParens = "TooManyParens"; 17 | public const string NestedQuantify = "NestedQuantify"; 18 | public const string QuantifyAfterNothing = "QuantifyAfterNothing"; 19 | public const string InternalError = "InternalError"; 20 | public const string IllegalRange = "IllegalRange"; 21 | public const string NotEnoughParens = "NotEnoughParens"; 22 | public const string BadClassInCharRange = "BadClassInCharRange"; 23 | public const string SubtractionMustBeLast = "SubtractionMustBeLast"; 24 | public const string ReversedCharRange = "ReversedCharRange"; 25 | public const string UnterminatedBracket = "UnterminatedBracket"; 26 | public const string InvalidGroupName = "InvalidGroupName"; 27 | public const string CapnumNotZero = "CapnumNotZero"; 28 | public const string UndefinedBackref = "UndefinedBackref"; 29 | public const string MalformedReference = "MalformedReference"; 30 | public const string AlternationCantHaveComment = "AlternationCantHaveComment"; 31 | public const string AlternationCantCapture = "AlternationCantCapture"; 32 | public const string UnrecognizedGrouping = "UnrecognizedGrouping"; 33 | public const string IllegalEndEscape = "IllegalEndEscape"; 34 | public const string CaptureGroupOutOfRange = "CaptureGroupOutOfRange"; 35 | public const string TooFewHex = "TooFewHex"; 36 | public const string MissingControl = "MissingControl"; 37 | public const string UnrecognizedControl = "UnrecognizedControl"; 38 | public const string UnrecognizedEscape = "UnrecognizedEscape"; 39 | public const string IncompleteSlashP = "IncompleteSlashP"; 40 | public const string MalformedSlashP = "MalformedSlashP"; 41 | public const string IllegalCondition = "IllegalCondition"; 42 | public const string TooManyAlternates = "TooManyAlternates"; 43 | public const string MakeException = "MakeException"; 44 | public const string UndefinedNameRef = "UndefinedNameRef"; 45 | public const string UndefinedReference = "UndefinedReference"; 46 | public const string UnterminatedComment = "UnterminatedComment"; 47 | public const string MalformedNameRef = "MalformedNameRef"; 48 | public const string UnknownProperty = "UnknownProperty"; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Automata/Templates/AutomatonTextTemplate.tt: -------------------------------------------------------------------------------- 1 | <#@ template language="C#" compilerOptions="optimize+" #> 2 | <#@ import namespace="System.Collections.Generic" #> 3 | <#@ import namespace="Microsoft.Automata" #> 4 | 5 | static bool <#= name #>(const <#= manager.CppStringTypeName #> & str) { 6 | unsigned short r = 0; 7 | unsigned short c = 0; 8 | UINT i = 0; 9 | UINT size = str.size(); 10 | const unsigned char* buffer = reinterpret_cast(str.buffer()); 11 | <#= new AutomatonMovesTextTemplate(manager.Solver, helperPredicates, automaton, 12 | isAtEndConditionText: "i == size", 13 | readNextCharText: 14 | @" if (!UTF8toUTF16(&r, &i, &c, size, buffer)) { 15 | return false; 16 | } 17 | ").TransformText() #> 18 | } 19 | <#+ public AutomatonTextTemplate(BREXManager manager, BDDHelperPredicates helperPredicates, string name, Automaton automaton) 20 | { 21 | this.manager = manager; 22 | this.helperPredicates = helperPredicates; 23 | this.name = name; 24 | this.automaton = automaton; 25 | } 26 | 27 | BREXManager manager; 28 | BDDHelperPredicates helperPredicates; 29 | string name; 30 | Automaton automaton; 31 | #> -------------------------------------------------------------------------------- /src/Automata/Utilities/HighTimer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Runtime.InteropServices; 5 | using System.Security; 6 | 7 | namespace Microsoft.Automata.Utilities 8 | { 9 | /// 10 | /// High precision timer 11 | /// 12 | internal static class HighTimer 13 | { 14 | [SuppressUnmanagedCodeSecurity] 15 | sealed class Win32 16 | { 17 | [DllImport("Kernel32.dll"), SuppressUnmanagedCodeSecurity] 18 | public static extern bool QueryPerformanceCounter(out long lpPerformanceCount); 19 | 20 | [DllImport("Kernel32.dll"), SuppressUnmanagedCodeSecurity] 21 | public static extern bool QueryPerformanceFrequency(out long lpFrequency); 22 | } 23 | 24 | private readonly static long frequency; 25 | static HighTimer() 26 | { 27 | if (!Win32.QueryPerformanceFrequency(out frequency)) 28 | { 29 | // high-performance counter not supported 30 | throw new Exception(); 31 | } 32 | } 33 | 34 | /// 35 | /// Gets the frequency. 36 | /// 37 | /// The frequency. 38 | public static long Frequency 39 | { 40 | get { return frequency; } 41 | } 42 | 43 | /// 44 | /// Gets the current ticks value. 45 | /// 46 | /// The now. 47 | public static long Now 48 | { 49 | get 50 | { 51 | long startTime; 52 | if (!Win32.QueryPerformanceCounter(out startTime)) 53 | throw new AutomataException("QueryPerformanceCounter failed"); 54 | return startTime; 55 | } 56 | } 57 | 58 | /// 59 | /// Returns the duration of the timer (in seconds) 60 | /// 61 | /// 62 | /// 63 | /// 64 | public static double ToSeconds(long start, long end) 65 | { 66 | return (end - start) / (double)frequency; 67 | } 68 | 69 | /// 70 | ///Returns the duration in seconds 71 | /// 72 | /// The ticks. 73 | /// 74 | public static double ToSeconds(long ticks) 75 | { 76 | return ticks / (double)frequency; 77 | } 78 | 79 | /// 80 | ///Returns the duration in seconds from 81 | /// 82 | /// The start. 83 | /// 84 | public static double ToSecondsFromNow(long start) 85 | { 86 | return ToSeconds(start, HighTimer.Now); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/Automata/Utilities/IgnoreCaseTransformer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Microsoft.Automata.Utilities 8 | { 9 | internal class IgnoreCaseTransformer 10 | { 11 | BDD IgnoreCaseRel; 12 | BDD domain; 13 | CharSetSolver solver; 14 | 15 | public IgnoreCaseTransformer(CharSetSolver charSetSolver) 16 | { 17 | this.solver = charSetSolver; 18 | IgnoreCaseRel = charSetSolver.Deserialize(Microsoft.Automata.Generated.IgnoreCaseRelation.ignorecase); 19 | domain = IgnoreCaseRel.ShiftRight(16); 20 | } 21 | 22 | /// 23 | /// For all letters in the bdd add their lower and upper case equivalents. 24 | /// 25 | public BDD Apply(BDD bdd) 26 | { 27 | if (domain.And(bdd).IsEmpty) 28 | return bdd; 29 | else 30 | { 31 | var ignorecase = bdd.And(IgnoreCaseRel).ShiftRight(16); 32 | var res = ignorecase.Or(bdd); 33 | return res; 34 | } 35 | } 36 | 37 | public bool IsInDomain(char c) 38 | { 39 | BDD c_bdd = solver.MkCharConstraint(c); 40 | if (c_bdd.And(domain).IsEmpty) 41 | return false; 42 | else 43 | return true; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Automata/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/Bek.Tests/AutomataKey.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AutomataDotNet/Automata/0242132fdbe9687bea22b7144afa0784d7cd927b/src/Bek.Tests/AutomataKey.snk -------------------------------------------------------------------------------- /src/Bek.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Bek.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Bek.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("4ff992af-4e00-4111-afcb-130d81417392")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/Bek.Tests/Samples/Bek/Base64decode.bek: -------------------------------------------------------------------------------- 1 | function D(x)=(ite(x=='/',63,ite(x=='+',62,ite(x<='9',x+4,ite(x<='Z',x-65,x-71))))); 2 | function InvalidChar(x)=(!((('A'<=x) && (x <= 'Z')) || (('a'<=x) && (x <= 'z')) || (('0'<=x) && (x <= '9')) || (x == '=') || (x=='/') || (x=='+'))); 3 | 4 | program base64decode(input){ 5 | return iter(x in input)[q:=0;r:=0;]{ 6 | case ((InvalidChar(x))|| //x is an invalid character 7 | ((x=='=')&&((q==0)||(q==1)))|| //in states 0 and 1 x must not be the end character '=' 8 | ((x=='=')&&(r!=0))|| //when x is the end character then r must be 0 9 | ((x!='=')&&(q==4))|| //x must be the end character in state 4 10 | (q==5)): //the input must end in state 5 11 | raise InvalidInput; 12 | 13 | case (q==0): r:=(D(x)<<2); q:=1; //r := [x5,x4,x3,x2,x1,x0,0,0] 14 | case (q==1): yield(r|(Bits(5,4,D(x)))); 15 | r:=((D(x)&0xF)<<4); q:=2; //r := [y3,y2,y1,y0,0,0,0,0] 16 | case (q==2): if (x=='=') {r:=0;q:=4;} 17 | else { //D(x) == [z5,z4,z3,z2,z1,z0] 18 | yield(r|(Bits(5,2,D(x)))); 19 | r:=((D(x)&3)<<6); q:=3; //r := [z1,z0,0,0,0,0,0,0] 20 | } 21 | case (q==3): if (x=='=') {r:=0; q:=5;} 22 | else { //D(x) == [w5,w4,w3,w2,w1,w0] 23 | yield(r|D(x)); 24 | r:=0;q:=0; 25 | } 26 | case (q==4): r:=0; q:=5; 27 | end case (!((q==0)||(q==5))): raise InvalidInput; //only 0 and 5 are accepting states 28 | }; 29 | } -------------------------------------------------------------------------------- /src/Bek.Tests/Samples/Bek/Base64encode.bek: -------------------------------------------------------------------------------- 1 | /* 2 | function base64 maps x to the following base64-digit 3 | 0..25 ==> 'A'..'Z' 4 | 26..51 ==> 'a'..'z' 5 | 52..61 ==> '0'..'9' 6 | 62 ==> '+' 7 | 63 ==> '/' 8 | */ 9 | function base64(x)=(ite(x<=25,x+65,ite(x<=51,x+71,ite(x<=61,x-4,ite(x==62,'+','/'))))); 10 | 11 | /* 12 | base64 encoder of an input of bytes, any value in the sequence > 0xFF raises an exception 13 | for example base64encode("Man") = "TWFu" 14 | */ 15 | program base64encode(input){ 16 | return iter(x in input)[q:=0;r:=0;]{ 17 | case (x>0xFF): raise InvalidCharacter; 18 | case (q==0): yield (base64(x>>2)); q:=1; r:=(x&3)<<4; 19 | case (q==1): yield (base64(r|(x>>4))); q:=2; r:=(x&0xF)<<2; 20 | case (q==2): yield (base64((r|(x>>6))), base64(x&0x3F)); q:=0; r:=0; 21 | end case (q==1): yield (base64(r),'=','='); 22 | end case (q==2): yield (base64(r),'='); 23 | }; 24 | } 25 | 26 | 27 | /* 28 | == 29 | eval(base64encode, "Man"); 30 | js(base64encode); 31 | */ 32 | 33 | -------------------------------------------------------------------------------- /src/Bek.Tests/Samples/Bek/BitsBug.bek: -------------------------------------------------------------------------------- 1 | program BitsBug(input){ 2 | return iter(c in input) 3 | { 4 | case (true): 5 | yield ((1 + (c & 7)) & 3); 6 | }; 7 | } -------------------------------------------------------------------------------- /src/Bek.Tests/Samples/Bek/CssEncode.bek: -------------------------------------------------------------------------------- 1 | 2 | function hexDigit(x) = ite(x <= 9, x + 48, x + 55); 3 | function hex0(x) = hexDigit(x&0xF); 4 | function hex1(x) = hexDigit((x>>4)&0xF); 5 | function hex2(x) = hexDigit((x>>8)&0xF); 6 | function hex3(x) = hexDigit((x>>12)&0xF); 7 | 8 | //CssEncode, register hs only stores the last two bits of the high surrogate needed for 9 | //uses if-then-else for more concise control flow 10 | program CssEncode(input){ 11 | return iter(c in input)[HS:=false; hs:=0;] 12 | { 13 | case ((c == 0xFFFE) || (c == 0xFFFF)): 14 | raise InvalidUnicodeValueException; 15 | 16 | case (HS): //the previous character was a high surrogate 17 | if (!((c >= 0xdc00) && (c <= 0xdfff))) { raise InvalidSurrogatePairException; } 18 | else { 19 | yield (hex0(((hs << 2)|((c >> 8) & 3))), hex1(c), hex0(c)); 20 | HS:=false; hs:=0; } 21 | 22 | case (true): //the previous character was a not a high surrogate 23 | if (((c >= 0xdc00) && (c <= 0xdfff))) { raise InvalidSurrogatePairException; } 24 | else if (((c >= 0xd800) && (c <= 0xdbff))) { 25 | yield ('\\', ite((((c >> 6) & 0xF)==0xF),'1','0'), hex0(((c >> 6) + 1)), hex0((c >> 2))); 26 | HS := true; hs := (c & 3); } 27 | else if (c > 0xFF) { yield ('\\','0','0',hex3(c),hex2(c),hex1(c),hex0(c));} 28 | else if ( (('0'<=c)&&(c<='9')) || (('A'<=c)&&(c<='Z')) || (('a'<=c)&&(c<='z')) ) { yield (c); } 29 | else { yield ('\\','0','0','0','0',hex1(c),hex0(c)); } 30 | } end { 31 | case (HS): raise InvalidSurrogatePairException; 32 | case (true): yield(); 33 | }; 34 | } -------------------------------------------------------------------------------- /src/Bek.Tests/Samples/Bek/CssEncode4.bek: -------------------------------------------------------------------------------- 1 | 2 | //CssEncode, register hs only stores the last two bits of the high surrogate needed for 3 | //combining with a following low surrogate. Thus the generated SFT has minimal nr of states. 4 | /* 5 | function IsLowSurrogate(c) = ((c >= 0xdc00) && (c <= 0xdfff)); 6 | function IsHighSurrogate(c) = ((c >= 0xd800) && (c <= 0xdbff)); 7 | 8 | function hexDigit(x) = ite(x <= 9, x + 48, x + 55); 9 | function hex0(x) = hexDigit(x&0xF); 10 | function hex1(x) = hexDigit((x>>4)&0xF); 11 | function hex2(x) = hexDigit((x>>8)&0xF); 12 | function hex3(x) = hexDigit((x>>12)&0xF); 13 | */ 14 | 15 | program CssEncode4(input){ 16 | return iter(c in input)[E1a:=false; E1b:=false; E2:=false; HS:=false; hs:=0;] 17 | { 18 | case (!(E1a || E1b || E2) && HS && !IsLowSurrogate(c)) : 19 | E1a := true; // InvalidSurrogatePairException 20 | 21 | case (!(E1a || E1b || E2) && !HS && IsLowSurrogate(c)) : 22 | E1b := true; // InvalidSurrogatePairException 23 | 24 | case (!(E1a || E1b || E2) && ((c == 0xFFFE) || (c == 0xFFFF))): 25 | E2 := true; // InvalidUnicodeValueException 26 | 27 | case (!(E1a || E1b || E2) && !HS && IsHighSurrogate(c)): 28 | //yield the beginning of the encoding, assuming a low surrogate follows 29 | yield ('\\'); 30 | yield (ite((((c >> 6) & 0xF)==0xF),'1','0')); 31 | yield (hex0(((c >> 6) + 1))); 32 | yield (hex0((c >> 2))); 33 | HS := true; // high surrogate bits are stored 34 | hs := (c & 3); // store the least two bits of the high surrogate needed for low surrogate combination 35 | 36 | case (!(E1a || E1b || E2) && HS && IsLowSurrogate(c)): 37 | // the value in hs is the lowest two bits of the prior high surrogate 38 | // and the current character is a low surrogate 39 | // yield the rest of the encoding of the combined codepoint 40 | yield (hex0(((hs << 2)|((c >> 8) & 3)))); 41 | yield (hex1(c)); 42 | yield (hex0(c)); 43 | HS:=false; hs:=0; 44 | 45 | case (!(E1a || E1b || E2) && (c > 0xFF)): 46 | yield ('\\','0','0',hex3(c),hex2(c),hex1(c),hex0(c)); 47 | HS:=false; hs:=0; 48 | 49 | case (!(E1a || E1b || E2) && !(c in "[0-9A-Za-z]")): 50 | yield ('\\','0','0','0','0',hex1(c),hex0(c)); 51 | HS:=false; hs:=0; 52 | 53 | case (!(E1a || E1b || E2)): 54 | yield (c); // c is in CssSafeList: [0-9A-Za-z] 55 | HS:=false; hs:=0; 56 | } 57 | end 58 | { 59 | case (!E1a && !E1b && !E2 && !HS): 60 | yield(); //succesful output 61 | 62 | //otherwise yield trailing error codes 63 | //this is just to mimic exception handling for now 64 | //it messes up the semantics of what is accepted and what is not accepted 65 | //case (E1a || E1b || HS): 66 | // yield(0); //InvalidSurrogatePairException 67 | //case (E2): 68 | // yield(1); //InvalidUnicodeValueException 69 | case (true): 70 | raise Exception; 71 | }; 72 | } 73 | -------------------------------------------------------------------------------- /src/Bek.Tests/Samples/Bek/CssEncode5.bek: -------------------------------------------------------------------------------- 1 | 2 | //CssEncode, register hs only stores the last two bits of the high surrogate needed for 3 | //combining with a following low surrogate. Thus the generated SFT has minimal nr of states. 4 | function IsLowSurrogate(c) = ((c >= 0xdc00) && (c <= 0xdfff)); 5 | 6 | function IsHighSurrogate(c) = ((c >= 0xd800) && (c <= 0xdbff)); 7 | 8 | function hexDigit(x) = ite(x <= 9, x + 48, x + 55); 9 | function hex0(x) = hexDigit(x&0xF); 10 | function hex1(x) = hexDigit((x>>4)&0xF); 11 | function hex2(x) = hexDigit((x>>8)&0xF); 12 | function hex3(x) = hexDigit((x>>12)&0xF); 13 | 14 | program CssEncode5(input){ 15 | return iter(c in input)[HS:=false; hs:=0;] 16 | { 17 | case ((HS && !IsLowSurrogate(c)) || (!HS && IsLowSurrogate(c))) : 18 | raise InvalidSurrogatePairException; 19 | 20 | case ((c == 0xFFFE) || (c == 0xFFFF)): 21 | raise InvalidUnicodeValueException; 22 | 23 | case (!HS && IsHighSurrogate(c)): 24 | yield ('\\', ite((((c >> 6) & 0xF)==0xF),'1','0'), hex0(((c >> 6) + 1)), hex0((c >> 2))); 25 | HS := true; 26 | hs := (c & 3); 27 | 28 | case (HS && IsLowSurrogate(c)): 29 | yield (hex0(((hs << 2)|((c >> 8) & 3)))); 30 | yield (hex1(c)); 31 | yield (hex0(c)); 32 | HS:=false; hs:=0; 33 | 34 | case (c > 0xFF): 35 | yield ('\\','0','0',hex3(c),hex2(c),hex1(c),hex0(c)); 36 | HS:=false; hs:=0; 37 | 38 | //case (!(c in "[0-9A-Za-z\x80-\x90\x93-\x9A\xA0-\xA5]")): //(!InCssSafeList(c)): 39 | case (!(c in "[0-9A-Za-z]")): 40 | yield ('\\','0','0','0','0',hex1(c),hex0(c)); 41 | HS:=false; hs:=0; 42 | 43 | case (true): 44 | yield (c); 45 | HS:=false; hs:=0; 46 | } 47 | end 48 | { 49 | case (HS): 50 | raise InvalidSurrogatePairException; 51 | case (true): 52 | yield(); 53 | }; 54 | } -------------------------------------------------------------------------------- /src/Bek.Tests/Samples/Bek/DecodeDigitPairs.bek: -------------------------------------------------------------------------------- 1 | //decode digits between '6' and '7' as the corresponding 2 | //ascii character, e.g. DecodeDigitPairs("77")='M' 3 | function dec(x,y)=((10*(x-48))+(y-48)); 4 | program DecodeDigitPairs(input) { 5 | return iter(c in input) [d := 0;] { 6 | case ((d == 0)&&(c>='6')&&(c<='7')) : d:=c; 7 | case ((d != 0)&&(c>='6')&&(c<='7')) : yield(dec(d,c));d:=0; 8 | case ((d == 0)&&!((c>='6')&&(c<='7'))): yield(c); 9 | case (true) : yield(d,c); d:=0; 10 | end case (d != 0) : yield (d); 11 | end case (true) : yield(); 12 | }; 13 | } -------------------------------------------------------------------------------- /src/Bek.Tests/Samples/Bek/UTF8Encode.bek: -------------------------------------------------------------------------------- 1 | 2 | 3 | //UTF8 encoding from UTF16 strings, hs is the lower two bits of the previous high surrogate 4 | //this encoder raises an exception when an invalid surrogate is detected 5 | program utf8encode(input){ 6 | return iter(c in input)[H:=false; r:=0;] 7 | { 8 | case (!H&&(0<=c)&&(c<=0x7F)): yield(c); //one octet 9 | case (!H&&(0x7F>6)&0x1F), 0x80|(c&0x3F)); //two octets 11 | case (!H&&(0x7FF0xDFFF))): 12 | yield(0xE0|((c>>12)&0xF), 0x80|((c>>6)&0x3F), 0x80|(c&0x3F)); //three octets 13 | case (!H&&(0xD800<=c)&&(c<=0xDBFF)): H:=true; r:=c&3; //high surrogate 14 | yield (0xF0|(((1+((c>>6)&0xF))>>2)&7),(0x80|(((1+((c>>6)&0xF))&3)<<4))|((c>>2)&0xF)); 15 | case (H&&(0xDC00<=c)&&(c<=0xDFFF)): H:=false; r:=0; //low surrogate 16 | yield((0x80|(r << 4))|((c>>6)&0xF), 0x80|(c&0x3F)); 17 | case (true): raise InvalidInput; 18 | end case (H): raise InvalidInput; 19 | }; 20 | } 21 | 22 | /* 23 | program UTF8Encode(input){ 24 | return iter(c in input)[HS:=false; hs:=0;] 25 | { 26 | case (HS): //the previous character was a high surrogate 27 | //(!IsLowSurrogate(c)) 28 | if (!((c >= 0xdc00) && (c <= 0xdfff))) { raise InvalidSurrogatePairException; } 29 | else { 30 | yield ((0x80|(hs << 4))|((c>>6)&0xF), 0x80|(c&0x3F)); 31 | HS:=false; hs:=0; 32 | } 33 | case (!HS): //the previous character was not a high surrogate 34 | if (c <= 0x7F) { yield(c); } //one byte: ASCII case 35 | else if (c <= 0x7FF) { //two bytes 36 | yield(0xC0 | ((c>>6) & 0x1F), 0x80 | (c & 0x3F)); 37 | } 38 | else if (!((c >= 0xd800) && (c <= 0xdbff))) { //!IsHighSurrogate(c) 39 | //(IsLowSurrogate(c)) 40 | if ((c >= 0xdc00) && (c <= 0xdfff)) { raise InvalidSurrogatePairException; } 41 | else { //three bytes 42 | yield(0xE0| ((c>>12) & 0xF), 0x80 | ((c>>6) & 0x3F), 0x80 | (c&0x3F)); 43 | } 44 | } 45 | else { 46 | yield (0xF0|(((1+((c>>6)&0xF))>>2)&7), (0x80|(((1+((c>>6)&0xF))&3)<<4))|((c>>2) & 0xF)); 47 | HS:=true; hs:=c&3; } 48 | } end { 49 | case (HS): raise InvalidSurrogatePairException; 50 | case (true): yield(); 51 | }; 52 | } 53 | */ -------------------------------------------------------------------------------- /src/Bek.Tests/Samples/Bek/decode.bek: -------------------------------------------------------------------------------- 1 | program decode(input) { 2 | return iter(c in input)[pc := 0;]{ 3 | case (pc == 0) : //initial state 4 | if (c == '&') { pc := 1; } 5 | else { yield (c); } 6 | case (pc == 1) : //memorized & 7 | if (c == '&') { yield ('&'); } 8 | else if (c == 'l') { pc := 2; } 9 | else if (c == 'g') { pc := 3; } 10 | else { yield ('&',c); pc := 0; } 11 | case (pc == 2) : //memorized &l 12 | if (c == 't') { pc := 4; } 13 | else { yield ('&','l',c); pc := 0; } 14 | case (pc == 3) : //memorized &g 15 | if (c == 't') { pc := 5; } 16 | else { yield ('&','g',c); pc := 0; } 17 | case (pc == 4) : //memorized < 18 | if (c == ';') 19 | { yield ('<'); pc := 0; } //finished < 20 | else 21 | { yield ('&','l','t',c); pc := 0; } 22 | case (true) : //memorized > 23 | if (c == ';') 24 | { yield ('>'); pc := 0; } //finished > 25 | else 26 | { yield ('&','g','t',c); pc := 0; } 27 | } end {//final nonempty yields are unfinished patterns 28 | case (pc == 0) : yield (); 29 | case (pc == 1) : yield ('&'); 30 | case (pc == 2) : yield ('&','l'); 31 | case (pc == 3) : yield ('&','g'); 32 | case (pc == 4) : yield ('&','l','t'); 33 | case (true) : yield ('&','g','t'); 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /src/Bek.Tests/Samples/Bek/escapeBrackets.bek: -------------------------------------------------------------------------------- 1 | 2 | //replace all occurrences of "<" by "<" and ">" by ">" 3 | program escapeBrackets(input) { 4 | return iter(c in input) 5 | { 6 | case (c == '<') : 7 | yield ('&'); 8 | yield ('l'); 9 | yield ('t'); 10 | yield (';'); 11 | 12 | case (c == '>') : 13 | yield ('&'); 14 | yield ('g'); 15 | yield ('t'); 16 | yield (';'); 17 | 18 | case(true): 19 | yield(c); 20 | 21 | };} 22 | -------------------------------------------------------------------------------- /src/Bek.Tests/Samples/Bek/escapeString.bek: -------------------------------------------------------------------------------- 1 | program escapeString(t); 2 | string s1; 3 | string s2; 4 | string s3; 5 | string s4; 6 | string s5; 7 | s1 := iter(c in t){b := false;} 8 | { 9 | case (c == '&') : 10 | yield ('&'); 11 | yield ('a'); 12 | yield ('m'); 13 | yield ('p'); 14 | yield (';'); 15 | 16 | case (true) : 17 | yield (c); 18 | }; 19 | s2 := iter(c in s1){b := false;} 20 | { 21 | case (c == '<') : 22 | yield ('&'); 23 | yield ('l'); 24 | yield ('t'); 25 | yield (';'); 26 | case (true) : 27 | yield (c); 28 | }; 29 | s3 := iter(c in s2){b := false;} 30 | { 31 | case (c == '>') : 32 | yield ('&'); 33 | yield ('g'); 34 | yield ('t'); 35 | yield (';'); 36 | case (true) : 37 | yield (c); 38 | }; 39 | s4 := iter(c in s3){b := false;} 40 | { 41 | case (c == '\"') : 42 | yield ('&'); 43 | yield ('q'); 44 | yield ('u'); 45 | yield ('o'); 46 | yield ('t'); 47 | yield (';'); 48 | case (true) : 49 | yield (c); 50 | }; 51 | s5 := iter(c in s4){b := false;} 52 | { 53 | case (c == '\'') : 54 | yield ('&'); 55 | yield ('#'); 56 | yield ('3'); 57 | yield ('9'); 58 | yield (';'); 59 | case (true) : 60 | yield (c); 61 | }; 62 | 63 | 64 | return s5; 65 | -------------------------------------------------------------------------------- /src/Bek.Tests/Samples/Bek/identity.bek: -------------------------------------------------------------------------------- 1 | program trivial(t) { 2 | return iter(c in t) { 3 | case (true): 4 | yield (c); 5 | }; 6 | } -------------------------------------------------------------------------------- /src/Bek.Tests/Samples/Bek/test3.bek: -------------------------------------------------------------------------------- 1 | 2 | program test3(t); 3 | string s; 4 | s := iter(c in t){b := false;} 5 | { 6 | case (!(b) && ((c == '\'') || (c == '\"'))) : 7 | b := false; 8 | yield ('\\'); 9 | yield (c); 10 | 11 | case (c == '\\') : 12 | b := !(b); 13 | yield (c); 14 | 15 | case (true) : 16 | b := false; 17 | yield (c); 18 | 19 | }; 20 | return s; 21 | -------------------------------------------------------------------------------- /src/Bek.Tests/Samples/Bek/test3b.bek: -------------------------------------------------------------------------------- 1 | 2 | program test3b(t); 3 | string s; 4 | s := iter(c in t){b := false;} 5 | { 6 | case (!(b) && ((c == '\'') || (c == '\"'))) : 7 | b := false; 8 | yield ('\\'); 9 | yield (c); 10 | 11 | case (c == '\\') : 12 | b := !(b); 13 | yield (c); 14 | yield (c); // <-- bug 15 | 16 | case (true) : 17 | b := false; 18 | yield (c); 19 | 20 | }; 21 | return s; 22 | -------------------------------------------------------------------------------- /src/Bek.Tests/Samples/Bex/Base64Encode.bek: -------------------------------------------------------------------------------- 1 | /* 2 | function base64 maps x to the following base64-digit 3 | 0..25 ==> 'A'..'Z' 4 | 26..51 ==> 'a'..'z' 5 | 52..61 ==> '0'..'9' 6 | 62 ==> '+' 7 | 63 ==> '/' 8 | */ 9 | function E(x)=(ite(x<=25,x+65,ite(x<=51,x+71,ite(x<=61,x-4,ite(x==62,'+','/'))))); 10 | 11 | /* 12 | Base64 encoder of an input of bytes. For example base64encode("Man") = "TWFu". 13 | Any value > 0xFF raises an exception. 14 | */ 15 | program base64encode(_){ 16 | replace { 17 | "..." ==> [E(Bits(7,2,#0)), E((Bits(1,0,#0)<<4)|Bits(7,4,#1)), E((Bits(3,0,#1)<<2)|Bits(7,6,#2)), E(Bits(5,0,#2))]; 18 | "..$" ==> [E(Bits(7,2,#0)), E((Bits(1,0,#0)<<4)|Bits(7,4,#1)), E(Bits(3,0,#1)<<2), '=']; 19 | ".$" ==> [E(Bits(7,2,#0)), E((Bits(1,0,#0)<<4), '=', '=']; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Bek.Tests/Samples/Bex/a2b.bek: -------------------------------------------------------------------------------- 1 | 2 | //replace "a" by "b" 3 | 4 | program a2b(_){ 5 | replace { 6 | "a" ==> "b"; 7 | }; 8 | } 9 | -------------------------------------------------------------------------------- /src/Bek.Tests/Samples/Bex/base16decode.bek: -------------------------------------------------------------------------------- 1 | function D(x)=ite(x < 58, x - 48, x - 55); 2 | program base16decode(input){ 3 | replace { 4 | "[A-Z0-9]{2}" ==> [(D(#0) << 4) + D(#1)]; 5 | } 6 | }; 7 | 8 | /* 9 | 10 | 11 | function E(x)=ite(x < 10, x + 48, x + 55); 12 | function D(x)=ite(x < 58, x - 48, x - 55); 13 | 14 | program base16encode(input){ 15 | replace { 16 | @"[\0-\xFF]" ==> [E(#0 >> 4),E(#0 & 0xF)]; 17 | } 18 | } 19 | 20 | program base16decode(input){ 21 | replace { 22 | "[A-Z0-9]{2}" ==> [(D(#0) << 4) + D(#1)]; 23 | } 24 | } 25 | // Identity Encoder 26 | program ID(_){replace { "." ==> [#0];}} 27 | == 28 | js(base16encode); 29 | BYTES = regex(@"^[\0-\xFF]*$"); //domain of sequences of bytes 30 | ID_BYTES = restrict(ID,BYTES); //identity over sequences of bytes 31 | ed = join(base16encode, base16decode); //composition, first encode then decode 32 | eq(ID_BYTES, ed); 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | */ -------------------------------------------------------------------------------- /src/Bek.Tests/Samples/Bex/base16encode.bek: -------------------------------------------------------------------------------- 1 | function E(x)=ite(x < 10, x + 48, x + 55); 2 | program base16encode(input){ 3 | replace { 4 | @"[\0-\xFF]" ==> [E(#0 >> 4),E(#0 & 0xF)]; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /src/Bek.Tests/Samples/Bex/encode_decode.bek: -------------------------------------------------------------------------------- 1 | program encode(input){ replace { "<" ==> "<"; ">" ==> ">"; else ==> [#0]; }} //. matches any character 2 | 3 | program decode(input){ replace { "<" ==> "<"; ">" ==> ">"; else ==> []; }} 4 | 5 | program id(input){ replace { "." ==> [#0]; }} 6 | 7 | /* 8 | 9 | == 10 | //Is encode idempotent ? 11 | eq(join(encode,encode),encode); 12 | //Is decode idempotent ? 13 | eq(join(decode,decode),decode); 14 | //Is it true that for all inputs decode(encode(input)) = input ? 15 | eq(join(encode,decode),id); 16 | //Is it true that for all inputs encode(decode(input)) = input ? 17 | eq(join(decode,encode),id); 18 | //generate JavaScript for decode 19 | js(decode); 20 | 21 | */ 22 | -------------------------------------------------------------------------------- /src/Bek.Tests/bek_master.html: -------------------------------------------------------------------------------- 1 | 
2 | Enter any text into the textbox below to see what the bek JavaScript outputs. 3 |
4 |
5 | 22 |
23 |
24 | Input is assumed to be an escaped JavaScript string. Example: OŒE and OŒE 25 | both represent OŒE 26 |
27 |
28 | type text in the textbox above...
29 | 
30 | -------------------------------------------------------------------------------- /src/Bek.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/Bek/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/Bek/AutomataKey.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AutomataDotNet/Automata/0242132fdbe9687bea22b7144afa0784d7cd927b/src/Bek/AutomataKey.snk -------------------------------------------------------------------------------- /src/Bek/Frontend/Meta.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Microsoft.Bek.Frontend.AST; 5 | using Microsoft.Bek.Frontend.TreeOps; 6 | 7 | namespace Microsoft.Bek.Frontend.Meta 8 | { 9 | public enum BekCharModes 10 | { 11 | //Unicode: code points are always < 2^16; all others are addressed using surrogate pairs as in .NET 12 | //BV32: only valid code points; surrogate pairs are consumed eagerly and converted to their target code point 13 | 14 | /// 15 | /// 7 bit ASCII encoding 16 | /// 17 | BV7 = 7, 18 | /// 19 | /// 8 bit Extended ASCII encoding 20 | /// 21 | BV8 = 8, 22 | /// 23 | /// 16 bit bit-vector encoding 24 | /// 25 | BV16 = 16, 26 | /// 27 | /// 32 bit bit-vector encoding 28 | /// 29 | BV32 = 32 30 | } 31 | 32 | public enum BekTypes 33 | { 34 | CHAR, 35 | STR, 36 | BOOL, 37 | ANY 38 | } 39 | 40 | public class AllowBekTypes : AllowTypes 41 | { 42 | public AllowBekTypes(params BekTypes[] allowed) 43 | { 44 | this.whichtypes = new List(); 45 | foreach (var b in allowed) 46 | { 47 | whichtypes.Add(b); 48 | } 49 | } 50 | public override string ToString() 51 | { 52 | StringBuilder sb = new StringBuilder(); 53 | sb.Append(typeof(AllowBekTypes).Name); 54 | sb.Append("("); 55 | for (int i = 0; i < whichtypes.Count; i++) 56 | { 57 | if (i > 0) 58 | sb.Append(","); 59 | sb.Append(whichtypes[i].ToString()); 60 | } 61 | sb.Append(")"); 62 | return sb.ToString(); 63 | } 64 | } 65 | 66 | public class BekException : Exception 67 | { 68 | public BekException() : base() { } 69 | public BekException(string message) : base(message) { } 70 | public BekException(string message, System.Exception inner) : base(message, inner) { } 71 | } 72 | 73 | public class BekParseException : BekException { 74 | public BekParseException() : base() { } 75 | public BekParseException(string message) : base(message) { } 76 | public BekParseException(string message, System.Exception inner) : base(message, inner) { } 77 | public BekParseException(int line, int pos, Exception inner) : base("", inner) { 78 | this.line = line; 79 | this.pos = pos; 80 | } 81 | public BekParseException(int line, int pos, string message) 82 | : base(message) 83 | { 84 | this.line = line; 85 | this.pos = pos; 86 | } 87 | 88 | public int line; 89 | public int pos; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/Bek/Frontend/ParserImpl/generateBekParser.bat: -------------------------------------------------------------------------------- 1 | ..\..\..\..\packages\Antlr34.3.4.19004.1\tools\Antlr3.exe bek.g 2 | del bek.tokens 3 | -------------------------------------------------------------------------------- /src/Bek/Frontend/TreeOps/Tags.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Microsoft.Bek.Frontend.TreeOps 6 | { 7 | [AttributeUsage(AttributeTargets.Field)] 8 | public class Child : System.Attribute 9 | { } 10 | 11 | [AttributeUsage(AttributeTargets.Field)] 12 | public class ChildList : System.Attribute 13 | { } 14 | 15 | [AttributeUsage(AttributeTargets.Field)] 16 | public abstract class AllowTypes : System.Attribute 17 | { 18 | public List whichtypes; 19 | } 20 | 21 | [AttributeUsage(AttributeTargets.Field)] 22 | public class MustMatchTag : System.Attribute 23 | { 24 | public MustMatchTag(string fieldname) 25 | { 26 | this.fieldname = fieldname; 27 | } 28 | 29 | public string fieldname; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Bek/Frontend/TreeOps/TreeInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Reflection; 5 | 6 | namespace Microsoft.Bek.Frontend.TreeOps 7 | { 8 | class TreeInfo 9 | { 10 | static internal IEnumerable ChildEntries(Object o) 11 | { 12 | foreach (var f in o.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance)) 13 | { 14 | if (f.GetCustomAttributes(typeof(Child), false).Length > 0) 15 | { 16 | yield return f; 17 | } 18 | 19 | } 20 | } 21 | 22 | static internal IEnumerable ChildListEntries(object o) 23 | { 24 | foreach (var f in o.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance)) 25 | { 26 | if (f.GetCustomAttributes(typeof(ChildList), false).Length > 0) 27 | { 28 | yield return f; 29 | } 30 | } 31 | } 32 | 33 | static internal IEnumerable NonChildEntries(Object o) 34 | { 35 | foreach (var f in o.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance)) 36 | { 37 | if (f.GetCustomAttributes(typeof(Child), false).Length == 0) 38 | { 39 | yield return f; 40 | } 41 | } 42 | } 43 | 44 | 45 | static internal IEnumerable AllChildValues(Object o) 46 | { 47 | foreach (var f in o.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance)) 48 | { 49 | if (f.GetCustomAttributes(typeof(Child), false).Length > 0) 50 | { 51 | yield return f.GetValue(o); 52 | } 53 | else if (f.GetCustomAttributes(typeof(ChildList), false).Length > 0) 54 | { 55 | // Type childtype = f.GetValue(o).GetType().GetGenericArguments()[0]; 56 | var enumerator = (System.Collections.IEnumerable)f.GetValue(o); 57 | foreach (var elt in enumerator) 58 | { 59 | yield return elt; 60 | } 61 | } 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Bek/Model/Converters/ABekProg.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Microsoft.Bek.Frontend; 5 | using Microsoft.Bek.Frontend.AST; 6 | using Microsoft.Bek.Frontend.TreeOps; 7 | using Microsoft.Bek.Frontend.Meta; 8 | 9 | using Microsoft.Automata; 10 | 11 | namespace Microsoft.Bek.Model.Converters 12 | { 13 | internal abstract class ABekProg : IConverter 14 | { 15 | public ABekProg(AStrExpr ase) { 16 | this.str_handler = ase; 17 | } 18 | 19 | protected AStrExpr str_handler; 20 | 21 | public virtual STModel Convert(BekProgram a) 22 | { 23 | var stringdic = new Dictionary(); 24 | Func strmapping = x => stringdic[a.stab.Get(x).id]; 25 | 26 | var ast = a.ast; 27 | var inputvar = ast.input; 28 | 29 | // should be exactly one return; this is checked 30 | // earlier so we assume it here 31 | var retfilter = new Filter(); 32 | 33 | 34 | if (ast.body is returnstmt) 35 | { 36 | returnstmt e = ast.body as returnstmt; 37 | return this.ReturnModel(a, str_handler.Convert(e.val, strmapping, a.stab)); 38 | } 39 | else 40 | throw new BekException("Bek program not supported."); 41 | } 42 | 43 | //protected abstract S InputModel(ident i); 44 | 45 | protected abstract STModel ReturnModel(BekProgram p, S res); 46 | 47 | public abstract void Dispose(); 48 | 49 | //public abstract ILibrary Library { get; } 50 | 51 | 52 | ILibrary IConverter.Library 53 | { 54 | get { throw new NotImplementedException(); } 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Bek/Model/Converters/AIterExpr.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | using Microsoft.Z3; 6 | using Microsoft.Automata.Z3; 7 | using Microsoft.Bek.Frontend; 8 | using Microsoft.Bek.Frontend.AST; 9 | using Microsoft.Bek.Frontend.TreeOps; 10 | using Microsoft.Bek.Frontend.Meta; 11 | 12 | namespace Microsoft.Bek.Model.Converters 13 | { 14 | internal abstract class AIterExpr { 15 | //public BekCharModes mode; 16 | 17 | public AIterExpr(AValueExpr expr_handler /*, BekCharModes mode*/) { 18 | this.expr_handler = expr_handler; 19 | //this.mode = mode; 20 | 21 | //if (expr_handler.mode != mode) 22 | //{ 23 | // throw new ModelException("Internal error: inconsistent encoding modes"); 24 | //} 25 | } 26 | 27 | //public abstract Converters.Z3.Library Library { get; } 28 | 29 | internal AValueExpr expr_handler; 30 | 31 | public abstract S Convert(iterexpr ie, Symtab stab); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/Bek/Model/Converters/AStrExpr.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.Bek.Frontend.TreeOps; 6 | using Microsoft.Bek.Frontend.AST; 7 | using Microsoft.Bek.Frontend; 8 | using Microsoft.Bek.Frontend.Meta; 9 | 10 | namespace Microsoft.Bek.Model.Converters 11 | { 12 | internal abstract class AStrExpr 13 | { 14 | //public BekCharModes mode; 15 | internal AIterExpr iter_handler; 16 | private Func strexprmapping; 17 | private Symtab stab; 18 | 19 | //public abstract Z3.Library Library { get; } 20 | 21 | public AStrExpr(AIterExpr iter_handler /*, BekCharModes mode*/) 22 | { 23 | //this.mode = mode; 24 | this.iter_handler = iter_handler; 25 | //if (iter_handler.mode != mode) 26 | //{ 27 | // throw new ModelException("Internal error: inconsistent encoding modes"); 28 | //} 29 | } 30 | 31 | public STModel Convert(expr e, Func strexprmapping, Symtab stab) 32 | { 33 | this.strexprmapping = strexprmapping; 34 | this.stab = stab; 35 | return router.Visit(this, e, false); 36 | } 37 | 38 | private static FuncVisitor, expr, STModel> router = new FuncVisitor, expr, STModel>() 39 | { 40 | (AStrExpr cc, iterexpr e) => cc.HandleIter(e), 41 | (AStrExpr cc, ident e) => cc.HandleIdent(e), 42 | (AStrExpr cc, strconst e) => cc.HandleStrLiteral(e) 43 | }; 44 | 45 | protected STModel HandleIter(iterexpr e) 46 | { 47 | return this.iter_handler.Convert(e, this.stab); 48 | } 49 | 50 | protected STModel HandleIdent(ident e) 51 | { 52 | return this.strexprmapping(e); 53 | } 54 | 55 | protected abstract STModel HandleStrLiteral(strconst e); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Bek/Model/Converters/AValueExpr.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | using Microsoft.Bek.Frontend.AST; 6 | using Microsoft.Bek.Frontend.TreeOps; 7 | using Microsoft.Z3; 8 | using Microsoft.Automata.Z3.Internal; 9 | using Microsoft.Bek.Frontend.Meta; 10 | 11 | namespace Microsoft.Bek.Model.Converters 12 | { 13 | internal abstract class AValueExpr 14 | { 15 | //public BekCharModes mode; 16 | 17 | public AValueExpr(/*BekCharModes mode*/) 18 | { 19 | //this.mode = mode; 20 | } 21 | 22 | //public abstract Converters.Z3.Library Library { get; } 23 | 24 | public T Convert(expr e, Func identmap) 25 | { 26 | this.identmap = identmap; 27 | var ret = router.Visit(this, e); 28 | if (ret == null) 29 | throw new ArgumentNullException(); 30 | return ret; 31 | } 32 | 33 | private static FuncVisitor, expr, T> router = new FuncVisitor, expr, T>() 34 | { 35 | // arithmetic ops 36 | (AValueExpr cc, boolconst be) => cc.MkBool(be.val), 37 | (AValueExpr cc, charconst be) => cc.MkChar(be.val), 38 | (AValueExpr cc, ident e) => cc.identmap(e), 39 | // special functions that need custom 40 | (AValueExpr cc, functioncall e) => cc.MkFunctionCall(e.id, e.args.ConvertAll(cc.Convert).ToArray()), 41 | //strings 42 | (AValueExpr cc, strconst e) => cc.MkFunctionCall(new ident("string",0,0), e.content.ConvertAll(cc.MkChar).ToArray()), 43 | }; 44 | 45 | private Func identmap; 46 | 47 | private T Convert(expr e) 48 | { 49 | return router.Visit(this, e); 50 | } 51 | 52 | protected abstract T MkBool(bool val); 53 | protected abstract T MkChar(int val); 54 | protected abstract T MkFunctionCall(ident name, params T[] args); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Bek/Model/Converters/IterInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.Bek.Frontend.TreeOps; 6 | using Microsoft.Bek.Frontend.AST; 7 | using Microsoft.Bek.Frontend; 8 | using Microsoft.Bek.Frontend.Meta; 9 | 10 | namespace Microsoft.Bek.Model.Converters 11 | { 12 | internal class IterInfo 13 | { 14 | private static Filter assign_filter = new Filter(); 15 | private static Filter yield_filter = new Filter(); 16 | 17 | public static IEnumerable InitialBools(iterexpr e, Symtab stab) 18 | { 19 | foreach (iterassgn ia in assign_filter.Apply(e.initializer)) 20 | { 21 | if (stab.Get(ia.lhs).type == BekTypes.BOOL) 22 | yield return ia; 23 | } 24 | } 25 | 26 | public static IEnumerable InitialChars(iterexpr e, Symtab stab) 27 | { 28 | foreach (iterassgn ia in assign_filter.Apply(e.initializer)) 29 | { 30 | if (stab.Get(ia.lhs).type == BekTypes.CHAR) 31 | yield return ia; 32 | } 33 | } 34 | 35 | public static IEnumerable Initializers(iterexpr e, Symtab stab) 36 | { 37 | foreach (iterassgn ia in assign_filter.Apply(e.initializer)) 38 | { 39 | yield return ia; 40 | } 41 | } 42 | 43 | public static IEnumerable BoolUpdatess(itercase ic, Symtab stab) 44 | { 45 | foreach (iterassgn ia in assign_filter.Apply(ic)) 46 | { 47 | if (stab.Get(ia.lhs).type == BekTypes.BOOL) 48 | yield return ia; 49 | } 50 | } 51 | 52 | public static IEnumerable CharUpdates(itercase ic, Symtab stab) 53 | { 54 | foreach (iterassgn ia in assign_filter.Apply(ic)) 55 | { 56 | if (stab.Get(ia.lhs).type == BekTypes.CHAR) 57 | yield return ia; 58 | } 59 | } 60 | 61 | public static IEnumerable AllUpdates(itercase ic, Symtab stab=null) 62 | { 63 | foreach (iterassgn ia in assign_filter.Apply(ic)) 64 | { 65 | yield return ia; 66 | } 67 | } 68 | 69 | public static IEnumerable YieldSeq(itercase ic) 70 | { 71 | foreach (yieldstmt ys in yield_filter.Apply(ic)) 72 | { 73 | foreach (expr ce in ys.args) 74 | { 75 | // This downcast should never fail, since 76 | // preprocessing steps eliminate all non-charexpr 77 | // yields... 78 | yield return (expr)ce; 79 | } 80 | } 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/Bek/Model/Converters/Z3/BekProg.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Microsoft.Automata.Z3; 5 | using Microsoft.Z3; 6 | using Microsoft.Bek.Frontend.Meta; 7 | using Microsoft.Bek.Frontend; 8 | 9 | using Microsoft.Automata; 10 | 11 | using STBuilderZ3 = Microsoft.Automata.STBuilder; 12 | using STModel = Microsoft.Automata.ST; 13 | 14 | namespace Microsoft.Bek.Model.Converters.Z3 15 | { 16 | internal class BekProg : ABekProg 17 | { 18 | internal STBuilderZ3 stb; 19 | internal Sort charsort; 20 | 21 | 22 | public BekProg(AStrExpr ase, STBuilderZ3 stb, Sort charsort) 23 | : base(ase) 24 | { 25 | this.stb = stb; 26 | this.charsort = charsort; 27 | } 28 | 29 | protected override STModel ReturnModel(BekProgram p, STModel res) 30 | { 31 | res.Name = p.ast.name; 32 | return res; 33 | } 34 | 35 | public override void Dispose() 36 | { 37 | //this.stb.Solver.Dispose(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Bek/Model/Converters/Z3/StrExpr.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.Automata.Z3; 6 | using Microsoft.Automata; 7 | using Microsoft.Z3; 8 | using Microsoft.Bek.Frontend.Meta; 9 | 10 | using STz3 = Microsoft.Automata.ST; 11 | using STbz3 = Microsoft.Automata.STb; 12 | using STBuilderZ3 = Microsoft.Automata.STBuilder; 13 | 14 | 15 | namespace Microsoft.Bek.Model.Converters.Z3 16 | { 17 | internal class StrExpr : AStrExpr 18 | { 19 | private STBuilderZ3 stb; 20 | private Sort charsort; 21 | public StrExpr(AIterExpr ith, STBuilderZ3 stb, Sort charsort) : base(ith /*, mode*/) 22 | { 23 | this.stb = stb; 24 | this.charsort = charsort; 25 | } 26 | 27 | protected override STz3 HandleStrLiteral(Frontend.AST.strconst e) 28 | { 29 | throw new NotImplementedException(); 30 | } 31 | 32 | } 33 | 34 | internal class StrExpr2STb : AStrExpr 35 | { 36 | private STBuilderZ3 stb; 37 | private Sort charsort; 38 | public StrExpr2STb(AIterExpr ith, STBuilderZ3 stb, Sort charsort) 39 | : base(ith /*, mode*/) 40 | { 41 | this.stb = stb; 42 | this.charsort = charsort; 43 | } 44 | 45 | protected override STbz3 HandleStrLiteral(Frontend.AST.strconst e) 46 | { 47 | //throw new NotImplementedException(); 48 | //create an STb that removes the input and just outputs the output string 49 | STbz3 res = new STbz3(this.stb.Solver, "fixed", this.charsort, this.charsort, this.stb.Solver.UnitSort, this.stb.Solver.UnitConst, 0); 50 | var rule = new BaseRule(Sequence.Empty, this.stb.Solver.UnitConst, 0); 51 | res.AssignRule(0, rule); 52 | List elems = new List(); 53 | foreach (var c in e.val) 54 | elems.Add(this.stb.Solver.MkCharExpr(c)); 55 | var yield = new Sequence(elems.ToArray()); 56 | var frule = new BaseRule(yield, this.stb.Solver.UnitConst, 0); 57 | res.AssignFinalRule(0, frule); 58 | return res; 59 | } 60 | 61 | BekCharModes ConvertCharEncoding(Microsoft.Automata.BitWidth enc) 62 | { 63 | switch (enc) 64 | { 65 | case Automata.BitWidth.BV16: return BekCharModes.BV16; 66 | case Automata.BitWidth.BV7: return BekCharModes.BV7; 67 | case Automata.BitWidth.BV32: return BekCharModes.BV32; 68 | case Automata.BitWidth.BV8: return BekCharModes.BV8; 69 | default: 70 | throw new BekException(); 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Bek/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Microsoft.Bek")] 9 | [assembly: AssemblyDescription("DSL for string sanitizers")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft Corporation")] 12 | [assembly: AssemblyProduct("Bek")] 13 | [assembly: AssemblyCopyright("Copyright (c) Microsoft Corporation. All rights reserved.")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("644751fd-9ef4-4dff-99d7-a8a797f8f69f")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("2.0.*")] 36 | [assembly: AssemblyFileVersion("2.0.*")] 37 | -------------------------------------------------------------------------------- /src/Bek/Query/Meta.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Microsoft.Bek.Query 7 | { 8 | public class QueryException : Exception 9 | { 10 | public QueryException() : base() { } 11 | public QueryException(string message) : base(message) { } 12 | public QueryException(string message, System.Exception inner) : base(message, inner) { } 13 | } 14 | 15 | 16 | public class QueryParseException : QueryException 17 | { 18 | public QueryParseException() : base() { } 19 | public QueryParseException(string message) : base(message) { } 20 | public QueryParseException(string message, System.Exception inner) : base(message, inner) { } 21 | public QueryParseException(int line, int pos, System.Exception inner) 22 | : base("", inner) 23 | { 24 | this.line = line; 25 | this.pos = pos; 26 | } 27 | public QueryParseException(int line, int pos, string msg) 28 | : base(msg) 29 | { 30 | this.line = line; 31 | this.pos = pos; 32 | } 33 | 34 | public int line; 35 | public int pos; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Bek/Query/ParserImpl/generateQueryParser.bat: -------------------------------------------------------------------------------- 1 | ..\..\..\..\packages\Antlr34.3.4.19004.1\tools\Antlr3.exe query.g 2 | del query.tokens 3 | -------------------------------------------------------------------------------- /src/Bek/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/CounterAutomata/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/CounterAutomata/AutomataKey.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AutomataDotNet/Automata/0242132fdbe9687bea22b7144afa0784d7cd927b/src/CounterAutomata/AutomataKey.snk -------------------------------------------------------------------------------- /src/CounterAutomata/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("CounterAutomata")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("CounterAutomata")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("29308bfc-d04e-4c27-93bc-91ff026c1a55")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/CounterAutomata/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /src/Experimentation/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/Experimentation/AutomataKey.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AutomataDotNet/Automata/0242132fdbe9687bea22b7144afa0784d7cd927b/src/Experimentation/AutomataKey.snk -------------------------------------------------------------------------------- /src/Experimentation/NFA/RandomNFAExperiment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Threading; 7 | using System.IO; 8 | 9 | using Microsoft.Automata.Z3; 10 | using Microsoft.Automata.Z3.Internal; 11 | using Microsoft.Automata; 12 | using Microsoft.Z3; 13 | using System.Diagnostics; 14 | 15 | namespace RunExperiments 16 | { 17 | class RandomNFAExperiment 18 | { 19 | static int startAt=0; 20 | static int endAt = 10; 21 | 22 | public static void RunTest() 23 | { 24 | CharSetSolver solver = new CharSetSolver(BitWidth.BV7); //new solver using ASCII encoding 25 | 26 | 27 | 28 | } 29 | 30 | public static Automaton fadoToSFA (string description, CharSetSolver solver){ 31 | 32 | var finalStates = new HashSet(); 33 | var moves = new List>(); 34 | 35 | moves.Add(new Move(0,1,solver.MkCharConstraint('a'))); 36 | 37 | 38 | 39 | return Automaton.Create(solver, 0, finalStates, moves).RemoveEpsilonLoops(); //This causes normalization 40 | } 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Experimentation/NFA/RegexExperiment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Threading; 7 | using System.IO; 8 | 9 | using Microsoft.Automata.Z3; 10 | using Microsoft.Automata.Z3.Internal; 11 | using Microsoft.Automata; 12 | using Microsoft.Z3; 13 | using System.Diagnostics; 14 | 15 | namespace RunExperiments 16 | { 17 | class RegexExperiment 18 | { 19 | static int startAt=0; 20 | static int endAt = 5000; 21 | 22 | public static void RunTest() 23 | { 24 | 25 | NFAUtil.PrintHeader(Program.regexOutputFile); 26 | 27 | var lines = File.ReadAllLines(Program.path + Program.regexInputFile); 28 | 29 | var rex = new Microsoft.Automata.Rex.RexEngine(BitWidth.BV16); 30 | var solver = rex.Solver; 31 | for (int i = 0; i < Math.Min(lines.Length, endAt); i++) 32 | { 33 | if (i >= startAt) 34 | { 35 | string regex = lines[i].Trim(); 36 | try 37 | { 38 | var sfa = rex.CreateFromRegexes(regex).RemoveEpsilons().MakeTotal(); 39 | NFAUtil.RunAllAlgorithms(sfa, i.ToString(), Program.regexOutputFile, solver); 40 | } 41 | catch (Exception e) 42 | { 43 | e = e; 44 | //Console.WriteLine("Can't parse " + regex); 45 | //Console.WriteLine(e); 46 | } 47 | } 48 | } 49 | } 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Experimentation/NFA/VerificationNFAExperiment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Threading; 7 | using System.IO; 8 | 9 | using Microsoft.Automata.Z3; 10 | using Microsoft.Automata.Z3.Internal; 11 | using Microsoft.Automata; 12 | using Microsoft.Z3; 13 | using System.Diagnostics; 14 | 15 | namespace RunExperiments 16 | { 17 | class VerificationNFAExperiment 18 | { 19 | static int startAt = 0; 20 | static int endAt = 1000; 21 | 22 | public static void RunTest() 23 | { 24 | CharSetSolver solver = new CharSetSolver(BitWidth.BV7); //new solver using ASCII encoding 25 | var nfaPath = Program.path + @"NFA\"; 26 | DirectoryInfo detDir = new DirectoryInfo(nfaPath); 27 | 28 | if (startAt == 0) 29 | NFAUtil.PrintHeader(Program.verifNFAOutputFile); 30 | 31 | int count = 0; 32 | foreach (var file in detDir.GetFiles("*", SearchOption.AllDirectories)) 33 | { 34 | if (startAt <= count && count <= endAt) 35 | { 36 | Automaton detAut = TimbukNFAParser.ParseVataFile(file.FullName, solver); 37 | NFAUtil.RunAllAlgorithms(detAut, file.Name, Program.verifNFAOutputFile, solver); 38 | 39 | } 40 | count++; 41 | } 42 | 43 | } 44 | 45 | public static void RunFinAlphTest() 46 | { 47 | var nfaPath = Program.path + @"NFA\"; 48 | DirectoryInfo detDir = new DirectoryInfo(nfaPath); 49 | 50 | if (startAt == 0) 51 | NFAUtil.PrintHeader(Program.verifNFAOutputFile); 52 | 53 | int count = 0; 54 | foreach (var file in detDir.GetFiles("*", SearchOption.AllDirectories)) 55 | { 56 | if (startAt <= count && count <= endAt) 57 | { 58 | var res = TimbukNFAParser.ParseVataFileFinSet(file.FullName); 59 | NFAUtil.RunAllAlgorithms(res.Item1, file.Name, Program.verifNFAOutputFile, res.Item2); 60 | 61 | } 62 | count++; 63 | } 64 | 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Experimentation/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Threading; 7 | using System.IO; 8 | 9 | using Microsoft.Automata.Z3; 10 | using Microsoft.Automata.Z3.Internal; 11 | using Microsoft.Automata; 12 | using Microsoft.Z3; 13 | using System.Diagnostics; 14 | using Automata.Tests; 15 | 16 | namespace RunExperiments 17 | { 18 | class Program 19 | { 20 | static internal string path = @"..\..\benchmark\"; 21 | static internal int timeOut = 299999; // 5 minutes 22 | static internal int numTests = 2; 23 | 24 | static internal string timbukFile = "timbukResults.txt"; 25 | static internal string timbukFileDM = "dtaminrestimbuk.txt"; 26 | static internal string largeAlphabetFile = "largeAlphabetResults.txt"; 27 | static internal string fastFile = "fastResults.txt"; 28 | 29 | static internal string regexOutputFile = "nfaRegexMinResults.txt"; 30 | static internal string verifNFAOutputFile = "nfaVerificationMinResults.txt"; 31 | 32 | static internal string regexInputFile = "regexlib-clean.txt"; 33 | 34 | static internal string timbukPrefix = "timbuk"; 35 | static internal string largeAlphabetPrefix = "large"; 36 | static internal string fastPrefix = "fast"; 37 | 38 | static void Main(string[] args) 39 | { 40 | //Test generation for Fast 41 | // This takes hours 42 | //RecognizerGenerator.GenerateTAUsingFast(10, 12, 50); 43 | // These two takes minutes 44 | //RecognizerGenerator.GenerateTAUsingFast(6, 15, 1000); 45 | //RecognizerGenerator.GenerateTAUsingFast(5, 16, 1000); 46 | 47 | //DTAMINParsing.RunLargeGeneration(); 48 | //DTAMINParsing.RunGeneration(); 49 | 50 | // Run experiments 51 | //LargeAlphabetExperiment.RunTest(); 52 | //FastExperiment.RunTest(); 53 | //TimbukExperiment.RunTest(); 54 | 55 | ////Gather results in text files 56 | //Util.GatherResults(largeAlphabetFile, largeAlphabetPrefix); 57 | //Util.GatherResults(fastFile, fastPrefix); 58 | //Util.GatherResultsTimbuk(timbukFile, timbukFileDM, timbukPrefix); 59 | 60 | 61 | //RegexExperiment.RunTest(); 62 | 63 | //VerificationNFAExperiment.RunTest(); 64 | 65 | /* 66 | Console.WriteLine("regex"); 67 | RegexExperiment.RunTest(); 68 | Console.WriteLine("nfa-verification"); 69 | VerificationNFAExperiment.RunFinAlphTest(); 70 | */ 71 | 72 | var tests = new RegexExtensionMethodTests(); 73 | tests.TestRegex_CompileToSymbolicRegex_IsMatch_IgnoreCaseTrue(); 74 | } 75 | 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Experimentation/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Experimentation")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Experimentation")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("f21f3fa7-c238-438d-b7f5-01f3312d55d0")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/Experimentation/STA/LargeAlphabetExperiment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Threading; 7 | using System.IO; 8 | 9 | using Microsoft.Automata.Z3; 10 | using Microsoft.Automata.Z3.Internal; 11 | using Microsoft.Automata; 12 | using Microsoft.Z3; 13 | using System.Diagnostics; 14 | 15 | namespace RunExperiments 16 | { 17 | class LargeAlphabetExperiment 18 | { 19 | 20 | static int startAt = 1; 21 | static int maxSize = 100; 22 | 23 | public static void RunTest() 24 | { 25 | if (startAt == 1) 26 | { 27 | using (System.IO.StreamWriter outfile = new System.IO.StreamWriter(Program.path + Program.largeAlphabetFile, false)) 28 | { 29 | outfile.WriteLine("ID, StateCount, RuleCount, CompleteRuleCount, MinStateCount, MinRuleCount, Algo1, Algo2, SFABased"); 30 | } 31 | } 32 | 33 | for (int i = startAt; i < maxSize; i++) 34 | RunTestForGivenSize(i); 35 | } 36 | 37 | private static void RunTestForGivenSize(int K) 38 | { 39 | Console.WriteLine(K); 40 | Z3Provider Z = new Z3Provider(); 41 | var A = (Z.TT.MkRankedAlphabet("A", Z.IntSort, new string[] { "zero", "two" }, new int[] { 0, 2 })); 42 | 43 | Func beta = (i => Z.MkEq(Z.MkInt(1), Z.MkMod(Z.MkDiv(A.AttrVar, Z.MkInt(1 << (i%32))), Z.MkInt(2)))); 44 | 45 | Expr e1 = Z.MkEq(Z.MkInt(1), A.AttrVar); 46 | Expr e2 = Z.MkEq(Z.MkInt(2), A.AttrVar); 47 | Expr e3 = Z.MkEq(Z.MkInt(3), A.AttrVar); 48 | 49 | var r1 = Z.TT.MkTreeAcceptorRule(A, 0, "zero", e1); 50 | var r2 = Z.TT.MkTreeAcceptorRule(A, 1, "zero", e2); 51 | var r3 = Z.TT.MkTreeAcceptorRule(A, 2, "zero", e3); 52 | var rules = new List(); 53 | 54 | rules.Add(r1); 55 | rules.Add(r2); 56 | rules.Add(r3); 57 | 58 | for (int i = 0; i < K; i++) 59 | { 60 | rules.Add(Z.TT.MkTreeAcceptorRule(A, 3 * i + 3, "two", beta(i), 3 * i, 3 * i + 2)); 61 | rules.Add(Z.TT.MkTreeAcceptorRule(A, 3 * i + 4, "two", beta(i), 3 * i + 1, 3 * i + 2)); 62 | rules.Add(Z.TT.MkTreeAcceptorRule(A, 3 * i + 5, "two", beta(i), 3 * i + 2, 3 * i + 2)); 63 | } 64 | 65 | var T = Z.TT.MkTreeAutomaton(new int[] { 3 * K , 3 * K +1 }, A, A, rules); 66 | var comp = T.Complete(); 67 | 68 | Util.RunAllAlgorithms(T, comp, K.ToString(), Program.largeAlphabetFile); 69 | } 70 | 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Experimentation/STA/TestMinLoris.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Threading; 7 | using System.IO; 8 | 9 | using Microsoft.Automata.Z3; 10 | using Microsoft.Automata.Z3.Internal; 11 | using Microsoft.Automata; 12 | using Microsoft.Z3; 13 | using System.Diagnostics; 14 | 15 | namespace RunExperiments 16 | { 17 | class TestMinLoris 18 | { 19 | static int startAt =2; 20 | static int maxSize = 3; 21 | 22 | public static void RunTest() 23 | { 24 | for (int i = startAt; i < maxSize; i++) 25 | RunTestForGivenSize(i); 26 | } 27 | 28 | private static void RunTestForGivenSize(int K) 29 | { 30 | Console.WriteLine(K); 31 | Z3Provider Z = new Z3Provider(); 32 | var A = (Z.TT.MkRankedAlphabet("A", Z.IntSort, new string[] { "zero", "two" }, new int[] { 0, 2 })); 33 | 34 | Func beta = (i => Z.MkEq(Z.MkInt(1), Z.MkMod(Z.MkDiv(A.AttrVar, Z.MkInt(1 << (i % 32))), Z.MkInt(2)))); 35 | 36 | Expr e1 = Z.MkEq(Z.MkInt(1), A.AttrVar); 37 | Expr e2 = Z.MkEq(Z.MkInt(2), A.AttrVar); 38 | Expr e3 = Z.MkEq(Z.MkInt(3), A.AttrVar); 39 | 40 | var r1 = Z.TT.MkTreeAcceptorRule(A, 0, "zero", e1); 41 | var r2 = Z.TT.MkTreeAcceptorRule(A, 1, "zero", e2); 42 | var r3 = Z.TT.MkTreeAcceptorRule(A, 2, "zero", e3); 43 | var rules = new List(); 44 | 45 | rules.Add(r1); 46 | rules.Add(r2); 47 | rules.Add(r3); 48 | 49 | for (int i = 0; i < K; i++) 50 | { 51 | rules.Add(Z.TT.MkTreeAcceptorRule(A, 3 * i + 3, "two", beta(i), 3 * i, 3 * i + 2)); 52 | rules.Add(Z.TT.MkTreeAcceptorRule(A, 3 * i + 4, "two", beta(i), 3 * i + 1, 3 * i + 2)); 53 | rules.Add(Z.TT.MkTreeAcceptorRule(A, 3 * i + 5, "two", beta(i), 3 * i + 2, 3 * i + 2)); 54 | } 55 | 56 | var T = Z.TT.MkTreeAutomaton(new int[] { 3 * K, 3 * K + 1 }, A, A, rules); 57 | //var comp = T.Complete(); 58 | 59 | Console.WriteLine(); 60 | Console.WriteLine(T.StateCount + " " + T.RuleCount); 61 | foreach (var r in T.GetRules()) 62 | Console.WriteLine(r.ToString()); 63 | 64 | var v = T.Minimize(); 65 | Console.WriteLine(v.StateCount + " " + v.RuleCount); 66 | foreach (var r in v.GetRules()) 67 | Console.WriteLine(r.ToString()); 68 | 69 | 70 | var v1 = T.MinimizeViaSFA(); 71 | Console.WriteLine(); 72 | Console.WriteLine(v1.StateCount + " " + v1.RuleCount); 73 | foreach (var r in v1.GetRules()) 74 | Console.WriteLine(r.ToString()); 75 | Console.WriteLine(); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Experimentation/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/Experiments/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/Experiments/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Text.RegularExpressions; 7 | 8 | namespace Experiments 9 | { 10 | class Program 11 | { 12 | static void Main(string[] args) 13 | { 14 | //HtmlEncode.Test.Run(); 15 | Trie.Test.Run(); 16 | //TestEvilRegex(); 17 | Console.ReadLine(); 18 | } 19 | 20 | public static void TestEvilRegex() 21 | { 22 | //@"^(([a-z0-9])+.)+[A-Z]([a-z0-9])+$" 23 | //Regex EvilRegex = new Regex(@"^(([^\0])+.)+[\0]([^\0])+$", RegexOptions.Compiled | (RegexOptions.Singleline)); 24 | Regex EvilRegex = new Regex(@"(.+.)+\n.+"); 25 | //Regex EvilRegex = new Regex("^(_?a?_?a?_?)+$"); 26 | //string b = "some arbitrary input string"; 27 | string b = "bb"; 28 | //takes time exponential in the length of a 29 | int t = 0; 30 | for (int i = 0; i < 50; i++) 31 | { 32 | t = System.Environment.TickCount; 33 | //bool res = new Regex("^(b?a?b?)+$").IsMatch("a" + b + "c"); 34 | //bool res = Regex.IsMatch("^(b?a?b?)+$", "a" + b + "c"); 35 | bool res = EvilRegex.IsMatch(b); 36 | t = System.Environment.TickCount - t; 37 | Console.WriteLine("{0}, {1}", b.Length, t); 38 | b += "b"; 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Experiments/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Experiments")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Experiments")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("9ae68b3b-2e5f-40c8-8bb1-7b0d05e9fd4f")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/Experiments/Trie/Test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Microsoft.Automata; 4 | using Microsoft.Automata.BooleanAlgebras; 5 | 6 | namespace Experiments.Trie 7 | { 8 | internal class Test 9 | { 10 | static PredicateTrie CreateRandomTrie(BV128Algebra alg, int k) 11 | { 12 | PredicateTrie trie = new PredicateTrie(alg); 13 | 14 | for (int j = 0; j < k; j++) 15 | { 16 | var pred = BV128.Random(); 17 | trie.Search(pred); 18 | } 19 | return trie; 20 | } 21 | 22 | internal static void Run() 23 | { 24 | Console.WriteLine("Trie.Test.RunRandom"); 25 | BV128Algebra alg = new BV128Algebra(); 26 | 27 | Console.WriteLine("log2(n), depth, avg depth, depth/log2(n), avg-log2(n)"); 28 | System.Diagnostics.Debug.WriteLine("log2(n), depth, avg depth"); 29 | 30 | int K = 100; 31 | 32 | double ACC = 0; 33 | double ACC2 = 0; 34 | double X = 0; 35 | 36 | for (double d = 5; d <= 10; d += 0.5) 37 | { 38 | int n = (int)Math.Pow(2.0, d); 39 | double count = 0; 40 | double depth = 0; 41 | double avg = 0; 42 | double avg2 = 0; 43 | for (int rep = 0; rep < K; rep++) 44 | { 45 | var trie = CreateRandomTrie(alg, n); 46 | count += (double)trie.LeafCount; 47 | depth += (double)trie.Depth; 48 | avg += trie.AverageNodeDepth(); 49 | avg2 += ((double)trie.TotalLeafDepth()) / ((double)trie.LeafCount); 50 | } 51 | count = count / (double)K; 52 | depth = depth / (double)K; 53 | avg = avg / (double)K; 54 | avg2 = avg2 / (double)K; 55 | 56 | double log2n = Math.Log((double)n, (double)2); 57 | 58 | ACC += (avg - log2n); 59 | ACC2 += (depth / log2n); 60 | X += 1; 61 | 62 | Console.WriteLine("{0:F2}, {1:F2}, {2:F5}, {3:F5}, {4:F5}", log2n, depth, avg, depth / log2n, avg - log2n); 63 | System.Diagnostics.Debug.WriteLine("{0:F2}, {1:F5}, {2:F5}", log2n, depth, avg); 64 | } 65 | System.Diagnostics.Debug.WriteLine("Median of avg-log2(n) = {0:F3}", ACC / X); 66 | System.Diagnostics.Debug.WriteLine("Median of depth/log2(n) = {0:F3}", ACC2 / X); 67 | } 68 | } 69 | } 70 | 71 | -------------------------------------------------------------------------------- /src/Experiments/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/aaa.fast: -------------------------------------------------------------------------------- 1 | Alphabet Node[i:int,s:string]{Three(3),One(1),Zero(0),Cons(2),Nil(0)} 2 | Public Lang goodinp:Node{ 3 | Nil() 4 | | Cons(x1,x2) given (inp2 x1) (goodinp x2) 5 | } 6 | Lang inp2:Node{ 7 | Zero() 8 | | Three(a,l,r) given (inp3 a) (inp2 l) (inp2 r) 9 | } 10 | Lang inp3:Node{ 11 | Zero() 12 | } 13 | Public Lang badout:Node{ 14 | Cons(x1,x2) given (twoeln x1) 15 | | Cons(x1,x2) given (badout x2) 16 | } 17 | Lang twoeln:Node{ 18 | Three(a,l,r) given (twoel a) 19 | | Three(a,l,r) given (twoeln l) 20 | | Three(a,l,r) given (twoeln r) 21 | } 22 | Lang twoel:Node{ 23 | One(a) given (oneel a) 24 | } 25 | Lang oneel:Node{ 26 | One(a) given (zeroel a) 27 | } 28 | Lang zeroel:Node{ 29 | Zero() 30 | } 31 | Public Trans t1: Node -> Node{ 32 | Nil() to (Nil [i, s]) 33 | | Cons (y1,y2) where (s == "a") 34 | to (Cons [i, s] (t1 y1) (t1 y2)) 35 | | Cons (y1,y2) where (not (s == "a")) to (Cons [i, s] y1 (t1 y2)) 36 | | Zero() to (Zero [i, s]) 37 | | Three(y1,y2,y3) where (i > 1) 38 | to (Three [i,s] (One [i,"tag"] y1) (t1 y2) (t1 y3)) 39 | } 40 | Public Trans t2: Node -> Node { 41 | Nil() to (Nil[i, s]) 42 | | Cons (y1,y2) where ((s == "a") or (s == "b")) 43 | to (Cons[i, s] (t2 y1) (t2 y2)) 44 | | Cons (y1,y2 ) where (not ((s == "a") or (s == "b"))) 45 | to (Cons[i, s] y1 (t2 y2)) 46 | | Zero() to (Zero [i,s]) 47 | | Three(y1,y2,y3) where (i < 3) 48 | to (Three [i,s] (One [i,"tag"] y1) (t2 y2) (t2 y3)) 49 | } 50 | Def t_0_1 : Node -> Node := (compose t1 t2) 51 | Def t_0_1_r : Node -> Node := (restrict_inp t_0_1 goodinp) 52 | Def t_0_1_rr : Node -> Node := (restrict_out t_0_1_r badout) 53 | Def la : Node := (domain t_0_1_rr) 54 | Print "t1 and t2 are conflicting" 55 | Print (is_empty_lang la) 56 | -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/apply.fast: -------------------------------------------------------------------------------- 1 | 2 | Alphabet A{zero(0),one(1),two(2)} 3 | Visible Trans q : A -> A { 4 | zero() where (true and true) to (zero []) 5 | | one(x) to (zero []) 6 | | two(x,y) given (no_twos y) to (one [] (q x)) 7 | } 8 | 9 | Lang no_twos : A { 10 | zero() 11 | | one(x) given (no_twos x) (no_twos x) 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/complement.fast: -------------------------------------------------------------------------------- 1 | //Language complement 2 | Alphabet BTree[]{Zero(0), One(1), Two(2)} 3 | 4 | Public Lang q1 : BTree { 5 | Zero() 6 | | Two(x,y) given (q1 x) (q1 y) 7 | } 8 | //The language of all trees 9 | Public Lang tot : BTree { 10 | Zero() 11 | | One(x) 12 | | Two(x,y) 13 | } 14 | Def c_q1 : BTree := (complement q1) 15 | Print c_q1 16 | Def c_c_q1 : BTree := (complement c_q1) 17 | Def all : BTree := (union c_q1 q1) 18 | //the union of q1 and its complement is the same as the language of all trees 19 | AssertTrue (eq_lang all tot) 20 | -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/compose.fast: -------------------------------------------------------------------------------- 1 | 2 | Alphabet A[s:string]{zero(0), two(2)} 3 | 4 | Alphabet B[j:bool]{nolla(0), kaksi(2)} 5 | 6 | Alphabet C[i:int]{zero(0), due(2)} 7 | 8 | Public Trans p : A -> B { 9 | two(x,y) to (kaksi [true] (a x) (a y)) 10 | | two(x,y) to (kaksi [false] (b x) (a y)) 11 | | two(x,y) to (kaksi [false] (a x) (b y)) 12 | | two(x,y) to (kaksi [false] (b x) (b y)) 13 | | zero() to (nolla [false] ) 14 | } 15 | 16 | Trans a : A -> B { 17 | two(x,y) where (s == "a") to (kaksi [true] (a x) (a y)) 18 | | two(x,y) where (s == "a") to (kaksi [false] (b x) (a y)) 19 | | two(x,y) where (s == "a") to (kaksi [false] (a x) (b y)) 20 | | two(x,y) where (s == "a") to (kaksi [false] (b x) (b y)) 21 | | zero() where (s == "a") to (nolla [false] ) 22 | } 23 | 24 | Public Trans id : B -> B { 25 | kaksi(x,y) to (kaksi [true] x y) 26 | | nolla() to (nolla [true] ) 27 | } 28 | 29 | Trans b : A -> B { 30 | two(x,y) where (not (s == "a")) to (kaksi [true] (a x) (a y)) 31 | | two(x,y) where (not (s == "a")) to (kaksi [false] (b x) (a y)) 32 | | two(x,y) where (not (s == "a")) to (kaksi [false] (a x) (b y)) 33 | | two(x,y) where (not (s == "a")) to (kaksi [false] (b x) (b y)) 34 | | zero() where (not (s == "a")) to (nolla [false] ) 35 | } 36 | 37 | Public Trans q : B -> C { 38 | kaksi(x,y) where (not j) to (due [2] (q x) (q y)) 39 | | kaksi(x,y) where j to (q y) 40 | | nolla() to (zero [0]) 41 | } 42 | 43 | /* 44 | 45 | Alphabet A1[s:string]{zero(0), one(1)} 46 | 47 | Alphabet B1[s:string]{nolla(0), yksi(1)} 48 | 49 | Alphabet C1[s:string]{zero(0), uno(1), due(2)} 50 | 51 | Public Trans nd1 : A1 -> B1 { 52 | one(x) to (yksi ["a"] (nd1 x)) 53 | | one(x) to (yksi ["b"] (nd1 x)) 54 | | zero() to (nolla ["a"]) 55 | | zero() to (nolla ["b"]) 56 | } 57 | 58 | Public Trans nd21 : B1 -> C1 { 59 | yksi(x) to (due [s] (nd22 x) (nd22 x)) 60 | } 61 | 62 | Public Trans nd22 : B1 -> C1 { 63 | yksi(x) to (uno [s] (nd22 x)) 64 | | yksi(x) to (uno [s] (nd22 x)) 65 | | nolla() to (zero [s] ) 66 | } 67 | */ 68 | 69 | Def r1 : A -> C := (compose (compose p id) q) 70 | 71 | //Def rnd : A1 -> C1 := (compose nd1 nd21) 72 | -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/compose1.fast: -------------------------------------------------------------------------------- 1 | Alphabet A[s:string]{Z(0), B(2)} 2 | 3 | Alphabet B[j:bool]{Z(0), B(2)} 4 | 5 | Alphabet C[i:int]{Z(0), B(2)} 6 | 7 | Public Trans p : A -> B { 8 | B(x,y) to (B [true] (a x) (a y)) 9 | | B(x,y) to (B [false] (b x) (a y)) 10 | | B(x,y) to (B [false] (a x) (b y)) 11 | | B(x,y) to (B [false] (b x) (b y)) 12 | | Z() to (Z [false] ) 13 | } 14 | 15 | Trans a : A -> B { 16 | B(x,y) where (s == "a") to (B [true] (a x) (a y)) 17 | | B(x,y) where (s == "a") to (B [false] (b x) (a y)) 18 | | B(x,y) where (s == "a") to (B [false] (a x) (b y)) 19 | | B(x,y) where (s == "a") to (B [false] (b x) (b y)) 20 | | Z() where (s == "a") to (Z [false] ) 21 | } 22 | 23 | Trans b : A -> B { 24 | B(x,y) where (not (s == "a")) to (B [true] (a x) (a y)) 25 | | B(x,y) where (not (s == "a")) to (B [false] (b x) (a y)) 26 | | B(x,y) where (not (s == "a")) to (B [false] (a x) (b y)) 27 | | B(x,y) where (not (s == "a")) to (B [false] (b x) (b y)) 28 | | Z() where (not (s == "a")) to (Z [false] ) 29 | } 30 | 31 | Public Trans q : B -> C { 32 | B(x,y) where j to (B [2] (q x) (q y)) 33 | | B(x,y) where (not j) to (q y) 34 | | Z() to (Z [0]) 35 | } 36 | 37 | 38 | Def p_q : A -> C := (compose p q) 39 | 40 | Tree t_1 : A := (B ["a"] (Z ["a"]) (Z ["b"])) 41 | 42 | Tree t_111 : B := (apply p t_1) 43 | 44 | Tree t_112 : C := (apply q t_111) 45 | 46 | Tree t_12 : C := (apply p_q t_1) 47 | 48 | 49 | Tree t_2 : A := (B ["b"] (Z ["a"]) (Z ["a"])) 50 | 51 | Tree t_211 : B := (apply p t_2) 52 | 53 | Tree t_212 : C := (apply q t_211) 54 | 55 | Tree t_22 : C := (apply p_q t_2) -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/constants.fast: -------------------------------------------------------------------------------- 1 | //Constants definitinos in Fast 2 | //Enum definitions (enum types in Fast are required to start with a capital letter) 3 | Enum Color {red, blue, green} 4 | //Constants 5 | Const pi : real := 3.14159 6 | Const piby4 : real := (pi / 4.0) 7 | Const red : Color := Color.red 8 | 9 | Alphabet A[r:real, c:Color]{zero(0),one(1),two(2)} 10 | 11 | //Language where every leaf is labeled with Color.red 12 | Lang l (a: A) { 13 | two(x,y) given (l x) (l y) 14 | | zero() where (a.c == Color.red) 15 | } 16 | //Example of transformation 17 | Public Trans t (a: A) : A { 18 | two(x,y) where ((pi <= 3.4) and (a.c == Color.red)) given (l x) (l y) to (two [(a.r + 0.1), a.c] (t y) (t x)) 19 | | zero() to (zero [(piby4 + 5/2), a.c]) 20 | } 21 | // Output the transducer 22 | Print t -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/cycletree.fast: -------------------------------------------------------------------------------- 1 | Alphabet BT[i:int]{Two(2),Zero(0)} 2 | 3 | Public Lang cycletree:BT{ 4 | Two(x,y) where (i == 0) given (pre x) (post y) 5 | } 6 | 7 | Lang pre:BT{ 8 | Zero() where (i < 0) 9 | | Two(x,y) where (i < 0) given (pre x) (in y) 10 | } 11 | 12 | Lang in:BT{ 13 | Zero() where (i == 0) 14 | | Two(x,y) where (i == 0) given (post x) (pre y) 15 | } 16 | 17 | Lang post:BT{ 18 | Zero() where (i > 0) 19 | | Two(x,y) where (i > 0) given (in x) (post y) 20 | } 21 | 22 | Def ct:BT := (complement cycletree) 23 | Print ct 24 | -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/deforestation.fast: -------------------------------------------------------------------------------- 1 | Alphabet IList[i:int]{nil(0),cons(1)} 2 | 3 | Public Trans mapC : IList -> IList { 4 | nil() where true to (nil [0]) 5 | | cons(x1) where true to (cons [((5 + (i mod 26)) mod 26)] (mapC x1)) 6 | } 7 | 8 | Public Trans mapC2 : IList -> IList { 9 | nil() where true to (nil [0]) 10 | | cons(x1) where true to (cons [((5 + ((5 + (i mod 26)) mod 26)) mod 26)] (mapC2 x1)) 11 | } 12 | 13 | -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/domain.fast: -------------------------------------------------------------------------------- 1 | Alphabet A[r:real]{Z(0),B(2)} 2 | 3 | Public Lang l1 : A { 4 | Z() where (r < 3.0) 5 | | B(x,y) where (r < 3.0) given (l2 x) (l2 y) 6 | } 7 | 8 | Lang l2 : A { 9 | Z() where (r < 3.0) 10 | | B(x,y) where (r < 3.0) given (l1 x) (l1 y) 11 | } 12 | 13 | Public Trans t1 : A -> A { 14 | Z() where (r < 3.0) to (Z [(r - 0.5)]) 15 | | B(x,y) where (r < 3.0) to (B [(r - 0.5)] (t2 x) (t2 y)) 16 | } 17 | 18 | Trans t2 : A -> A { 19 | Z() where (r < 3.0) to (Z [(r - 0.5)]) 20 | | B(x,y) where (r < 3.0) to (B [(r - 0.5)] (t1 x) (t1 y)) 21 | } 22 | 23 | Def d_t : A := (domain t1) 24 | 25 | Tree t_1 : A := (B [1.5] (Z [1.2]) (Z [1.4])) 26 | 27 | Print(contains l1 t_1) 28 | 29 | Print(contains d_t t_1) 30 | 31 | 32 | Tree t_2 : A := (B [3.0] (Z [1.2]) (Z [1.4])) 33 | 34 | Print(contains l1 t_2) 35 | 36 | Print(contains d_t t_2) -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/equivalence.fast: -------------------------------------------------------------------------------- 1 | //Language equivalence 2 | Alphabet A[r:real]{Z(0),O(1),B(2)} 3 | //Language definitions 4 | Public Lang q1 : A { 5 | Z() where (r > 1.0) 6 | | O(x) where (r > 1.0) given (q2 x) 7 | | B(x,y) where (r > 1.0) given (q2 x) (q2 y) 8 | } 9 | Lang q2 : A { 10 | Z() where (r > 1.0) 11 | | O(x) where (r > 1.0) given (q1 x) 12 | | B(x,y) where (r > 1.0) given (q1 x) (q1 y) 13 | } 14 | 15 | Public Lang r1 : A { 16 | Z() where (r < 2.0) 17 | | O(x) where (r < 2.0) given (r2 x) 18 | | B(x,y) where (r < 2.0) given (r2 x) (r2 y) 19 | } 20 | Lang r2 : A { 21 | Z() where (r < 2.0) 22 | | O(x) where (r < 2.0) given (r1 x) 23 | | B(x,y) where (r < 2.0) given (r1 x) (r1 y) 24 | } 25 | //Checks whether the intersection is commutative using equivalence 26 | Def q1r1 : A := (intersect q1 r1) 27 | Def r1q1 : A := (intersect r1 q1) 28 | AssertTrue (eq_lang q1r1 r1q1) 29 | 30 | Print (eq_lang q1r1 q1) -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/exforslides.fast: -------------------------------------------------------------------------------- 1 | 2 | Fun even (i:int) : bool := ((% i 2) == 0) 3 | 4 | Alphabet BinTree [i:int] {Nil(0),Bin(2)} 5 | 6 | Public Lang evenNode : BinTree { 7 | Nil() where (even i) 8 | | Bin(l,r) where (even i) 9 | } 10 | 11 | Public Lang oddNode : BinTree { 12 | Nil() where (not (even i)) 13 | | Bin(l,r) where (not (even i)) 14 | } 15 | 16 | Public Trans negateIfLeftOdd : BinTree -> BinTree { 17 | Nil() to (Nil [i]) 18 | | Bin(l,r) given (evenNode l) to (Bin [i] (negateIfLeftOdd l) (negateIfLeftOdd r)) 19 | | Bin(l,r) given (oddNode l) to (Bin [(0 - i)] (negateIfLeftOdd l) (negateIfLeftOdd r)) 20 | } 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/functions.fast: -------------------------------------------------------------------------------- 1 | Const five : int := 5 2 | 3 | Fun f (i:int) : int := (i + 1) 4 | 5 | Const six : int := (f five) 6 | 7 | 8 | Fun f1 (i:int) (b:bool) : int := ((((f i) == 3) and b) ? 1 : 2) 9 | 10 | 11 | Alphabet A[i : int]{zero(0),one(1),two(2)} 12 | 13 | Public Trans t : A -> A { 14 | two(x,y) where ((five mod (f i)) == 1) to (two [i] (t x) (t y)) 15 | | zero() where (six >= (f1 five true)) to (zero [(f i)]) 16 | } -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/intersect.fast: -------------------------------------------------------------------------------- 1 | //Language complement 2 | Alphabet BTree[]{Zero(0),One(1),Two(2)} 3 | 4 | Public Lang q1 : BTree { 5 | Zero() 6 | | Two(x,y) given (q1 x) (q1 y) 7 | } 8 | //The language of all trees 9 | Public Lang tot : BTree { 10 | Zero() 11 | | One(x) 12 | | Two(x,y) 13 | } 14 | 15 | Def complement_q1 : BTree := (complement q1) 16 | Def c_complement_q1 : BTree :=(complement complement_q1) 17 | Print c_complement_q1 18 | //Show correctness 19 | Def unionq1cq1 : BTree := (union complement_q1 q1) 20 | //the union of q1 and its complement is the same as the language of all trees 21 | AssertTrue (eq_lang unionq1cq1 tot) 22 | -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/minimization.fast: -------------------------------------------------------------------------------- 1 | // Datatype definition 2 | Alphabet HtmlE[tag : string]{nil(0),val(1),attr(2),node(3)} 3 | // Language of HTML trees 4 | Public Lang nodeTree : HtmlE { 5 | node(x1,x2,x3) given (attrTree x1) (nodeTree x2) (nodeTree x3) 6 | | nil() where (tag == "") 7 | } 8 | Lang attrTree:HtmlE { 9 | attr(x1,x2) given (valTree x1) (attrTree x2) 10 | | nil() where (tag == "") 11 | } 12 | Lang valTree:HtmlE { 13 | val(x1) where (not (tag == "")) given (valTree x1) 14 | | nil() where (tag == "") 15 | } 16 | 17 | Public Lang badOutput : HtmlE { 18 | node(x1,x2,x3) where (tag == "script") 19 | | node(x1,x2,x3) given (badOutput x2) 20 | | node(x1,x2,x3) given (badOutput x3) 21 | } 22 | 23 | AssertTrue (eq_lang badOutput (minimize badOutput)) 24 | //AssertTrue (eq_lang nodeTree (minimize nodeTree)) 25 | //AssertTrue (eq_lang attrTree (minimize attrTree)) 26 | //AssertTrue (eq_lang valTree (minimize valTree)) 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/nondet.fast: -------------------------------------------------------------------------------- 1 | Alphabet A[b:bool]{zero(0),one(1)} 2 | 3 | Public Lang l0 : A { 4 | zero() 5 | | one(x) 6 | } 7 | 8 | Print (eq_lang l0 l0) 9 | -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/nondetcs.fast: -------------------------------------------------------------------------------- 1 | Alphabet A[b:bool]{zero(0),one(1)} 2 | 3 | Public Lang l0 : A { 4 | zero() 5 | | one(x) 6 | } 7 | 8 | Public Trans t : A -> A { 9 | zero() to (zero [b]) 10 | | one(x) to (zero [b]) 11 | } 12 | 13 | Print l0 14 | Print (gen_csharp) -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/operators.fast: -------------------------------------------------------------------------------- 1 | 2 | Alphabet A[r:int]{zero(0),one(1)} 3 | 4 | Public Trans q : A -> A { 5 | zero() where ((r + r + r + r) > 5 * 7 + 4) and (r < 10) && true || true to (zero [r]) 6 | | one(x) to (zero [r]) 7 | } 8 | -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/preimage.fast: -------------------------------------------------------------------------------- 1 | //Example of preimage computation 2 | AssertTrue (eq_lang evenTree (pre_image mapInc oddTree)) 3 | //Trees with even elements 4 | Lang evenTree : BT { 5 | Nil() where (even i) 6 | | Bin(l,r) where (even i) given (evenTree l) (evenTree r) 7 | } 8 | //Trees with odd elements 9 | Lang oddTree : BT { 10 | Nil() where (odd i) 11 | | Bin(l,r) where (odd i) given (oddTree l) (oddTree r) 12 | } 13 | //Increment every node in the tree by 1 14 | Public Trans mapInc : BT -> BT { 15 | Nil() to (Nil [(i + 1)]) 16 | | Bin(l,r) to (Bin [(i + 1)] (mapInc l) (mapInc r)) 17 | } 18 | //Functions and alphabet 19 | Fun even (i:int) : bool := ((i % 2) == 0) 20 | Fun odd (i:int) : bool := (not (even i)) 21 | Alphabet BT [i:int] {Nil(0),Bin(2)} 22 | -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/recognizers.fast: -------------------------------------------------------------------------------- 1 | Alphabet Node[i:int,x:real,y:real,s:string]{Three(3),One(1),Zero(0),Cons(2),Nil(0)} 2 | Public Lang goodinp:Node{ 3 | Nil() 4 | | Cons(x1,x2) given (inp2 x1) (goodinp x2) 5 | } 6 | Lang inp2:Node{ 7 | Zero() 8 | | Three(a,l,r) given (inp3 a) (inp2 l) (inp2 r) 9 | } 10 | Lang inp3:Node{ 11 | Zero() 12 | } 13 | Public Lang badout:Node{ 14 | Cons(x1,x2) given (twoeln x1) 15 | | Cons(x1,x2) given (badout x2) 16 | } 17 | Lang twoeln:Node{ 18 | Three(a,l,r) given (twoel a) 19 | | Three(a,l,r) given (twoeln l) 20 | | Three(a,l,r) given (twoeln r) 21 | } 22 | Lang twoel:Node{ 23 | One(a) given (oneel a) 24 | } 25 | Lang oneel:Node{ 26 | One(a) given (zeroel a) 27 | } 28 | Lang zeroel:Node{ 29 | Zero() 30 | } 31 | Public Trans t0 : Node -> Node { 32 | Zero() to (Zero [i,x,y,s]) 33 | | Three(x1,x2,x3) to (Three [i,x,y,s] x1 x2 x3) 34 | | Cons(x1,x2) where ((s == "45") or ((s == "40") or ((s == "2") or (s == "7")))) to (Cons [i,x,y,s] (t0 x1) (t0 x2)) 35 | | Cons(x1,x2) where (not ((s == "45") or ((s == "40") or ((s == "2") or (s == "7"))))) to (Cons [i,x,y,s] x1 (t0 x2)) 36 | | Nil() to (Nil [i,x,y,s]) 37 | | Three(x1,x2,x3) where (true and ((true and true) and (true and (0.002 == 0.637)))) to (Three [i,x,y,s] (One [i,x,y,s] x1) (t0 x2) (t0 x3)) 38 | } 39 | Public Trans t1 : Node -> Node { 40 | Zero() to (Zero [i,x,y,s]) 41 | | Three(x1,x2,x3) to (Three [i,x,y,s] x1 x2 x3) 42 | | Cons(x1,x2) where (s == "29") to (Cons [i,x,y,s] (t1 x1) (t1 x2)) 43 | | Cons(x1,x2) where (not (s == "29")) to (Cons [i,x,y,s] x1 (t1 x2)) 44 | | Nil() to (Nil [i,x,y,s]) 45 | | Three(x1,x2,x3) where ((x > 0.205) and (true and true)) to (Three [i,x,y,s] (One [i,x,y,s] x1) (t0 x2) (t0 x3)) 46 | } 47 | Def t_0_1 : Node -> Node := (compose t0 t1) 48 | Def t_0_1_r : Node -> Node := (restrict_inp t_0_1 goodinp) 49 | Def t_0_1_rr : Node -> Node := (restrict_out t_0_1_r badout) 50 | -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/restrict.fast: -------------------------------------------------------------------------------- 1 | Alphabet A[r:real]{Z(0),B(2)} 2 | 3 | //Restriction over input and output 4 | Def t1il1 : A -> A := (restrict_inp t1 l1) 5 | Def t1ol1 : A -> A := (restrict_out t1 l1) 6 | 7 | Tree t_1 : A := (B [1.5] (Z [1.5]) (Z [1.4])) 8 | Tree t_11 : A := (apply t1 t_1) 9 | Tree t_12 : A := (apply t1il1 t_1) 10 | 11 | Tree t_2 : A := (B [1.0] (Z [1.2]) (Z [1.4])) 12 | Tree t_21 : A := (apply t1 t_2) 13 | Tree t_22 : A := (apply t1il1 t_2) 14 | 15 | Tree t_3 : A := (B [1.6] (Z [1.7]) (Z [1.8])) 16 | Tree t_31 : A := (apply t1 t_3) 17 | Tree t_32 : A := (apply t1ol1 t_3) 18 | 19 | Tree t_4 : A := (B [1.3] (Z [1.7]) (Z [1.8])) 20 | Tree t_41 : A := (apply t1 t_4) 21 | Tree t_42 : A := (apply t1ol1 t_4) 22 | 23 | Print t_42 24 | 25 | 26 | 27 | //Language we use for restriction 28 | Public Lang l1 : A { 29 | Z() where (r > 1.0) 30 | | B(x,y) where (r > 1.0) given (l2 x) 31 | } 32 | Lang l2 : A { 33 | Z() where (r > 1.0) 34 | | B(x,y) where (r > 1.0) given (l1 x) 35 | } 36 | //Transformation 37 | Public Trans t1 : A -> A { 38 | Z() where (r < 3.0) to (Z [(r - 0.5)]) 39 | | B(x,y) where (r < 3.0) to (B [(r - 0.5)] (t2 x) (t2 y)) 40 | } 41 | Trans t2 : A -> A { 42 | Z() where (r < 3.0) to (Z [(r - 0.5)]) 43 | | B(x,y) where (r < 3.0) to (B [(r - 0.5)] (t1 x) (t1 y)) 44 | } -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/sample.fast: -------------------------------------------------------------------------------- 1 | Enum Color {red, blue, green} 2 | 3 | Alphabet A[s:string, b:bool, r:real, c:Color, i:int]{zero(0),one(1),two(2)} 4 | 5 | Alphabet B[i:real, j:bool]{kaks(2), nuull(0)} 6 | 7 | Public Lang q : A { 8 | zero() where ((true ? "bb" : @"aaa") == "foo") 9 | | one(x) where ((((1 == 1) and ((true and b) ? (1 == 1) : (c == Color.red))) and (s == @"\x39red")) and (i == 1)) given (q x) (q x) 10 | | two(x,y) given (q x) 11 | } 12 | 13 | Public Trans p : A -> B { 14 | two(x,y) where (1.7 <= 0.3) to (kaks [0.05, true] (p x) (p x)) 15 | | zero() to (nuull [5/2, false] ) 16 | } 17 | 18 | Public Lang q2 : B { 19 | kaks(x,y) where (i == (3.5 + 0.5)) given (q2 x) (q2 y) 20 | | nuull() 21 | } 22 | 23 | Public Trans r : B -> B { 24 | kaks(x,y) to (kaks [0.05, true] (r x) (r x)) 25 | | nuull() to (nuull [0.0,true]) 26 | } 27 | 28 | Def a : A -> B := (compose p r) 29 | 30 | Def bb : B -> B := (restrict_inp r q2) 31 | 32 | Def cc : B := (union q2 q2) 33 | 34 | Def dd : B := (intersect q2 q2) 35 | 36 | Def ddd : B := (domain bb) -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/shiftchars.fast: -------------------------------------------------------------------------------- 1 | Fun shift1 (c:char) : char := (c + '\x01') 2 | Fun shift2 (c:char) : char := (c + '\x02') 3 | 4 | Alphabet STR[i : char]{nil(0),cons(1)} 5 | 6 | Public Trans caesar1 : STR -> STR { 7 | cons(rest) where ((i >= 'a') && (i <= 'z')) to (cons [(shift1 i)] (caesar2 rest)) 8 | | nil() to (nil [i]) 9 | } 10 | 11 | Trans caesar2 : STR -> STR { 12 | cons(rest) where ((i >= 'A') && (i <= 'Z')) to (cons [(shift2 i)] (caesar1 rest)) 13 | } 14 | -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/trees.fast: -------------------------------------------------------------------------------- 1 | Alphabet A[s:string]{zero(0), two(2)} 2 | 3 | Alphabet B[j:bool]{nolla(0), kaksi(2)} 4 | 5 | Public Trans p : A -> B { 6 | two(x,y) to (kaksi [true] (a x) (a y)) 7 | | two(x,y) to (kaksi [false] (b x) (a y)) 8 | | two(x,y) to (kaksi [false] (a x) (b y)) 9 | | two(x,y) to (kaksi [false] (b x) (b y)) 10 | | zero() to (nolla [false] ) 11 | } 12 | 13 | Trans a : A -> B { 14 | two(x,y) where (s == "a") to (kaksi [true] (a x) (a y)) 15 | | two(x,y) where (s == "a") to (kaksi [false] (b x) (a y)) 16 | | two(x,y) where (s == "a") to (kaksi [false] (a x) (b y)) 17 | | two(x,y) where (s == "a") to (kaksi [false] (b x) (b y)) 18 | | zero() where (s == "a") to (nolla [false] ) 19 | } 20 | 21 | Trans b : A -> B { 22 | two(x,y) where (not (s == "a")) to (kaksi [true] (a x) (a y)) 23 | | two(x,y) where (not (s == "a")) to (kaksi [false] (b x) (a y)) 24 | | two(x,y) where (not (s == "a")) to (kaksi [false] (a x) (b y)) 25 | | two(x,y) where (not (s == "a")) to (kaksi [false] (b x) (b y)) 26 | | zero() where (not (s == "a")) to (nolla [false] ) 27 | } 28 | 29 | Tree t1 : A := (two ["a"] (zero ["a"]) (zero ["b"])) 30 | 31 | Tree t2 : B := (apply p t1) 32 | 33 | Print t1 34 | 35 | Print t2 36 | 37 | -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/typechecking.fast: -------------------------------------------------------------------------------- 1 | Fun even (i:int) : bool := ((i mod 2) == 0) 2 | Fun odd (i:int) : bool := (not (even i)) 3 | Alphabet BT [i:int] {Nil(0),Bin(2)} 4 | 5 | Lang evenTree : BT { 6 | Nil() where (even i) 7 | | Bin(l,r) where (even i) given (evenTree l) (evenTree r) 8 | } 9 | 10 | Lang oddTree : BT { 11 | Nil() where (odd i) 12 | | Bin(l,r) where (odd i) given (oddTree l) (oddTree r) 13 | } 14 | 15 | Public Trans mapInc : BT -> BT { 16 | Nil() to (Nil [(i + 1)]) 17 | | Bin(l,r) to (Bin [(i + 1)] (mapInc l) (mapInc r)) 18 | } 19 | 20 | Public Trans mapIncBuggy : BT -> BT { 21 | Nil() to (Nil [(i + 1)]) 22 | | Bin(l,r) to (Bin [(i + 1)] (mapInc l) r) 23 | } 24 | 25 | AssertFalse (is_empty_lang evenTree) 26 | 27 | AssertTrue (typecheck evenTree mapInc oddTree) 28 | AssertFalse (typecheck evenTree mapIncBuggy oddTree) 29 | AssertTrue (typecheck oddTree mapInc evenTree) 30 | AssertFalse (typecheck oddTree mapIncBuggy evenTree) 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/union.fast: -------------------------------------------------------------------------------- 1 | Alphabet A[r:real]{Z(0),O(1),B(2)} 2 | 3 | Public Lang q1 : A { 4 | Z() where (r > 1.0) 5 | | O(x) where (r > 1.0) given (q2 x) 6 | | B(x,y) where (r > 1.0) given (q2 x) (q2 y) 7 | } 8 | 9 | Lang q2 : A { 10 | Z() where (r > 1.0) 11 | | O(x) where (r > 1.0) given (q1 x) 12 | | B(x,y) where (r > 1.0) given (q1 x) (q1 y) 13 | } 14 | 15 | Public Lang r1 : A { 16 | Z() where (r < 2.0) 17 | | O(x) where (r < 2.0) given (r2 x) 18 | | B(x,y) where (r < 2.0) given (r2 x) (r2 y) 19 | } 20 | 21 | Lang r2 : A { 22 | Z() where (r < 2.0) 23 | | O(x) where (r < 2.0) given (r1 x) 24 | | B(x,y) where (r < 2.0) given (r1 x) (r1 y) 25 | } 26 | 27 | Def union_q1r1 : A := (union q1 r1) 28 | 29 | Tree t_1 : A := (B [1.5] (Z [1.2]) (Z [3.0])) 30 | 31 | Tree t_2 : A := (B [0.5] (Z [1.2]) (Z [1.4])) 32 | 33 | Tree t_12 : A := (B [1.3] (Z [1.2]) (Z [1.4])) 34 | Tree t_not : A := (B [10.5] (Z [3.2]) (Z [0.4])) -------------------------------------------------------------------------------- /src/Fast.Tests/FastSamples/witness.fast: -------------------------------------------------------------------------------- 1 | Alphabet A[r:real]{Z(0),O(1),B(2)} 2 | 3 | Public Lang q1 : A { 4 | Z() 5 | | O(x) given (q2 x) 6 | | B(x,y) given (q2 x) (q2 y) 7 | } 8 | Lang q2 : A { 9 | Z() 10 | |B(x,y) given (q1 x) (q1 y) 11 | } 12 | 13 | Tree t_1 : A := (get_witness (complement q1)) 14 | Print t_1 15 | 16 | AssertFalse (contains q1 t_1) -------------------------------------------------------------------------------- /src/Fast.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Fast.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Fast.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("37a5ed44-ed27-4071-9068-8bd583d65195")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/Fast.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/Fast/AutomataKey.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AutomataDotNet/Automata/0242132fdbe9687bea22b7144afa0784d7cd927b/src/Fast/AutomataKey.snk -------------------------------------------------------------------------------- /src/Fast/FastAssertException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Microsoft.Fast 4 | { 5 | public class FastAssertException : Exception 6 | { 7 | public int line; 8 | public int pos; 9 | public string file; 10 | 11 | public FastAssertException() : base() { } 12 | public FastAssertException(string message) : base(message) { } 13 | public FastAssertException(string message, System.Exception inner) : base(message, inner) { } 14 | 15 | public FastAssertException(string assertion, int line, int pos) 16 | : base(string.Format("ASSERTION FAILED: '{2}'", line, pos, assertion)) 17 | { 18 | this.line = line; 19 | this.pos = pos; 20 | this.file = ""; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Fast/FastException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Microsoft.Fast 6 | { 7 | public enum FastExceptionKind 8 | { 9 | NotImplemented, 10 | UnexpectedArgument, 11 | InvalidSort, 12 | EmptyEnumeration, 13 | InvalidArity, 14 | DuplicateRecordField, 15 | InvalidRecordField, 16 | InternalError, 17 | NotCharacter, 18 | UnknownFunction 19 | } 20 | 21 | public class FastException : Exception 22 | { 23 | public readonly FastExceptionKind kind; 24 | public FastException(FastExceptionKind kind) 25 | { 26 | this.kind = kind; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Fast/FastLog.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.IO; 6 | 7 | 8 | namespace Microsoft.Fast 9 | { 10 | public enum LogLevel { None, Minimal, Normal, Maximal} 11 | 12 | public class FastLog 13 | { 14 | TextWriter tw = Console.Out; 15 | LogLevel lv = LogLevel.Normal; 16 | 17 | public FastLog() { } 18 | public FastLog(TextWriter tw) { this.tw = tw; } 19 | 20 | public void setLogLevel(LogLevel lv) 21 | { 22 | this.lv = lv; 23 | } 24 | 25 | public void SetTextWriter(TextWriter textw) 26 | { 27 | tw = textw; 28 | } 29 | 30 | public void WriteLog(LogLevel lv, string s) 31 | { 32 | if(this.lv>=lv) 33 | tw.WriteLine(s); 34 | } 35 | 36 | public void Reset() 37 | { 38 | tw.Flush(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Fast/FastParseException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Fast.AST; 3 | 4 | namespace Microsoft.Fast 5 | { 6 | [Serializable] 7 | public class FastParseException : Exception 8 | { 9 | internal FastLexLocation location = null; 10 | string _file = null; 11 | 12 | public int StartLine 13 | { 14 | get { return (location == null ? 0 : location.StartLine); } 15 | } 16 | public int StartColumn 17 | { 18 | get { return (location == null ? 0 : location.StartColumn + 1); } 19 | } 20 | public int EndLine 21 | { 22 | get { return (location == null ? 0 : location.EndLine); } 23 | } 24 | public int EndColumn 25 | { 26 | get { return (location == null ? 0 : location.EndColumn + 1); } 27 | } 28 | 29 | public bool HasLocationInfo 30 | { 31 | get { return location != null; } 32 | } 33 | 34 | public string File 35 | { 36 | get 37 | { 38 | if (_file != null) 39 | return _file; 40 | else 41 | return location.File; 42 | } 43 | } 44 | 45 | internal FastParseException() 46 | : base() 47 | { 48 | } 49 | internal FastParseException(string message, string file = null) 50 | : base(message) 51 | { 52 | this._file = file; 53 | } 54 | internal FastParseException(string message, System.Exception inner) 55 | : base(message, inner) 56 | { 57 | } 58 | 59 | internal FastParseException(FastLexLocation location, string message, string file = null) 60 | : base(message) 61 | { 62 | this.location = location; 63 | this._file = file; 64 | } 65 | 66 | public override string ToString() 67 | { 68 | string res = ""; 69 | if (File != null) 70 | res += File; 71 | if (location != null) 72 | res += string.Format("({0},{1},{2},{3})", StartLine, StartColumn, EndLine, EndColumn); 73 | if (res != "") 74 | res += ": "; 75 | res += "error : " + Message; 76 | return res; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/Fast/FastProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Microsoft.Fast 7 | { 8 | public class FastProvider 9 | { 10 | /// 11 | /// Check if the input file is a correct Fast program: returns true if correct, returns false and 12 | /// prints an exception if it is not. 13 | /// 14 | /// the Fast file to be checked 15 | public static bool CheckSyntax(String inputPath) 16 | { 17 | try 18 | { 19 | var pgm = Parser.ParseFromFile(inputPath); 20 | } 21 | catch (FastParseException fpe) 22 | { 23 | Console.WriteLine(fpe.ToString()); 24 | return false; 25 | } 26 | return true; 27 | } 28 | 29 | 30 | /// 31 | /// Generates C# code from a Fast program 32 | /// 33 | /// the Fast file from which it generates the CSharp code 34 | /// the C# file into which the CSharp code is generated 35 | /// the package the generated file will belong to 36 | /// true to generate the transducer's optimized version 37 | public static bool GenerateCSharp(String inputPath, String outputPath, String ns, bool flag){ 38 | 39 | var pgm = Parser.ParseFromFile(inputPath); 40 | FastTransducerInstance fti = FastTransducerInstance.MkFastTransducerInstance(pgm); 41 | StringBuilder sb = new StringBuilder(); 42 | fti.ToFast(sb); 43 | pgm = Parser.ParseFromString(sb.ToString()); 44 | return CsharpGenerator.GenerateCode(pgm, outputPath, ns); 45 | } 46 | 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Fast/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.IO; 5 | using Microsoft.Fast.AST; 6 | 7 | namespace Microsoft.Fast 8 | { 9 | public static class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | if (args.Length < 1 || args.Length > 2) 14 | { 15 | Console.WriteLine("Usage: tool.exe []"); 16 | return; 17 | } 18 | 19 | string cs_master_file = (args.Length > 1 ? args[1] : ""); 20 | 21 | Run(File.ReadAllText(args[0]), null, cs_master_file, args[0]); 22 | } 23 | 24 | public static void Run(string source, TextWriter tw = null, string cs_master_file = "", string filename = "pgm.fast") 25 | { 26 | if (tw == null) 27 | tw = Console.Out; 28 | try 29 | { 30 | var pgm = FastPgmParser.Parse(source, filename); 31 | FastTransducerInstance fti = FastTransducerInstance.MkFastTransducerInstance(pgm, tw,LogLevel.Minimal); 32 | FastTransducerInstance.DisposeZ3P(); 33 | } 34 | catch (FastParseException e) 35 | { 36 | tw.WriteLine(e.ToString()); 37 | return; 38 | } 39 | catch (FastAssertException e) 40 | { 41 | tw.WriteLine("{3}({0},{1}): error : AssertionViolated, {2}", min1(e.line), min1(e.pos), e.Message, filename); 42 | return; 43 | } 44 | catch (FastException e) 45 | { 46 | tw.WriteLine("{3}({0},{1}): error : FastError, {2}", 1, 1, e.Message, filename); 47 | return; 48 | } 49 | catch (Exception e) 50 | { 51 | tw.WriteLine("{3}({0},{1}): error : InternalError, {2}", 1, 1, filename); 52 | return; 53 | } 54 | } 55 | 56 | static int min1(int i) 57 | { 58 | if (i < 1) 59 | return 1; 60 | else return i; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Fast/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Microsoft.Fast")] 9 | [assembly: AssemblyDescription("Functional Abstraction of Symbolic Transductions")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft Corporation")] 12 | [assembly: AssemblyProduct("Microsoft.Fast")] 13 | [assembly: AssemblyCopyright("Copyright (c) Microsoft Corporation. All rights reserved.")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("334cf95e-a4f3-472f-8592-05222dfcbfed")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("2.0.*")] 36 | [assembly: AssemblyFileVersion("2.0.*")] 37 | -------------------------------------------------------------------------------- /src/Fast/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/Fast/parser/genparser.bat: -------------------------------------------------------------------------------- 1 | gplex /babel /unicode /out:fast.lex.cs fast.lex 2 | gppg /gplex /babel /out:fast.y.cs fast.y 3 | -------------------------------------------------------------------------------- /src/MSO.Eval/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/MSO.Eval/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | using System.Diagnostics; 7 | 8 | using Microsoft.Automata.MSO; 9 | using Microsoft.Automata; 10 | using Microsoft.Automata.Z3; 11 | using Microsoft.Automata.Z3.Internal; 12 | using Microsoft.Z3; 13 | using System.IO; 14 | using Microsoft.Automata.MSO.Mona; 15 | using System.Threading; 16 | 17 | namespace MSO.Eval 18 | { 19 | static class Run 20 | { 21 | /// 22 | /// The main entry point for the application. 23 | /// 24 | public static void Main(string[] args) 25 | { 26 | if (args.Length >= 1 && args[0] == "-h") 27 | { 28 | Console.WriteLine( 29 | "MSO.Eval.exe -> runs all experiments\n" + 30 | "MSO.Eval.exe 7.1 \n" + 31 | "runs all experiments in sec 7.1(similarly for 7.2, 7.3)\n" + 32 | "\n" + 33 | "Further options\n" + 34 | "MSO.Eval.exe 7.1 t(runs 1st part of Table 2)\n" + 35 | "MSO.Eval.exe 7.1 ws1s(runs 2nd part of Table 2)\n" + 36 | "MSO.Eval.exe 7.1 ltl(runs 3rd part of Table 2)\n" + 37 | " \n" + 38 | "Each experiments produces a print on screen as well as a file with the results.\n"); 39 | return; 40 | } 41 | 42 | if (args.Length == 0 || args[0] == "7.1") 43 | { 44 | if (args.Length <= 1 || args[1] == "t") 45 | { 46 | Console.WriteLine("t1,t2,t3,t4 in Figure 6"); 47 | MSOPopl14.RunPOPLTests(); 48 | } 49 | if (args.Length <= 1 || args[1] == "ws1s") 50 | { 51 | Console.WriteLine("horn-sub to set-closed in Figure 6"); 52 | LTLMSO.RunWS1S(); 53 | } 54 | if (args.Length <= 1 || args[1] == "ltl") 55 | { 56 | Console.WriteLine("LTL in Figure 6"); 57 | LTLMSO.RunM2LSTR(); 58 | } 59 | } 60 | 61 | if (args.Length == 0 || args[0] == "7.2") 62 | { 63 | Console.WriteLine("f1, f2 in Figure 7"); 64 | LargeMinterm.Run(); 65 | } 66 | 67 | if (args.Length == 0 || args[0] == "7.3") 68 | { 69 | Console.WriteLine("Figure 8"); 70 | GenRandomMSO.Run(); 71 | } 72 | } 73 | 74 | } 75 | } 76 | 77 | -------------------------------------------------------------------------------- /src/MSO.Eval/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("MSO.Eval")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("MSO.Eval")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("b5a929db-813a-4acc-acdc-7fc7348e47dc")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/MSO.Eval/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/MSO.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("MSO.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("MSO.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("fbd88a69-f462-4c2c-b892-f3148b4b938e")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/MSO.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/MSO/AutomataKey.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AutomataDotNet/Automata/0242132fdbe9687bea22b7144afa0784d7cd927b/src/MSO/AutomataKey.snk -------------------------------------------------------------------------------- /src/MSO/Mona/MonaParseException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using System.Text.RegularExpressions; 6 | using QUT.Gppg; 7 | 8 | namespace Microsoft.Automata.MSO.Mona 9 | { 10 | public enum MonaParseExceptionKind 11 | { 12 | SytaxError, 13 | InternalError, 14 | DuplicateDeclaration, 15 | UndeclaredIdentifier, 16 | InvalidIntegerFormat, 17 | TypeMismatch, 18 | UnknownArithmeticOperator, 19 | UnexpectedCharacter, 20 | UnexpectedToken, 21 | InvalidUniverseDeclaration, 22 | UndeclaredConstant, 23 | IdentifierIsNotDeclaredConstant, 24 | InvalidUseOfPredicateOrMacroName, 25 | UndeclaredPredicate, 26 | InvalidUseOfName, 27 | InvalidNrOfParameters, 28 | InvalidUniverseReference, 29 | DuplicateAllpos, 30 | UnexpectedDeclaration, 31 | } 32 | 33 | [Serializable] 34 | public class MonaParseException : Exception 35 | { 36 | internal LexLocationInFile location = null; 37 | MonaParseExceptionKind kind = MonaParseExceptionKind.SytaxError; 38 | 39 | public MonaParseExceptionKind Kind 40 | { 41 | get 42 | { 43 | return kind; 44 | } 45 | } 46 | 47 | public int StartLine 48 | { 49 | get { return (location == null ? 0 : location.StartLine); } 50 | } 51 | public int StartColumn 52 | { 53 | get { return (location == null ? 0 : location.StartColumn + 1); } 54 | } 55 | public int EndLine 56 | { 57 | get { return (location == null ? 0 : location.EndLine); } 58 | } 59 | public int EndColumn 60 | { 61 | get { return (location == null ? 0 : location.EndColumn + 1); } 62 | } 63 | 64 | public string File 65 | { 66 | get { return (location == null ? "" : location.File); } 67 | } 68 | 69 | public bool HasLocationInfo 70 | { 71 | get { return location != null; } 72 | } 73 | 74 | internal MonaParseException() 75 | : base() 76 | { 77 | } 78 | 79 | internal MonaParseException(string message, Exception innerexception) : base(message, innerexception) 80 | { 81 | } 82 | 83 | internal MonaParseException(MonaParseExceptionKind kind, LexLocationInFile location, string message = "") 84 | : base(kind.ToString() + (message== "" ? "" : ": " + message)) 85 | { 86 | this.location = location; 87 | this.kind = kind; 88 | } 89 | 90 | public override string ToString() 91 | { 92 | string res = ""; 93 | if (location != null) 94 | res += string.Format("{5}({0},{1},{2},{3})", StartLine, StartColumn, EndLine, EndColumn, File); 95 | if (res != "") 96 | res += ": "; 97 | res += Message; 98 | return res; 99 | } 100 | } 101 | } 102 | 103 | -------------------------------------------------------------------------------- /src/MSO/Mona/genparser.bat: -------------------------------------------------------------------------------- 1 | gplex /babel /unicode /out:mona.lex.cs mona.lex 2 | gppg /gplex /babel /conflicts /report /out:mona.y.cs mona.y -------------------------------------------------------------------------------- /src/MSO/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Microsoft.MSO")] 9 | [assembly: AssemblyDescription("Monadic Second-Order Logic In Symbolic Automata")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft Corporation")] 12 | [assembly: AssemblyProduct("Microsoft.MSO")] 13 | [assembly: AssemblyCopyright("Copyright (c) Microsoft Corporation. All rights reserved.")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("9894000b-c9cd-4925-aca8-21a7238b3715")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/MSO/Variable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | using Microsoft.Automata; 6 | 7 | namespace Microsoft.Automata.MSO 8 | { 9 | /// 10 | /// First-order or second-order variable 11 | /// 12 | public class Variable : IComparable 13 | { 14 | bool isfo; 15 | string name; 16 | public bool IsFirstOrder 17 | { 18 | get 19 | { 20 | return isfo; 21 | } 22 | } 23 | public string Name 24 | { 25 | get 26 | { 27 | return name; 28 | } 29 | } 30 | public Variable(string name, bool isFirstOrder) 31 | { 32 | this.name = name; 33 | this.isfo = isFirstOrder; 34 | } 35 | public override string ToString() 36 | { 37 | return name; 38 | } 39 | public override bool Equals(object obj) 40 | { 41 | var v = obj as Variable; 42 | if (v == null) 43 | return false; 44 | return (name.Equals(v.name)); 45 | } 46 | public override int GetHashCode() 47 | { 48 | return name.GetHashCode(); 49 | } 50 | 51 | public int CompareTo(object obj) 52 | { 53 | var v = obj as Variable; 54 | if (v == null) 55 | return -1; 56 | return name.CompareTo(v.name); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/MSO/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /src/RegenerateUnicodeTables/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/RegenerateUnicodeTables/AutomataKey.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AutomataDotNet/Automata/0242132fdbe9687bea22b7144afa0784d7cd927b/src/RegenerateUnicodeTables/AutomataKey.snk -------------------------------------------------------------------------------- /src/RegenerateUnicodeTables/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Microsoft.Automata 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | Utilities.UnicodeCategoryRangesGenerator.Generate("Microsoft.Automata.Generated", "UnicodeCategoryRanges", ""); 14 | Utilities.IgnoreCaseRelationGenerator.Generate("Microsoft.Automata.Generated", "IgnoreCaseRelation", ""); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/RegenerateUnicodeTables/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("RegenerateUnicodeTables")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("RegenerateUnicodeTables")] 13 | [assembly: AssemblyCopyright("Copyright © 2018")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("3c95141e-cf30-40e1-a198-138b14d822f7")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/RegenerateUnicodeTables/RegenerateUnicodeTables.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {3C95141E-CF30-40E1-A198-138B14D822F7} 8 | Exe 9 | Properties 10 | RegenerateUnicodeTables 11 | RegenerateUnicodeTables 12 | v4.5.2 13 | 512 14 | true 15 | 16 | 17 | x64 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | true 37 | 38 | 39 | AutomataKey.snk 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | {bc861e29-027d-4ac6-ab24-a7b0cd0fb5e8} 55 | Automata 56 | 57 | 58 | 59 | 66 | --------------------------------------------------------------------------------