please rate
this thread
  •  
  • Subject
  • Author
  • Date
Posted by Jim Thompson on June 6, 2009, 12:01 am
  On Fri, 05 Jun 2009 18:05:02 -0800, "Paul Hovnanian P.E."


Thanks!  I'll check that out!

                                        ...Jim Thompson
--
| James E.Thompson, P.E.                           |    mens     |
| Analog Innovations, Inc.                         |     et      |
| Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    |
| Phoenix, Arizona  85048    Skype: Contacts Only  |             |
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  |
| E-mail Icon at http://www.analog-innovations.com |    1962     |
            
 I love to cook with wine     Sometimes I even put it in the food

Posted by Mike on June 6, 2009, 5:28 pm
 
There are two very good introductory tutorials for regular expressions. The
first is by Tom Christiansen, one of the Perl gurus. His description was a
usenet post some years ago, and it's widely available around the web. Like,
for example, here:

http://www.perl.com/doc/FMTEYEWTK/regexps.html

The other is by Aaron Kuchling, a Python guru. It's also widely available -
a pdf version is here:

http://www.engr.uvic.ca/~seng265/Documentation/Python/howto-regex.pdf

Tom and Aaron both recommend using verbose mode; even though it's far more
readable and understandable, your editor will probably make it difficult. It
really is far more readable, though. Just imagine trying to troubleshoot
this relatively simple regexp if there were no spaces, no formatting, and no
comments (it parses a SPICE instantiation):

spice_instance  = r"""\s*
      # Instance name (one occurrence). The instance may be either a
primitive or a
      # subcircuit. Subcircuit calls begin with 'x', primitive calls begin
with anything else.
      (?:
         (?P<primitive>
             [a-wyzA-WYZ_]                      # Primitive names begin with
anything except 'x'
             $INST_ID
         )
         |                                      # OR...
         (?P<subckt>
             [xX]                               # Subcircuit calls begin
with 'x':
             $INST_ID
         )
      )
      \s+                                    # Whitespace
      # Net list (at least one net is required)
      (?P<nets>
         (?:
             $NODE_NAME
             \s+                           # followed by white space
         )+
      )
      # Primitive or subcircuit name (one occurrence)
      (?P<name>
         $COMP_NAME
      )
      (?:\s+|$)                               # followed by white space or
EOL,
      (?!\s*=)                                # but not '='
      # Parameter = Value pairs or $keywords (zero or more occurrences)
      (?P<params>
         (?:
             $PARAM_NAME                      # Parameter name
             \s*=\s*                          # =
             $VALUE                           # Value
             (?:\s+|$|$)                       # White space or $ or EOL
         )*                                   # zero or more p-v pairs or
keywords
      )
    """

-- Mike --


Posted by Jim Thompson on June 6, 2009, 6:31 pm
 wrote:


My situation is more straight forward, essentially all find & replace
operations (<rns> = random number of spaces including none):

ParamName<rns>=<rns>'MathEquation'

with...

ParamName<rns>=<rns>

or renaming:

ParamName1<rns>=<rns>'MathEquation'

with...

ParamName2<rns>=<rns>

or tossing (not used by PSpice):

ParamName<rns>=<rns>'MathEquation'

to...

;ParamName<rns>=<rns>'MathEquation' \n+

Some other more subtle things...

I need to learn a scripting language, so I can process a library in
one swell foop, rather than eating days of boredom ;-)

                                        ...Jim Thompson
--
| James E.Thompson, P.E.                           |    mens     |
| Analog Innovations, Inc.                         |     et      |
| Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    |
| Phoenix, Arizona  85048    Skype: Contacts Only  |             |
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  |
| E-mail Icon at http://www.analog-innovations.com |    1962     |
            
 I love to cook with wine     Sometimes I even put it in the food

Posted by Mike on June 6, 2009, 7:32 pm
 

etc, etc.

Understood - that's what a scripting language will do for you, more quickly
and efficiently than an editor can. In addition, instead of commenting out
some of those equation lines hat PSPICE can't understand, you could either
calculate the value and substitute that for the equation, or translate the
equation into something PSPICE can understand.

For the simple case you show, a regexp matching valid HSPICE parameter names
is [a-zA-Z_][a-zA-Z0-9%$#_]*, and assuming your equations are all pretty
simple and you don't need to validate them (so your existing regexp matching
the equation is good enough), the matching regexp is something like this:

[a-zA-Z_][a-zA-Z0-9%$#_]*\s*=\s*'[a-zA-Z0-9\+\-\.\*\/\(\)\_]+'

You need the parenthesis to group the parameter name and the equation:

([a-zA-Z_][a-zA-Z0-9%$#_]*)\s*=\s*'([a-zA-Z0-9\+\-\.\*\/\(\)\_]+)'

To keep the same parameter name and equation, replacing the quotes with
braces, replace that with:

= {}

-- Mike --


Posted by Jasen Betts on June 6, 2009, 10:30 pm
 wrote:

it looks like sed could handle these translations easily.

<rns> is ' *' in regex.


s/\(ParamName *= *\)'\([^']*\)'/{}/;


s/ParamName1\( *= *\)'\([^']*\)'/ParamName2{}/;


s/ParamName\( *= *\)'\([^']*\)'/;ParamName{}/;


so the sed script would look like
 
s/\(ParamName *= *\)'\([^']*\)'/{}/;
s/ParamName1\( *= *\)'\([^']*\)'/ParamName2{}/;
s/ParamName\( *= *\)'\([^']*\)'/;ParamName{}/;

with each line repeated as often as needed.

except probably I'd put the rename and comment-out operations first
and do the translates with a catch-all,

  • Subject
  • Date