Skip to content
Tcl Source Code Artifact [47c144da07]
Login

Artifact [47c144da07]

Artifact 47c144da07e60980a0ed897e5acfbb858c15aed9:

Ticket change [47c144da07] - New ticket [1517602fffffffff|1517602fff] <i>long expressions and Tcl_Tokens</i>. by dgp on 2006-07-05 15:52:45.
D 2006-07-05T15:52:45
J assignee dgp
J cmimetype text/plain
J comment \nThe\sarray\sof\sTcl_Tokens\sthat\nTcl's\sparser\sgenerates\shas\nseveral\sdesign\sflaws\swhen\sused\nto\sparse\slong\sexpressions.\n\nconsider\sthe\ssimple\sexpression\n"1+1".\s\sIt\sparses\sinto\sthe\nTcl_Token\sstream:\n\nsubexpr\s1+1\s5\noperator\s+\s0\nsubexpr\s1\s1\ntext\s1\s0\nsubexpr\s1\s1\ntext\s1\s0\n\nThat's\ssix\sTcl_Tokens\sto\nrepresent\sa\s3\scharacter\nexpression.\s\sAt\s16\sbytes\neach\s(more\son\s64-bit\ssystem),\nthat's\sa\sconsiderable\sbloat\nof\smemory.\s\sApply\sthat\sto\n\nexpr\s[string\srepeat\s+1\s10000]\n\nand\syou\sneed\s640Kbytes\sjust\nto\shold\sthe\sfinal\sTcl_Token\sarray\nfor\sa\s10Kbyte\sexpression.\n\nWorse,\syou\sneed\sthat\s640KBytes\nas\sone\scontiguous\sblock\sof\smemory,\nso\seven\sif\syou\smight\shave\sthe\sRAM\navailable,\syou\scan\spanic\sif\sits\nnot\savailable\sin\sa\slarge\senough\sblock.\n\nA\sfairly\sstraightforward\ssimplification\nto\san\sRPN\sstyle\stoken\sstream\swould\sgive:\n\noperator\s+\s2\ntext\s1\s0\ntext\s1\s0\n\nThe\sexpr\sparser\salready\sadds\sTCL_TOKEN_WORD\ntokens\sto\sflag\smulti-token\soperands.\s\sThere's\nno\sapparent\sneed\sfor\sthe\sTCL_TOKEN_SUB_EXPR\nto\smark\sthe\sstart\sof\soperands.\s\sThe\sother\nvalue\sTCL_TOKEN_SUB_EXPR\soffers\sis\sto\skeep\s\nthe\ssubstring\s"1+1"\sdistinct\sfrom\sthe\s\nsubstring\s"+"\sin\sthe\sTCL_TOKEN_OPERATOR\ntoken\sor\sthe\ssubstring\s"{foo}"\sdistinct\nfrom\sthe\ssubstring\s"foo".\s\sThe\smain\sutility\nof\sthat,\sthough,\sis\sto\shave\sthe\sstring\srep\nof\sthe\swhole\ssubexpression\shandy\sfor\serror\nmessages\sor\sdebug\strace\smessages.\s\sMakes\nmore\ssense\sto\sme\sto\shave\ssuch\smessages\stake\nlonger\sto\sgenerate,\swith\sthe\stradeoff\sthat\nlarger\slegal\sexpressions\sare\susable.\n\nOne\sother\sissue\swhere\sTcl_Tokens\sdon't\nserve\sexpressions\swell.\s\sIn\sorder\sto\nparse\sthe\sboundaries\sof\sliteral\sstring\nrepresentations\sof\snumbers,\sTclParseNumber()\ndetermines\sthe\snumeric\svalue.\s\sThis\sis\nsimply\sdiscarded\sbecause\sTcl_Tokens\sonly\nstore\sstrings.\s\sLater,\swhen\sthe\sexpression\nis\sactually\sevaluated,\sthe\sstring\sform\sof\nthe\snumber\shas\sto\sbe\sparsed\sall\sover\sagain\nto\sget\sthe\snumeric\svalue.\s\sA\srevision\nthat\spermitted\spassing\sthrough\sa\sTcl_Obj\nwould\sbe\snice.\s\sAn\sadditional\sTcl_Token\ntype\smight\spermit\sthat.\n\nThe\sproblem\swith\smost\sof\sthese\sideas\nis\sthat\sthe\scurrent\sdesign\sfor\sthe\nTcl_Token\sarray\srepresentation\sof\nexpressions\sis\sdocumented\sas\spart\nof\sthe\sTcl_ParseExpr()\sroutine.\s\sIf\nwe\smake\sany\sof\sthese\schanges,\swe'll\nat\sleast\shave\sto\sbuild\sa\sconverter\nto\sthe\sold\slayout\sinto\sT_PE.
J foundin None
J priority 5\sMedium
J resolution None
J status Open
J submitter dgp
J subsystem 45.\sParsing\sand\sEval
J title long\sexpressions\sand\sTcl_Tokens
J type RFE
K 1517602fffffffffffffffffffffffffffffffff
U dgp
Z 632ed48d8e56c0b51f6d109055f100db