When the TCL script data file format is written in front, when I saw this article on the forum, I was impulsive, issued a post: Let me try. After I really saw the original text, I regret it, I am not afraid of work Big, just worry whether this article can express this article in accordance with the author's meaning. Not afraid of jokes, before this, I almost have heard of TCL (only TCL ---- ace), more Don't have to say it. There is no way, you can only learn to sell. I found the article on the online introduction of TCL. I learned it carefully. I can only understand it. I don't understand it. I am now on the computer. It's really tired, because as a system administrator, there are updates every day waiting for you to learn, you must keep the geography, but you can't have a tablet, otherwise you will face the danger of being eliminated, sometimes true It feels very tired, but there is no way, this is life, you said to a thick book, I see you nausea, I don't want to touch you. But sleep, you have to take it as A good teacher, a friend. My English level is general, and the TCL language is a new thing for me, although there is a certain understanding, but some of the terms, I still understand it is not thorough enough. All translations The place may make everyone feel confused, may even have a bit ridiculous, please understand this. I hope that some experts can point out the mistakes in the translation. Don't let me influence the learning of all netizens. At the same time, I hope everyone will give everyone I am letter, make friends, and improve together. My email: zkzxl@etang.com I don't know if my translation is coming out, I have already translated it, I hope to communicate with each other. ********** *********************************************************** ******************* TCL Script Data File Format Introduction A typical TCL script saves its internal data in list and arrays (two main data structures in TCL) ). For example, assume that you want to write a TCL application that can save the data first on the disk, then read the TCL application, which will allow your users to save a project first, and then reload. You need One way, writing data from its internal storage (list and array), and also, there is also a way to read data from the file to the running script. You can choose The data is saved as a binary format or text format. This article discusses only the text format, we will consider several possible data formats and how to use TCL to analyze. We will specifically introduce some simple skills to make text file analysis easier. This article assumes that you are familiar with the TCL language, at least have written a few scripts in the TCL language. ▲ A simple example assumes that you have a simple drawing tool, you can put the text and rectangles on the canvas In order to save the picture, you need a file that must be readily read, the first to think of the most, the easiest file is like this: example1 / datafile.datRectangle 10 10 150 50 2 BlueERECTANGLE 7 7 153 53 2 Bluetext 80 30 "Simple Drawing Tool" c red The first two lines of this file represent the data for two blue, horizontally stretched rectangles with a line thickness of 3. The final line places a piece of red text, anchored at the center (hence the "c"), in the middle of the two rectangles. The front two lines of the file represent the two blue horizontal expansion rectangles, the line width is 2 (3 this is 3, which may be a pen error, the translator's note). final A red text is placed in the center (specified by "C") ---- in the middle of the two rectangles. Save your data with text files make the program's debugging, because you can check the program output To ensure that everything is normal.
It also allows users to manually modify saved data (so may be good, maybe it may be good, depending on your intention). When you read this format, you may have to analyze the file first and then create data Structure. When analyzing files, you have to try one line in a line, using tools like regexp to analyze the different parts of the text. Below is a possible process: example1 / parser.tclcanvas .cpack .c set fid [Open "datafile. DAT "r] While {! [EOF $ FID]} {# read a line from the file and analyze it.gets $ FID line if {[regexp / {^ Rectangle ([0-9] ) ([0 -9] ) ([0-9] ) ([0-9] ) ([0-9] ) (. *) $} / $ Line Dummy X1 Y1 x2 Y2 Thickness Color] } {.c Create Rectangle $ x1 $ y1 $ x2 $ y2 -width $ thickness -outline $ color} elseif {[regexp / {^ text ([0-9] ) ([0-9] ) ("[^"] * ") ([^] ) (. *) $} / $ line dummy xy txt anchor color]} {.c create text $ y -text $ txt -genchor $ anchor -fill $ color} elseif {[regexp {^ * $} $ line]} {ignore blank lines} Else {PUTS "error: unknown keyword."}} Close $ FID We read a line of data, using regular expressions Finding the line representative is a certain data type. By checking the first word, we can distinguish between representative of data and data on behalf of text, so the first word is a keyword, which clearly tells us that we are dealing with What type of data. Similarly, we analyze the coordinates, colors and other properties of each project. The packet part of the regular expression in parentheses enables us to find the result of the variable 'x1', 'x2', etc., if you know the regular expression While work, this is a very simple implementation. But I think it is difficult to maintain, and the regular expression makes it difficult to understand. There is also a more simple solution, called "ACTIVE File (active document) ". It was originally thought of by Nat Pryce in design samples. This method is based on a very simple offer: with its TCL to write the grammar analyzer (with regexp or other means), why don't you let TCL's grammatical analyzer to do these jobs? ▲ Active document design samples are explained to this design sample, we continue to use the simple drawing tools in the previous section. First we write two processes in Tcl, a painting rectangle, a writing text. example2 / parser.tclcanvas .cpack .c proc d_rect {x1 y1 x2 y2 thickness color} {.c create rectangle $ x1 $ y1 $ x2 $ y2 -width $ thickness -outline $ color} proc d_text {xy text anchor color} { .c create text $ x $ y -text $ text -anchor $ anchor -fill $ color} Now you have to draw on the canvas, we call these two processes, each time you call one. For example, you need to draw the graphics described above, you need the following three calls.
Example2 / DataFile.datd_Rect 10 10 150 50 2 Blued_Rect 7 7 153 53 2 Blued_text 80 30 "Simple Drawing Tool" C Red looks familiar? The code for calling the process looks almost exactly the same as the code we analyzed. The only difference is that the keyword is "Rectangle" and "text" becomes "D_Rect" and "D_Text". Now we have seen the Sample Tips: To analyze the data file, we have to treat it as a TCL script. Treat it. We only put the call to us in a file, and use this file as a data file. The core of design samples is that the data file actually contains calls to the TCL process. Analyzing data files are now too easy: SOURCE "DataFile.dat" built-in TCL command source read files, analyzes and executes commands in the file. Because we have completed the D_Rect and D_Text procedures, the source command will automatically call these two processes with the correct parameters. We will d_rect And D_Text calls the analysis process. We don't have to do anything, don't have a regular expression, don't use a line to loop, don't turn on / off. Just call the source command to complete all work. The data file has become a TCL script that can be executed. Because it is an executable command, not just passive data, it is called active file. Active file can be running normally in most scripting locale, NAT Pryce's homepage has a detailed description. ▲ Use the advantages of the active file sample: No need to write an analyst, Source calls the TCL analysis program to complete. Easy to read the data file format. Use the shortcomings of the active file sample: If the data file contains a dangerous command, like L -A EXEC RM *, which will bring serious consequences after they execute. Solving this problem is to perform active files in safe mode to prevent dangerous commands. Specific information can be found in the "Security Interpreter" section in the TCL manual. ▲ Limitations of active file samples This sample is not valid for all possible data formats. The data format must be based on behavioral, each line must start with a keyword. The TCL process is started with the keyword, turning the passive keyword into active command.
This also means that you can't use keywords like IF or WHILE, because TCL does not allow you to write the process with such names. In fact, I change the keyword to d_text in fact, because of the development kit There is already a reserved word text, which is used to create text tools. ▲ English speech until we can write a simple file format: D_Rect 10 10 150 50 2 Blued_Rect 7 7 153 53 2 Blued_text 80 30 "Simple Drawing Tool "C RED We have a very simple analysis program, which is two analysts and SOURCE commands. Now let's take a look at how to improve. When you observe a lot of such data, it is easy to be confused by data. First The line contains 10 10 110 50 3, you have some experience in this area, you can quickly understand the first two represent a coordinate, the next two is another coordinate, the last one is the line width. We can use additional text in the data. Method to make a programmer more easily when reading .Example3 / datafile.datd_rect from 10 TO 150 50 Thick 2 CLR BLUED_RECT FROM 7 7 TO 153 53 Thick 2 Cl R BLUED_TEXT AT 80 30 "Simple Drawing Tool" Anchor C CLR Red Word To and from, parameter name Thick and Color make the data more like English sentences, in order to adapt to these messes, our analysis process requires additional parameters: eXample3 / parser.tclproc D_Rect {from x1 y1 to x2 Y2 Thick Thickness ClR Color} {.c Create Rectangle $ x1 $ y1 $ x2 $ y2 -width $ thickness -outline $ color} As you can see, the execution process has not changed. The new parameter is not used in the process body; its purpose is only It is to use data readability. Then follow the option name, then it is its value) and standardized (many other TCL extensions use the same syntax to configure their part). After using the option / value pair, the data file looks like this: example4 / datafile.datd_Rect -x1 10 -Y1 10 -X2 150 -Y2 50 -Thickness 2D_Rect -Thickness 2 -X1 7 -Y1 7 -X2 153 -Y2 53D_Text -x 80 -y 30 -Text "Simple Drawing Tool" -anchor c -color red is analyzed, we need to analyze process D_Rect and D_Text Introduced option / value pair, we first try to use matte varies with English process. Proc D_Rect {OPT1 X1 OPT2 Y1 OPT3 X2 OPT4 Y2 OPT5 Thickness Opt6 Color} {.c Create Rectangle $ x1 $ y1 $ x2 $ y2 -width $ Thickness -Outline $ Color} We have seen it again that the process of implementation has not changed. Although this solution is only valid for the simplest data format, it is very clear. It has two advantages: options in the parameter list The location is fixed. For example, you cannot put the color (color property) in front of Thickness. This method is not bad for a pure data file format (because the numerical is stored in the same order), But when you want to enter the manually input data in the script, this method has become an obstacle. The option does not have the default value: You must provide the value of all options, and you cannot miss any one. Below is a solution to all Problem process. EXAMPLE4 / PARSER.TCLPROC D_RECT {Args} {# First {args} {# first, Specify Some Defaultsset A (-Thickness) 1set A (-color) Blue # THEN, 'PARSE'
THE User-Supplied Options and ValuesArray Set A $ args # create the recrestangle.c Create Rectangle $ A (-X1) $ a (-y1) $ a (-x2) $ a (-y2) / -width $ a (- Thickness) -outline $ a (-color)} Different from using a long parameter table, the analysis process now has only one parameter named Args, which is used to collect all actual parameters when the calling process is collected. Parameters x1, Y1, etc. It disappeared. They are now handled by a partial array. We will explain the center. The first part of the code sets the default value, the second part analyzes the option / value pairs in the ARGS. Trip processing module It is very good for this. It first creates a new entry in the array A, use the option name (including the front guide "-") as an index, and select the value as an array value. If the user is not specified in the call - The COLOR option, the default value of the entry of A (-Color) remains unchanged. Instead of using an array entry instead of the process parameters, the last line in the process body is the same as the previous implementation. If the user calls, forget the specified option -X1, then -x1 The array entry will not be set (without its default), creating a rectangular call will trigger an error. In this case you can specify the default value for some options, allowing it to choose, while others do not specify the default Value, forced it must be specified by the user. ▲ The best format is usually the combination of various methods Now we have understood the common methods of TCL data files (active files, English processes, options / value pairs), we can The respective advantages combination into a separate data format. For mandatory options, we use fixed position parameters to enhance readability with diometric words (see English-language process). And all options option It is advisable to use the option / value pair mechanism, so that the user can empty the option or change its location when calling. Finally, the data file may be like this: D_Rect from 10 TO 150 50 --Thickness 2D_Rect from 7 7 To 153 53-THICKNESS 2D_TEXT AT 60 30 "Simple Drawing Tool" -anchor c -color red assumes that the default value of all items is "blue". As a personal habit, I usually write such a command: D_Rect / From 10 / to 150 50 / -THICKNESS 2D_RECT / FROM 7 7 / TO 153 53 / -THICKN ESS 2D_Text / AT 80 30 "Simple Drawing Tool" / -anchor C / -Color Red i Find It Slightly More Readable, But Taste (or in My Case Lack of Taste :-). I think readable Sex, but this is just a personal preference problem. (Or in my copy lack of taste) (this sentence is the author is ridicuing himself, but I don't know how to translate it. Which heroes help points. , Translator's note) -------------------------------- ----------------------------------- ▲ More complex data so far, we have been very simple The example contains examples of rectangular and text. This data format is very easy to read and analyzed with active file design samples. Now let's look at a more complex data format to explain more "advanced" advanced " "The skill. This will make you an expert in using TCL data file format. ▲ Data Warehouse Tool I have collected design samples in the past, form a sample library, each has a short instructions and some properties. I still Remember the name of the book, the author and the ISBN number, as a reference, as a reference to the future. In order to record all of this information, I wrote a data warehouse tool with TCL. The main function is to put the sample according to the category and level Classify, point out each sample in the book and tell the page number. This tool is in touch with this: # First,
I introduce some books you can find a good design sample and the custom writing method when designing the program. Each book, # Each URL, or other sample resources are specified in the keyword "source", followed by a unique labels and other attachment # additional information Source GOF {Design patternsElements of reusable object-oriented softwareGamm, Helm, Johnson, VlissidesAddison-Wesley, 19950 201 63361 2} Source SYST {A system of patternsPattern-oriented software architectureBuschmann, Meunier, Rohnert, Sommerlad, Stalwiley, 19960 471 95869 7} # Next, I introduce some categories, in order to make it easier to find the sample, I want to group the sample. Each category # has a name (such as "Access Control) and a short description .Category "Access control" {How to let one object control the access to one or moreother objects.} Category "Distributed systems" {Distributing computation over multiple processes, managingcommunication between them.} Category "Resource handling" {Preventing memory leaks, managing RESOURCES.} category "structrain" {to BREAK Monoliths Down INTO Indpendent Components.} #, I introduced the sample itself, each has a name, belonging to one or more categories, appearing in the above - the list of resources One or more. Every sample is level, may be "Arch" (for structural samples), # "design" represents a smaller scale design sample, "iDiom" representative language specified sample.pattern "Broker" {Categories {"distributed systems"} Level Arch Sour CES {SYST: 99}; # This means that this sample is in books marked "SYST". { "Access control" "Structural decomposition :: object"} Level design # Both these books talk about the Proxy pattern: Sources {SYST: 263 GOF: 207} Info {. Communicate with a representative rather than with theactual object}} pattern " Facade "{Categories {" Access control "" Structural decomposition :: object "} Sources {GOF:. 185} Level designInfo {Group sub-interfaces into a single interface}} Pattern" Counted Pointer "{Categories {"
Resource Handling "} Level IDiomsources {SYST: 353} Info {Reference Counting Prevents Memory Leaks} This is only part of the input file I originally written, but it still contains enough data to be used as a better example. Sample The description is very short, there is a little clumsy, but it is enough for this example. As you can see, a few new features of this data file: ▲ Data is included in some structures, parentheses {} Each structure is starting with a keyword. These structures can be nested, such as structure "pattern" can include a "info" structure. ▲ The elements in the structure can be used in many forms.
Some of them are markers or strings (such as elements "level"), others look like a special code (such as SYST: 353), and some even free format text (such as Category and INFO) The order of the elements in each structure is arbitrary. Observe that the last two samples will find that the order of the two elements of Level and Sources can be interchanged. All elements can actually press what you want. The order of order. ▲ Data file contains TCL comment statements, but can not only appear between structures, but can even appear inside the structure. Note statements can make your data more easily understand. You may want this format than the previous example It's much more complicated, using the Tcl language to write a parser for it almost impossible. It may seem to be too clear, we can also use the active documents to make this more simple. Analysis (parsing) process is more than the previous Thin, but it is not "complex". Below is my analysis of my analysis as the above data file: # We put data in the following three lists: set l_patterns [list] set l_sources [list] set l_categories [list] # 我们There is also a need for a variable to track our current PatterN structure set curpattern "" "The following is the keyword" source "analysis process. # As you can see, the keyword is followed by a ID number (Sowce's only sign ), there is described of source text # .proc Source {id info} {# Remember that we saw this source.global l_sourceslappend l_sources $ curSource # Remember the info of this source in a global array.global a_sourcesset a_sources ($ curSource, info ) $ info} # The parsing proc for the 'Category' keyword is similar.proc Category {id info} {global l_categorieslappend l_categories $ curCategory global a_categoriesset a_categories ($ curCategory, info) $ info} # This is the parsing proc for the ' P attern '. keyword # Since a' Pattern 'structure can contain sub-structures, # we use' uplevel 'to recursively handle those.proc Pattern {name args} {global curPatternset curPattern $ name; # This will be used in the sub- structures # which are parsed nextglobal l_patternslappend l_patterns $ curPattern # We treat the final argument as a piece of TCL code. # We execute that code in the caller's scope, to parse the elements # of the structure. # 'uplevel' will call 'Categories ',' Level 'and other commands That # handle the sub-structures. # This is similar to how we use the' source '
Command to Parse The Entire # data file.uplevel 1 [Lindex $ args end] set curpattern "} # the Parsing proc for one of the sub-structures. It is caled # by 'upded' when the 'Pattern' Keyword Is Handled .proc Categories {categoryList} {global curPattern; # We access the global variable 'curPattern' # to find out inside which structure we are.global a_patternsset a_patterns ($ curPattern, categories) $ categoryList} # The following parsing procs are for the other sub-structures # of the Pattern structure proc Level {level} {global curPatternglobal a_patternsset a_patterns ($ curPattern, level) $ level} proc Sources {sourceList} {global curPatternglobal a_patterns # We store the codes such as. 'SYST: 99' in a global array. # My implementation uses regular expressions to extract the source tag # and the page number from such a code (not shown here) .set a_patterns ($ curPattern, sources) $ sourceList} proc info {info} {global curPatternglobal a_patternsset A_Patterns ($ Curpattern, Info) $ INFO} This program is better than We do more in a relatively simple drawing example. But considering the functionality of this method, only a few analytics processes and flexible use of the command "UPLVEL", we can also analyze the complex structure, note, nesting Data file of structure and free format text data. Imagine how difficult it will be more difficult to write from the header. The data is parsed by the process of Source, Pattern or INFO. The parsed data is stored inside three lists and three Among the arrays. The nested data of the data is processed by calling UPLVEL.
Use variables Curpattern to remember our current location. To note that this method requires your data to understand TCL syntax. This means that braces should be placed in the end, not the beginning of the next line. ▲ Recursive structure In the sample of the warehouse, the structure of the Pattern type contains other types of sub-structures such as INFO and SOURCES. So how do a structure contains the same type of sub-structure? In other words, how do we handle recursive structures? For example, you want to describe an object-oriented system design, the design and implementation .example6 / datafile.dat # description of recursive subsystem of an object-oriented video gameSystem VideoGame {system Maze {system Walls {Object WallGeneratorObject TextureMapper} system Monsters {Object FightingEngineObject Monstermanipulator}}} system score {object scorekeeper}} To track which System system structure we are currently in, it seems that we need not only a global variable currpattern. At any time of the analysis, we may be in many nesting System structures. Therefore, we need more than two variables. We may need some kind of stack, pressing a value while encountering the SYSTEM process, playing again at the end of the process. We can construct such a stack with a TCL list. But if You don't want to maintain a stack, you can also use it. This method is based on a very simple suggestion: When you need to use a stack, see if you can use the function call stack. When you process recursive data, I usually use this. a method to achieve my analysis of .example6 / parser.tclset currSystem "" proc System {name args} {# Instead of pushing the new system on the 'stack' of current systems, # we remember it in a local variable, which Ends Up on Tcl's # function call stack.global currsystem setset tmpsystem $ currsystemset currstem $ name; # Thanks to this, all sub-structures called by # 'uplevel' will know what the name of their # immediate parent System is # Store the system in an internal data structure # (details not shown here) puts "Storing system $ currSystem" # Execute the parsing procedures for the sub-systemsuplevel 1 [lindex $ args end] # Pop the system off the 'stack' again.set currSystem $ tmpSystem} proc Object {name} {global currSystem # Store the object in the internal data structure of the current # system (Details Not Shown Here) Puts "System $ Currsystem Contains Object $ Name"} Source "DataFile.dat"
Starting with the nested system name in a stack (the stack is simulated by the TCL list or array), we only store the object name in a local variable named TMPSYSTEM. Since the resolution process will be based on the TCL The order is automatically called, and we don't have to reverse the / pop up any data. And generate a pure HTML file. This document contains a core list, formatted text, and other HTML elements. The analysis process calls the UPLVEL process recipient structure. The following is part of DON code, tell you how he applies this article tells the skills. # Output preformatted text. This text must be surrounded by '
' tags. # Since it can recursively contain other tags such as '' or hyperlinks, # the procedure uses 'uplevel' on its final argument.proc cgi_preformatted {args} {cgi_put "" if {[llength $ args]} {cgi_put "[cgi_lrange $ args 0 [expr [llength $ args] -2]]" } cgi_puts ">" uplevel 1 [lindex $ args end] cgi_close_proc} # Output a single list bullet.proc cgi_li {args} {cgi_put1} {cgi_put "[cgi_lrange $ args 0 [expr [LLENGTH $ ARGS] -2]] "} cgi_puts"> [lindex $ args end] "} # outprust a bullets, represented # by calls to 'cgi_li' Above. Those Calls Aree Executed Thanks # To 'uplevel'.p ROC CGI_BULLET_LIST {Args} {CGI_PUT " " IF {[LLENGTH $ Args]> 1} {cgi_put "[CGI_LRANGE $ ARGS 0 [EXPR [LLENGTH $ ARGS] -2]"} CGI_PUTS ">" UPLVEL 1 [Lindex $ args end] cgi_close_proc} I don't want to explain this large library details, you can download it from Don's homepage. --------- -------------------------------------------------- -------------------- As another example, my Todl tool uses the analysis process of the class and method to analyze the design of the surface object. Below is my tool An example of a input file: # Todl Schema for Module 'Shapes'
. It describes classes for some # geometrical shapes such as rectangles and squares odl_module shapes {######## Classes # Base class for all shapes.class shape {} {attr id 0;. # Attribute 'id' is inherited by all shapes # and has default value 0.} # Rectangle with a width and height. # Inherits from 'shape'.class rect {shape} {attr w 10attr h 10 # Some methods to calculate properties for the shape, # and to Draw it on the screen.method "" Perimeter {} method "" area {} method "" DRAW {x {y 0}}} class square {shape} {... ##}} ## ###### Module Parameters # all classes Automatic Get A 'print' Method.Param all {print} # name of the 'delete' proc.param delete_name delete # we want debugging output: param debug 1} After viewing this file Can you point out a list of all analysts? --------------------------------------- ----------------------------------------- I used to write for C classes One (very) simple parser. Because it is too lazy, I use the TCL language. It turns out that it is too complicated, but it shows the powerful function of the active file sample. Let's take a look at this included complicated C data file: Class MyListelt: Public Clistelt, Private FString {This is a documentation string for the class' myListElt'.You can see multiple inheritance here.} {Public:. Method int GetLength (void) {This is a documentation stringReturns the total length of the FString} {// This is the final argument of the 'method' parsing proc.// It contains freeform text, so this is where I can write // pure C code, including the comment you are now reading.return myLength;} method char * GetString (void) {Returns The Complete FString.} {Append (0); return (char *) data;} private: Method Virtual Void PrivateMethod (Short Int P1, Short Int P2) {Note That Just Saying "Short"
IS Not Enough: You Have to Say "Short Int".} {printf ("Boo! P1 =% D, P2 =% D / N", P1, P2);}} Data Short Int B {this Is Just A Counter } data void * somePointer {to store the end-of-list or something like that} method void error (short int errNo, char * message) {This is a global library procedure, whichreports an error message.} {cout << " Hey, There Was An Error ("<< Errno <<" "<< Message << Endl;} CPP_REPORT This example may be stronger, but it shows powerful features of the active file sample. You see the TCL code, But it looks like a C code, it can automatically generate documents, class diagrams, programming references, and of course there is compilament C code. The resolution process is like a method and class to store C in the internal TCL data structure, and finally, Call CPP_REPORT Generate the final C code. The following from the analyzer's program segment means you can read files similar to C syntax. # Parsing procuments: # - class name # - Class Name # - list of inheritance specifications, optional # - comment block # - body blockproc class {args} {global _cpp # split names from signs like:, * set cargs [expand [lrange $ args 0 [expr [llength $ args] - 3] ] # -3 To avoid the comment block and the class body. # First process the nameset classname [lindex $ cargs 0] if {$ _CPP (CL) == "} {set _CPP (CL ) $ ClassName; # This is like 'currPattern' in the # pattern repository example} else {error "Class definition for $ className: we are already inside class $ _cpp (CL)"} # Then process the inheritance arguments # Obvisouly,. THIS Already a lot more complicated trion one inh # previous example.set inhr [list] set mode before process {i == ": {¥ $ ==": {¥ $ == ": {¥ $ ! = "BeforeColon"} {Error "misplaced /": / "in declaration /" Class $ ClassName $ Restargs / "} set mode aftercolon} elseif {$ arg =
= "public" || $ arg == "private"} {if {$ mode! = "instercolon"} {error "misplaced /" $ arg / "in declaration /" class $ classname $ restargs / "} set Mode $ arg} elseif {$ arg == ","} {if {$ mode! = "insterinherit"} {error "misplaced /", / "in declaration /" class $ classname $ restaurants / "} set mode aftercolon} Else {if {$ mode! = "public" && $ mode! = "private"} {error "misplaced /" $ arg / "in declarative /" class $ classname $ restargs / "} if {! [isid $ arg ]} {warning "$ arg is not a valid c identifier ..."} lappend inhr [list $ mod $ arg] set mode! = "instryinherit" && $ mode! = "before arch"} {error "Missing something at end of declaration /" class $ className $ restArgs / ""} set _cpp (CLih) $ inhrset _cpp (CLac) "private" # First execute the comment blockuplevel 1 [list syn_cpp_docClass [lindex $ args [expr [LLENGTH $ ARGS] - 2]] #1 EXECUTE THE BODYUPLEVEL 1 [LIST SYN_CPP_BODYCLASS [LINDEX $ Args End]] Set_CPP (CL) "" SET _CPP (CLIH) ""} - --------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- ---- About lazy Press Larry Wall, the most important potential of a good programmer is lazy. That is to say, there is a creative lazy. This article mentioned two suggestions, they can be attributed to one thing: lazy. When you need a parser, use an off-the-shelf parser to modify your file format to create the requirements of the analyzer (of course, you have reached the realm of free choice of file format)) When you need to use a stack, you can Call the stack with ready-made functions, forget the press, pop up, and other operations. "Reuse" does not only indicate the hidden in packages and information. Sometimes it only means laziness. -------------- -------------------------------------------------- ------------------ Data file formats for TCL scripts original author: Koen Van Damme
Chinese translator: John Silver