Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2005-09-29
00:12 • Closed ticket [1306288fff]: Tcl_ParseExpr misdocumented and/or misnamed plus... artifact: 50abe3241d user: dgp
2005-09-28
05:17 • Ticket [1306288fff]: 1 change artifact: 80fccf8d7e user: msofer
2005-09-27
21:56 • New ticket [1306288fff]. artifact: 28c9ae7551 user: rrh

Tcl_ParseExpr misdocumented and/or misnamed

Closed / Wont Fix1306288fffffffffffffffffffffffffffffffffCreated 21 years agoUpdated 21 years ago
Descriptionplain2005-09-27 21:56:35
The function Tcl_ParseExpr does more than do lexical
and syntactic (parsing) analysis.  It also does some
semantic analysis, to provide meaning to some lexemes,
which leads to it detecting faults in plausibly well
formed expressions.

Thus, parsing 1+0x100000000000000000 (say) will fail,
since semantic analysis determines that the underlying
value this represents is bigger than an underlying
"int" data type.

The man page is silent on this matter, unless you count
the phrase "...parses Tcl expressions...", and consider
a Tcl expression to be malformed  if the literal
numbers don't fit in an "int".

This behaviour of Tcl_ParseExpr makes it
difficult/impossible to use Tcl_ParseExpr to crack open
expressions that use the domain of multi-precision
arithmetic.  Perhaps Tcl 8.5a?,with the introduction of
mp artithmetic, will clear up some of this?
msofer Ticket [1306288fff]: 1 change [History diff]2005-09-28 05:17:22
dgpplain2005-09-29 00:12:32
Logged In: YES 
user_id=80530


 "These are not the droids you are looking for"

Tcl_ParseExpr() is meant to parse a string
as a Tcl expression.  If/when Tcl's expression
support changes, so does Tcl_ParseExpr(),
so you'll see that the ** operator for exponentiation
is parsed in Tcl 8.5 but not in earlier Tcl releases.
Likewise, as you suggest, if/when Tcl expressions
support operating on unlimited range integers
(pending for Tcl 8.5 -- TIP 237) the expression
parser will accept them as
syntactically valid Tcl expressions.

Tcl_ParseExpr() isn't meant to be any kind
of general parsing engine for general expressions.

Whether that's misdocumentation of misnaming,
or just a strong assumption that within Tcl we
assume a context of Tcl is a matter of opinion
I suppose.

And I do see your point about the implementation
not providing a 100% "clean" separation between
lexical matters and semantic matters.  That will
continue to be true in the forseeable future.
Log in (anonymous is fine) to add a comment.