Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Method to determine diff between string and list

Status
Not open for further replies.

verplexd

Programmer
Feb 12, 2003
36
US
Hi,

I am working on a parser/translator script in hopes of sharing variables across different tool language domains. Because most EDA tools support TCL as the native language, I decided to tackle my first TCL script. Below is a rough description of what I've done so far:

1.) read all variable definitions (from file) into memory and build list of variables to translate.

2.) Determine if the variable is an array, list, or string.

3.) Call the appropriate translation procedure.

I'm using the built-in tcl function [array exists] to test variable for an array. However, I am having alot of trouble distinguishing between a string and a list. This test is needed in order to translate variables to different languages successfully. Perhaps an example of what Im tryin to acheive would help:

TCL vars:

set string "Im a string"
set simple {"Im a simple list"}
set list {"Im" {"a"} "list"}
set num 10

output (Scheme format)

define string "Im a string"
define simple '("Im a simple list")
define list '("Im ("a") "list")
define num 10

Any help is greatly appreciated.

Thanks!
 
There really isn't any difference between a list and a string. I think the choice is arbitrary in Tcl. What are the ramifications of translating them both as strings?

_________________
Bob Rashkin
rrashkin@csc.com
 
Ideally, I would want lists to translate as lists so data structure operations could be used. (foreach loop, lookup by index, etc.). So basically what your saying is the following two variables are the same in TCL:

set string "foo"
set list {"foo"}

Thanks!
 
Yes. I think that's true. Do the following test in the Tcl shell:
Code:
% set str1 abc;#a string
abc
% lappend str1 123;# treat it as a list
abc 123
% append str1 "0 xyz";# treat it as a string
abc 1230 xyz
% foreach el $str1 {puts $el};# list operator
abc
1230
xyz
%

_________________
Bob Rashkin
rrashkin@csc.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top