Sponsored Content
Full Discussion: Syntax error in tcl/tk code
Top Forums Programming Syntax error in tcl/tk code Post 302357518 by milindb on Wednesday 30th of September 2009 04:22:53 AM
Old 09-30-2009
Question Syntax error in tcl/tk code

Hi All,
I have written a code in tcl which is supposed to open an GUI in which numbers will be entered & after performing selected operation it wil show a result.

Code:
 
#!/usr/local/bin/wish
#package require Tk
#global opr 
proc DoOperation {} {
global opr
set fstno [ .entno1 get]
set scdno [ .entno2 get]
set result [expr {$fstno  $opr  $scdno}] 
.entres insert 0 $result
}
proc AddOpr {} {
set opr +
}
proc SubOpr {} {
set opr -
}
proc MulOpr {} {
set opr *
}
proc DivOpr {} {
set opr /
}
 
###Creation on widgets
wm title . "Wants to create Calculator"
frame .frm
label .labno1 -text "Enter First Number Here: "
label .labno2 -text "Enter Second number Here: "
label .labres -text "Result is : "
entry .entno1
entry .entno2
entry .entres
button .butadd -text "+" -width 4 -command "AddOpr"
button .butneg -text "-" -width 4 -command "SubOpr"
button .butmul -text "*" -width 4 -command "MulOpr"
button .butdiv -text "/" -width 4 -command "DivOpr"
button .butcalc -text "CALCULATE" -command "DoOperation" 
button .butext -text "EXIT" -command {exit}
###setting widgets 
#grid .but1 
grid .labno1 -in .frm -row 1 -column 1 -sticky w 
grid .labno2 -in .frm -row 2 -column 1 -sticky w
grid .labres -in .frm -row 3 -column 1 -sticky w
grid .entno1 -in .frm -row 1 -column 2 -sticky e
grid .entno2 -in .frm -row 2 -column 2 -sticky e
grid .entres -in .frm -row 3 -column 2 -sticky e
grid .butadd -in .frm -row 4 -column 1 -padx "0 65" -pady "5 5" 
grid .butneg -in .frm -row 4 -column 1 -padx "65 0" -pady "5 5" ;# -columnspan 2
grid .butmul -in .frm -row 4 -column 2 -padx "0 65" -pady "5 5";# -columnspan 2
grid .butdiv -in .frm -row 4 -column 2 -padx "65 0" -pady  "5 5"
grid .butcalc -in .frm -row 5 -column 1 -columnspan 1 -pady  "5 5"
grid .butext -in .frm -row 5 -column 2 -columnspan 2 -pady  "5 5"
pack .frm

Error I am getting is-
Code:
 
syntax error in expression "$fstno  $opr  $scdno": extra tokens at end of expression
syntax error in expression "$fstno  $opr  $scdno": extra tokens at end of expression
    while executing
"expr {$fstno  $opr  $scdno}"
    (procedure "DoOperation" line 5)

This is the first program I have created after completing my basic training of TCL/Tk so pls forgive me for silly mistakes.

Help appreciated in resolving this error.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

awk Shell Script error : "Syntax Error : `Split' unexpected

hi there i write one awk script file in shell programing the code is related to dd/mm/yy to month, day year format but i get an error please can anybody help me out in this problem ?????? i give my code here including error awk ` # date-month -- convert mm/dd/yy to month day,... (2 Replies)
Discussion started by: Herry
2 Replies

2. Shell Programming and Scripting

why is this code generating syntax error?pls help

#!/bin/sh copy() { source=`stat -c %s $1` dest=0 cd $2 while ;do cp $1 $2 & pct=`((100 * $dest) / $source )` dest=`dest+1` echo -en ".$pct%\b\b\b" sleep 1 done } echo "starting now" copy /file1 /tmp (3 Replies)
Discussion started by: wrapster
3 Replies

3. AIX

nim mksysb error :/usr/bin/savevg[33]: 1016,07: syntax error

-------------------------------------------------------------------------------- Hello, help me please. I am trying to create a mksysb bakup using nim. I am geting this error, how to correct it ? : Command : failed stdout: yes stderr: no... (9 Replies)
Discussion started by: astjen
9 Replies

4. Shell Programming and Scripting

Need help line 35: syntax error: unexpected end of file only 34 lines of code

I am not sure what I am doing wrong here, I did some research and only confused myself further. Any help would be greatly appreciated. I need to make this work for work tomorrow. There are only 34 lines of code in this script, yet its complaining about line 35 Here is the code: ... (7 Replies)
Discussion started by: BkontheShell718
7 Replies

5. Shell Programming and Scripting

Syntax error calling TCL script from shell script

hello everyone i am beginner on shell scripting .and i am working on my project work on ad hoc network i wrote a batch (.sh) to do a looping and execute a tcl script i wrote before in each iteration ..but i got this problem " syntax error near unexpected token `('... (1 Reply)
Discussion started by: marcoss90
1 Replies

6. Shell Programming and Scripting

Need help with TCL code to find IP address from a URL

Need help with a a tcl code. Need to find out the ip address from a URL if it is present to do some activity. The URLs will be of the form <domain>?a=12345&d=somestring1(Note: c not present) <domain>?c=10.10.10.100&d=somestring1 <domain>?a=12345&b=somestring1&c=10.1.2.4&d=somestring2... (1 Reply)
Discussion started by: ampak
1 Replies

7. UNIX for Advanced & Expert Users

Error in tcl script

hi all , i am trying to link a file with another file present in some other location in tcl shell. This is the way i am doing it if {} { file link /data/athena_dev/tanvi/tcl/tanvi.log "/data/athena_dev/tanvi/tanvi.tcl" } I am getting the error that /data/athena_dev/tanvi/tcl/ta nvi.log... (1 Reply)
Discussion started by: harjinder
1 Replies

8. Shell Programming and Scripting

TCL: syntax error in expression with "*"

I'm using tcl scripts in ns2 ( network simulator) through cygwin. It works fine , however, I downloaded an example when i run it , I got the following syntax error: syntax error in expression with " *2" : unexpected operator * while executing : "expr $bw *2" invoked from within: "$ns... (1 Reply)
Discussion started by: ENG_MOHD
1 Replies

9. Shell Programming and Scripting

IF section problem. syntax error: unexpected end of file error

Hello, I have another problem with my script. Please accept my apologies, but I am really nooby in sh scripts. I am writing it for first time. My script: returned=`tail -50 SapLogs.log | grep -i "Error"` echo $returned if ; then echo "There is no errors in the logs" fi And after... (10 Replies)
Discussion started by: jedzio
10 Replies

10. UNIX for Beginners Questions & Answers

Syntax error in code snippet

Hello, I am attaching a code snippet. Some of the variables are set in earlier code like count, arrays harr1, harr2, barr1 and barr2. The code below gives syntax errors. I am very new to Bash. for (( i=0; i<=$(( $count -1 )); i++ )) do #Now read the element at barr2 location i. Also find... (2 Replies)
Discussion started by: ngabrani
2 Replies
mathfunc(n)						    Tcl Mathematical Functions						       mathfunc(n)

__________________________________________________________________________________________________________________________________________________

NAME
mathfunc - Mathematical functions for Tcl expressions SYNOPSIS
package require Tcl 8.5 ::tcl::mathfunc::abs arg ::tcl::mathfunc::acos arg ::tcl::mathfunc::asin arg ::tcl::mathfunc::atan arg ::tcl::mathfunc::atan2 y x ::tcl::mathfunc::bool arg ::tcl::mathfunc::ceil arg ::tcl::mathfunc::cos arg ::tcl::mathfunc::cosh arg ::tcl::mathfunc::double arg ::tcl::mathfunc::entier arg | ::tcl::mathfunc::exp arg ::tcl::mathfunc::floor arg ::tcl::mathfunc::fmod x y ::tcl::mathfunc::hypot x y ::tcl::mathfunc::int arg ::tcl::mathfunc::isqrt arg ::tcl::mathfunc::log arg ::tcl::mathfunc::log10 arg ::tcl::mathfunc::max arg ?arg ...? ::tcl::mathfunc::min arg ?arg ...? ::tcl::mathfunc::pow x y ::tcl::mathfunc::rand ::tcl::mathfunc::round arg ::tcl::mathfunc::sin arg ::tcl::mathfunc::sinh arg ::tcl::mathfunc::sqrt arg ::tcl::mathfunc::srand arg ::tcl::mathfunc::tan arg ::tcl::mathfunc::tanh arg ::tcl::mathfunc::wide arg _________________________________________________________________ DESCRIPTION
The expr command handles mathematical functions of the form sin($x) or atan2($y,$x) by converting them to calls of the form [tcl::math- func::sin [expr {$x}]] or [tcl::mathfunc::atan2 [expr {$y}] [expr {$x}]]. A number of math functions are available by default within the namespace ::tcl::mathfunc; these functions are also available for code apart from expr, by invoking the given commands directly. Tcl supports the following mathematical functions in expressions, all of which work solely with floating-point numbers unless otherwise noted: abs acos asin atan atan2 bool ceil cos cosh double entier exp floor fmod hypot int isqrt log log10 max min pow rand round sin sinh sqrt srand tan tanh wide In addition to these predefined functions, applications may define additional functions by using proc (or any other method, such as interp alias or Tcl_CreateObjCommand) to define new commands in the tcl::mathfunc namespace. In addition, an obsolete interface named Tcl_Cre- ateMathFunc() is available to extensions that are written in C. The latter interface is not recommended for new implementations. DETAILED DEFINITIONS abs arg Returns the absolute value of arg. Arg may be either integer or floating-point, and the result is returned in the same form. acos arg Returns the arc cosine of arg, in the range [0,pi] radians. Arg should be in the range [-1,1]. asin arg Returns the arc sine of arg, in the range [-pi/2,pi/2] radians. Arg should be in the range [-1,1]. atan arg Returns the arc tangent of arg, in the range [-pi/2,pi/2] radians. atan2 y x Returns the arc tangent of y/x, in the range [-pi,pi] radians. x and y cannot both be 0. If x is greater than 0, this is equiva- lent to "atan [expr {y/x}]". bool arg Accepts any numeric value, or any string acceptable to string is boolean, and returns the corresponding boolean value 0 or 1. Non- zero numbers are true. Other numbers are false. Non-numeric strings produce boolean value in agreement with string is true and string is false. ceil arg Returns the smallest integral floating-point value (i.e. with a zero fractional part) not less than arg. The argument may be any numeric value. cos arg Returns the cosine of arg, measured in radians. cosh arg Returns the hyperbolic cosine of arg. If the result would cause an overflow, an error is returned. double arg The argument may be any numeric value, If arg is a floating-point value, returns arg, otherwise converts arg to floating-point and returns the converted value. May return Inf or -Inf when the argument is a numeric value that exceeds the floating-point range. entier arg The argument may be any numeric value. The integer part of arg is determined and returned. The integer range returned by this | function is unlimited, unlike int and wide which truncate their range to fit in particular storage widths. exp arg Returns the exponential of arg, defined as e**arg. If the result would cause an overflow, an error is returned. floor arg Returns the largest integral floating-point value (i.e. with a zero fractional part) not greater than arg. The argument may be any numeric value. fmod x y Returns the floating-point remainder of the division of x by y. If y is 0, an error is returned. hypot x y Computes the length of the hypotenuse of a right-angled triangle "sqrt [expr {x*x+y*y}]". int arg The argument may be any numeric value. The integer part of arg is determined, and then the low order bits of that integer value up to the machine word size are returned as an integer value. For reference, the number of bytes in the machine word are stored in tcl_platform(wordSize). isqrt arg Computes the integer part of the square root of arg. Arg must be a positive value, either an integer or a floating point number. Unlike sqrt, which is limited to the precision of a floating point number, isqrt will return a result of arbitrary precision. log arg Returns the natural logarithm of arg. Arg must be a positive value. log10 arg Returns the base 10 logarithm of arg. Arg must be a positive value. max arg ... Accepts one or more numeric arguments. Returns the one argument with the greatest value. min arg ... Accepts one or more numeric arguments. Returns the one argument with the least value. pow x y Computes the value of x raised to the power y. If x is negative, y must be an integer value. rand Returns a pseudo-random floating-point value in the range (0,1). The generator algorithm is a simple linear congruential generator that is not cryptographically secure. Each result from rand completely determines all future results from subsequent calls to rand, so rand should not be used to generate a sequence of secrets, such as one-time passwords. The seed of the generator is initialized from the internal clock of the machine or may be set with the srand function. round arg If arg is an integer value, returns arg, otherwise converts arg to integer by rounding and returns the converted value. sin arg Returns the sine of arg, measured in radians. sinh arg Returns the hyperbolic sine of arg. If the result would cause an overflow, an error is returned. sqrt arg The argument may be any non-negative numeric value. Returns a floating-point value that is the square root of arg. May return Inf when the argument is a numeric value that exceeds the square of the maximum value of the floating-point range. srand arg The arg, which must be an integer, is used to reset the seed for the random number generator of rand. Returns the first random num- ber (see rand) from that seed. Each interpreter has its own seed. tan arg Returns the tangent of arg, measured in radians. tanh arg Returns the hyperbolic tangent of arg. wide arg The argument may be any numeric value. The integer part of arg is determined, and then the low order 64 bits of that integer value are returned as an integer value. SEE ALSO
expr(n), mathop(n), namespace(n) COPYRIGHT
Copyright (c) 1993 The Regents of the University of California. Copyright (c) 1994-2000 Sun Microsystems Incorporated. Copyright (c) 2005, 2006 by Kevin B. Kenny <kennykb@acm.org>. Tcl 8.5 mathfunc(n)
All times are GMT -4. The time now is 02:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy