+
2
|
list
|
skin
|
login
|
editor
α-wwwiki
::
regexp_evaluator
user:none
(3366 bytes)
_h1 regexp evaluator{sup (3)} {div {@ style="text-align:center; color:red; background:#eee;box-shadow:0 0 8px black;"} [[basic evaluator|?view=basic_evaluator]] | [[extended eval|?view=extended_evaluator]] | regexp eval | [[alpha lisp|?view=lisp_evaluator]] | [[monodico lisp|?view=monodicolisp]] } _p The standard approach of a Lisp evaluator uses arrays : s-expressions are translated in nested arrays and the arrays are walked through recursively. It works fine in a "console" context, where strings can be easily embedded between quotes. It is not so good in a wiki page where plain text is the principal data and quoting would be "boring". The alphawiki's parser is built on a different approach built on a single loop working with Regular Expressions (RegExp). The code can be seen here : [[parser|meca/JS.js]]. The present {b stringlisp} evaluator is a study towards a cleaner rewritting of the alphawiki's parser. _p This work is no more integrated in the wiki page and can be better analyzed and tested in the outside console : {div {@ style="text-align:center; color:red; background:#eee;box-shadow:0 0 8px black;font-size:3em;"}[[stringlisp console|data/stringlisp/]]} {pre {@ style="white-space:pre-wrap;font:normal 0.9em georgia"} Rewriting the alphawiki's parser, before integration in the wiki structure. {b 1) stringlisp} is a small interpreter built on a single loop using a regular expression evaluating a sequence of nested s-expressions °°{first rest}°° where first is a built-in name (operator or function) defined in a single dictionary, and rest is a string or an s-expression °°{first rest}°°. {b 2) dictionary} : HTML : @, div, span, ul, ol, li, dl, dt, dd, table, tr, td, h1, h2, h3, h4, h5, h6, p, br, hr, b, i, u, a, img, sup, sub, del, pre, center, blockquote, code, note, show, and more to come … MATH : if, >, <, =, not, or, and, +, *, -, /, %, abs, acos, asin, atan, atan2, ceil, cos, exp, floor, log, max, min, pow, random, round, sin, sqrt, tan, PI, E, serie, map, reduce, lib {b 3) notes} : the dictionary can be extended using the lambda and def operators, ie : define&call : °°{{lambda {:a :b} {sqrt {+ {* :a :a}{* :b :b}}} 3 4}°° -> 5 defining : °°{def hypo {lambda {:a :b} {sqrt {+ {* :a :a}{* :b :b}}}}°° and calling : °°{hypo 3 4}°° -> 5 function's parameters must be prefixed by an hyphen : x -> :x the input operator can be used for inline javascript coding. hiding any text is done this way : {sup o}{sup o}{sup o} comment {sup o}{sup o}{sup o}. prevent evaluation of s-expressions this way : {sup o}{sup o}{* 1 2 3}{sup o}{sup o} > {* 1 2 3}. {b 4) console} Any number of valid s-expressions entered in the light yellow red border frame below are evaluated in real-time in the green border frame. You can copy/paste examples of s-expressions from the blue frame. You may have to type something in the editor to "awake" the interpreter ! The source code contains about 130 JS lines for the evaluator and 160 JS lines for the dictionary, and can be seen in the file [[stringlisp.js|data/stringlisp/stringlisp.js]]. } _p This page will give a description of the code, focusing on its essential part, the evaluator.