0 | |
{"name":"Tamsin","tagline":"Look! Up on Github! Is it a parser generator? Is it a programming language? Is it a rubbish lister? No... it's Tamsin!","body":"Tamsin\r\n======\r\n\r\nTamsin is an oddball little language that can't decide if it's a\r\n[meta-language](https://github.com/catseye/Tamsin/blob/master/doc/Philosophy.markdown#meta-language), a\r\n[programming language](https://github.com/catseye/Tamsin/blob/master/doc/Philosophy.markdown#programming-language), or a\r\n[rubbish lister](https://github.com/catseye/Tamsin/blob/master/doc/Philosophy.markdown#rubbish-lister).\r\n\r\nIts primary goal is to allow the rapid development of **parsers**,\r\n**static analyzers**, **interpreters**, and **compilers**, and to allow them\r\nto be expressed *compactly*. Golf your grammar! (Or write it like a decent\r\nhuman being, if you must.)\r\n\r\nThe current released version of Tamsin is 0.3; the development version is\r\n0.4-PRE. As indicated by the 0.x version number, it is a **work in progress**,\r\nwith the usual caveat that things may change rapidly (and that version 0.4 might\r\nlook completely different.) See [HISTORY](https://github.com/catseye/Tamsin/blob/master/HISTORY.markdown)\r\nfor a list of major changes.\r\n\r\nCode Examples\r\n-------------\r\n\r\nMake a story more exciting in **1 line of code**:\r\n\r\n main = (\".\" & '!' | \"?\" & '?!' | any)/''.\r\n\r\nParse an algebraic expression for syntactic correctness in **4 lines of code**:\r\n\r\n main = (expr0 & eof & 'ok').\r\n expr0 = expr1 & {\"+\" & expr1}.\r\n expr1 = term & {\"*\" & term}.\r\n term = \"x\" | \"y\" | \"z\" | \"(\" & expr0 & \")\".\r\n\r\nTranslate an algebraic expression to RPN (Reverse Polish Notation) in\r\n**7 lines of code**:\r\n\r\n main = expr0 → E & walk(E).\r\n expr0 = expr1 → E1 & {\"+\" & expr1 → E2 & E1 ← add(E1,E2)} & E1.\r\n expr1 = term → E1 & {\"*\" & term → E2 & E1 ← mul(E1,E2)} & E1.\r\n term = \"x\" | \"y\" | \"z\" | \"(\" & expr0 → E & \")\" & E.\r\n walk(add(L,R)) = walk(L) → LS & walk(R) → RS & return LS+RS+' +'.\r\n walk(mul(L,R)) = walk(L) → LS & walk(R) → RS & return LS+RS+' *'.\r\n walk(X) = return ' '+X.\r\n\r\nParse a CSV file (handling quoted commas and quotes correctly) and write\r\nout the 2nd-last field of each record — in **11 lines of code**:\r\n\r\n main = line → L & L ← lines(nil, L) &\r\n {\"\\n\" & line → M & L ← lines(L, M)} & extract(L) & ''.\r\n line = field → F & {\",\" & field → G & F ← fields(G, F)} & F.\r\n field = strings | bare.\r\n strings = string → T & {string → S & T ← T + '\"' + S} & T.\r\n string = \"\\\"\" & (!\"\\\"\" & any)/'' → T & \"\\\"\" & T.\r\n bare = (!(\",\"|\"\\n\") & any)/''.\r\n extract(lines(Ls, L)) = extract(Ls) & extract_field(L).\r\n extract(L) = L.\r\n extract_field(fields(L, fields(T, X))) = print T.\r\n extract_field(X) = X.\r\n\r\nEvaluate an (admittedly trivial) S-expression based language in\r\n**15 lines of code**:\r\n\r\n main = sexp → S using scanner & reverse(S, nil) → SR & eval(SR).\r\n scanner = ({\" \"} & (\"(\" | \")\" | $:alnum/'')) using $:utf8.\r\n sexp = $:alnum | list.\r\n list = \"(\" & sexp/nil/pair → L & \")\" & L.\r\n head(pair(A, B)) = A.\r\n tail(pair(A, B)) = B.\r\n cons(A, B) = return pair(A, B).\r\n eval(pair(head, pair(X, nil))) = eval(X) → R & head(R).\r\n eval(pair(tail, pair(X, nil))) = eval(X) → R & tail(R).\r\n eval(pair(cons, pair(A, pair(B, nil)))) =\r\n eval(A) → AE & eval(B) → BE & return pair(AE, BE).\r\n eval(X) = X.\r\n reverse(pair(H, T), A) = reverse(H, nil) → HR & reverse(T, pair(HR, A)).\r\n reverse(nil, A) = A.\r\n reverse(X, A) = X.\r\n\r\nInterpret a small subset of Tamsin in\r\n**[30 lines of code](https://github.com/catseye/Tamsin/blob/master/mains/micro-tamsin.tamsin)**\r\n(not counting the included batteries.)\r\n\r\nFor more information\r\n--------------------\r\n\r\nIf the above has piqued your curiosity, you may want to read the specification,\r\nwhich contains many more small examples written to demonstrate (and test) the\r\nsyntax and behavior of Tamsin:\r\n\r\n* [The Tamsin Language Specification](https://github.com/catseye/Tamsin/blob/master/doc/Tamsin.markdown)\r\n\r\nNote that this is the current development version of the specification, and\r\nit may differ from the examples in this document.\r\n\r\nQuick Start\r\n-----------\r\n\r\nThe Tamsin reference repository is [hosted on Github](https://github.com/catseye/Tamsin)\r\nwith a [Mercurial mirror on Bitbucket](https://bitbucket.org/catseye/tamsin).\r\n\r\nThis repository contains the reference implementation of Tamsin, called\r\n`tamsin`, written in Python 2.7. It can both interpret a Tamsin program and\r\ncompile a program written in Tamsin to C.\r\n\r\nThe distribution also contains a (tiny subset of) Tamsin interpreter written\r\nin Tamsin, and a (tiny subset of) Tamsin-to-C compiler written in Tamsin.\r\nWe're still a ways from a fully bootrapped implementation, but we're getting\r\ncloser.\r\n\r\nWhile the interpreter is fine for prototyping, note that some informal\r\nbenchmarking revealed the compiled C programs to be about 30x faster. **Note**\r\nhowever that while the compiler passes all the tests, it is still largely\r\nunproven (e.g. its UTF-8 support is not RFC 3629-compliant), so it should be\r\nconsidered a **proof of concept**.\r\n\r\nTo start using `tamsin`,\r\n\r\n* Clone the repository — `git clone https://github.com/catseye/tamsin`\r\n* Either:\r\n * Put the repo's `bin` directory on your `$PATH`, or\r\n * Make a symbolic link to `bin/tamsin` somewhere already on your `$PATH`.\r\n* Errr... that's it.\r\n\r\n(Or, to make those steps trivial, you could use\r\n[toolshelf](https://github.com/catseye/toolshelf) and run\r\n`toolshelf dock gh:catseye/tamsin`)\r\n\r\nThen you can run `tamsin` like so:\r\n\r\n* `tamsin run eg/csv_parse.tamsin < eg/names.csv`\r\n\r\nYou can also compile to C and compile the C to an executable and run the\r\nexecutable all in one step, like so:\r\n\r\n* `tamsin loadngo eg/csv_extract.tamsin < eg/names.csv`\r\n\r\nDesign Goals\r\n------------\r\n\r\n* Allow parsers, static analyzers, interpreters, and compilers to be\r\n quickly prototyped. (And in the future, processor simulators and VM's\r\n and such things too.)\r\n* Allow writing these things very compactly.\r\n* Allow writing anything using only recursive-descent parsing techniques\r\n (insofar as this is possible.)\r\n* Allow writing parsers that look very similar to the grammar of the\r\n language being parsed, so that the structure of the language can be\r\n clearly seen.\r\n* Provide means to solve practical problems.\r\n* Keep the language simple — the grammar should fit on a page, ideally.\r\n* Recognize that the preceding two goals are in tension.\r\n* Have a relatively simple reference implementation (currently less than\r\n 3500 lines of code, including everything — debugging and the C runtime\r\n used by the compiler.)\r\n\r\nLicense\r\n-------\r\n\r\nBSD-style license; see the file [LICENSE](https://github.com/catseye/Tamsin/blob/master/LICENSE).\r\n\r\nRelated work\r\n------------\r\n\r\n* [CoCo/R](http://www.scifac.ru.ac.za/coco/) (parser generation)\r\n* [Parsec](http://www.haskell.org/haskellwiki/Parsec) (parser combinators)\r\n* [Perl](http://perl.com/) (rubbish listing)\r\n* [Prolog](https://en.wikipedia.org/wiki/Prolog) (pattern-matching, terms,\r\n backtracking(-ish...))\r\n* [K](https://github.com/kevinlawler/kona) (similar feel; Tamsin\r\n is a _vertical language_)\r\n* [Cat's Eye Technologies](http://catseye.tc)' esoteric and experimental\r\n languages:\r\n * [Squishy2K](http://catseye.tc/node/Squishy2K)\r\n * [Arboretuum](http://catseye.tc/node/Arboretuum)\r\n * [Treacle](http://catseye.tc/node/Treacle)\r\n","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."}⏎
|
|
0 |
{"name":"Tamsin","tagline":"Look! Up on Github! Is it a parser generator? Is it a programming language? Is it a rubbish lister? No... it's Tamsin!","body":"Tamsin\r\n======\r\n\r\nTamsin is an oddball little language that can't decide if it's a\r\n[meta-language](https://github.com/catseye/Tamsin/blob/master/doc/Philosophy.markdown#meta-language), a\r\n[programming language](https://github.com/catseye/Tamsin/blob/master/doc/Philosophy.markdown#programming-language), or a\r\n[rubbish lister](https://github.com/catseye/Tamsin/blob/master/doc/Philosophy.markdown#rubbish-lister).\r\n\r\nIts primary goal is to allow the rapid development of **parsers**,\r\n**static analyzers**, **interpreters**, and **compilers**, and to allow them\r\nto be expressed *compactly*. Golf your grammar! (Or write it like a decent\r\nhuman being, if you must.)\r\n\r\nThe current released version of Tamsin is 0.4; the development version is\r\n0.5-PRE. As indicated by the 0.x version number, it is a **work in progress**,\r\nwith the usual caveat that things may change rapidly (and that version 0.5 might\r\nlook completely different.) See [HISTORY](https://github.com/catseye/Tamsin/blob/master/HISTORY.markdown)\r\nfor a list of major changes.\r\n\r\nCode Examples\r\n-------------\r\n\r\nMake a story more exciting in **1 line of code**:\r\n\r\n main = (\".\" & '!' | \"?\" & '?!' | any)/''.\r\n\r\nParse an algebraic expression for syntactic correctness in **4 lines of code**:\r\n\r\n main = (expr0 & eof & 'ok').\r\n expr0 = expr1 & {\"+\" & expr1}.\r\n expr1 = term & {\"*\" & term}.\r\n term = \"x\" | \"y\" | \"z\" | \"(\" & expr0 & \")\".\r\n\r\nTranslate an algebraic expression to RPN (Reverse Polish Notation) in\r\n**7 lines of code**:\r\n\r\n main = expr0 → E & walk(E).\r\n expr0 = expr1 → E1 & {\"+\" & expr1 → E2 & E1 ← add(E1,E2)} & E1.\r\n expr1 = term → E1 & {\"*\" & term → E2 & E1 ← mul(E1,E2)} & E1.\r\n term = \"x\" | \"y\" | \"z\" | \"(\" & expr0 → E & \")\" & E.\r\n walk(add(L,R)) = walk(L) → LS & walk(R) → RS & return LS+RS+' +'.\r\n walk(mul(L,R)) = walk(L) → LS & walk(R) → RS & return LS+RS+' *'.\r\n walk(X) = return ' '+X.\r\n\r\nParse a CSV file (handling quoted commas and quotes correctly) and write\r\nout the 2nd-last field of each record — in **11 lines of code**:\r\n\r\n main = line → L & L ← lines(nil, L) &\r\n {\"\\n\" & line → M & L ← lines(L, M)} & extract(L) & ''.\r\n line = field → F & {\",\" & field → G & F ← fields(G, F)} & F.\r\n field = strings | bare.\r\n strings = string → T & {string → S & T ← T + '\"' + S} & T.\r\n string = \"\\\"\" & (!\"\\\"\" & any)/'' → T & \"\\\"\" & T.\r\n bare = (!(\",\"|\"\\n\") & any)/''.\r\n extract(lines(Ls, L)) = extract(Ls) & extract_field(L).\r\n extract(L) = L.\r\n extract_field(fields(L, fields(T, X))) = print T.\r\n extract_field(X) = X.\r\n\r\nEvaluate an (admittedly trivial) S-expression based language in\r\n**15 lines of code**:\r\n\r\n main = sexp → S using scanner & reverse(S, nil) → SR & eval(SR).\r\n scanner = ({\" \"} & (\"(\" | \")\" | $:alnum/'')) using $:utf8.\r\n sexp = $:alnum | list.\r\n list = \"(\" & sexp/nil/pair → L & \")\" & L.\r\n head(pair(A, B)) = A.\r\n tail(pair(A, B)) = B.\r\n cons(A, B) = return pair(A, B).\r\n eval(pair(head, pair(X, nil))) = eval(X) → R & head(R).\r\n eval(pair(tail, pair(X, nil))) = eval(X) → R & tail(R).\r\n eval(pair(cons, pair(A, pair(B, nil)))) =\r\n eval(A) → AE & eval(B) → BE & return pair(AE, BE).\r\n eval(X) = X.\r\n reverse(pair(H, T), A) = reverse(H, nil) → HR & reverse(T, pair(HR, A)).\r\n reverse(nil, A) = A.\r\n reverse(X, A) = X.\r\n\r\nInterpret a small subset of Tamsin in\r\n**[30 lines of code](https://github.com/catseye/Tamsin/blob/master/mains/micro-tamsin.tamsin)**\r\n(not counting the [included batteries](https://github.com/catseye/Tamsin/blob/master/doc/Philosophy.markdown#batteries-included).)\r\n\r\nCompile Tamsin to C in\r\n**[700 lines of code](https://github.com/catseye/Tamsin/blob/master/mains/compiler.tamsin)**\r\n(again, not counting the included batteries.)\r\n\r\nFor more information\r\n--------------------\r\n\r\nIf the above has piqued your curiosity, you may want to read the specification,\r\nwhich contains many more small examples written to demonstrate (and test) the\r\nsyntax and behavior of Tamsin:\r\n\r\n* [The Tamsin Language Specification](https://github.com/catseye/Tamsin/blob/master/doc/Tamsin.markdown)\r\n\r\nNote that this is the current development version of the specification, and\r\nit may differ from the examples in this document.\r\n\r\nQuick Start\r\n-----------\r\n\r\nThe Tamsin reference repository is [hosted on Github](https://github.com/catseye/Tamsin)\r\nwith a [Mercurial mirror on Bitbucket](https://bitbucket.org/catseye/tamsin).\r\n\r\nThis repository contains the reference implementation of Tamsin, called\r\n`tamsin`, written in Python 2.7. It can both interpret a Tamsin program and\r\ncompile a program written in Tamsin to C.\r\n\r\nThe distribution also contains a Tamsin-to-C compiler written in Tamsin. It\r\npasses all the tests, and can compile itself.\r\n\r\nWhile the interpreter is fine for prototyping, note that some informal\r\nbenchmarking revealed the compiled C programs to be about 30x faster. **Note**\r\nhowever that while the compiler passes all the tests, it is still largely\r\nunproven (e.g. its UTF-8 support is not RFC 3629-compliant), so it should be\r\nconsidered a **proof of concept**.\r\n\r\nTo start using `tamsin`,\r\n\r\n* Clone the repository — `git clone https://github.com/catseye/tamsin`\r\n* Either:\r\n * Put the repo's `bin` directory on your `$PATH`, or\r\n * Make a symbolic link to `bin/tamsin` somewhere already on your `$PATH`.\r\n* Errr... that's it.\r\n\r\n(Or, to make those steps trivial, you could use\r\n[toolshelf](https://github.com/catseye/toolshelf) and run\r\n`toolshelf dock gh:catseye/tamsin`)\r\n\r\nThen you can run `tamsin` like so:\r\n\r\n* `tamsin eg/csv_parse.tamsin < eg/names.csv`\r\n\r\nYou can also compile to C and compile the C to an executable and run the\r\nexecutable all in one step, like so:\r\n\r\n* `tamsin loadngo eg/csv_extract.tamsin < eg/names.csv`\r\n\r\nDesign Goals\r\n------------\r\n\r\n* Allow parsers, static analyzers, interpreters, and compilers to be\r\n quickly prototyped. (And in the future, processor simulators and VM's\r\n and such things too.)\r\n* Allow writing these things very compactly.\r\n* Allow writing anything using only recursive-descent parsing techniques\r\n (insofar as this is possible.)\r\n* Allow writing parsers that look very similar to the grammar of the\r\n language being parsed, so that the structure of the language can be\r\n clearly seen.\r\n* Provide means to solve practical problems.\r\n* Keep the language simple — the grammar should fit on a page, ideally.\r\n* Recognize that the preceding two goals are in tension.\r\n* Have a relatively simple reference implementation (currently less than\r\n 5 KLoC, including everything — debugging support and the C runtime\r\n used by the compiler and the Tamsin modules and implementations.)\r\n\r\nLicense\r\n-------\r\n\r\nBSD-style license; see the file [LICENSE](https://github.com/catseye/Tamsin/blob/master/LICENSE).\r\n\r\nRelated work\r\n------------\r\n\r\n* [CoCo/R](http://www.scifac.ru.ac.za/coco/) (parser generation)\r\n* [Parsec](http://www.haskell.org/haskellwiki/Parsec) (parser combinators)\r\n* [Perl](http://perl.com/) (rubbish listing)\r\n* [Prolog](https://en.wikipedia.org/wiki/Prolog) (pattern-matching, terms,\r\n backtracking(-ish...))\r\n* [K](https://github.com/kevinlawler/kona) (similar feel; Tamsin\r\n is a _vertical language_)\r\n* [Cat's Eye Technologies](http://catseye.tc)' esoteric and experimental\r\n languages:\r\n * [Squishy2K](http://catseye.tc/node/Squishy2K)\r\n * [Arboretuum](http://catseye.tc/node/Arboretuum)\r\n * [Treacle](http://catseye.tc/node/Treacle)\r\n","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."}⏎
|