The LIL Language
What is LIL
What is LIL
 LIL is a small programming language
 LIL stands for Little Interpreted Language
 Focused on being an extension language
 Highly dynamic
 Minimal syntax
 Easy to embed
LIL is small
 A small core set of functions (about 50)
 String handling
 Lists
 Flow control
 etc
 A pair of .c and .h files
 About 3000 lines of C source code
 Could be smaller, but had to be usable :-)
 The ”lil” executable is ~40K (Linux x86)
Extension languages
 A language to write extensions for a host
program
 Extensions depend on the program but most
complex programs can be extended via scripts
 A wizard for an office application
 The logic for a game character
 Responses for web requests in a server
 A text editor script to convert a set of ”#define” lines
to ”case” lines for C code which return a string with
the constant's name without some prefix
 I need this more often than i would want...
LIL is an extension language
 A host can extend the language by providing
new functions
 in LIL everything is done via functions, including
control structures like if, for, while, etc
 a function can execute code passed as a function
argument, set a new local or global variable, create
new execution environments, etc
 Listen to callbacks for I/O, errors, exit requests,
writing and reading to variables, etc
 I/O callbacks can be used to sandbox script
 Variable callbacks can expose host variables
LIL is highly dynamic
 No separate compilation and execution step
 The runtime can be modified at any time
 New variables can be introduced
 New functions can be defined – or redefined
 Functions can be renamed – including natives
 The runtime can be inspected via reflection
 All code and data is stored as strings and
converted to the appropriate type when needed
 Code can be generated and is evaluated lazyly
 String functions can be used with, e.g. lists
LIL has minimal syntax
 Everything follows a simple format:
word1 word2 word3 … wordn
 For commands the first word is the function name
and the rest are the function arguments
 Words are separated by space, but they can
contain special characters and/or be inside
special quotes (single quotes, double quotes,
braces and brackets)
 Words can contain spaces or other special
characters, including – if escaped properly –
characters with a special meaning for LIL
LIL has minimal syntax (cont.)
 Single and double quotes can be used to
include spaces and/or escaping characters
 A command inside [ and ] is executed and its
result is used in place of the […]
 Anything inside { and } is used as-is
 however LIL will count the {s and }s so that they can
be nested
 $ followed by a word evalutes to a variable read
 this can be changed at runtime to do other things
 And that is it. See LIL's readme.txt for details
LIL is easy to embed
 Uses a readable and permissive license: zlib
 Written in C89 with few common C99 features
 Can be used as a shared or static library
 or just drop the lil.c and lil.h pair in your project
 Small API to learn with few simple calls needed
for practical use
 Can be used with C and C++ directly and from
languages which support C shared libraries
 Import LIL is a project that provides bindings for
Free Pascal and .NET (and others in the future)
Some examples
LIL language examples
LIL examples
 Mandatory hello world
print Hello, world
 Notice how quotes are not needed
 Error-try-catch
try { if stuff { error ”Bad stuff” } } { print 
Got an error: [reflect error] }
 Factorial of 10
print [[func {x} { if [expr $x == 1] { return 1 
} { return [expr [[reflect name] [expr $x ­ 1]] 
* $x] }}] 10]
LIL examples (cont.)
# print all known functions with name lengths
# less than five characters
set known­funcs [reflect funcs]
set predicate {[length $x] < 5}
set small­funcs [filter $known­funcs $predicate]
print "Functions with small names:"
foreach $small­funcs {print "  $i"}
C API examples
 Create and destroy a LIL runtime
lil_t lil = lil_new();
/* do stuff here */
lil_free(lil);
 Run some LIL code
lil_free_value(lil_parse(lil,”print hi”,0,0));
 Register a custom function
lil_register(lil, ”newfunc”, fnc_newfunc);
 fnc_newfunc is defined in the next slide
C API examples (cont.)
/* myfunc native function */
LILCALLBACK lil_value_t fnc_myfunc(
    lil_t lil,         /* lil runtime */
    size_t argc,       /* number of arguments */
    lil_value_t* argv) /* arguments array */
{
    size_t i;
    printf(”I've got %i arguments:”, (int)argc);
    for (i=0; i<argc; i++)
        printf(”  '%s'n”,
            lil_to_string(argv[i]));
    return lil_alloc_string(”myfunc result!”);
}
print ”That was it”
That was it
More information
 LIL at github: https://github.com/badsector/lil
 Latest source code
 Wiki
 Issue db
 The readme.txt file in LIL's source code
 Everything about LIL
 Syntax
 Reference
 Import LIL: https://github.com/badsector/implil
 Bindings for Free Pascal, .NET and maybe others

LIL Presentation

  • 1.
  • 2.
    What is LIL LIL is a small programming language  LIL stands for Little Interpreted Language  Focused on being an extension language  Highly dynamic  Minimal syntax  Easy to embed
  • 3.
    LIL is small A small core set of functions (about 50)  String handling  Lists  Flow control  etc  A pair of .c and .h files  About 3000 lines of C source code  Could be smaller, but had to be usable :-)  The ”lil” executable is ~40K (Linux x86)
  • 4.
    Extension languages  Alanguage to write extensions for a host program  Extensions depend on the program but most complex programs can be extended via scripts  A wizard for an office application  The logic for a game character  Responses for web requests in a server  A text editor script to convert a set of ”#define” lines to ”case” lines for C code which return a string with the constant's name without some prefix  I need this more often than i would want...
  • 5.
    LIL is anextension language  A host can extend the language by providing new functions  in LIL everything is done via functions, including control structures like if, for, while, etc  a function can execute code passed as a function argument, set a new local or global variable, create new execution environments, etc  Listen to callbacks for I/O, errors, exit requests, writing and reading to variables, etc  I/O callbacks can be used to sandbox script  Variable callbacks can expose host variables
  • 6.
    LIL is highlydynamic  No separate compilation and execution step  The runtime can be modified at any time  New variables can be introduced  New functions can be defined – or redefined  Functions can be renamed – including natives  The runtime can be inspected via reflection  All code and data is stored as strings and converted to the appropriate type when needed  Code can be generated and is evaluated lazyly  String functions can be used with, e.g. lists
  • 7.
    LIL has minimalsyntax  Everything follows a simple format: word1 word2 word3 … wordn  For commands the first word is the function name and the rest are the function arguments  Words are separated by space, but they can contain special characters and/or be inside special quotes (single quotes, double quotes, braces and brackets)  Words can contain spaces or other special characters, including – if escaped properly – characters with a special meaning for LIL
  • 8.
    LIL has minimalsyntax (cont.)  Single and double quotes can be used to include spaces and/or escaping characters  A command inside [ and ] is executed and its result is used in place of the […]  Anything inside { and } is used as-is  however LIL will count the {s and }s so that they can be nested  $ followed by a word evalutes to a variable read  this can be changed at runtime to do other things  And that is it. See LIL's readme.txt for details
  • 9.
    LIL is easyto embed  Uses a readable and permissive license: zlib  Written in C89 with few common C99 features  Can be used as a shared or static library  or just drop the lil.c and lil.h pair in your project  Small API to learn with few simple calls needed for practical use  Can be used with C and C++ directly and from languages which support C shared libraries  Import LIL is a project that provides bindings for Free Pascal and .NET (and others in the future)
  • 10.
  • 11.
    LIL examples  Mandatoryhello world print Hello, world  Notice how quotes are not needed  Error-try-catch try { if stuff { error ”Bad stuff” } } { print  Got an error: [reflect error] }  Factorial of 10 print [[func {x} { if [expr $x == 1] { return 1  } { return [expr [[reflect name] [expr $x ­ 1]]  * $x] }}] 10]
  • 12.
  • 13.
    C API examples Create and destroy a LIL runtime lil_t lil = lil_new(); /* do stuff here */ lil_free(lil);  Run some LIL code lil_free_value(lil_parse(lil,”print hi”,0,0));  Register a custom function lil_register(lil, ”newfunc”, fnc_newfunc);  fnc_newfunc is defined in the next slide
  • 14.
    C API examples(cont.) /* myfunc native function */ LILCALLBACK lil_value_t fnc_myfunc(     lil_t lil,         /* lil runtime */     size_t argc,       /* number of arguments */     lil_value_t* argv) /* arguments array */ {     size_t i;     printf(”I've got %i arguments:”, (int)argc);     for (i=0; i<argc; i++)         printf(”  '%s'n”,             lil_to_string(argv[i]));     return lil_alloc_string(”myfunc result!”); }
  • 15.
    print ”That wasit” That was it
  • 16.
    More information  LILat github: https://github.com/badsector/lil  Latest source code  Wiki  Issue db  The readme.txt file in LIL's source code  Everything about LIL  Syntax  Reference  Import LIL: https://github.com/badsector/implil  Bindings for Free Pascal, .NET and maybe others