From: Fredrik Karlsson on 25 Apr 2010 05:47 Dear list, sorry for starting a new thread related to another one, but I thought the header of this one: http://groups.google.se/group/comp.lang.tcl/browse_thread/thread/ce4c91dd1593a3cb would be misleading. I am looking for a combination of lexer / parser generator that 1) outputs a Tcl parser / Lexer (of some sort) 2) works well together 3) handles UTF-8 without problems (I guess this is generally not a big problem) 4) has some kind of documentation that would enable to learn how to use it. So, any suggestions? /Fredrik
From: Gerald W. Lester on 25 Apr 2010 08:43 Fredrik Karlsson wrote: > Dear list, > > sorry for starting a new thread related to another one, but I thought > the header of this one: > http://groups.google.se/group/comp.lang.tcl/browse_thread/thread/ce4c91dd1593a3cb > would be misleading. > > I am looking for a combination of lexer / parser generator that > > 1) outputs a Tcl parser / Lexer (of some sort) > 2) works well together > 3) handles UTF-8 without problems (I guess this is generally not a big > problem) > 4) has some kind of documentation that would enable to learn how to > use it. > > So, any suggestions? > > /Fredrik Since you are asking for recommendations.... I like to use the Tcl parser itself. Structure my new language so it fits inside of the Tcl syntax (the 11 rules). Then use an safe interpreter with just commands/aliases for my new language to evaluate programs in the language. This meets all of your above criteria. -- +------------------------------------------------------------------------+ | Gerald W. Lester | |"The man who fights for his ideals is the man who is alive." - Cervantes| +------------------------------------------------------------------------+
From: Arjen Markus on 26 Apr 2010 03:04 On 25 apr, 14:43, "Gerald W. Lester" <Gerald.Les...(a)cox.net> wrote: > Fredrik Karlsson wrote: > > Dear list, > > > sorry for starting a new thread related to another one, but I thought > > the header of this one: > >http://groups.google.se/group/comp.lang.tcl/browse_thread/thread/ce4c... > > would be misleading. > > > I am looking for a combination of lexer / parser generator that > > > 1) outputs a Tcl parser / Lexer (of some sort) > > 2) works well together > > 3) handles UTF-8 without problems (I guess this is generally not a big > > problem) > > 4) has some kind of documentation that would enable to learn how to > > use it. > > > So, any suggestions? > > > /Fredrik > > Since you are asking for recommendations.... > > I like to use the Tcl parser itself. Structure my new language so it fits > inside of the Tcl syntax (the 11 rules). Then use an safe interpreter with > just commands/aliases for my new language to evaluate programs in the language. > > This meets all of your above criteria. > > -- > +------------------------------------------------------------------------+ > | Gerald W. Lester | > |"The man who fights for his ideals is the man who is alive." - Cervantes| > +------------------------------------------------------------------------+- Tekst uit oorspronkelijk bericht niet weergeven - > > - Tekst uit oorspronkelijk bericht weergeven - In general I agree with Gerald, but that presumes that you have some control over the format of the data that you are reading. Could you, Fredrik, explain the kind of data you want to parse? There exist numerous specialised solutions, for instance for XML, HTML or CSV files. If you have control over the format of the data, then design the format as if it were Tcl code. One simple example - book titles: book "J.Ousterhout" "Tcl and the Tk Toolkit" book "B.Welch" Practical Programming in Tcl and Tk" book "C. Flynt" "Tcl/Tk: A Developer's Guide" proc book {authors title} { global book_data global book_number set book_data(authors,$book_number) $authors set book_data(title,$book_number) $title incr book_number } Just a silly example, but that way your data can be interpreted as Tcl commands. Regards, Arjen
From: tom.rmadilo on 26 Apr 2010 16:17 On Apr 25, 2:47 am, Fredrik Karlsson <dargo...(a)gmail.com> wrote: > Dear list, > > sorry for starting a new thread related to another one, but I thought > the header of this one:http://groups.google.se/group/comp.lang.tcl/browse_thread/thread/ce4c... > would be misleading. > > I am looking for a combination of lexer / parser generator that > > 1) outputs a Tcl parser / Lexer (of some sort) > 2) works well together > 3) handles UTF-8 without problems (I guess this is generally not a big > problem) > 4) has some kind of documentation that would enable to learn how to > use it. > > So, any suggestions? > > /Fredrik The link in the other thread talked about using templates to write code. You might be interested in a Tcl-like templating language/compiler: http://junom.com/gitweb/gitweb.perl?p=tnt.git;a=tree;f=packages/view Documentation and examples are live here: http://junom.com/document/twt/view/ (see www/README) The templating language allows you to write exact text, such as programming code or nicely formatted HTML. Although it may not be important for your application, templates are "safe" Using Arjen's example, you could do: [set data {J.Ousterhout {Tcl and the Tk Toolkit} B.Welch "Practical Programming in Tcl and Tk" "C. Flynt" "Tcl/Tk: A Developer's Guide"}/] [set book_number 1/] [foreach {author title} $data /] [set book_data(authors,$book_number) $author /] [set book_data(title,$book_number) $title /] [incr book_number /] [/foreach/] If this is stored in books.tmpl, then you could compile this into a Tcl script: $ ./tcompile < books.tmpl > books.tcl $ tclsh % source books.tcl % array get book_data J.Ousterhout {Tcl and the Tk Toolkit} B.Welch "Practical Programming in Tcl and Tk" "C. Flynt" "Tcl/Tk: A Developer's Guide" None of the commands in the above script actually generate output and whitespace is suppressed by the tag ending /]. But you could write a proc template given params: [set proc myproc/] [set args {name {{age 10}}} /] [set body { puts "$name is $age years old" }/] proc $proc {[join $args]} {$body} Note that if the variables are already set in the Tcl interp, you only need the last line in the template file.
|
Pages: 1 Prev: Running interactive script Next: "string is dict"? How to get that? |