コード例 #1
0
        public static T _accionChison <T>(this T term, int pos, DefinitionDelegate definitionDelegate) where T : BnfTerm
        {
            term.AstConfig.NodeCreator = (c, n) =>
            {
                var values = n.ChildNodes.Select(child => (dynamic)child.AstNode).ToArray();
                n.AstNode = definitionDelegate(values);

                /*
                 * if (n.AstNode is Instruccion node)
                 * {
                 *  try
                 *  {
                 *      node.Location = n.ChildNodes[pos].Span.Location;
                 *      //Console.WriteLine("++");
                 *
                 *  }
                 *  catch (SystemException e)
                 *  {
                 *      node.Location = new SourceLocation(-1,-1,-1);
                 *      Console.WriteLine("++++++");
                 *  }
                 * }*/
            };
            return(term);
        }
コード例 #2
0
 /// <summary>
 /// Registra una accion que se ejecutara cuando se reduzca la produccion.
 ///
 /// Esta accion debe de crear un objeto que representa un nodo Ast.
 ///
 /// La accion recibe un array de los valores que han generado las acciones de los hijos.
 /// </summary>
 /// <param name="term"></param>
 /// <param name="definitionDelegate"></param>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static T _accion <T>(this T term, DefinitionDelegate definitionDelegate) where T : BnfTerm
 {
     term.AstConfig.NodeCreator = (c, n) =>
     {
         var values = n.ChildNodes.Select(child => (dynamic)child.AstNode).ToArray();
         n.AstNode = definitionDelegate(values);
     };
     return(term);
 }