Пример #1
0
		public static void Main (string[] args)
		{
			string line;
			noCaption = args.Contains("-n");
			while((line = Console.ReadLine ()) != null) {
				var parser = Parser.Parse (line);

				if (parser.Expression != null) {
					var table = new TruthTable (parser.Parameters.Values.ToArray (), parser.Expression);
					// 真理値表
					if (args.Contains("-T")) {
						caption ("[Truth Table]");
						echo (table.ToString());
					}
					// 主加法標準形
					if (args.Contains("-D")) {
						caption ("[Disjunctive]");
						echo (table.ToDisjunctiveCanonicalExpression ().ToSimpleString ());
					}
					// 主乗法標準形
					if (args.Contains("-C")) {
						caption ("[Conjunctive]");
						echo (table.ToConjunctiveCanonicalExpression ().ToSimpleString ());
					}

					// 省力化
					if (!args.Any (s => s.StartsWith("-q") || s.StartsWith("-c"))) {
						Console.WriteLine ();
						continue;
					}

					// QM法
					var qmc = new QuineMcCluskey (table);
					foreach (IEnumerable<TruthTableColumn> result in qmc.Compressed) {
						var newTable = new TruthTable (table.Parameters, result);
						// QM法 真理値
						if (args.Contains("-qT")) {
							caption ("[QM'ed Truth Table]");
							echo (newTable.ToString ());
						}
						// QM法 主加法標準形
						if (args.Contains("-qD")) {
							caption ("[QM'ed Disjunctive]");
							echo (newTable.ToDisjunctiveCanonicalExpression ().ToSimpleString ());
						}

						var checkTable = new TruthTable (table.Parameters, newTable.ToDisjunctiveCanonicalExpression ());
						// 確認用 真理値表
						if (args.Contains("-cT")) {
							caption ("[Check Truth Table]");
							echo (checkTable.ToString ());
						}
						// 確認用 主乗法標準形
						if (args.Contains("-cC")) {
							caption ("[Check Conjunctive]");
							echo (checkTable.ToConjunctiveCanonicalExpression ().ToSimpleString ());
						}
						// 確認用 主加法標準形
						if (args.Contains("-cD")) {
							caption ("[Check Disjunctive]");
							echo (checkTable.ToDisjunctiveCanonicalExpression ().ToSimpleString ());
						}
					}
					Console.WriteLine ();
				} else {
					Console.Error.WriteLine("Parse Error.");
				}
			}
		}