[Leaplist] How many of you use awk?

Jesse Goerz jgoerz at cfl.rr.com
Sun Apr 22 18:06:12 EDT 2007


On Sun, 2007-04-22 at 14:11 -0400, Steve Litt wrote:
> On Sunday 22 April 2007 09:02, Jesse Goerz wrote:
> 
> > 7.  It's a fantastic code generator
> > In no time at all you can create a _simple_ "specification language"
> > that you parse with awk and using functions, turn into, well, whatever
> > you want...  I used this technique at my old job, parsing csv files that
> > had border values (supplied by system engineers) into test programs that
> > tested those values.
> 
> Hi Jesse,
> 
> I'd REALLY like to hear more about your point #7. 
> 
> I tried to rewrite my EMDL to UMENU parser in awk, and although it worked, 
> inserting the error and warning detection got too complicated (and I ran out 
> of time). Reading your point #7, perhaps there's a different/better way to do 
> it. My EMDL to UMENU parser, is, in my opinion, on a per-line basis the most 
> complex and challenging code I ever wrote. I've written it in Perl twice (the 
> first version was an affront to the concept of development), and now in awk.
> 
> SteveT

I really tried to simplify it.  I'm not familiar with EMDL so I'm not
sure if it will work.  Here's what happened.

I had to test a GUI interface.  It is so old that it is character based
(not pixel based).  It was reading values from a model that we could
manipulate through another interface.  That interface allowed us to
write test programs to change the model in a timed sequence.  I asked
the modeler (the person in charge of creating/maintaining the models) to
send me the program she used in the past to do these kind of sequences.
It was in a proprietary language but it was simple enough to figure out.
Now the system engineer wanted the GUI to turn different colors in
different places depending on the values in the model.  So I asked him
to give me a csv file with the location, colors, and values.  I parsed
the csv file using awk and generated the program file using a template I
created from the example the modeler sent me.  Rather than get fancy
with data structures and looping, the code generated was very simple
(not optimized) and simply unrolled any loops and generated the code
line by line.  

That is pretty much it.  I actually thought it was a "throw away"
technique but everyone was really impressed by it.  If you want a really
good reference on code generation I recommend "Code Generation in
Action."  It's where I learned about code generation and got infected.

If what you're doing is complex, I would suggest considering XML.  It's
actually simpler than most people make it, writing your own dtd isn't to
bad, and once you do that, there are a ton of tools you can use to
validate, parse, etc.  The validation part (think tidy) really makes
debugging your input/output a lot easier.  I have finals next week, but
maybe once that is over, I'll take a look at your EMDL web page and
explore.  It's been a while since I've done something fun.

hth,
Jesse



More information about the Leaplist mailing list