View on GitHub

YACQ, a Programming Language

YACQ (pronounced as yacc) is an application-embeddable programming language for querying and scripting, runs on the .NET platform.


YACQ is a library that provides run-time scripting and querying for .NET applications. YACQ has the following features mainly:


Construct an expression tree from a YACQ code string.

Expression expr =
    YacqServices.Parse("(+ 1 2 3)");
    // same as ((1 + 2) + 3)

Lambdas which has only one argument can construct easily by the helper method.

Expression<Func<string, string>> lambda =
    YacqServices.ParseFunc<string, string>("it.(ToUpper).(Replace 'FOO' 'bar')");
    // same as (string it) => it.ToUpper().Replace("foo", "bar")

Constructed lambdas can compile and evaluate by the standard .NET feature in run-time.

Func<string, string> func = lambda.Compile();
func("foooo"); // returns "barOO"

You can use YACQ in LINQ queries.

var query = Enumerable.Range(1, 100)
    .Where("(== (% it 3) 0)")
    .GroupBy("(/ it 10)")

// Same as:
Enumerable.Range(1, 100)
    .Where(it => it % 3 == 0)
    .GroupBy(it => it / 10)
    .Select(it => it.Average())
    .OrderByDescending(it => it);

YACQ provides expression trees serializer. In vanilla environments, they are not serializable.

string xml = YacqServices.SaveText(lambda);
Expression lambda2 = YacqServices.LoadText(xml);

You can construct complex expression trees with the YACQ-extended Expression Trees system.

Expression expr2 = YacqExpression.TypeCandidate(typeof(Enumerable))
    .Method("Range", Expression.Constant(1), Expression.Constant(100))
    .Method("Take", Expression.Constant(10))

// Same as:
Expression.Call(typeof(Enumerable), "Sum", null,
    Expression.Call(typeof(Enumerable), "Take", new [] { typeof(int), },
        Expression.Call(typeof(Enumerable), "Reverse", new [] { typeof(int), },
            Expression.Call(typeof(Enumerable), "Range", null, Expression.Constant(1), Expression.Constant(100))
        ), Expression.Constant(10)));

Although the main use of YACQ is to embed in other applications, YACQ also can use in standalone. A complier frontend and a REPL environment are bundled.

Get Started

You can embed YACQ by referring Yacq.dll in your application. There are some way to get the system:

Other resources are also available in the Download Page.



Copyright © 2011-2013 Takeshi KIRIYA (aka takeshik) (Web | Mail | GitHub | Twitter), All rights reserved.

YACQ is Free Software. Its source codes, binaries, and all other resources are licensed under the MIT License.