MMRScriptTokenize.cs 126 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. /**
  28. * @brief Parse raw source file string into token list.
  29. *
  30. * Usage:
  31. *
  32. * emsg = some function to output error messages to
  33. * source = string containing entire source file
  34. *
  35. * TokenBegin tokenBegin = TokenBegin.Construct (emsg, source);
  36. *
  37. * tokenBegin = null: tokenizing error
  38. * else: first (dummy) token in file
  39. * the rest are chained by nextToken,prevToken
  40. * final token is always a (dummy) TokenEnd
  41. */
  42. using System;
  43. using System.Collections.Generic;
  44. using System.IO;
  45. using System.Net;
  46. using System.Reflection;
  47. using System.Reflection.Emit;
  48. using System.Text;
  49. using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
  50. using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
  51. using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  52. using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
  53. using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
  54. using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  55. using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
  56. namespace OpenSim.Region.ScriptEngine.Yengine
  57. {
  58. public delegate void TokenErrorMessage(Token token, string message);
  59. /**
  60. * @brief base class for all tokens
  61. */
  62. public class Token
  63. {
  64. public static readonly int MAX_NAME_LEN = 255;
  65. public static readonly int MAX_STRING_LEN = 4096;
  66. public Token nextToken;
  67. public Token prevToken;
  68. public bool nr2l;
  69. // used for error message printing
  70. public TokenErrorMessage emsg;
  71. public string file = "";
  72. public int line;
  73. public int posn;
  74. public Token copiedFrom;
  75. /**
  76. * @brief construct a token coming directly from a source file
  77. * @param emsg = object that error messages get sent to
  78. * @param file = source file name (or "" if none)
  79. * @param line = source file line number
  80. * @param posn = token's position within that source line
  81. */
  82. public Token(TokenErrorMessage emsg, string file, int line, int posn)
  83. {
  84. this.emsg = emsg;
  85. this.file = file;
  86. this.line = line;
  87. this.posn = posn;
  88. }
  89. /**
  90. * @brief construct a token with same error message parameters
  91. * @param original = original token to create from
  92. */
  93. public Token(Token original)
  94. {
  95. if(original != null)
  96. {
  97. this.emsg = original.emsg;
  98. this.file = original.file;
  99. this.line = original.line;
  100. this.posn = original.posn;
  101. this.nr2l = original.nr2l;
  102. }
  103. }
  104. /**
  105. * @brief output an error message associated with this token
  106. * sends the message to the token's error object
  107. * @param message = error message string
  108. */
  109. public void ErrorMsg(string message)
  110. {
  111. if(emsg != null)
  112. {
  113. emsg(this, message);
  114. }
  115. }
  116. /*
  117. * Generate a unique string (for use in CIL label names, etc)
  118. */
  119. public string Unique
  120. {
  121. get
  122. {
  123. return file + "_" + line + "_" + posn;
  124. }
  125. }
  126. /*
  127. * Generate source location string (for use in error messages)
  128. */
  129. public string SrcLoc
  130. {
  131. get
  132. {
  133. string loc = file + "(" + line + "," + posn + ")";
  134. if(copiedFrom == null)
  135. return loc;
  136. string fromLoc = copiedFrom.SrcLoc;
  137. if(fromLoc.StartsWith(loc))
  138. return fromLoc;
  139. return loc + ":" + fromLoc;
  140. }
  141. }
  142. /*
  143. * Used in generic instantiation to copy token.
  144. * Only valid for parsing tokens, not reduction tokens
  145. * because it is a shallow copy.
  146. */
  147. public Token CopyToken(Token src)
  148. {
  149. Token t = (Token)this.MemberwiseClone();
  150. t.file = src.file;
  151. t.line = src.line;
  152. t.posn = src.posn;
  153. t.copiedFrom = this;
  154. return t;
  155. }
  156. /*
  157. * Generate debugging string - should look like source code.
  158. */
  159. public virtual void DebString(StringBuilder sb)
  160. {
  161. sb.Append(this.ToString());
  162. }
  163. }
  164. /**
  165. * @brief token that begins a source file
  166. * Along with TokenEnd, it keeps insertion/removal of intermediate tokens
  167. * simple as the intermediate tokens always have non-null nextToken,prevToken.
  168. */
  169. public class TokenBegin: Token
  170. {
  171. private class Options
  172. {
  173. public bool arrays; // has seen 'XMROption arrays;'
  174. public bool advFlowCtl; // has seen 'XMROption advFlowCtl;'
  175. public bool tryCatch; // has seen 'XMROption tryCatch;'
  176. public bool objects; // has seen 'XMROption objects;'
  177. public bool chars; // has seen 'XMROption chars;'
  178. public bool noRightToLeft; // has seen 'XMROption noRightToLeft;'
  179. public bool dollarsigns; // has seen 'XMROption dollarsigns;'
  180. }
  181. private bool youveAnError; // there was some error tokenizing
  182. private int bolIdx; // index in 'source' at begining of current line
  183. private int lineNo; // current line in source file, starting at 0
  184. private string filNam; // current source file name
  185. private string source; // the whole script source code
  186. private Token lastToken; // last token created so far
  187. private string cameFrom; // where the source came from
  188. private TextWriter saveSource; // save copy of source here (or null)
  189. private Options options = new Options();
  190. /**
  191. * @brief convert a source file in the form of a string
  192. * to a list of raw tokens
  193. * @param cameFrom = where the source came from
  194. * @param emsg = where to output messages to
  195. * @param source = whole source file contents
  196. * @returns null: conversion error, message already output
  197. * else: list of tokens, starting with TokenBegin, ending with TokenEnd.
  198. */
  199. public static TokenBegin Construct(string cameFrom, TextWriter saveSource, TokenErrorMessage emsg, string source, out string sourceHash)
  200. {
  201. sourceHash = null;
  202. // Now do the tokenization.
  203. TokenBegin tokenBegin = new TokenBegin(emsg, "", 0, 0);
  204. tokenBegin.cameFrom = cameFrom;
  205. tokenBegin.saveSource = saveSource;
  206. tokenBegin.lastToken = tokenBegin;
  207. tokenBegin.source = source;
  208. tokenBegin.filNam = cameFrom;
  209. if(saveSource != null)
  210. saveSource.WriteLine(source);
  211. tokenBegin.Tokenize();
  212. if(tokenBegin.youveAnError)
  213. return null;
  214. tokenBegin.AppendToken(new TokenEnd(emsg, tokenBegin.filNam, ++tokenBegin.lineNo, 0));
  215. /*
  216. * Return source hash so caller can know if source changes.
  217. */
  218. System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
  219. byte[] hashBytes = md5.ComputeHash(new TokenStream(tokenBegin));
  220. int hashBytesLen = hashBytes.Length;
  221. StringBuilder sb = new StringBuilder(hashBytesLen * 2);
  222. for(int i = 0; i < hashBytesLen; i++)
  223. {
  224. sb.Append(hashBytes[i].ToString("X2"));
  225. }
  226. sourceHash = sb.ToString();
  227. if(saveSource != null)
  228. {
  229. saveSource.WriteLine(" ");
  230. saveSource.WriteLine("********************************************************************************");
  231. saveSource.WriteLine("**** source hash: " + sourceHash);
  232. saveSource.WriteLine("********************************************************************************");
  233. }
  234. return tokenBegin;
  235. }
  236. private TokenBegin(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  237. /*
  238. * Stream consisting of all the tokens.
  239. * Null delimeters between the tokens.
  240. * Used for creating the source hash.
  241. */
  242. private class TokenStream: Stream
  243. {
  244. private Token curTok;
  245. private bool delim;
  246. private byte[] curBuf;
  247. private int curOfs;
  248. private int curLen;
  249. public TokenStream(Token t)
  250. {
  251. curTok = t;
  252. }
  253. public override bool CanRead
  254. {
  255. get
  256. {
  257. return true;
  258. }
  259. }
  260. public override bool CanSeek
  261. {
  262. get
  263. {
  264. return false;
  265. }
  266. }
  267. public override bool CanWrite
  268. {
  269. get
  270. {
  271. return false;
  272. }
  273. }
  274. public override long Length
  275. {
  276. get
  277. {
  278. return 0;
  279. }
  280. }
  281. public override long Position
  282. {
  283. get
  284. {
  285. return 0;
  286. }
  287. set
  288. {
  289. }
  290. }
  291. public override void Write(byte[] buffer, int offset, int count)
  292. {
  293. }
  294. public override void Flush()
  295. {
  296. }
  297. public override long Seek(long offset, SeekOrigin origin)
  298. {
  299. return 0;
  300. }
  301. public override void SetLength(long value)
  302. {
  303. }
  304. public override int Read(byte[] buffer, int offset, int count)
  305. {
  306. int len, total;
  307. for(total = 0; total < count; total += len)
  308. {
  309. while((len = curLen - curOfs) <= 0)
  310. {
  311. if(curTok is TokenEnd)
  312. goto done;
  313. curTok = curTok.nextToken;
  314. if(curTok is TokenEnd)
  315. goto done;
  316. curBuf = System.Text.Encoding.UTF8.GetBytes(curTok.ToString());
  317. curOfs = 0;
  318. curLen = curBuf.Length;
  319. delim = true;
  320. }
  321. if(delim)
  322. {
  323. buffer[offset + total] = 0;
  324. delim = false;
  325. len = 1;
  326. }
  327. else
  328. {
  329. if(len > count - total)
  330. len = count - total;
  331. Array.Copy(curBuf, curOfs, buffer, offset + total, len);
  332. curOfs += len;
  333. }
  334. }
  335. done:
  336. return total;
  337. }
  338. }
  339. /*
  340. * Produces raw token stream: names, numbers, strings, keywords/delimeters.
  341. * @param this.source = whole source file in one string
  342. * @returns this.nextToken = filled in with tokens
  343. * this.youveAnError = true: some tokenizing error
  344. * false: successful
  345. */
  346. private void Tokenize()
  347. {
  348. bolIdx = 0;
  349. lineNo = 0;
  350. for(int i = 0; i < source.Length; i++)
  351. {
  352. char c = source[i];
  353. if(c == '\n')
  354. {
  355. // Increment source line number and set char index of beg of next line.
  356. lineNo++;
  357. bolIdx = i + 1;
  358. // Check for '#' lineno filename newline
  359. // lineno is line number of next line in file
  360. // If found, save values and remove tokens from stream
  361. if((lastToken is TokenStr) &&
  362. (lastToken.prevToken is TokenInt) &&
  363. (lastToken.prevToken.prevToken is TokenKwHash))
  364. {
  365. filNam = ((TokenStr)lastToken).val;
  366. lineNo = ((TokenInt)lastToken.prevToken).val;
  367. lastToken = lastToken.prevToken.prevToken.prevToken;
  368. lastToken.nextToken = null;
  369. }
  370. continue;
  371. }
  372. // Skip over whitespace.
  373. if(c <= ' ')
  374. continue;
  375. // Skip over comments.
  376. if((i + 2 <= source.Length) && source.Substring(i, 2).Equals("//"))
  377. {
  378. while((i < source.Length) && (source[i] != '\n'))
  379. i++;
  380. lineNo++;
  381. bolIdx = i + 1;
  382. continue;
  383. }
  384. if((i + 2 <= source.Length) && (source.Substring(i, 2).Equals("/*")))
  385. {
  386. i += 2;
  387. while((i + 1 < source.Length) && (((c = source[i]) != '*') || (source[i + 1] != '/')))
  388. {
  389. if(c == '\n')
  390. {
  391. lineNo++;
  392. bolIdx = i + 1;
  393. }
  394. i++;
  395. }
  396. i++;
  397. continue;
  398. }
  399. // Check for numbers.
  400. if((c >= '0') && (c <= '9'))
  401. {
  402. int j = TryParseFloat(i);
  403. if(j == 0)
  404. j = TryParseInt(i);
  405. i = --j;
  406. continue;
  407. }
  408. if((c == '.') && (i + 1 < source.Length) && (source[i + 1] >= '0') && (source[i + 1] <= '9'))
  409. {
  410. int j = TryParseFloat(i);
  411. if(j > 0)
  412. i = --j;
  413. continue;
  414. }
  415. // Check for quoted strings.
  416. if(c == '"')
  417. {
  418. StringBuilder sb = new StringBuilder();
  419. bool backslash;
  420. int j;
  421. backslash = false;
  422. for(j = i; ++j < source.Length;)
  423. {
  424. c = source[j];
  425. if(c == '\\' && !backslash)
  426. {
  427. backslash = true;
  428. continue;
  429. }
  430. if(c == '\n')
  431. {
  432. lineNo++;
  433. bolIdx = j + 1;
  434. }
  435. else
  436. {
  437. if(!backslash && (c == '"'))
  438. break;
  439. if(backslash && (c == 'n'))
  440. c = '\n';
  441. if(backslash && (c == 't'))
  442. {
  443. sb.Append(" ");
  444. c = ' ';
  445. }
  446. }
  447. backslash = false;
  448. sb.Append(c);
  449. }
  450. if(j - i > MAX_STRING_LEN)
  451. {
  452. TokenError(i, "string too long, max " + MAX_STRING_LEN);
  453. }
  454. else
  455. {
  456. AppendToken(new TokenStr(emsg, filNam, lineNo, i - bolIdx, sb.ToString()));
  457. }
  458. i = j;
  459. continue;
  460. }
  461. // Check for quoted characters.
  462. if(c == '\'')
  463. {
  464. char cb = (char)0;
  465. bool backslash, overflow, underflow;
  466. int j;
  467. backslash = false;
  468. overflow = false;
  469. underflow = true;
  470. for(j = i; ++j < source.Length;)
  471. {
  472. c = source[j];
  473. if(c == '\\' && !backslash)
  474. {
  475. backslash = true;
  476. continue;
  477. }
  478. if(c == '\n')
  479. {
  480. lineNo++;
  481. bolIdx = j + 1;
  482. }
  483. else
  484. {
  485. if(!backslash && (c == '\''))
  486. break;
  487. if(backslash && (c == 'n'))
  488. c = '\n';
  489. if(backslash && (c == 't'))
  490. c = '\t';
  491. }
  492. backslash = false;
  493. overflow = !underflow;
  494. underflow = false;
  495. cb = c;
  496. }
  497. if(underflow || overflow)
  498. {
  499. TokenError(i, "character must be exactly one character");
  500. }
  501. else
  502. {
  503. AppendToken(new TokenChar(emsg, filNam, lineNo, i - bolIdx, cb));
  504. }
  505. i = j;
  506. continue;
  507. }
  508. // Check for keywords/names.
  509. if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c == '_') || (c == '$' && options.dollarsigns))
  510. {
  511. int j;
  512. for(j = i; ++j < source.Length;)
  513. {
  514. c = source[j];
  515. if(c >= 'a' && c <= 'z')
  516. continue;
  517. if(c >= 'A' && c <= 'Z')
  518. continue;
  519. if(c >= '0' && c <= '9')
  520. continue;
  521. if(c == '$' && options.dollarsigns)
  522. continue;
  523. if(c != '_')
  524. break;
  525. }
  526. if(j - i > MAX_NAME_LEN)
  527. {
  528. TokenError(i, "name too long, max " + MAX_NAME_LEN);
  529. }
  530. else
  531. {
  532. string name = source.Substring(i, j - i);
  533. if(name == "quaternion")
  534. name = "rotation"; // see lslangtest1.lsl
  535. if(keywords.ContainsKey(name))
  536. {
  537. Object[] args = new Object[] { emsg, filNam, lineNo, i - bolIdx };
  538. AppendToken((Token)keywords[name].Invoke(args));
  539. }
  540. else if(options.arrays && arrayKeywords.ContainsKey(name))
  541. {
  542. Object[] args = new Object[] { emsg, filNam, lineNo, i - bolIdx };
  543. AppendToken((Token)arrayKeywords[name].Invoke(args));
  544. }
  545. else if(options.advFlowCtl && advFlowCtlKeywords.ContainsKey(name))
  546. {
  547. Object[] args = new Object[] { emsg, filNam, lineNo, i - bolIdx };
  548. AppendToken((Token)advFlowCtlKeywords[name].Invoke(args));
  549. }
  550. else if(options.tryCatch && tryCatchKeywords.ContainsKey(name))
  551. {
  552. Object[] args = new Object[] { emsg, filNam, lineNo, i - bolIdx };
  553. AppendToken((Token)tryCatchKeywords[name].Invoke(args));
  554. }
  555. else if(options.objects && objectsKeywords.ContainsKey(name))
  556. {
  557. Object[] args = new Object[] { emsg, filNam, lineNo, i - bolIdx };
  558. AppendToken((Token)objectsKeywords[name].Invoke(args));
  559. }
  560. else if(options.chars && charsKeywords.ContainsKey(name))
  561. {
  562. Object[] args = new Object[] { emsg, filNam, lineNo, i - bolIdx };
  563. AppendToken((Token)charsKeywords[name].Invoke(args));
  564. }
  565. else
  566. {
  567. AppendToken(new TokenName(emsg, filNam, lineNo, i - bolIdx, name));
  568. }
  569. }
  570. i = --j;
  571. continue;
  572. }
  573. // Check for option enables.
  574. if ((c == ';') && (lastToken is TokenName) &&
  575. (strcasecmp(((TokenName)lastToken).val, "yoptions") == 0))
  576. {
  577. options.advFlowCtl = true;
  578. options.tryCatch = true;
  579. lastToken = lastToken.prevToken;
  580. lastToken.nextToken = null;
  581. continue;
  582. }
  583. else if ((c == ';') && (lastToken is TokenName) &&
  584. (lastToken.prevToken is TokenName) &&
  585. (strcasecmp(((TokenName)lastToken.prevToken).val, "yoption") == 0))
  586. {
  587. string opt = ((TokenName)lastToken).val;
  588. if(strcasecmp(opt, "allowall") == 0)
  589. {
  590. options.arrays = true;
  591. options.advFlowCtl = true;
  592. options.tryCatch = true;
  593. options.objects = true;
  594. options.chars = true;
  595. // options.noRightToLeft = true;
  596. options.dollarsigns = true;
  597. }
  598. else if(strcasecmp(opt, "arrays") == 0)
  599. options.arrays = true;
  600. else if(strcasecmp(opt, "advflowctl") == 0)
  601. options.advFlowCtl = true;
  602. else if(strcasecmp(opt, "trycatch") == 0)
  603. options.tryCatch = true;
  604. else if(strcasecmp(opt, "objects") == 0)
  605. options.objects = true;
  606. else if(strcasecmp(opt, "chars") == 0)
  607. options.chars = true;
  608. else if(strcasecmp(opt, "norighttoleft") == 0)
  609. options.noRightToLeft = true;
  610. else if(strcasecmp(opt, "dollarsigns") == 0)
  611. options.dollarsigns = true;
  612. else
  613. lastToken.ErrorMsg("unknown YOption");
  614. lastToken = lastToken.prevToken.prevToken;
  615. lastToken.nextToken = null;
  616. continue;
  617. }
  618. // Lastly, check for delimeters.
  619. {
  620. int j;
  621. int len = 0;
  622. for(j = 0; j < delims.Length; j++)
  623. {
  624. len = delims[j].str.Length;
  625. if((i + len <= source.Length) && (source.Substring(i, len).Equals(delims[j].str)))
  626. break;
  627. }
  628. if(j < delims.Length)
  629. {
  630. Object[] args = { emsg, filNam, lineNo, i - bolIdx };
  631. Token kwToken = (Token)delims[j].ctorInfo.Invoke(args);
  632. AppendToken(kwToken);
  633. i += --len;
  634. continue;
  635. }
  636. }
  637. // Don't know what it is!
  638. TokenError(i, "unknown character '" + c + "'");
  639. }
  640. }
  641. private static int strcasecmp(String s, String t)
  642. {
  643. return String.Compare(s, t, StringComparison.OrdinalIgnoreCase);
  644. }
  645. /**
  646. * @brief try to parse a floating-point number from the source
  647. * @param i = starting position within this.source of number
  648. * @returns 0: not a floating point number, try something else
  649. * else: position in this.source of terminating character, ie, past number
  650. * TokenFloat appended to token list
  651. * or error message has been output
  652. */
  653. private int TryParseFloat(int i)
  654. {
  655. bool decimals, error, negexp, nulexp;
  656. char c;
  657. double f, f10;
  658. int exponent, j, x, y;
  659. ulong m, mantissa;
  660. decimals = false;
  661. error = false;
  662. exponent = 0;
  663. mantissa = 0;
  664. for(j = i; j < source.Length; j++)
  665. {
  666. c = source[j];
  667. if((c >= '0') && (c <= '9'))
  668. {
  669. m = mantissa * 10 + (ulong)(c - '0');
  670. if(m / 10 != mantissa)
  671. {
  672. if(!decimals)
  673. exponent++;
  674. }
  675. else
  676. {
  677. mantissa = m;
  678. if(decimals)
  679. exponent--;
  680. }
  681. continue;
  682. }
  683. if(c == '.')
  684. {
  685. if(decimals)
  686. {
  687. TokenError(i, "more than one decimal point");
  688. return j;
  689. }
  690. decimals = true;
  691. continue;
  692. }
  693. if((c == 'E') || (c == 'e'))
  694. {
  695. if(++j >= source.Length)
  696. {
  697. TokenError(i, "floating exponent off end of source");
  698. return j;
  699. }
  700. c = source[j];
  701. negexp = (c == '-');
  702. if(negexp || (c == '+'))
  703. j++;
  704. y = 0;
  705. nulexp = true;
  706. for(; j < source.Length; j++)
  707. {
  708. c = source[j];
  709. if((c < '0') || (c > '9'))
  710. break;
  711. x = y * 10 + (c - '0');
  712. if(x / 10 != y)
  713. {
  714. if(!error)
  715. TokenError(i, "floating exponent overflow");
  716. error = true;
  717. }
  718. y = x;
  719. nulexp = false;
  720. }
  721. if(nulexp)
  722. {
  723. TokenError(i, "bad or missing floating exponent");
  724. return j;
  725. }
  726. if(negexp)
  727. {
  728. x = exponent - y;
  729. if(x > exponent)
  730. {
  731. if(!error)
  732. TokenError(i, "floating exponent overflow");
  733. error = true;
  734. }
  735. }
  736. else
  737. {
  738. x = exponent + y;
  739. if(x < exponent)
  740. {
  741. if(!error)
  742. TokenError(i, "floating exponent overflow");
  743. error = true;
  744. }
  745. }
  746. exponent = x;
  747. }
  748. if ((c == 'F') || (c == 'f'))
  749. {
  750. if (++j >= source.Length)
  751. {
  752. TokenError(i, "f at end of source");
  753. return j;
  754. }
  755. c = source[j];
  756. if (((c >= '0') && (c <= '9')) || c == '.' || ((c == 'E') || (c == 'e')) || ((c == 'F') || (c == 'f')))
  757. {
  758. TokenError(j-1, "Syntax error");
  759. return j;
  760. }
  761. break;
  762. }
  763. break;
  764. }
  765. if(!decimals)
  766. {
  767. return 0;
  768. }
  769. f = mantissa;
  770. if((exponent != 0) && (mantissa != 0) && !error)
  771. {
  772. f10 = 10.0;
  773. if(exponent < 0)
  774. {
  775. exponent = -exponent;
  776. while(exponent > 0)
  777. {
  778. if((exponent & 1) != 0)
  779. {
  780. f /= f10;
  781. }
  782. exponent /= 2;
  783. f10 *= f10;
  784. }
  785. }
  786. else
  787. {
  788. while(exponent > 0)
  789. {
  790. if((exponent & 1) != 0)
  791. {
  792. f *= f10;
  793. }
  794. exponent /= 2;
  795. f10 *= f10;
  796. }
  797. }
  798. }
  799. if(!error)
  800. {
  801. AppendToken(new TokenFloat(emsg, filNam, lineNo, i - bolIdx, f));
  802. }
  803. return j;
  804. }
  805. /**
  806. * @brief try to parse an integer number from the source
  807. * @param i = starting position within this.source of number
  808. * @returns 0: not an integer number, try something else
  809. * else: position in this.source of terminating character, ie, past number
  810. * TokenInt appended to token list
  811. * or error message has been output
  812. */
  813. private int TryParseInt(int i)
  814. {
  815. bool error;
  816. char c;
  817. int j;
  818. uint basse, m, mantissa;
  819. basse = 10;
  820. error = false;
  821. mantissa = 0;
  822. for(j = i; j < source.Length; j++)
  823. {
  824. c = source[j];
  825. if((c >= '0') && (c <= '9'))
  826. {
  827. m = mantissa * basse + (uint)(c - '0');
  828. if(m / basse != mantissa)
  829. {
  830. if(!error)
  831. TokenError(i, "integer overflow");
  832. error = true;
  833. }
  834. mantissa = m;
  835. continue;
  836. }
  837. if((basse == 16) && ((c >= 'A') && (c <= 'F')))
  838. {
  839. m = mantissa * basse + (uint)(c - 'A') + 10U;
  840. if(m / basse != mantissa)
  841. {
  842. if(!error)
  843. TokenError(i, "integer overflow");
  844. error = true;
  845. }
  846. mantissa = m;
  847. continue;
  848. }
  849. if((basse == 16) && ((c >= 'a') && (c <= 'f')))
  850. {
  851. m = mantissa * basse + (uint)(c - 'a') + 10U;
  852. if(m / basse != mantissa)
  853. {
  854. if(!error)
  855. TokenError(i, "integer overflow");
  856. error = true;
  857. }
  858. mantissa = m;
  859. continue;
  860. }
  861. if(((c == 'x') || (c == 'X')) && (mantissa == 0) && (basse == 10))
  862. {
  863. basse = 16;
  864. continue;
  865. }
  866. break;
  867. }
  868. if(!error)
  869. {
  870. AppendToken(new TokenInt(emsg, filNam, lineNo, i - bolIdx, (int)mantissa));
  871. }
  872. return j;
  873. }
  874. /**
  875. * @brief append token on to end of list
  876. * @param newToken = token to append
  877. * @returns with token appended onto this.lastToken
  878. */
  879. private void AppendToken(Token newToken)
  880. {
  881. newToken.nextToken = null;
  882. newToken.prevToken = lastToken;
  883. newToken.nr2l = this.options.noRightToLeft;
  884. lastToken.nextToken = newToken;
  885. lastToken = newToken;
  886. }
  887. /**
  888. * @brief print tokenizing error message
  889. * and remember that we've an error
  890. * @param i = position within source file of the error
  891. * @param message = error message text
  892. * @returns with this.youveAnError set
  893. */
  894. private void TokenError(int i, string message)
  895. {
  896. Token temp = new Token(this.emsg, this.filNam, this.lineNo, i - this.bolIdx);
  897. temp.ErrorMsg(message);
  898. youveAnError = true;
  899. }
  900. /**
  901. * @brief get a token's constructor
  902. * @param tokenType = token's type
  903. * @returns token's constructor
  904. */
  905. private static Type[] constrTypes = new Type[] {
  906. typeof (TokenErrorMessage), typeof (string), typeof (int), typeof (int)
  907. };
  908. private static System.Reflection.ConstructorInfo GetTokenCtor(Type tokenType)
  909. {
  910. return tokenType.GetConstructor(constrTypes);
  911. }
  912. /**
  913. * @brief delimeter table
  914. */
  915. private class Delim
  916. {
  917. public string str;
  918. public System.Reflection.ConstructorInfo ctorInfo;
  919. public Delim(string str, Type type)
  920. {
  921. this.str = str;
  922. ctorInfo = GetTokenCtor(type);
  923. }
  924. }
  925. private static Delim[] delims = new Delim[] {
  926. new Delim ("...", typeof (TokenKwDotDotDot)),
  927. new Delim ("&&&", typeof (TokenKwAndAndAnd)),
  928. new Delim ("|||", typeof (TokenKwOrOrOr)),
  929. new Delim ("<<=", typeof (TokenKwAsnLSh)),
  930. new Delim (">>=", typeof (TokenKwAsnRSh)),
  931. new Delim ("<=", typeof (TokenKwCmpLE)),
  932. new Delim (">=", typeof (TokenKwCmpGE)),
  933. new Delim ("==", typeof (TokenKwCmpEQ)),
  934. new Delim ("!=", typeof (TokenKwCmpNE)),
  935. new Delim ("++", typeof (TokenKwIncr)),
  936. new Delim ("--", typeof (TokenKwDecr)),
  937. new Delim ("&&", typeof (TokenKwAndAnd)),
  938. new Delim ("||", typeof (TokenKwOrOr)),
  939. new Delim ("+=", typeof (TokenKwAsnAdd)),
  940. new Delim ("&=", typeof (TokenKwAsnAnd)),
  941. new Delim ("-=", typeof (TokenKwAsnSub)),
  942. new Delim ("*=", typeof (TokenKwAsnMul)),
  943. new Delim ("/=", typeof (TokenKwAsnDiv)),
  944. new Delim ("%=", typeof (TokenKwAsnMod)),
  945. new Delim ("|=", typeof (TokenKwAsnOr)),
  946. new Delim ("^=", typeof (TokenKwAsnXor)),
  947. new Delim ("<<", typeof (TokenKwLSh)),
  948. new Delim (">>", typeof (TokenKwRSh)),
  949. new Delim ("~", typeof (TokenKwTilde)),
  950. new Delim ("!", typeof (TokenKwExclam)),
  951. new Delim ("@", typeof (TokenKwAt)),
  952. new Delim ("%", typeof (TokenKwMod)),
  953. new Delim ("^", typeof (TokenKwXor)),
  954. new Delim ("&", typeof (TokenKwAnd)),
  955. new Delim ("*", typeof (TokenKwMul)),
  956. new Delim ("(", typeof (TokenKwParOpen)),
  957. new Delim (")", typeof (TokenKwParClose)),
  958. new Delim ("-", typeof (TokenKwSub)),
  959. new Delim ("+", typeof (TokenKwAdd)),
  960. new Delim ("=", typeof (TokenKwAssign)),
  961. new Delim ("{", typeof (TokenKwBrcOpen)),
  962. new Delim ("}", typeof (TokenKwBrcClose)),
  963. new Delim ("[", typeof (TokenKwBrkOpen)),
  964. new Delim ("]", typeof (TokenKwBrkClose)),
  965. new Delim (";", typeof (TokenKwSemi)),
  966. new Delim (":", typeof (TokenKwColon)),
  967. new Delim ("<", typeof (TokenKwCmpLT)),
  968. new Delim (">", typeof (TokenKwCmpGT)),
  969. new Delim (",", typeof (TokenKwComma)),
  970. new Delim (".", typeof (TokenKwDot)),
  971. new Delim ("?", typeof (TokenKwQMark)),
  972. new Delim ("/", typeof (TokenKwDiv)),
  973. new Delim ("|", typeof (TokenKwOr)),
  974. new Delim ("#", typeof (TokenKwHash))
  975. };
  976. /**
  977. * @brief keyword tables
  978. * The keyword tables translate a keyword string
  979. * to the corresponding token constructor.
  980. */
  981. private static Dictionary<string, System.Reflection.ConstructorInfo> keywords = BuildKeywords();
  982. private static Dictionary<string, System.Reflection.ConstructorInfo> arrayKeywords = BuildArrayKeywords();
  983. private static Dictionary<string, System.Reflection.ConstructorInfo> advFlowCtlKeywords = BuildAdvFlowCtlKeywords();
  984. private static Dictionary<string, System.Reflection.ConstructorInfo> tryCatchKeywords = BuildTryCatchKeywords();
  985. private static Dictionary<string, System.Reflection.ConstructorInfo> objectsKeywords = BuildObjectsKeywords();
  986. private static Dictionary<string, System.Reflection.ConstructorInfo> charsKeywords = BuildCharsKeywords();
  987. private static Dictionary<string, System.Reflection.ConstructorInfo> BuildKeywords()
  988. {
  989. Dictionary<string, System.Reflection.ConstructorInfo> kws = new Dictionary<string, System.Reflection.ConstructorInfo>();
  990. kws.Add("default", GetTokenCtor(typeof(TokenKwDefault)));
  991. kws.Add("do", GetTokenCtor(typeof(TokenKwDo)));
  992. kws.Add("else", GetTokenCtor(typeof(TokenKwElse)));
  993. kws.Add("float", GetTokenCtor(typeof(TokenTypeFloat)));
  994. kws.Add("for", GetTokenCtor(typeof(TokenKwFor)));
  995. kws.Add("if", GetTokenCtor(typeof(TokenKwIf)));
  996. kws.Add("integer", GetTokenCtor(typeof(TokenTypeInt)));
  997. kws.Add("list", GetTokenCtor(typeof(TokenTypeList)));
  998. kws.Add("jump", GetTokenCtor(typeof(TokenKwJump)));
  999. kws.Add("key", GetTokenCtor(typeof(TokenTypeKey)));
  1000. kws.Add("return", GetTokenCtor(typeof(TokenKwRet)));
  1001. kws.Add("rotation", GetTokenCtor(typeof(TokenTypeRot)));
  1002. kws.Add("state", GetTokenCtor(typeof(TokenKwState)));
  1003. kws.Add("string", GetTokenCtor(typeof(TokenTypeStr)));
  1004. kws.Add("vector", GetTokenCtor(typeof(TokenTypeVec)));
  1005. kws.Add("while", GetTokenCtor(typeof(TokenKwWhile)));
  1006. return kws;
  1007. }
  1008. private static Dictionary<string, System.Reflection.ConstructorInfo> BuildArrayKeywords()
  1009. {
  1010. Dictionary<string, System.Reflection.ConstructorInfo> kws = new Dictionary<string, System.Reflection.ConstructorInfo>();
  1011. kws.Add("array", GetTokenCtor(typeof(TokenTypeArray)));
  1012. kws.Add("foreach", GetTokenCtor(typeof(TokenKwForEach)));
  1013. kws.Add("in", GetTokenCtor(typeof(TokenKwIn)));
  1014. kws.Add("is", GetTokenCtor(typeof(TokenKwIs)));
  1015. kws.Add("object", GetTokenCtor(typeof(TokenTypeObject)));
  1016. kws.Add("undef", GetTokenCtor(typeof(TokenKwUndef)));
  1017. return kws;
  1018. }
  1019. private static Dictionary<string, System.Reflection.ConstructorInfo> BuildAdvFlowCtlKeywords()
  1020. {
  1021. Dictionary<string, System.Reflection.ConstructorInfo> kws = new Dictionary<string, System.Reflection.ConstructorInfo>();
  1022. kws.Add("break", GetTokenCtor(typeof(TokenKwBreak)));
  1023. kws.Add("case", GetTokenCtor(typeof(TokenKwCase)));
  1024. kws.Add("constant", GetTokenCtor(typeof(TokenKwConst)));
  1025. kws.Add("continue", GetTokenCtor(typeof(TokenKwCont)));
  1026. kws.Add("switch", GetTokenCtor(typeof(TokenKwSwitch)));
  1027. return kws;
  1028. }
  1029. private static Dictionary<string, System.Reflection.ConstructorInfo> BuildTryCatchKeywords()
  1030. {
  1031. Dictionary<string, System.Reflection.ConstructorInfo> kws = new Dictionary<string, System.Reflection.ConstructorInfo>();
  1032. kws.Add("catch", GetTokenCtor(typeof(TokenKwCatch)));
  1033. kws.Add("exception", GetTokenCtor(typeof(TokenTypeExc)));
  1034. kws.Add("finally", GetTokenCtor(typeof(TokenKwFinally)));
  1035. kws.Add("throw", GetTokenCtor(typeof(TokenKwThrow)));
  1036. kws.Add("try", GetTokenCtor(typeof(TokenKwTry)));
  1037. return kws;
  1038. }
  1039. private static Dictionary<string, System.Reflection.ConstructorInfo> BuildObjectsKeywords()
  1040. {
  1041. Dictionary<string, System.Reflection.ConstructorInfo> kws = new Dictionary<string, System.Reflection.ConstructorInfo>();
  1042. kws.Add("abstract", GetTokenCtor(typeof(TokenKwAbstract)));
  1043. kws.Add("base", GetTokenCtor(typeof(TokenKwBase)));
  1044. kws.Add("class", GetTokenCtor(typeof(TokenKwClass)));
  1045. kws.Add("constructor", GetTokenCtor(typeof(TokenKwConstructor)));
  1046. kws.Add("delegate", GetTokenCtor(typeof(TokenKwDelegate)));
  1047. kws.Add("destructor", GetTokenCtor(typeof(TokenKwDestructor)));
  1048. kws.Add("final", GetTokenCtor(typeof(TokenKwFinal)));
  1049. kws.Add("get", GetTokenCtor(typeof(TokenKwGet)));
  1050. kws.Add("interface", GetTokenCtor(typeof(TokenKwInterface)));
  1051. kws.Add("new", GetTokenCtor(typeof(TokenKwNew)));
  1052. kws.Add("override", GetTokenCtor(typeof(TokenKwOverride)));
  1053. kws.Add("partial", GetTokenCtor(typeof(TokenKwPartial)));
  1054. kws.Add("private", GetTokenCtor(typeof(TokenKwPrivate)));
  1055. kws.Add("protected", GetTokenCtor(typeof(TokenKwProtected)));
  1056. kws.Add("public", GetTokenCtor(typeof(TokenKwPublic)));
  1057. kws.Add("set", GetTokenCtor(typeof(TokenKwSet)));
  1058. kws.Add("static", GetTokenCtor(typeof(TokenKwStatic)));
  1059. kws.Add("this", GetTokenCtor(typeof(TokenKwThis)));
  1060. kws.Add("typedef", GetTokenCtor(typeof(TokenKwTypedef)));
  1061. kws.Add("virtual", GetTokenCtor(typeof(TokenKwVirtual)));
  1062. return kws;
  1063. }
  1064. private static Dictionary<string, System.Reflection.ConstructorInfo> BuildCharsKeywords()
  1065. {
  1066. Dictionary<string, System.Reflection.ConstructorInfo> kws = new Dictionary<string, System.Reflection.ConstructorInfo>();
  1067. kws.Add("char", GetTokenCtor(typeof(TokenTypeChar)));
  1068. return kws;
  1069. }
  1070. }
  1071. /**
  1072. * @brief All output token types in addition to TokenBegin.
  1073. * They are all sub-types of Token.
  1074. */
  1075. public class TokenChar: Token
  1076. {
  1077. public char val;
  1078. public TokenChar(TokenErrorMessage emsg, string file, int line, int posn, char val) : base(emsg, file, line, posn)
  1079. {
  1080. this.val = val;
  1081. }
  1082. public TokenChar(Token original, char val) : base(original)
  1083. {
  1084. this.val = val;
  1085. }
  1086. public override string ToString()
  1087. {
  1088. switch(val)
  1089. {
  1090. case '\'':
  1091. return "'\\''";
  1092. case '\\':
  1093. return "'\\\\'";
  1094. case '\n':
  1095. return "'\\n'";
  1096. case '\t':
  1097. return "'\\t'";
  1098. default:
  1099. return "'" + val + "'";
  1100. }
  1101. }
  1102. }
  1103. public class TokenFloat: Token
  1104. {
  1105. public double val;
  1106. public TokenFloat(TokenErrorMessage emsg, string file, int line, int posn, double val) : base(emsg, file, line, posn)
  1107. {
  1108. this.val = val;
  1109. }
  1110. public override string ToString()
  1111. {
  1112. return val.ToString();
  1113. }
  1114. }
  1115. public class TokenInt: Token
  1116. {
  1117. public int val;
  1118. public TokenInt(TokenErrorMessage emsg, string file, int line, int posn, int val) : base(emsg, file, line, posn)
  1119. {
  1120. this.val = val;
  1121. }
  1122. public TokenInt(Token original, int val) : base(original)
  1123. {
  1124. this.val = val;
  1125. }
  1126. public override string ToString()
  1127. {
  1128. return val.ToString();
  1129. }
  1130. }
  1131. public class TokenName: Token
  1132. {
  1133. public string val;
  1134. public TokenName(TokenErrorMessage emsg, string file, int line, int posn, string val) : base(emsg, file, line, posn)
  1135. {
  1136. this.val = val;
  1137. }
  1138. public TokenName(Token original, string val) : base(original)
  1139. {
  1140. this.val = val;
  1141. }
  1142. public override string ToString()
  1143. {
  1144. return this.val;
  1145. }
  1146. }
  1147. public class TokenStr: Token
  1148. {
  1149. public string val;
  1150. public TokenStr(TokenErrorMessage emsg, string file, int line, int posn, string val) : base(emsg, file, line, posn)
  1151. {
  1152. this.val = val;
  1153. }
  1154. public override string ToString()
  1155. {
  1156. if((val.IndexOf('"') < 0) &&
  1157. (val.IndexOf('\\') < 0) &&
  1158. (val.IndexOf('\n') < 0) &&
  1159. (val.IndexOf('\t') < 0))
  1160. return "\"" + val + "\"";
  1161. int len = val.Length;
  1162. StringBuilder sb = new StringBuilder(len * 2 + 2);
  1163. sb.Append('"');
  1164. for(int i = 0; i < len; i++)
  1165. {
  1166. char c = val[i];
  1167. switch(c)
  1168. {
  1169. case '"':
  1170. {
  1171. sb.Append('\\');
  1172. sb.Append('"');
  1173. break;
  1174. }
  1175. case '\\':
  1176. {
  1177. sb.Append('\\');
  1178. sb.Append('\\');
  1179. break;
  1180. }
  1181. case '\n':
  1182. {
  1183. sb.Append('\\');
  1184. sb.Append('n');
  1185. break;
  1186. }
  1187. case '\t':
  1188. {
  1189. sb.Append('\\');
  1190. sb.Append('t');
  1191. break;
  1192. }
  1193. default:
  1194. {
  1195. sb.Append(c);
  1196. break;
  1197. }
  1198. }
  1199. }
  1200. return sb.ToString();
  1201. }
  1202. }
  1203. /*
  1204. * This one marks the end-of-file.
  1205. */
  1206. public class TokenEnd: Token
  1207. {
  1208. public TokenEnd(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  1209. }
  1210. /*
  1211. * Various keywords and delimeters.
  1212. */
  1213. public delegate object TokenRValConstBinOpDelegate(object left, object right);
  1214. public delegate object TokenRValConstUnOpDelegate(object right);
  1215. public class TokenKw: Token
  1216. {
  1217. public TokenRValConstBinOpDelegate binOpConst;
  1218. public TokenRValConstUnOpDelegate unOpConst;
  1219. public bool sdtClassOp;
  1220. public TokenKw(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn)
  1221. {
  1222. }
  1223. public TokenKw(Token original) : base(original)
  1224. {
  1225. }
  1226. }
  1227. public class TokenKwDotDotDot: TokenKw
  1228. {
  1229. public TokenKwDotDotDot(TokenErrorMessage emsg, string file,
  1230. int line, int posn) : base(emsg, file, line, posn)
  1231. {
  1232. binOpConst = TokenRValConstOps.Null;
  1233. unOpConst = TokenRValConstOps.Null;
  1234. sdtClassOp = false;
  1235. }
  1236. public TokenKwDotDotDot(Token original) : base(original)
  1237. {
  1238. binOpConst = TokenRValConstOps.Null;
  1239. unOpConst = TokenRValConstOps.Null;
  1240. sdtClassOp = false;
  1241. }
  1242. public override string ToString()
  1243. {
  1244. return "...";
  1245. }
  1246. }
  1247. public class TokenKwAndAndAnd: TokenKw
  1248. {
  1249. public TokenKwAndAndAnd(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn)
  1250. {
  1251. binOpConst = TokenRValConstOps.Null;
  1252. unOpConst = TokenRValConstOps.Null;
  1253. sdtClassOp = false;
  1254. }
  1255. public TokenKwAndAndAnd(Token original) : base(original)
  1256. {
  1257. binOpConst = TokenRValConstOps.Null;
  1258. unOpConst = TokenRValConstOps.Null;
  1259. sdtClassOp = false;
  1260. }
  1261. public override string ToString()
  1262. {
  1263. return "&&&";
  1264. }
  1265. }
  1266. public class TokenKwOrOrOr: TokenKw
  1267. {
  1268. public TokenKwOrOrOr(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn)
  1269. {
  1270. binOpConst = TokenRValConstOps.Null;
  1271. unOpConst = TokenRValConstOps.Null;
  1272. sdtClassOp = false;
  1273. }
  1274. public TokenKwOrOrOr(Token original) : base(original)
  1275. {
  1276. binOpConst = TokenRValConstOps.Null;
  1277. unOpConst = TokenRValConstOps.Null;
  1278. sdtClassOp = false;
  1279. }
  1280. public override string ToString()
  1281. {
  1282. return "|||";
  1283. }
  1284. }
  1285. public class TokenKwAsnLSh: TokenKw
  1286. {
  1287. public TokenKwAsnLSh(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn)
  1288. {
  1289. binOpConst = TokenRValConstOps.Null;
  1290. unOpConst = TokenRValConstOps.Null;
  1291. sdtClassOp = true;
  1292. }
  1293. public TokenKwAsnLSh(Token original) : base(original)
  1294. {
  1295. binOpConst = TokenRValConstOps.Null;
  1296. unOpConst = TokenRValConstOps.Null;
  1297. sdtClassOp = true;
  1298. }
  1299. public override string ToString()
  1300. {
  1301. return "<<=";
  1302. }
  1303. }
  1304. public class TokenKwAsnRSh: TokenKw
  1305. {
  1306. public TokenKwAsnRSh(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1307. public TokenKwAsnRSh(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1308. public override string ToString()
  1309. {
  1310. return ">>=";
  1311. }
  1312. }
  1313. public class TokenKwCmpLE: TokenKw
  1314. {
  1315. public TokenKwCmpLE(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.binConstsLE; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1316. public TokenKwCmpLE(Token original) : base(original) { binOpConst = TokenRValConstOps.binConstsLE; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1317. public override string ToString()
  1318. {
  1319. return "<=";
  1320. }
  1321. }
  1322. public class TokenKwCmpGE: TokenKw
  1323. {
  1324. public TokenKwCmpGE(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.binConstsGE; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1325. public TokenKwCmpGE(Token original) : base(original) { binOpConst = TokenRValConstOps.binConstsGE; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1326. public override string ToString()
  1327. {
  1328. return ">=";
  1329. }
  1330. }
  1331. public class TokenKwCmpEQ: TokenKw
  1332. {
  1333. public TokenKwCmpEQ(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.binConstsEQ; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1334. public TokenKwCmpEQ(Token original) : base(original) { binOpConst = TokenRValConstOps.binConstsEQ; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1335. public override string ToString()
  1336. {
  1337. return "==";
  1338. }
  1339. }
  1340. public class TokenKwCmpNE: TokenKw
  1341. {
  1342. public TokenKwCmpNE(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.binConstsNE; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1343. public TokenKwCmpNE(Token original) : base(original) { binOpConst = TokenRValConstOps.binConstsNE; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1344. public override string ToString()
  1345. {
  1346. return "!=";
  1347. }
  1348. }
  1349. public class TokenKwIncr: TokenKw
  1350. {
  1351. public TokenKwIncr(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1352. public TokenKwIncr(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1353. public override string ToString()
  1354. {
  1355. return "++";
  1356. }
  1357. }
  1358. public class TokenKwDecr: TokenKw
  1359. {
  1360. public TokenKwDecr(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1361. public TokenKwDecr(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1362. public override string ToString()
  1363. {
  1364. return "--";
  1365. }
  1366. }
  1367. public class TokenKwAndAnd: TokenKw
  1368. {
  1369. public TokenKwAndAnd(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1370. public TokenKwAndAnd(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1371. public override string ToString()
  1372. {
  1373. return "&&";
  1374. }
  1375. }
  1376. public class TokenKwOrOr: TokenKw
  1377. {
  1378. public TokenKwOrOr(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1379. public TokenKwOrOr(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1380. public override string ToString()
  1381. {
  1382. return "||";
  1383. }
  1384. }
  1385. public class TokenKwAsnAdd: TokenKw
  1386. {
  1387. public TokenKwAsnAdd(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1388. public TokenKwAsnAdd(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1389. public override string ToString()
  1390. {
  1391. return "+=";
  1392. }
  1393. }
  1394. public class TokenKwAsnAnd: TokenKw
  1395. {
  1396. public TokenKwAsnAnd(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1397. public TokenKwAsnAnd(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1398. public override string ToString()
  1399. {
  1400. return "&=";
  1401. }
  1402. }
  1403. public class TokenKwAsnSub: TokenKw
  1404. {
  1405. public TokenKwAsnSub(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1406. public TokenKwAsnSub(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1407. public override string ToString()
  1408. {
  1409. return "-=";
  1410. }
  1411. }
  1412. public class TokenKwAsnMul: TokenKw
  1413. {
  1414. public TokenKwAsnMul(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1415. public TokenKwAsnMul(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1416. public override string ToString()
  1417. {
  1418. return "*=";
  1419. }
  1420. }
  1421. public class TokenKwAsnDiv: TokenKw
  1422. {
  1423. public TokenKwAsnDiv(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1424. public TokenKwAsnDiv(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1425. public override string ToString()
  1426. {
  1427. return "/=";
  1428. }
  1429. }
  1430. public class TokenKwAsnMod: TokenKw
  1431. {
  1432. public TokenKwAsnMod(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1433. public TokenKwAsnMod(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1434. public override string ToString()
  1435. {
  1436. return "%=";
  1437. }
  1438. }
  1439. public class TokenKwAsnOr: TokenKw
  1440. {
  1441. public TokenKwAsnOr(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1442. public TokenKwAsnOr(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1443. public override string ToString()
  1444. {
  1445. return "|=";
  1446. }
  1447. }
  1448. public class TokenKwAsnXor: TokenKw
  1449. {
  1450. public TokenKwAsnXor(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1451. public TokenKwAsnXor(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1452. public override string ToString()
  1453. {
  1454. return "^=";
  1455. }
  1456. }
  1457. public class TokenKwLSh: TokenKw
  1458. {
  1459. public TokenKwLSh(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.LSh; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1460. public TokenKwLSh(Token original) : base(original) { binOpConst = TokenRValConstOps.LSh; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1461. public override string ToString()
  1462. {
  1463. return "<<";
  1464. }
  1465. }
  1466. public class TokenKwRSh: TokenKw
  1467. {
  1468. public TokenKwRSh(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.RSh; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1469. public TokenKwRSh(Token original) : base(original) { binOpConst = TokenRValConstOps.RSh; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1470. public override string ToString()
  1471. {
  1472. return ">>";
  1473. }
  1474. }
  1475. public class TokenKwTilde: TokenKw
  1476. {
  1477. public TokenKwTilde(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Not; sdtClassOp = true; }
  1478. public TokenKwTilde(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Not; sdtClassOp = true; }
  1479. public override string ToString()
  1480. {
  1481. return "~";
  1482. }
  1483. }
  1484. public class TokenKwExclam: TokenKw
  1485. {
  1486. public TokenKwExclam(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1487. public TokenKwExclam(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1488. public override string ToString()
  1489. {
  1490. return "!";
  1491. }
  1492. }
  1493. public class TokenKwAt: TokenKw
  1494. {
  1495. public TokenKwAt(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1496. public TokenKwAt(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1497. public override string ToString()
  1498. {
  1499. return "@";
  1500. }
  1501. }
  1502. public class TokenKwMod: TokenKw
  1503. {
  1504. public TokenKwMod(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Mod; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1505. public TokenKwMod(Token original) : base(original) { binOpConst = TokenRValConstOps.Mod; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1506. public override string ToString()
  1507. {
  1508. return "%";
  1509. }
  1510. }
  1511. public class TokenKwXor: TokenKw
  1512. {
  1513. public TokenKwXor(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Xor; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1514. public TokenKwXor(Token original) : base(original) { binOpConst = TokenRValConstOps.Xor; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1515. public override string ToString()
  1516. {
  1517. return "^";
  1518. }
  1519. }
  1520. public class TokenKwAnd: TokenKw
  1521. {
  1522. public TokenKwAnd(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.And; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1523. public TokenKwAnd(Token original) : base(original) { binOpConst = TokenRValConstOps.And; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1524. public override string ToString()
  1525. {
  1526. return "&";
  1527. }
  1528. }
  1529. public class TokenKwMul: TokenKw
  1530. {
  1531. public TokenKwMul(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Mul; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1532. public TokenKwMul(Token original) : base(original) { binOpConst = TokenRValConstOps.Mul; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1533. public override string ToString()
  1534. {
  1535. return "*";
  1536. }
  1537. }
  1538. public class TokenKwParOpen: TokenKw
  1539. {
  1540. public TokenKwParOpen(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1541. public TokenKwParOpen(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1542. public override string ToString()
  1543. {
  1544. return "(";
  1545. }
  1546. }
  1547. public class TokenKwParClose: TokenKw
  1548. {
  1549. public TokenKwParClose(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1550. public TokenKwParClose(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1551. public override string ToString()
  1552. {
  1553. return ")";
  1554. }
  1555. }
  1556. public class TokenKwSub: TokenKw
  1557. {
  1558. public TokenKwSub(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Sub; unOpConst = TokenRValConstOps.Neg; sdtClassOp = true; }
  1559. public TokenKwSub(Token original) : base(original) { binOpConst = TokenRValConstOps.Sub; unOpConst = TokenRValConstOps.Neg; sdtClassOp = true; }
  1560. public override string ToString()
  1561. {
  1562. return "-";
  1563. }
  1564. }
  1565. public class TokenKwAdd: TokenKw
  1566. {
  1567. public TokenKwAdd(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Add; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1568. public TokenKwAdd(Token original) : base(original) { binOpConst = TokenRValConstOps.Add; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1569. public override string ToString()
  1570. {
  1571. return "+";
  1572. }
  1573. }
  1574. public class TokenKwAssign: TokenKw
  1575. {
  1576. public TokenKwAssign(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1577. public TokenKwAssign(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1578. public override string ToString()
  1579. {
  1580. return "=";
  1581. }
  1582. }
  1583. public class TokenKwBrcOpen: TokenKw
  1584. {
  1585. public TokenKwBrcOpen(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1586. public TokenKwBrcOpen(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1587. public override string ToString()
  1588. {
  1589. return "{";
  1590. }
  1591. }
  1592. public class TokenKwBrcClose: TokenKw
  1593. {
  1594. public TokenKwBrcClose(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1595. public TokenKwBrcClose(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1596. public override string ToString()
  1597. {
  1598. return "}";
  1599. }
  1600. }
  1601. public class TokenKwBrkOpen: TokenKw
  1602. {
  1603. public TokenKwBrkOpen(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1604. public TokenKwBrkOpen(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1605. public override string ToString()
  1606. {
  1607. return "[";
  1608. }
  1609. }
  1610. public class TokenKwBrkClose: TokenKw
  1611. {
  1612. public TokenKwBrkClose(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1613. public TokenKwBrkClose(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1614. public override string ToString()
  1615. {
  1616. return "]";
  1617. }
  1618. }
  1619. public class TokenKwSemi: TokenKw
  1620. {
  1621. public TokenKwSemi(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1622. public TokenKwSemi(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1623. public override string ToString()
  1624. {
  1625. return ";";
  1626. }
  1627. }
  1628. public class TokenKwColon: TokenKw
  1629. {
  1630. public TokenKwColon(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1631. public TokenKwColon(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1632. public override string ToString()
  1633. {
  1634. return ":";
  1635. }
  1636. }
  1637. public class TokenKwCmpLT: TokenKw
  1638. {
  1639. public TokenKwCmpLT(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.binConstsLT; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1640. public TokenKwCmpLT(Token original) : base(original) { binOpConst = TokenRValConstOps.binConstsLT; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1641. public override string ToString()
  1642. {
  1643. return "<";
  1644. }
  1645. }
  1646. public class TokenKwCmpGT: TokenKw
  1647. {
  1648. public TokenKwCmpGT(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.binConstsGT; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1649. public TokenKwCmpGT(Token original) : base(original) { binOpConst = TokenRValConstOps.binConstsGT; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1650. public override string ToString()
  1651. {
  1652. return ">";
  1653. }
  1654. }
  1655. public class TokenKwComma: TokenKw
  1656. {
  1657. public TokenKwComma(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1658. public TokenKwComma(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1659. public override string ToString()
  1660. {
  1661. return ",";
  1662. }
  1663. }
  1664. public class TokenKwDot: TokenKw
  1665. {
  1666. public TokenKwDot(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1667. public TokenKwDot(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1668. public override string ToString()
  1669. {
  1670. return ".";
  1671. }
  1672. }
  1673. public class TokenKwQMark: TokenKw
  1674. {
  1675. public TokenKwQMark(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1676. public TokenKwQMark(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1677. public override string ToString()
  1678. {
  1679. return "?";
  1680. }
  1681. }
  1682. public class TokenKwDiv: TokenKw
  1683. {
  1684. public TokenKwDiv(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Div; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1685. public TokenKwDiv(Token original) : base(original) { binOpConst = TokenRValConstOps.Div; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1686. public override string ToString()
  1687. {
  1688. return "/";
  1689. }
  1690. }
  1691. public class TokenKwOr: TokenKw
  1692. {
  1693. public TokenKwOr(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Or; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1694. public TokenKwOr(Token original) : base(original) { binOpConst = TokenRValConstOps.Or; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1695. public override string ToString()
  1696. {
  1697. return "|";
  1698. }
  1699. }
  1700. public class TokenKwHash: TokenKw
  1701. {
  1702. public TokenKwHash(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1703. public TokenKwHash(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1704. public override string ToString()
  1705. {
  1706. return "#";
  1707. }
  1708. }
  1709. public class TokenKwAbstract: TokenKw
  1710. {
  1711. public TokenKwAbstract(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1712. public TokenKwAbstract(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1713. public override string ToString()
  1714. {
  1715. return "abstract";
  1716. }
  1717. }
  1718. public class TokenKwBase: TokenKw
  1719. {
  1720. public TokenKwBase(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1721. public TokenKwBase(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1722. public override string ToString()
  1723. {
  1724. return "base";
  1725. }
  1726. }
  1727. public class TokenKwBreak: TokenKw
  1728. {
  1729. public TokenKwBreak(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1730. public TokenKwBreak(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1731. public override string ToString()
  1732. {
  1733. return "break";
  1734. }
  1735. }
  1736. public class TokenKwCase: TokenKw
  1737. {
  1738. public TokenKwCase(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1739. public TokenKwCase(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1740. public override string ToString()
  1741. {
  1742. return "case";
  1743. }
  1744. }
  1745. public class TokenKwCatch: TokenKw
  1746. {
  1747. public TokenKwCatch(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1748. public TokenKwCatch(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1749. public override string ToString()
  1750. {
  1751. return "catch";
  1752. }
  1753. }
  1754. public class TokenKwClass: TokenKw
  1755. {
  1756. public TokenKwClass(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1757. public TokenKwClass(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1758. public override string ToString()
  1759. {
  1760. return "class";
  1761. }
  1762. }
  1763. public class TokenKwConst: TokenKw
  1764. {
  1765. public TokenKwConst(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1766. public TokenKwConst(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1767. public override string ToString()
  1768. {
  1769. return "constant";
  1770. }
  1771. }
  1772. public class TokenKwConstructor: TokenKw
  1773. {
  1774. public TokenKwConstructor(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1775. public TokenKwConstructor(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1776. public override string ToString()
  1777. {
  1778. return "constructor";
  1779. }
  1780. }
  1781. public class TokenKwCont: TokenKw
  1782. {
  1783. public TokenKwCont(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1784. public TokenKwCont(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1785. public override string ToString()
  1786. {
  1787. return "continue";
  1788. }
  1789. }
  1790. public class TokenKwDelegate: TokenKw
  1791. {
  1792. public TokenKwDelegate(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1793. public TokenKwDelegate(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1794. public override string ToString()
  1795. {
  1796. return "delegate";
  1797. }
  1798. }
  1799. public class TokenKwDefault: TokenKw
  1800. {
  1801. public TokenKwDefault(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1802. public TokenKwDefault(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1803. public override string ToString()
  1804. {
  1805. return "default";
  1806. }
  1807. }
  1808. public class TokenKwDestructor: TokenKw
  1809. {
  1810. public TokenKwDestructor(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1811. public TokenKwDestructor(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1812. public override string ToString()
  1813. {
  1814. return "destructor";
  1815. }
  1816. }
  1817. public class TokenKwDo: TokenKw
  1818. {
  1819. public TokenKwDo(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1820. public TokenKwDo(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1821. public override string ToString()
  1822. {
  1823. return "do";
  1824. }
  1825. }
  1826. public class TokenKwElse: TokenKw
  1827. {
  1828. public TokenKwElse(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1829. public TokenKwElse(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1830. public override string ToString()
  1831. {
  1832. return "else";
  1833. }
  1834. }
  1835. public class TokenKwFinal: TokenKw
  1836. {
  1837. public TokenKwFinal(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1838. public TokenKwFinal(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1839. public override string ToString()
  1840. {
  1841. return "final";
  1842. }
  1843. }
  1844. public class TokenKwFinally: TokenKw
  1845. {
  1846. public TokenKwFinally(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1847. public TokenKwFinally(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1848. public override string ToString()
  1849. {
  1850. return "finally";
  1851. }
  1852. }
  1853. public class TokenKwFor: TokenKw
  1854. {
  1855. public TokenKwFor(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1856. public TokenKwFor(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1857. public override string ToString()
  1858. {
  1859. return "for";
  1860. }
  1861. }
  1862. public class TokenKwForEach: TokenKw
  1863. {
  1864. public TokenKwForEach(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1865. public TokenKwForEach(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1866. public override string ToString()
  1867. {
  1868. return "foreach";
  1869. }
  1870. }
  1871. public class TokenKwGet: TokenKw
  1872. {
  1873. public TokenKwGet(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1874. public TokenKwGet(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1875. public override string ToString()
  1876. {
  1877. return "get";
  1878. }
  1879. }
  1880. public class TokenKwIf: TokenKw
  1881. {
  1882. public TokenKwIf(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1883. public TokenKwIf(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1884. public override string ToString()
  1885. {
  1886. return "if";
  1887. }
  1888. }
  1889. public class TokenKwIn: TokenKw
  1890. {
  1891. public TokenKwIn(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1892. public TokenKwIn(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1893. public override string ToString()
  1894. {
  1895. return "in";
  1896. }
  1897. }
  1898. public class TokenKwInterface: TokenKw
  1899. {
  1900. public TokenKwInterface(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1901. public TokenKwInterface(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1902. public override string ToString()
  1903. {
  1904. return "interface";
  1905. }
  1906. }
  1907. public class TokenKwIs: TokenKw
  1908. {
  1909. public TokenKwIs(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1910. public TokenKwIs(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1911. public override string ToString()
  1912. {
  1913. return "is";
  1914. }
  1915. }
  1916. public class TokenKwJump: TokenKw
  1917. {
  1918. public TokenKwJump(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1919. public TokenKwJump(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1920. public override string ToString()
  1921. {
  1922. return "jump";
  1923. }
  1924. }
  1925. public class TokenKwNew: TokenKw
  1926. {
  1927. public TokenKwNew(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1928. public TokenKwNew(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1929. public override string ToString()
  1930. {
  1931. return "new";
  1932. }
  1933. }
  1934. public class TokenKwOverride: TokenKw
  1935. {
  1936. public TokenKwOverride(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1937. public TokenKwOverride(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1938. public override string ToString()
  1939. {
  1940. return "override";
  1941. }
  1942. }
  1943. public class TokenKwPartial: TokenKw
  1944. {
  1945. public TokenKwPartial(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1946. public TokenKwPartial(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1947. public override string ToString()
  1948. {
  1949. return "partial";
  1950. }
  1951. }
  1952. public class TokenKwPrivate: TokenKw
  1953. {
  1954. public TokenKwPrivate(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1955. public TokenKwPrivate(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1956. public override string ToString()
  1957. {
  1958. return "private";
  1959. }
  1960. }
  1961. public class TokenKwProtected: TokenKw
  1962. {
  1963. public TokenKwProtected(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1964. public TokenKwProtected(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1965. public override string ToString()
  1966. {
  1967. return "protected";
  1968. }
  1969. }
  1970. public class TokenKwPublic: TokenKw
  1971. {
  1972. public TokenKwPublic(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1973. public TokenKwPublic(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1974. public override string ToString()
  1975. {
  1976. return "public";
  1977. }
  1978. }
  1979. public class TokenKwRet: TokenKw
  1980. {
  1981. public TokenKwRet(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1982. public TokenKwRet(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1983. public override string ToString()
  1984. {
  1985. return "return";
  1986. }
  1987. }
  1988. public class TokenKwSet: TokenKw
  1989. {
  1990. public TokenKwSet(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1991. public TokenKwSet(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1992. public override string ToString()
  1993. {
  1994. return "set";
  1995. }
  1996. }
  1997. public class TokenKwState: TokenKw
  1998. {
  1999. public TokenKwState(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2000. public TokenKwState(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2001. public override string ToString()
  2002. {
  2003. return "state";
  2004. }
  2005. }
  2006. public class TokenKwStatic: TokenKw
  2007. {
  2008. public TokenKwStatic(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2009. public TokenKwStatic(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2010. public override string ToString()
  2011. {
  2012. return "static";
  2013. }
  2014. }
  2015. public class TokenKwSwitch: TokenKw
  2016. {
  2017. public TokenKwSwitch(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2018. public TokenKwSwitch(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2019. public override string ToString()
  2020. {
  2021. return "switch";
  2022. }
  2023. }
  2024. public class TokenKwThis: TokenKw
  2025. {
  2026. public TokenKwThis(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2027. public TokenKwThis(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2028. public override string ToString()
  2029. {
  2030. return "this";
  2031. }
  2032. }
  2033. public class TokenKwThrow: TokenKw
  2034. {
  2035. public TokenKwThrow(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2036. public TokenKwThrow(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2037. public override string ToString()
  2038. {
  2039. return "throw";
  2040. }
  2041. }
  2042. public class TokenKwTry: TokenKw
  2043. {
  2044. public TokenKwTry(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2045. public TokenKwTry(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2046. public override string ToString()
  2047. {
  2048. return "try";
  2049. }
  2050. }
  2051. public class TokenKwTypedef: TokenKw
  2052. {
  2053. public TokenKwTypedef(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2054. public TokenKwTypedef(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2055. public override string ToString()
  2056. {
  2057. return "typedef";
  2058. }
  2059. }
  2060. public class TokenKwUndef: TokenKw
  2061. {
  2062. public TokenKwUndef(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2063. public TokenKwUndef(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2064. public override string ToString()
  2065. {
  2066. return "undef";
  2067. }
  2068. }
  2069. public class TokenKwVirtual: TokenKw
  2070. {
  2071. public TokenKwVirtual(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2072. public TokenKwVirtual(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2073. public override string ToString()
  2074. {
  2075. return "virtual";
  2076. }
  2077. }
  2078. public class TokenKwWhile: TokenKw
  2079. {
  2080. public TokenKwWhile(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2081. public TokenKwWhile(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2082. public override string ToString()
  2083. {
  2084. return "while";
  2085. }
  2086. }
  2087. /**
  2088. * @brief These static functions attempt to perform arithmetic on two constant
  2089. * operands to generate the resultant constant.
  2090. * Likewise for unary operators.
  2091. *
  2092. * @param left = left-hand value
  2093. * @param right = right-hand value
  2094. * @returns null: not able to perform computation
  2095. * else: resultant value object
  2096. *
  2097. * Note: it is ok for these to throw any exception (such as overflow or div-by-zero),
  2098. * and it will be treated as the 'not able to perform computation' case.
  2099. */
  2100. public class TokenRValConstOps
  2101. {
  2102. public static object Null(object left, object right)
  2103. {
  2104. return null;
  2105. }
  2106. public static object Div(object left, object right)
  2107. {
  2108. double r;
  2109. try
  2110. {
  2111. if ((left is int) && (right is int))
  2112. {
  2113. return (int)left / (int)right;
  2114. }
  2115. if ((left is double) && (right is int))
  2116. {
  2117. r = (double)left / (int)right;
  2118. if (double.IsNaN(r) || double.IsInfinity(r))
  2119. throw new Exception("Division by Zero");
  2120. return r;
  2121. }
  2122. }
  2123. catch (DivideByZeroException)
  2124. {
  2125. throw new Exception("Division by Zero");
  2126. }
  2127. if ((left is int) && (right is double))
  2128. {
  2129. r = (int)left / (double)right;
  2130. }
  2131. else if((left is double) && (right is double))
  2132. {
  2133. r= (double)left / (double)right;
  2134. }
  2135. else
  2136. return null;
  2137. if (double.IsNaN(r) || double.IsInfinity(r))
  2138. throw new Exception("Division by Zero");
  2139. return r;
  2140. }
  2141. public static object Mod(object left, object right)
  2142. {
  2143. double r;
  2144. try
  2145. {
  2146. if ((left is int) && (right is int))
  2147. {
  2148. return (int)left % (int)right;
  2149. }
  2150. if ((left is double) && (right is int))
  2151. {
  2152. r = (double)left % (int)right;
  2153. if (double.IsNaN(r) || double.IsInfinity(r))
  2154. throw new Exception("Division by Zero");
  2155. return r;
  2156. }
  2157. }
  2158. catch (DivideByZeroException)
  2159. {
  2160. throw new Exception("Division by Zero");
  2161. }
  2162. if ((left is int) && (right is double))
  2163. {
  2164. r = (int)left % (double)right;
  2165. }
  2166. else if ((left is double) && (right is double))
  2167. {
  2168. r = (double)left % (double)right;
  2169. }
  2170. else
  2171. return null;
  2172. if (double.IsNaN(r) || double.IsInfinity(r))
  2173. throw new Exception("Division by Zero");
  2174. return r;
  2175. }
  2176. public static object Mul(object left, object right)
  2177. {
  2178. if((left is int) && (right is int))
  2179. {
  2180. return (int)left * (int)right;
  2181. }
  2182. if((left is int) && (right is double))
  2183. {
  2184. return (int)left * (double)right;
  2185. }
  2186. if((left is double) && (right is int))
  2187. {
  2188. return (double)left * (int)right;
  2189. }
  2190. if((left is double) && (right is double))
  2191. {
  2192. return (double)left * (double)right;
  2193. }
  2194. return null;
  2195. }
  2196. public static object And(object left, object right)
  2197. {
  2198. if((left is int) && (right is int))
  2199. {
  2200. return (int)left & (int)right;
  2201. }
  2202. if((left is int) && (right is double))
  2203. {
  2204. return (int)left & (int)(double)right;
  2205. }
  2206. if((left is double) && (right is int))
  2207. {
  2208. return (int)(double)left & (int)right;
  2209. }
  2210. if((left is double) && (right is double))
  2211. {
  2212. return (int)(double)left & (int)(double)right;
  2213. }
  2214. return null;
  2215. }
  2216. public static object LSh(object left, object right)
  2217. {
  2218. if((left is int) && (right is int))
  2219. {
  2220. return (int)left << (int)right;
  2221. }
  2222. if((left is int) && (right is double))
  2223. {
  2224. return (int)left << (int)(double)right;
  2225. }
  2226. if((left is double) && (right is int))
  2227. {
  2228. return (int)(double)left << (int)right;
  2229. }
  2230. if((left is double) && (right is double))
  2231. {
  2232. return (int)(double)left << (int)(double)right;
  2233. }
  2234. return null;
  2235. }
  2236. public static object Or(object left, object right)
  2237. {
  2238. if((left is int) && (right is int))
  2239. {
  2240. return (int)left | (int)right;
  2241. }
  2242. if((left is int) && (right is double))
  2243. {
  2244. return (int)left | (int)(double)right;
  2245. }
  2246. if((left is double) && (right is int))
  2247. {
  2248. return (int)(double)left | (int)right;
  2249. }
  2250. if((left is double) && (right is double))
  2251. {
  2252. return (int)(double)left | (int)(double)right;
  2253. }
  2254. return null;
  2255. }
  2256. public static object RSh(object left, object right)
  2257. {
  2258. if((left is int) && (right is int))
  2259. {
  2260. return (int)left >> (int)right;
  2261. }
  2262. if((left is int) && (right is double))
  2263. {
  2264. return (int)left >> (int)(double)right;
  2265. }
  2266. if((left is double) && (right is int))
  2267. {
  2268. return (int)(double)left >> (int)right;
  2269. }
  2270. if((left is double) && (right is double))
  2271. {
  2272. return (int)(double)left >> (int)(double)right;
  2273. }
  2274. return null;
  2275. }
  2276. public static object Xor(object left, object right)
  2277. {
  2278. if((left is int) && (right is int))
  2279. {
  2280. return (int)left ^ (int)right;
  2281. }
  2282. if((left is int) && (right is double))
  2283. {
  2284. return (int)left ^ (int)(double)right;
  2285. }
  2286. if((left is double) && (right is int))
  2287. {
  2288. return (int)(double)left ^ (int)right;
  2289. }
  2290. if((left is double) && (right is double))
  2291. {
  2292. return (int)(double)left ^ (int)(double)right;
  2293. }
  2294. return null;
  2295. }
  2296. public static object Add(object left, object right)
  2297. {
  2298. if((left is char) && (right is int))
  2299. {
  2300. return (char)((char)left + (int)right);
  2301. }
  2302. if((left is double) && (right is double))
  2303. {
  2304. return (double)left + (double)right;
  2305. }
  2306. if((left is double) && (right is int))
  2307. {
  2308. return (double)left + (int)right;
  2309. }
  2310. if((left is double) && (right is string))
  2311. {
  2312. return TypeCast.FloatToString((double)left) + (string)right;
  2313. }
  2314. if((left is int) && (right is double))
  2315. {
  2316. return (int)left + (double)right;
  2317. }
  2318. if((left is int) && (right is int))
  2319. {
  2320. return (int)left + (int)right;
  2321. }
  2322. if((left is int) && (right is string))
  2323. {
  2324. return TypeCast.IntegerToString((int)left) + (string)right;
  2325. }
  2326. if((left is string) && (right is char))
  2327. {
  2328. return (string)left + (char)right;
  2329. }
  2330. if((left is string) && (right is double))
  2331. {
  2332. return (string)left + TypeCast.FloatToString((double)right);
  2333. }
  2334. if((left is string) && (right is int))
  2335. {
  2336. return (string)left + TypeCast.IntegerToString((int)right);
  2337. }
  2338. if((left is string) && (right is string))
  2339. {
  2340. return (string)left + (string)right;
  2341. }
  2342. return null;
  2343. }
  2344. public static object Sub(object left, object right)
  2345. {
  2346. if((left is char) && (right is int))
  2347. {
  2348. return (char)((char)left - (int)right);
  2349. }
  2350. if((left is int) && (right is int))
  2351. {
  2352. return (int)left - (int)right;
  2353. }
  2354. if((left is int) && (right is double))
  2355. {
  2356. return (int)left - (double)right;
  2357. }
  2358. if((left is double) && (right is int))
  2359. {
  2360. return (double)left - (int)right;
  2361. }
  2362. if((left is double) && (right is double))
  2363. {
  2364. return (double)left - (double)right;
  2365. }
  2366. return null;
  2367. }
  2368. public static object Null(object right)
  2369. {
  2370. return null;
  2371. }
  2372. public static object Neg(object right)
  2373. {
  2374. if(right is int)
  2375. {
  2376. return -(int)right;
  2377. }
  2378. if(right is double)
  2379. {
  2380. return -(double)right;
  2381. }
  2382. return null;
  2383. }
  2384. public static object Not(object right)
  2385. {
  2386. if(right is int)
  2387. {
  2388. return ~(int)right;
  2389. }
  2390. return null;
  2391. }
  2392. public static int binConstCompare(object left, object right)
  2393. {
  2394. double a;
  2395. if (left is bool lb)
  2396. a = lb ? 1.0 : 0.0;
  2397. else if (left is int li)
  2398. a = li;
  2399. else if (left is float lf)
  2400. a = lf;
  2401. else if (left is double ld)
  2402. a = ld;
  2403. else if(left is string ls)
  2404. {
  2405. if(!(right is string rs))
  2406. return -2;
  2407. return ls.CompareTo(rs);
  2408. }
  2409. else
  2410. return -2;
  2411. double b;
  2412. if (right is bool rb)
  2413. b = rb ? 1.0 : 0.0;
  2414. else if (right is int ri)
  2415. b = ri;
  2416. else if (right is float rf)
  2417. b = rf;
  2418. else if (right is double rd)
  2419. b = rd;
  2420. else
  2421. return -2;
  2422. return a.CompareTo(b);
  2423. }
  2424. public static object binConstsLT(object left, object right)
  2425. {
  2426. int res = binConstCompare(left, right);
  2427. if (res == -2)
  2428. return null;
  2429. return (res < 0) ? 1 : 0;
  2430. }
  2431. public static object binConstsLE(object left, object right)
  2432. {
  2433. int res = binConstCompare(left, right);
  2434. if (res == -2)
  2435. return null;
  2436. return (res <= 0) ? 1 : 0;
  2437. }
  2438. public static object binConstsGT(object left, object right)
  2439. {
  2440. int res = binConstCompare(left, right);
  2441. if (res == -2)
  2442. return null;
  2443. return (res > 0) ? 1 : 0;
  2444. }
  2445. public static object binConstsGE(object left, object right)
  2446. {
  2447. int res = binConstCompare(left, right);
  2448. if (res == -2)
  2449. return null;
  2450. return (res >= 0) ? 1 : 0;
  2451. }
  2452. public static object binConstsEQ(object left, object right)
  2453. {
  2454. int res = binConstCompare(left, right);
  2455. if (res == -2)
  2456. return null;
  2457. return (res == 0) ? 1 : 0;
  2458. }
  2459. public static object binConstsNE(object left, object right)
  2460. {
  2461. int res = binConstCompare(left, right);
  2462. if (res == -2)
  2463. return null;
  2464. return (res != 0) ? 1 : 0;
  2465. }
  2466. }
  2467. /*
  2468. * Various datatypes.
  2469. */
  2470. public abstract class TokenType: Token
  2471. {
  2472. public TokenType(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2473. public TokenType(Token original) : base(original) { }
  2474. public static TokenType FromSysType(Token original, System.Type typ)
  2475. {
  2476. if(typ == typeof(LSL_List))
  2477. return new TokenTypeList(original);
  2478. if(typ == typeof(LSL_Rotation))
  2479. return new TokenTypeRot(original);
  2480. if(typ == typeof(void))
  2481. return new TokenTypeVoid(original);
  2482. if(typ == typeof(LSL_Vector))
  2483. return new TokenTypeVec(original);
  2484. if(typ == typeof(float))
  2485. return new TokenTypeFloat(original);
  2486. if(typ == typeof(int))
  2487. return new TokenTypeInt(original);
  2488. if(typ == typeof(string))
  2489. return new TokenTypeStr(original);
  2490. if(typ == typeof(double))
  2491. return new TokenTypeFloat(original);
  2492. if(typ == typeof(bool))
  2493. return new TokenTypeBool(original);
  2494. if(typ == typeof(object))
  2495. return new TokenTypeObject(original);
  2496. if(typ == typeof(XMR_Array))
  2497. return new TokenTypeArray(original);
  2498. if(typ == typeof(LSL_Integer))
  2499. return new TokenTypeLSLInt(original);
  2500. if(typ == typeof(LSL_Float))
  2501. return new TokenTypeLSLFloat(original);
  2502. if(typ == typeof(LSL_String))
  2503. return new TokenTypeLSLString(original);
  2504. if(typ == typeof(char))
  2505. return new TokenTypeChar(original);
  2506. if(typ == typeof(Exception))
  2507. return new TokenTypeExc(original);
  2508. throw new Exception("unknown script type " + typ.ToString());
  2509. }
  2510. public static TokenType FromLSLType(Token original, string typ)
  2511. {
  2512. if(typ == "list")
  2513. return new TokenTypeList(original);
  2514. if(typ == "rotation")
  2515. return new TokenTypeRot(original);
  2516. if(typ == "vector")
  2517. return new TokenTypeVec(original);
  2518. if(typ == "float")
  2519. return new TokenTypeFloat(original);
  2520. if(typ == "integer")
  2521. return new TokenTypeInt(original);
  2522. if(typ == "key")
  2523. return new TokenTypeKey(original);
  2524. if(typ == "string")
  2525. return new TokenTypeStr(original);
  2526. if(typ == "object")
  2527. return new TokenTypeObject(original);
  2528. if(typ == "array")
  2529. return new TokenTypeArray(original);
  2530. if(typ == "bool")
  2531. return new TokenTypeBool(original);
  2532. if(typ == "void")
  2533. return new TokenTypeVoid(original);
  2534. if(typ == "char")
  2535. return new TokenTypeChar(original);
  2536. if(typ == "exception")
  2537. return new TokenTypeExc(original);
  2538. throw new Exception("unknown type " + typ);
  2539. }
  2540. /**
  2541. * @brief Estimate the number of bytes of memory taken by one of these
  2542. * objects. For objects with widely varying size, return the
  2543. * smallest it can be.
  2544. */
  2545. public static int StaticSize(System.Type typ)
  2546. {
  2547. if(typ == typeof(LSL_List))
  2548. return 96;
  2549. if(typ == typeof(LSL_Rotation))
  2550. return 80;
  2551. if(typ == typeof(void))
  2552. return 0;
  2553. if(typ == typeof(LSL_Vector))
  2554. return 72;
  2555. if(typ == typeof(float))
  2556. return 8;
  2557. if(typ == typeof(int))
  2558. return 8;
  2559. if(typ == typeof(string))
  2560. return 40;
  2561. if(typ == typeof(double))
  2562. return 8;
  2563. if(typ == typeof(bool))
  2564. return 8;
  2565. if(typ == typeof(XMR_Array))
  2566. return 96;
  2567. if(typ == typeof(object))
  2568. return 32;
  2569. if(typ == typeof(char))
  2570. return 2;
  2571. if(typ == typeof(LSL_Integer))
  2572. return 32;
  2573. if(typ == typeof(LSL_Float))
  2574. return 32;
  2575. if(typ == typeof(LSL_String))
  2576. return 40;
  2577. throw new Exception("unknown type " + typ.ToString());
  2578. }
  2579. /**
  2580. * @brief Return the corresponding system type.
  2581. */
  2582. public abstract Type ToSysType();
  2583. /**
  2584. * @brief Return the equivalent LSL wrapping type.
  2585. *
  2586. * null: normal
  2587. * else: LSL-style wrapping, ie, LSL_Integer, LSL_Float, LSL_String
  2588. * ToSysType()=System.Int32; lslWrapping=LSL_Integer
  2589. * ToSysType()=System.Float; lslWrapping=LSL_Float
  2590. * ToSysType()=System.String; lslWrapping=LSL_String
  2591. */
  2592. public virtual Type ToLSLWrapType()
  2593. {
  2594. return null;
  2595. }
  2596. /**
  2597. * @brief Assign slots in either the global variable arrays or the script-defined type instance arrays.
  2598. * These only need to be implemented for script-visible types, ie, those that a script writer
  2599. * can actually define a variable as.
  2600. */
  2601. public virtual void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2602. {
  2603. throw new Exception("not implemented for " + ToString() + " (" + GetType() + ")");
  2604. }
  2605. /**
  2606. * @brief Get heap tracking type.
  2607. * null indicates there is no heap tracker for the type.
  2608. */
  2609. public virtual Type ToHeapTrackerType()
  2610. {
  2611. return null;
  2612. }
  2613. public virtual ConstructorInfo GetHeapTrackerCtor()
  2614. {
  2615. throw new ApplicationException("no GetHeapTrackerCtor for " + this.GetType());
  2616. }
  2617. public virtual void CallHeapTrackerPopMeth(Token errorAt, ScriptMyILGen ilGen)
  2618. {
  2619. throw new ApplicationException("no CallHeapTrackerPopMeth for " + this.GetType());
  2620. }
  2621. public virtual void CallHeapTrackerPushMeth(Token errorAt, ScriptMyILGen ilGen)
  2622. {
  2623. throw new ApplicationException("no CallHeapTrackerPushMeth for " + this.GetType());
  2624. }
  2625. }
  2626. public class TokenTypeArray: TokenType
  2627. {
  2628. private static readonly FieldInfo iarArraysFieldInfo = typeof(XMRInstArrays).GetField("iarArrays");
  2629. public TokenTypeArray(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2630. public TokenTypeArray(Token original) : base(original) { }
  2631. public override Type ToSysType()
  2632. {
  2633. return typeof(XMR_Array);
  2634. }
  2635. public override string ToString()
  2636. {
  2637. return "array";
  2638. }
  2639. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2640. {
  2641. declVar.vTableArray = iarArraysFieldInfo;
  2642. declVar.vTableIndex = arSizes.iasArrays++;
  2643. }
  2644. }
  2645. public class TokenTypeBool: TokenType
  2646. {
  2647. public TokenTypeBool(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2648. public TokenTypeBool(Token original) : base(original) { }
  2649. public override Type ToSysType()
  2650. {
  2651. return typeof(bool);
  2652. }
  2653. public override string ToString()
  2654. {
  2655. return "bool";
  2656. }
  2657. }
  2658. public class TokenTypeChar: TokenType
  2659. {
  2660. private static readonly FieldInfo iarCharsFieldInfo = typeof(XMRInstArrays).GetField("iarChars");
  2661. public TokenTypeChar(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2662. public TokenTypeChar(Token original) : base(original) { }
  2663. public override Type ToSysType()
  2664. {
  2665. return typeof(char);
  2666. }
  2667. public override string ToString()
  2668. {
  2669. return "char";
  2670. }
  2671. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2672. {
  2673. declVar.vTableArray = iarCharsFieldInfo;
  2674. declVar.vTableIndex = arSizes.iasChars++;
  2675. }
  2676. }
  2677. public class TokenTypeExc: TokenType
  2678. {
  2679. private static readonly FieldInfo iarObjectsFieldInfo = typeof(XMRInstArrays).GetField("iarObjects");
  2680. public TokenTypeExc(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2681. public TokenTypeExc(Token original) : base(original) { }
  2682. public override Type ToSysType()
  2683. {
  2684. return typeof(Exception);
  2685. }
  2686. public override string ToString()
  2687. {
  2688. return "exception";
  2689. }
  2690. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2691. {
  2692. declVar.vTableArray = iarObjectsFieldInfo;
  2693. declVar.vTableIndex = arSizes.iasObjects++;
  2694. }
  2695. }
  2696. public class TokenTypeFloat: TokenType
  2697. {
  2698. private static readonly FieldInfo iarFloatsFieldInfo = typeof(XMRInstArrays).GetField("iarFloats");
  2699. public TokenTypeFloat(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2700. public TokenTypeFloat(Token original) : base(original) { }
  2701. public override Type ToSysType()
  2702. {
  2703. return typeof(double);
  2704. }
  2705. public override string ToString()
  2706. {
  2707. return "float";
  2708. }
  2709. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2710. {
  2711. declVar.vTableArray = iarFloatsFieldInfo;
  2712. declVar.vTableIndex = arSizes.iasFloats++;
  2713. }
  2714. }
  2715. public class TokenTypeInt: TokenType
  2716. {
  2717. private static readonly FieldInfo iarIntegersFieldInfo = typeof(XMRInstArrays).GetField("iarIntegers");
  2718. public TokenTypeInt(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2719. public TokenTypeInt(Token original) : base(original) { }
  2720. public override Type ToSysType()
  2721. {
  2722. return typeof(int);
  2723. }
  2724. public override string ToString()
  2725. {
  2726. return "integer";
  2727. }
  2728. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2729. {
  2730. declVar.vTableArray = iarIntegersFieldInfo;
  2731. declVar.vTableIndex = arSizes.iasIntegers++;
  2732. }
  2733. }
  2734. public class TokenTypeKey: TokenType
  2735. {
  2736. private static readonly FieldInfo iarStringsFieldInfo = typeof(XMRInstArrays).GetField("iarStrings");
  2737. public TokenTypeKey(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2738. public TokenTypeKey(Token original) : base(original) { }
  2739. public override Type ToSysType()
  2740. {
  2741. return typeof(string);
  2742. }
  2743. public override string ToString()
  2744. {
  2745. return "key";
  2746. }
  2747. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2748. {
  2749. declVar.vTableArray = iarStringsFieldInfo;
  2750. declVar.vTableIndex = arSizes.iasStrings++;
  2751. }
  2752. }
  2753. public class TokenTypeList: TokenType
  2754. {
  2755. private static readonly FieldInfo iarListsFieldInfo = typeof(XMRInstArrays).GetField("iarLists");
  2756. private static readonly ConstructorInfo htListCtor = typeof(HeapTrackerList).GetConstructor(new Type[] { typeof(XMRInstAbstract) });
  2757. public TokenTypeList(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2758. public TokenTypeList(Token original) : base(original) { }
  2759. public override Type ToSysType()
  2760. {
  2761. return typeof(LSL_List);
  2762. }
  2763. public override string ToString()
  2764. {
  2765. return "list";
  2766. }
  2767. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2768. {
  2769. declVar.vTableArray = iarListsFieldInfo;
  2770. declVar.vTableIndex = arSizes.iasLists++;
  2771. }
  2772. public override Type ToHeapTrackerType()
  2773. {
  2774. return typeof(HeapTrackerList);
  2775. }
  2776. public override ConstructorInfo GetHeapTrackerCtor()
  2777. {
  2778. return htListCtor;
  2779. }
  2780. public override void CallHeapTrackerPopMeth(Token errorAt, ScriptMyILGen ilGen)
  2781. {
  2782. HeapTrackerList.GenPop(errorAt, ilGen);
  2783. }
  2784. public override void CallHeapTrackerPushMeth(Token errorAt, ScriptMyILGen ilGen)
  2785. {
  2786. HeapTrackerList.GenPush(errorAt, ilGen);
  2787. }
  2788. }
  2789. public class TokenTypeObject: TokenType
  2790. {
  2791. private static readonly FieldInfo iarObjectsFieldInfo = typeof(XMRInstArrays).GetField("iarObjects");
  2792. private static readonly ConstructorInfo htObjectCtor = typeof(HeapTrackerObject).GetConstructor(new Type[] { typeof(XMRInstAbstract) });
  2793. public TokenTypeObject(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2794. public TokenTypeObject(Token original) : base(original) { }
  2795. public override Type ToSysType()
  2796. {
  2797. return typeof(object);
  2798. }
  2799. public override string ToString()
  2800. {
  2801. return "object";
  2802. }
  2803. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2804. {
  2805. declVar.vTableArray = iarObjectsFieldInfo;
  2806. declVar.vTableIndex = arSizes.iasObjects++;
  2807. }
  2808. public override Type ToHeapTrackerType()
  2809. {
  2810. return typeof(HeapTrackerObject);
  2811. }
  2812. public override ConstructorInfo GetHeapTrackerCtor()
  2813. {
  2814. return htObjectCtor;
  2815. }
  2816. public override void CallHeapTrackerPopMeth(Token errorAt, ScriptMyILGen ilGen)
  2817. {
  2818. HeapTrackerObject.GenPop(errorAt, ilGen);
  2819. }
  2820. public override void CallHeapTrackerPushMeth(Token errorAt, ScriptMyILGen ilGen)
  2821. {
  2822. HeapTrackerObject.GenPush(errorAt, ilGen);
  2823. }
  2824. }
  2825. public class TokenTypeRot: TokenType
  2826. {
  2827. private static readonly FieldInfo iarRotationsFieldInfo = typeof(XMRInstArrays).GetField("iarRotations");
  2828. public TokenTypeRot(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2829. public TokenTypeRot(Token original) : base(original) { }
  2830. public override Type ToSysType()
  2831. {
  2832. return typeof(LSL_Rotation);
  2833. }
  2834. public override string ToString()
  2835. {
  2836. return "rotation";
  2837. }
  2838. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2839. {
  2840. declVar.vTableArray = iarRotationsFieldInfo;
  2841. declVar.vTableIndex = arSizes.iasRotations++;
  2842. }
  2843. }
  2844. public class TokenTypeStr: TokenType
  2845. {
  2846. private static readonly FieldInfo iarStringsFieldInfo = typeof(XMRInstArrays).GetField("iarStrings");
  2847. private static readonly ConstructorInfo htStringCtor = typeof(HeapTrackerString).GetConstructor(new Type[] { typeof(XMRInstAbstract) });
  2848. public TokenTypeStr(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2849. public TokenTypeStr(Token original) : base(original) { }
  2850. public override Type ToSysType()
  2851. {
  2852. return typeof(string);
  2853. }
  2854. public override string ToString()
  2855. {
  2856. return "string";
  2857. }
  2858. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2859. {
  2860. declVar.vTableArray = iarStringsFieldInfo;
  2861. declVar.vTableIndex = arSizes.iasStrings++;
  2862. }
  2863. public override Type ToHeapTrackerType()
  2864. {
  2865. return typeof(HeapTrackerString);
  2866. }
  2867. public override ConstructorInfo GetHeapTrackerCtor()
  2868. {
  2869. return htStringCtor;
  2870. }
  2871. public override void CallHeapTrackerPopMeth(Token errorAt, ScriptMyILGen ilGen)
  2872. {
  2873. HeapTrackerString.GenPop(errorAt, ilGen);
  2874. }
  2875. public override void CallHeapTrackerPushMeth(Token errorAt, ScriptMyILGen ilGen)
  2876. {
  2877. HeapTrackerString.GenPush(errorAt, ilGen);
  2878. }
  2879. }
  2880. public class TokenTypeUndef: TokenType
  2881. { // for the 'undef' constant, ie, null object pointer
  2882. public TokenTypeUndef(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2883. public TokenTypeUndef(Token original) : base(original) { }
  2884. public override Type ToSysType()
  2885. {
  2886. return typeof(object);
  2887. }
  2888. public override string ToString()
  2889. {
  2890. return "undef";
  2891. }
  2892. }
  2893. public class TokenTypeVec: TokenType
  2894. {
  2895. private static readonly FieldInfo iarVectorsFieldInfo = typeof(XMRInstArrays).GetField("iarVectors");
  2896. public TokenTypeVec(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2897. public TokenTypeVec(Token original) : base(original) { }
  2898. public override Type ToSysType()
  2899. {
  2900. return typeof(LSL_Vector);
  2901. }
  2902. public override string ToString()
  2903. {
  2904. return "vector";
  2905. }
  2906. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2907. {
  2908. declVar.vTableArray = iarVectorsFieldInfo;
  2909. declVar.vTableIndex = arSizes.iasVectors++;
  2910. }
  2911. }
  2912. public class TokenTypeVoid: TokenType
  2913. { // used only for function/method return types
  2914. public TokenTypeVoid(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2915. public TokenTypeVoid(Token original) : base(original) { }
  2916. public override Type ToSysType()
  2917. {
  2918. return typeof(void);
  2919. }
  2920. public override string ToString()
  2921. {
  2922. return "void";
  2923. }
  2924. }
  2925. public class TokenTypeLSLFloat: TokenTypeFloat
  2926. {
  2927. public TokenTypeLSLFloat(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2928. public TokenTypeLSLFloat(Token original) : base(original) { }
  2929. public override Type ToLSLWrapType()
  2930. {
  2931. return typeof(LSL_Float);
  2932. }
  2933. }
  2934. public class TokenTypeLSLInt: TokenTypeInt
  2935. {
  2936. public TokenTypeLSLInt(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2937. public TokenTypeLSLInt(Token original) : base(original) { }
  2938. public override Type ToLSLWrapType()
  2939. {
  2940. return typeof(LSL_Integer);
  2941. }
  2942. }
  2943. public class TokenTypeLSLKey: TokenTypeKey
  2944. {
  2945. public TokenTypeLSLKey(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2946. public TokenTypeLSLKey(Token original) : base(original) { }
  2947. public override Type ToLSLWrapType()
  2948. {
  2949. return typeof(LSL_Key);
  2950. }
  2951. }
  2952. public class TokenTypeLSLString: TokenTypeStr
  2953. {
  2954. public TokenTypeLSLString(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2955. public TokenTypeLSLString(Token original) : base(original) { }
  2956. public override Type ToLSLWrapType()
  2957. {
  2958. return typeof(LSL_String);
  2959. }
  2960. }
  2961. }