示例#1
0
        /// <summary>
        /// Learn tokens which evalutes to the `expected` string.
        /// </summary>
        /// <param name="input">Input.</param>
        /// <param name="expected">Output: the expected string.</param>
        /// <returns>Consistent programs.</returns>
        private ProgramSet LearnToken(TInput input, string expected)
        {
            var programs = new List <ProgramNode>();

            // Option 1: err token.
            if (expected == input.errNode.code)
            {
                programs.Add(ErrToken());
            }

            // Option 2: variable token.
            input.TryFind(expected).Select(key =>
            {
                programs.Add(VarToken(key));
            });

            // Option 3: constant token.
            programs.Add(ConstToken(expected));

            return(ProgramSet.List(Symbol("token"), programs));
        }
示例#2
0
文件: Semantics.cs 项目: thufv/Prem
 public static string ErrToken(TInput input) => input.errNode.code;
示例#3
0
文件: Semantics.cs 项目: thufv/Prem
 public static string VarToken(TInput input, EnvKey key) => input[key];
示例#4
0
文件: Semantics.cs 项目: thufv/Prem
 public static SyntaxNode Var(TInput input, EnvKey key) =>
 input.inputTree.Leaves().Where(l => l.code == input[key]).ArgMin(l => l.depth);
示例#5
0
文件: Semantics.cs 项目: thufv/Prem
 public static SyntaxNode Err(TInput input) => input.errNode;