1
0

MMRScriptTokenize.cs 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069
  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. {
  576. if(strcasecmp(((TokenName)lastToken).val, "yoptions") == 0)
  577. {
  578. options.advFlowCtl = true;
  579. options.tryCatch = true;
  580. lastToken = lastToken.prevToken;
  581. lastToken.nextToken = null;
  582. continue;
  583. }
  584. else if ((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. }
  619. // Lastly, check for delimeters.
  620. {
  621. int j;
  622. int len = 0;
  623. for(j = 0; j < delims.Length; j++)
  624. {
  625. len = delims[j].str.Length;
  626. if((i + len <= source.Length) && (source.Substring(i, len).Equals(delims[j].str)))
  627. break;
  628. }
  629. if(j < delims.Length)
  630. {
  631. Object[] args = { emsg, filNam, lineNo, i - bolIdx };
  632. Token kwToken = (Token)delims[j].ctorInfo.Invoke(args);
  633. AppendToken(kwToken);
  634. i += --len;
  635. continue;
  636. }
  637. }
  638. // Don't know what it is!
  639. TokenError(i, "unknown character '" + c + "'");
  640. }
  641. }
  642. private static int strcasecmp(String s, String t)
  643. {
  644. return String.Compare(s, t, StringComparison.OrdinalIgnoreCase);
  645. }
  646. /**
  647. * @brief try to parse a floating-point number from the source
  648. * @param i = starting position within this.source of number
  649. * @returns 0: not a floating point number, try something else
  650. * else: position in this.source of terminating character, ie, past number
  651. * TokenFloat appended to token list
  652. * or error message has been output
  653. */
  654. private int TryParseFloat(int i)
  655. {
  656. bool decimals, error, negexp, nulexp;
  657. char c;
  658. double f, f10;
  659. int exponent, j, x, y;
  660. ulong m, mantissa;
  661. decimals = false;
  662. error = false;
  663. exponent = 0;
  664. mantissa = 0;
  665. for(j = i; j < source.Length; j++)
  666. {
  667. c = source[j];
  668. if((c >= '0') && (c <= '9'))
  669. {
  670. m = mantissa * 10 + (ulong)(c - '0');
  671. if(m / 10 != mantissa)
  672. {
  673. if(!decimals)
  674. exponent++;
  675. }
  676. else
  677. {
  678. mantissa = m;
  679. if(decimals)
  680. exponent--;
  681. }
  682. continue;
  683. }
  684. if(c == '.')
  685. {
  686. if(decimals)
  687. {
  688. TokenError(i, "more than one decimal point");
  689. return j;
  690. }
  691. decimals = true;
  692. continue;
  693. }
  694. if((c == 'E') || (c == 'e'))
  695. {
  696. if(++j >= source.Length)
  697. {
  698. TokenError(i, "floating exponent off end of source");
  699. return j;
  700. }
  701. c = source[j];
  702. negexp = (c == '-');
  703. if(negexp || (c == '+'))
  704. j++;
  705. y = 0;
  706. nulexp = true;
  707. for(; j < source.Length; j++)
  708. {
  709. c = source[j];
  710. if((c < '0') || (c > '9'))
  711. break;
  712. x = y * 10 + (c - '0');
  713. if(x / 10 != y)
  714. {
  715. if(!error)
  716. TokenError(i, "floating exponent overflow");
  717. error = true;
  718. }
  719. y = x;
  720. nulexp = false;
  721. }
  722. if(nulexp)
  723. {
  724. TokenError(i, "bad or missing floating exponent");
  725. return j;
  726. }
  727. if(negexp)
  728. {
  729. x = exponent - y;
  730. if(x > exponent)
  731. {
  732. if(!error)
  733. TokenError(i, "floating exponent overflow");
  734. error = true;
  735. }
  736. }
  737. else
  738. {
  739. x = exponent + y;
  740. if(x < exponent)
  741. {
  742. if(!error)
  743. TokenError(i, "floating exponent overflow");
  744. error = true;
  745. }
  746. }
  747. exponent = x;
  748. }
  749. if ((c == 'F') || (c == 'f'))
  750. {
  751. if (++j >= source.Length)
  752. {
  753. TokenError(i, "f at end of source");
  754. return j;
  755. }
  756. c = source[j];
  757. if (((c >= '0') && (c <= '9')) || c == '.' || ((c == 'E') || (c == 'e')) || ((c == 'F') || (c == 'f')))
  758. {
  759. TokenError(j-1, "Syntax error");
  760. return j;
  761. }
  762. break;
  763. }
  764. break;
  765. }
  766. if(!decimals)
  767. {
  768. return 0;
  769. }
  770. f = mantissa;
  771. if((exponent != 0) && (mantissa != 0) && !error)
  772. {
  773. f10 = 10.0;
  774. if(exponent < 0)
  775. {
  776. exponent = -exponent;
  777. while(exponent > 0)
  778. {
  779. if((exponent & 1) != 0)
  780. {
  781. f /= f10;
  782. }
  783. exponent /= 2;
  784. f10 *= f10;
  785. }
  786. }
  787. else
  788. {
  789. while(exponent > 0)
  790. {
  791. if((exponent & 1) != 0)
  792. {
  793. f *= f10;
  794. }
  795. exponent /= 2;
  796. f10 *= f10;
  797. }
  798. }
  799. }
  800. if(!error)
  801. {
  802. AppendToken(new TokenFloat(emsg, filNam, lineNo, i - bolIdx, f));
  803. }
  804. return j;
  805. }
  806. /**
  807. * @brief try to parse an integer number from the source
  808. * @param i = starting position within this.source of number
  809. * @returns 0: not an integer number, try something else
  810. * else: position in this.source of terminating character, ie, past number
  811. * TokenInt appended to token list
  812. * or error message has been output
  813. */
  814. private int TryParseInt(int i)
  815. {
  816. bool error;
  817. char c;
  818. int j;
  819. uint basse, m, mantissa;
  820. basse = 10;
  821. error = false;
  822. mantissa = 0;
  823. for(j = i; j < source.Length; j++)
  824. {
  825. c = source[j];
  826. if((c >= '0') && (c <= '9'))
  827. {
  828. m = mantissa * basse + (uint)(c - '0');
  829. if(m / basse != mantissa)
  830. {
  831. if(!error)
  832. TokenError(i, "integer overflow");
  833. error = true;
  834. }
  835. mantissa = m;
  836. continue;
  837. }
  838. if((basse == 16) && ((c >= 'A') && (c <= 'F')))
  839. {
  840. m = mantissa * basse + (uint)(c - 'A') + 10U;
  841. if(m / basse != mantissa)
  842. {
  843. if(!error)
  844. TokenError(i, "integer overflow");
  845. error = true;
  846. }
  847. mantissa = m;
  848. continue;
  849. }
  850. if((basse == 16) && ((c >= 'a') && (c <= 'f')))
  851. {
  852. m = mantissa * basse + (uint)(c - 'a') + 10U;
  853. if(m / basse != mantissa)
  854. {
  855. if(!error)
  856. TokenError(i, "integer overflow");
  857. error = true;
  858. }
  859. mantissa = m;
  860. continue;
  861. }
  862. if(((c == 'x') || (c == 'X')) && (mantissa == 0) && (basse == 10))
  863. {
  864. basse = 16;
  865. continue;
  866. }
  867. break;
  868. }
  869. if(!error)
  870. {
  871. AppendToken(new TokenInt(emsg, filNam, lineNo, i - bolIdx, (int)mantissa));
  872. }
  873. return j;
  874. }
  875. /**
  876. * @brief append token on to end of list
  877. * @param newToken = token to append
  878. * @returns with token appended onto this.lastToken
  879. */
  880. private void AppendToken(Token newToken)
  881. {
  882. newToken.nextToken = null;
  883. newToken.prevToken = lastToken;
  884. newToken.nr2l = this.options.noRightToLeft;
  885. lastToken.nextToken = newToken;
  886. lastToken = newToken;
  887. }
  888. /**
  889. * @brief print tokenizing error message
  890. * and remember that we've an error
  891. * @param i = position within source file of the error
  892. * @param message = error message text
  893. * @returns with this.youveAnError set
  894. */
  895. private void TokenError(int i, string message)
  896. {
  897. Token temp = new Token(this.emsg, this.filNam, this.lineNo, i - this.bolIdx);
  898. temp.ErrorMsg(message);
  899. youveAnError = true;
  900. }
  901. /**
  902. * @brief get a token's constructor
  903. * @param tokenType = token's type
  904. * @returns token's constructor
  905. */
  906. private static Type[] constrTypes = new Type[] {
  907. typeof (TokenErrorMessage), typeof (string), typeof (int), typeof (int)
  908. };
  909. private static System.Reflection.ConstructorInfo GetTokenCtor(Type tokenType)
  910. {
  911. return tokenType.GetConstructor(constrTypes);
  912. }
  913. /**
  914. * @brief delimeter table
  915. */
  916. private class Delim
  917. {
  918. public string str;
  919. public System.Reflection.ConstructorInfo ctorInfo;
  920. public Delim(string str, Type type)
  921. {
  922. this.str = str;
  923. ctorInfo = GetTokenCtor(type);
  924. }
  925. }
  926. private static Delim[] delims = new Delim[] {
  927. new Delim ("...", typeof (TokenKwDotDotDot)),
  928. new Delim ("&&&", typeof (TokenKwAndAndAnd)),
  929. new Delim ("|||", typeof (TokenKwOrOrOr)),
  930. new Delim ("<<=", typeof (TokenKwAsnLSh)),
  931. new Delim (">>=", typeof (TokenKwAsnRSh)),
  932. new Delim ("<=", typeof (TokenKwCmpLE)),
  933. new Delim (">=", typeof (TokenKwCmpGE)),
  934. new Delim ("==", typeof (TokenKwCmpEQ)),
  935. new Delim ("!=", typeof (TokenKwCmpNE)),
  936. new Delim ("++", typeof (TokenKwIncr)),
  937. new Delim ("--", typeof (TokenKwDecr)),
  938. new Delim ("&&", typeof (TokenKwAndAnd)),
  939. new Delim ("||", typeof (TokenKwOrOr)),
  940. new Delim ("+=", typeof (TokenKwAsnAdd)),
  941. new Delim ("&=", typeof (TokenKwAsnAnd)),
  942. new Delim ("-=", typeof (TokenKwAsnSub)),
  943. new Delim ("*=", typeof (TokenKwAsnMul)),
  944. new Delim ("/=", typeof (TokenKwAsnDiv)),
  945. new Delim ("%=", typeof (TokenKwAsnMod)),
  946. new Delim ("|=", typeof (TokenKwAsnOr)),
  947. new Delim ("^=", typeof (TokenKwAsnXor)),
  948. new Delim ("<<", typeof (TokenKwLSh)),
  949. new Delim (">>", typeof (TokenKwRSh)),
  950. new Delim ("~", typeof (TokenKwTilde)),
  951. new Delim ("!", typeof (TokenKwExclam)),
  952. new Delim ("@", typeof (TokenKwAt)),
  953. new Delim ("%", typeof (TokenKwMod)),
  954. new Delim ("^", typeof (TokenKwXor)),
  955. new Delim ("&", typeof (TokenKwAnd)),
  956. new Delim ("*", typeof (TokenKwMul)),
  957. new Delim ("(", typeof (TokenKwParOpen)),
  958. new Delim (")", typeof (TokenKwParClose)),
  959. new Delim ("-", typeof (TokenKwSub)),
  960. new Delim ("+", typeof (TokenKwAdd)),
  961. new Delim ("=", typeof (TokenKwAssign)),
  962. new Delim ("{", typeof (TokenKwBrcOpen)),
  963. new Delim ("}", typeof (TokenKwBrcClose)),
  964. new Delim ("[", typeof (TokenKwBrkOpen)),
  965. new Delim ("]", typeof (TokenKwBrkClose)),
  966. new Delim (";", typeof (TokenKwSemi)),
  967. new Delim (":", typeof (TokenKwColon)),
  968. new Delim ("<", typeof (TokenKwCmpLT)),
  969. new Delim (">", typeof (TokenKwCmpGT)),
  970. new Delim (",", typeof (TokenKwComma)),
  971. new Delim (".", typeof (TokenKwDot)),
  972. new Delim ("?", typeof (TokenKwQMark)),
  973. new Delim ("/", typeof (TokenKwDiv)),
  974. new Delim ("|", typeof (TokenKwOr)),
  975. new Delim ("#", typeof (TokenKwHash))
  976. };
  977. /**
  978. * @brief keyword tables
  979. * The keyword tables translate a keyword string
  980. * to the corresponding token constructor.
  981. */
  982. private static Dictionary<string, System.Reflection.ConstructorInfo> keywords = BuildKeywords();
  983. private static Dictionary<string, System.Reflection.ConstructorInfo> arrayKeywords = BuildArrayKeywords();
  984. private static Dictionary<string, System.Reflection.ConstructorInfo> advFlowCtlKeywords = BuildAdvFlowCtlKeywords();
  985. private static Dictionary<string, System.Reflection.ConstructorInfo> tryCatchKeywords = BuildTryCatchKeywords();
  986. private static Dictionary<string, System.Reflection.ConstructorInfo> objectsKeywords = BuildObjectsKeywords();
  987. private static Dictionary<string, System.Reflection.ConstructorInfo> charsKeywords = BuildCharsKeywords();
  988. private static Dictionary<string, System.Reflection.ConstructorInfo> BuildKeywords()
  989. {
  990. Dictionary<string, System.Reflection.ConstructorInfo> kws = new Dictionary<string, System.Reflection.ConstructorInfo>();
  991. kws.Add("default", GetTokenCtor(typeof(TokenKwDefault)));
  992. kws.Add("do", GetTokenCtor(typeof(TokenKwDo)));
  993. kws.Add("else", GetTokenCtor(typeof(TokenKwElse)));
  994. kws.Add("float", GetTokenCtor(typeof(TokenTypeFloat)));
  995. kws.Add("for", GetTokenCtor(typeof(TokenKwFor)));
  996. kws.Add("if", GetTokenCtor(typeof(TokenKwIf)));
  997. kws.Add("integer", GetTokenCtor(typeof(TokenTypeInt)));
  998. kws.Add("list", GetTokenCtor(typeof(TokenTypeList)));
  999. kws.Add("jump", GetTokenCtor(typeof(TokenKwJump)));
  1000. kws.Add("key", GetTokenCtor(typeof(TokenTypeKey)));
  1001. kws.Add("return", GetTokenCtor(typeof(TokenKwRet)));
  1002. kws.Add("rotation", GetTokenCtor(typeof(TokenTypeRot)));
  1003. kws.Add("state", GetTokenCtor(typeof(TokenKwState)));
  1004. kws.Add("string", GetTokenCtor(typeof(TokenTypeStr)));
  1005. kws.Add("vector", GetTokenCtor(typeof(TokenTypeVec)));
  1006. kws.Add("while", GetTokenCtor(typeof(TokenKwWhile)));
  1007. return kws;
  1008. }
  1009. private static Dictionary<string, System.Reflection.ConstructorInfo> BuildArrayKeywords()
  1010. {
  1011. Dictionary<string, System.Reflection.ConstructorInfo> kws = new Dictionary<string, System.Reflection.ConstructorInfo>();
  1012. kws.Add("array", GetTokenCtor(typeof(TokenTypeArray)));
  1013. kws.Add("foreach", GetTokenCtor(typeof(TokenKwForEach)));
  1014. kws.Add("in", GetTokenCtor(typeof(TokenKwIn)));
  1015. kws.Add("is", GetTokenCtor(typeof(TokenKwIs)));
  1016. kws.Add("object", GetTokenCtor(typeof(TokenTypeObject)));
  1017. kws.Add("undef", GetTokenCtor(typeof(TokenKwUndef)));
  1018. return kws;
  1019. }
  1020. private static Dictionary<string, System.Reflection.ConstructorInfo> BuildAdvFlowCtlKeywords()
  1021. {
  1022. Dictionary<string, System.Reflection.ConstructorInfo> kws = new Dictionary<string, System.Reflection.ConstructorInfo>();
  1023. kws.Add("break", GetTokenCtor(typeof(TokenKwBreak)));
  1024. kws.Add("case", GetTokenCtor(typeof(TokenKwCase)));
  1025. kws.Add("constant", GetTokenCtor(typeof(TokenKwConst)));
  1026. kws.Add("continue", GetTokenCtor(typeof(TokenKwCont)));
  1027. kws.Add("switch", GetTokenCtor(typeof(TokenKwSwitch)));
  1028. return kws;
  1029. }
  1030. private static Dictionary<string, System.Reflection.ConstructorInfo> BuildTryCatchKeywords()
  1031. {
  1032. Dictionary<string, System.Reflection.ConstructorInfo> kws = new Dictionary<string, System.Reflection.ConstructorInfo>();
  1033. kws.Add("catch", GetTokenCtor(typeof(TokenKwCatch)));
  1034. kws.Add("exception", GetTokenCtor(typeof(TokenTypeExc)));
  1035. kws.Add("scriptexception", GetTokenCtor(typeof(TokenTypeExc)));
  1036. kws.Add("finally", GetTokenCtor(typeof(TokenKwFinally)));
  1037. kws.Add("throw", GetTokenCtor(typeof(TokenKwThrow)));
  1038. kws.Add("try", GetTokenCtor(typeof(TokenKwTry)));
  1039. return kws;
  1040. }
  1041. private static Dictionary<string, System.Reflection.ConstructorInfo> BuildObjectsKeywords()
  1042. {
  1043. Dictionary<string, System.Reflection.ConstructorInfo> kws = new Dictionary<string, System.Reflection.ConstructorInfo>();
  1044. kws.Add("abstract", GetTokenCtor(typeof(TokenKwAbstract)));
  1045. kws.Add("base", GetTokenCtor(typeof(TokenKwBase)));
  1046. kws.Add("class", GetTokenCtor(typeof(TokenKwClass)));
  1047. kws.Add("constructor", GetTokenCtor(typeof(TokenKwConstructor)));
  1048. kws.Add("delegate", GetTokenCtor(typeof(TokenKwDelegate)));
  1049. kws.Add("destructor", GetTokenCtor(typeof(TokenKwDestructor)));
  1050. kws.Add("final", GetTokenCtor(typeof(TokenKwFinal)));
  1051. kws.Add("get", GetTokenCtor(typeof(TokenKwGet)));
  1052. kws.Add("interface", GetTokenCtor(typeof(TokenKwInterface)));
  1053. kws.Add("new", GetTokenCtor(typeof(TokenKwNew)));
  1054. kws.Add("override", GetTokenCtor(typeof(TokenKwOverride)));
  1055. kws.Add("partial", GetTokenCtor(typeof(TokenKwPartial)));
  1056. kws.Add("private", GetTokenCtor(typeof(TokenKwPrivate)));
  1057. kws.Add("protected", GetTokenCtor(typeof(TokenKwProtected)));
  1058. kws.Add("public", GetTokenCtor(typeof(TokenKwPublic)));
  1059. kws.Add("set", GetTokenCtor(typeof(TokenKwSet)));
  1060. kws.Add("static", GetTokenCtor(typeof(TokenKwStatic)));
  1061. kws.Add("this", GetTokenCtor(typeof(TokenKwThis)));
  1062. kws.Add("typedef", GetTokenCtor(typeof(TokenKwTypedef)));
  1063. kws.Add("virtual", GetTokenCtor(typeof(TokenKwVirtual)));
  1064. return kws;
  1065. }
  1066. private static Dictionary<string, System.Reflection.ConstructorInfo> BuildCharsKeywords()
  1067. {
  1068. Dictionary<string, System.Reflection.ConstructorInfo> kws = new Dictionary<string, System.Reflection.ConstructorInfo>();
  1069. kws.Add("char", GetTokenCtor(typeof(TokenTypeChar)));
  1070. return kws;
  1071. }
  1072. }
  1073. /**
  1074. * @brief All output token types in addition to TokenBegin.
  1075. * They are all sub-types of Token.
  1076. */
  1077. public class TokenChar: Token
  1078. {
  1079. public char val;
  1080. public TokenChar(TokenErrorMessage emsg, string file, int line, int posn, char val) : base(emsg, file, line, posn)
  1081. {
  1082. this.val = val;
  1083. }
  1084. public TokenChar(Token original, char val) : base(original)
  1085. {
  1086. this.val = val;
  1087. }
  1088. public override string ToString()
  1089. {
  1090. switch(val)
  1091. {
  1092. case '\'':
  1093. return "'\\''";
  1094. case '\\':
  1095. return "'\\\\'";
  1096. case '\n':
  1097. return "'\\n'";
  1098. case '\t':
  1099. return "'\\t'";
  1100. default:
  1101. return "'" + val + "'";
  1102. }
  1103. }
  1104. }
  1105. public class TokenFloat: Token
  1106. {
  1107. public double val;
  1108. public TokenFloat(TokenErrorMessage emsg, string file, int line, int posn, double val) : base(emsg, file, line, posn)
  1109. {
  1110. this.val = val;
  1111. }
  1112. public override string ToString()
  1113. {
  1114. return val.ToString();
  1115. }
  1116. }
  1117. public class TokenInt: Token
  1118. {
  1119. public int val;
  1120. public TokenInt(TokenErrorMessage emsg, string file, int line, int posn, int val) : base(emsg, file, line, posn)
  1121. {
  1122. this.val = val;
  1123. }
  1124. public TokenInt(Token original, int val) : base(original)
  1125. {
  1126. this.val = val;
  1127. }
  1128. public override string ToString()
  1129. {
  1130. return val.ToString();
  1131. }
  1132. }
  1133. public class TokenName: Token
  1134. {
  1135. public string val;
  1136. public TokenName(TokenErrorMessage emsg, string file, int line, int posn, string val) : base(emsg, file, line, posn)
  1137. {
  1138. this.val = val;
  1139. }
  1140. public TokenName(Token original, string val) : base(original)
  1141. {
  1142. this.val = val;
  1143. }
  1144. public override string ToString()
  1145. {
  1146. return this.val;
  1147. }
  1148. }
  1149. public class TokenStr: Token
  1150. {
  1151. public string val;
  1152. public TokenStr(TokenErrorMessage emsg, string file, int line, int posn, string val) : base(emsg, file, line, posn)
  1153. {
  1154. this.val = val;
  1155. }
  1156. public override string ToString()
  1157. {
  1158. if((val.IndexOf('"') < 0) &&
  1159. (val.IndexOf('\\') < 0) &&
  1160. (val.IndexOf('\n') < 0) &&
  1161. (val.IndexOf('\t') < 0))
  1162. return "\"" + val + "\"";
  1163. int len = val.Length;
  1164. StringBuilder sb = new StringBuilder(len * 2 + 2);
  1165. sb.Append('"');
  1166. for(int i = 0; i < len; i++)
  1167. {
  1168. char c = val[i];
  1169. switch(c)
  1170. {
  1171. case '"':
  1172. {
  1173. sb.Append('\\');
  1174. sb.Append('"');
  1175. break;
  1176. }
  1177. case '\\':
  1178. {
  1179. sb.Append('\\');
  1180. sb.Append('\\');
  1181. break;
  1182. }
  1183. case '\n':
  1184. {
  1185. sb.Append('\\');
  1186. sb.Append('n');
  1187. break;
  1188. }
  1189. case '\t':
  1190. {
  1191. sb.Append('\\');
  1192. sb.Append('t');
  1193. break;
  1194. }
  1195. default:
  1196. {
  1197. sb.Append(c);
  1198. break;
  1199. }
  1200. }
  1201. }
  1202. return sb.ToString();
  1203. }
  1204. }
  1205. /*
  1206. * This one marks the end-of-file.
  1207. */
  1208. public class TokenEnd: Token
  1209. {
  1210. public TokenEnd(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  1211. }
  1212. /*
  1213. * Various keywords and delimeters.
  1214. */
  1215. public delegate object TokenRValConstBinOpDelegate(object left, object right);
  1216. public delegate object TokenRValConstUnOpDelegate(object right);
  1217. public class TokenKw: Token
  1218. {
  1219. public TokenRValConstBinOpDelegate binOpConst;
  1220. public TokenRValConstUnOpDelegate unOpConst;
  1221. public bool sdtClassOp;
  1222. public TokenKw(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn)
  1223. {
  1224. }
  1225. public TokenKw(Token original) : base(original)
  1226. {
  1227. }
  1228. }
  1229. public class TokenKwDotDotDot: TokenKw
  1230. {
  1231. public TokenKwDotDotDot(TokenErrorMessage emsg, string file,
  1232. int line, int posn) : base(emsg, file, line, posn)
  1233. {
  1234. binOpConst = TokenRValConstOps.Null;
  1235. unOpConst = TokenRValConstOps.Null;
  1236. sdtClassOp = false;
  1237. }
  1238. public TokenKwDotDotDot(Token original) : base(original)
  1239. {
  1240. binOpConst = TokenRValConstOps.Null;
  1241. unOpConst = TokenRValConstOps.Null;
  1242. sdtClassOp = false;
  1243. }
  1244. public override string ToString()
  1245. {
  1246. return "...";
  1247. }
  1248. }
  1249. public class TokenKwAndAndAnd: TokenKw
  1250. {
  1251. public TokenKwAndAndAnd(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn)
  1252. {
  1253. binOpConst = TokenRValConstOps.binConstsLogicAndAnd;
  1254. unOpConst = TokenRValConstOps.Null;
  1255. sdtClassOp = false;
  1256. }
  1257. public TokenKwAndAndAnd(Token original) : base(original)
  1258. {
  1259. binOpConst = TokenRValConstOps.binConstsLogicAndAnd;
  1260. unOpConst = TokenRValConstOps.Null;
  1261. sdtClassOp = false;
  1262. }
  1263. public override string ToString()
  1264. {
  1265. return "&&&";
  1266. }
  1267. }
  1268. public class TokenKwOrOrOr: TokenKw
  1269. {
  1270. public TokenKwOrOrOr(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn)
  1271. {
  1272. binOpConst = TokenRValConstOps.binConstsLoginOrOr;
  1273. unOpConst = TokenRValConstOps.Null;
  1274. sdtClassOp = false;
  1275. }
  1276. public TokenKwOrOrOr(Token original) : base(original)
  1277. {
  1278. binOpConst = TokenRValConstOps.binConstsLoginOrOr;
  1279. unOpConst = TokenRValConstOps.Null;
  1280. sdtClassOp = false;
  1281. }
  1282. public override string ToString()
  1283. {
  1284. return "|||";
  1285. }
  1286. }
  1287. public class TokenKwAsnLSh: TokenKw
  1288. {
  1289. public TokenKwAsnLSh(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn)
  1290. {
  1291. binOpConst = TokenRValConstOps.Null;
  1292. unOpConst = TokenRValConstOps.Null;
  1293. sdtClassOp = true;
  1294. }
  1295. public TokenKwAsnLSh(Token original) : base(original)
  1296. {
  1297. binOpConst = TokenRValConstOps.Null;
  1298. unOpConst = TokenRValConstOps.Null;
  1299. sdtClassOp = true;
  1300. }
  1301. public override string ToString()
  1302. {
  1303. return "<<=";
  1304. }
  1305. }
  1306. public class TokenKwAsnRSh: TokenKw
  1307. {
  1308. public TokenKwAsnRSh(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1309. public TokenKwAsnRSh(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1310. public override string ToString()
  1311. {
  1312. return ">>=";
  1313. }
  1314. }
  1315. public class TokenKwCmpLE: TokenKw
  1316. {
  1317. public TokenKwCmpLE(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.binConstsLE; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1318. public TokenKwCmpLE(Token original) : base(original) { binOpConst = TokenRValConstOps.binConstsLE; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1319. public override string ToString()
  1320. {
  1321. return "<=";
  1322. }
  1323. }
  1324. public class TokenKwCmpGE: TokenKw
  1325. {
  1326. public TokenKwCmpGE(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.binConstsGE; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1327. public TokenKwCmpGE(Token original) : base(original) { binOpConst = TokenRValConstOps.binConstsGE; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1328. public override string ToString()
  1329. {
  1330. return ">=";
  1331. }
  1332. }
  1333. public class TokenKwCmpEQ: TokenKw
  1334. {
  1335. public TokenKwCmpEQ(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.binConstsEQ; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1336. public TokenKwCmpEQ(Token original) : base(original) { binOpConst = TokenRValConstOps.binConstsEQ; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1337. public override string ToString()
  1338. {
  1339. return "==";
  1340. }
  1341. }
  1342. public class TokenKwCmpNE: TokenKw
  1343. {
  1344. public TokenKwCmpNE(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.binConstsNE; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1345. public TokenKwCmpNE(Token original) : base(original) { binOpConst = TokenRValConstOps.binConstsNE; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1346. public override string ToString()
  1347. {
  1348. return "!=";
  1349. }
  1350. }
  1351. public class TokenKwIncr: TokenKw
  1352. {
  1353. public TokenKwIncr(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1354. public TokenKwIncr(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1355. public override string ToString()
  1356. {
  1357. return "++";
  1358. }
  1359. }
  1360. public class TokenKwDecr: TokenKw
  1361. {
  1362. public TokenKwDecr(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1363. public TokenKwDecr(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1364. public override string ToString()
  1365. {
  1366. return "--";
  1367. }
  1368. }
  1369. public class TokenKwAndAnd: TokenKw
  1370. {
  1371. public TokenKwAndAnd(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.binConstsLogicAndAnd; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1372. public TokenKwAndAnd(Token original) : base(original) { binOpConst = TokenRValConstOps.binConstsLogicAndAnd; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1373. public override string ToString()
  1374. {
  1375. return "&&";
  1376. }
  1377. }
  1378. public class TokenKwOrOr: TokenKw
  1379. {
  1380. public TokenKwOrOr(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.binConstsLoginOrOr; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1381. public TokenKwOrOr(Token original) : base(original) { binOpConst = TokenRValConstOps.binConstsLoginOrOr; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1382. public override string ToString()
  1383. {
  1384. return "||";
  1385. }
  1386. }
  1387. public class TokenKwAsnAdd: TokenKw
  1388. {
  1389. public TokenKwAsnAdd(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1390. public TokenKwAsnAdd(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1391. public override string ToString()
  1392. {
  1393. return "+=";
  1394. }
  1395. }
  1396. public class TokenKwAsnAnd: TokenKw
  1397. {
  1398. public TokenKwAsnAnd(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1399. public TokenKwAsnAnd(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1400. public override string ToString()
  1401. {
  1402. return "&=";
  1403. }
  1404. }
  1405. public class TokenKwAsnSub: TokenKw
  1406. {
  1407. public TokenKwAsnSub(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1408. public TokenKwAsnSub(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1409. public override string ToString()
  1410. {
  1411. return "-=";
  1412. }
  1413. }
  1414. public class TokenKwAsnMul: TokenKw
  1415. {
  1416. public TokenKwAsnMul(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1417. public TokenKwAsnMul(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1418. public override string ToString()
  1419. {
  1420. return "*=";
  1421. }
  1422. }
  1423. public class TokenKwAsnDiv: TokenKw
  1424. {
  1425. public TokenKwAsnDiv(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1426. public TokenKwAsnDiv(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1427. public override string ToString()
  1428. {
  1429. return "/=";
  1430. }
  1431. }
  1432. public class TokenKwAsnMod: TokenKw
  1433. {
  1434. public TokenKwAsnMod(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1435. public TokenKwAsnMod(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1436. public override string ToString()
  1437. {
  1438. return "%=";
  1439. }
  1440. }
  1441. public class TokenKwAsnOr: TokenKw
  1442. {
  1443. public TokenKwAsnOr(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1444. public TokenKwAsnOr(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1445. public override string ToString()
  1446. {
  1447. return "|=";
  1448. }
  1449. }
  1450. public class TokenKwAsnXor: TokenKw
  1451. {
  1452. public TokenKwAsnXor(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1453. public TokenKwAsnXor(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1454. public override string ToString()
  1455. {
  1456. return "^=";
  1457. }
  1458. }
  1459. public class TokenKwLSh: TokenKw
  1460. {
  1461. public TokenKwLSh(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.LSh; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1462. public TokenKwLSh(Token original) : base(original) { binOpConst = TokenRValConstOps.LSh; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1463. public override string ToString()
  1464. {
  1465. return "<<";
  1466. }
  1467. }
  1468. public class TokenKwRSh: TokenKw
  1469. {
  1470. public TokenKwRSh(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.RSh; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1471. public TokenKwRSh(Token original) : base(original) { binOpConst = TokenRValConstOps.RSh; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1472. public override string ToString()
  1473. {
  1474. return ">>";
  1475. }
  1476. }
  1477. public class TokenKwTilde: TokenKw
  1478. {
  1479. public TokenKwTilde(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Not; sdtClassOp = true; }
  1480. public TokenKwTilde(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Not; sdtClassOp = true; }
  1481. public override string ToString()
  1482. {
  1483. return "~";
  1484. }
  1485. }
  1486. public class TokenKwExclam: TokenKw
  1487. {
  1488. public TokenKwExclam(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.unOpExclam; sdtClassOp = true; }
  1489. public TokenKwExclam(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.unOpExclam; sdtClassOp = true; }
  1490. public override string ToString()
  1491. {
  1492. return "!";
  1493. }
  1494. }
  1495. public class TokenKwAt: TokenKw
  1496. {
  1497. public TokenKwAt(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1498. public TokenKwAt(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1499. public override string ToString()
  1500. {
  1501. return "@";
  1502. }
  1503. }
  1504. public class TokenKwMod: TokenKw
  1505. {
  1506. public TokenKwMod(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Mod; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1507. public TokenKwMod(Token original) : base(original) { binOpConst = TokenRValConstOps.Mod; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1508. public override string ToString()
  1509. {
  1510. return "%";
  1511. }
  1512. }
  1513. public class TokenKwXor: TokenKw
  1514. {
  1515. public TokenKwXor(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Xor; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1516. public TokenKwXor(Token original) : base(original) { binOpConst = TokenRValConstOps.Xor; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1517. public override string ToString()
  1518. {
  1519. return "^";
  1520. }
  1521. }
  1522. public class TokenKwAnd: TokenKw
  1523. {
  1524. public TokenKwAnd(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.And; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1525. public TokenKwAnd(Token original) : base(original) { binOpConst = TokenRValConstOps.And; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1526. public override string ToString()
  1527. {
  1528. return "&";
  1529. }
  1530. }
  1531. public class TokenKwMul: TokenKw
  1532. {
  1533. public TokenKwMul(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Mul; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1534. public TokenKwMul(Token original) : base(original) { binOpConst = TokenRValConstOps.Mul; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1535. public override string ToString()
  1536. {
  1537. return "*";
  1538. }
  1539. }
  1540. public class TokenKwParOpen: TokenKw
  1541. {
  1542. public TokenKwParOpen(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1543. public TokenKwParOpen(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1544. public override string ToString()
  1545. {
  1546. return "(";
  1547. }
  1548. }
  1549. public class TokenKwParClose: TokenKw
  1550. {
  1551. public TokenKwParClose(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1552. public TokenKwParClose(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1553. public override string ToString()
  1554. {
  1555. return ")";
  1556. }
  1557. }
  1558. public class TokenKwSub: TokenKw
  1559. {
  1560. public TokenKwSub(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Sub; unOpConst = TokenRValConstOps.Neg; sdtClassOp = true; }
  1561. public TokenKwSub(Token original) : base(original) { binOpConst = TokenRValConstOps.Sub; unOpConst = TokenRValConstOps.Neg; sdtClassOp = true; }
  1562. public override string ToString()
  1563. {
  1564. return "-";
  1565. }
  1566. }
  1567. public class TokenKwAdd: TokenKw
  1568. {
  1569. public TokenKwAdd(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Add; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1570. public TokenKwAdd(Token original) : base(original) { binOpConst = TokenRValConstOps.Add; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1571. public override string ToString()
  1572. {
  1573. return "+";
  1574. }
  1575. }
  1576. public class TokenKwAssign: TokenKw
  1577. {
  1578. public TokenKwAssign(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1579. public TokenKwAssign(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1580. public override string ToString()
  1581. {
  1582. return "=";
  1583. }
  1584. }
  1585. public class TokenKwBrcOpen: TokenKw
  1586. {
  1587. public TokenKwBrcOpen(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1588. public TokenKwBrcOpen(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1589. public override string ToString()
  1590. {
  1591. return "{";
  1592. }
  1593. }
  1594. public class TokenKwBrcClose: TokenKw
  1595. {
  1596. public TokenKwBrcClose(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1597. public TokenKwBrcClose(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1598. public override string ToString()
  1599. {
  1600. return "}";
  1601. }
  1602. }
  1603. public class TokenKwBrkOpen: TokenKw
  1604. {
  1605. public TokenKwBrkOpen(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1606. public TokenKwBrkOpen(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1607. public override string ToString()
  1608. {
  1609. return "[";
  1610. }
  1611. }
  1612. public class TokenKwBrkClose: TokenKw
  1613. {
  1614. public TokenKwBrkClose(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1615. public TokenKwBrkClose(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1616. public override string ToString()
  1617. {
  1618. return "]";
  1619. }
  1620. }
  1621. public class TokenKwSemi: TokenKw
  1622. {
  1623. public TokenKwSemi(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1624. public TokenKwSemi(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1625. public override string ToString()
  1626. {
  1627. return ";";
  1628. }
  1629. }
  1630. public class TokenKwColon: TokenKw
  1631. {
  1632. public TokenKwColon(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1633. public TokenKwColon(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1634. public override string ToString()
  1635. {
  1636. return ":";
  1637. }
  1638. }
  1639. public class TokenKwCmpLT: TokenKw
  1640. {
  1641. public TokenKwCmpLT(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.binConstsLT; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1642. public TokenKwCmpLT(Token original) : base(original) { binOpConst = TokenRValConstOps.binConstsLT; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1643. public override string ToString()
  1644. {
  1645. return "<";
  1646. }
  1647. }
  1648. public class TokenKwCmpGT: TokenKw
  1649. {
  1650. public TokenKwCmpGT(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.binConstsGT; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1651. public TokenKwCmpGT(Token original) : base(original) { binOpConst = TokenRValConstOps.binConstsGT; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1652. public override string ToString()
  1653. {
  1654. return ">";
  1655. }
  1656. }
  1657. public class TokenKwComma: TokenKw
  1658. {
  1659. public TokenKwComma(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1660. public TokenKwComma(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1661. public override string ToString()
  1662. {
  1663. return ",";
  1664. }
  1665. }
  1666. public class TokenKwDot: TokenKw
  1667. {
  1668. public TokenKwDot(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1669. public TokenKwDot(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1670. public override string ToString()
  1671. {
  1672. return ".";
  1673. }
  1674. }
  1675. public class TokenKwQMark: TokenKw
  1676. {
  1677. public TokenKwQMark(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1678. public TokenKwQMark(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1679. public override string ToString()
  1680. {
  1681. return "?";
  1682. }
  1683. }
  1684. public class TokenKwDiv: TokenKw
  1685. {
  1686. public TokenKwDiv(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Div; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1687. public TokenKwDiv(Token original) : base(original) { binOpConst = TokenRValConstOps.Div; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1688. public override string ToString()
  1689. {
  1690. return "/";
  1691. }
  1692. }
  1693. public class TokenKwOr: TokenKw
  1694. {
  1695. public TokenKwOr(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Or; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1696. public TokenKwOr(Token original) : base(original) { binOpConst = TokenRValConstOps.Or; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1697. public override string ToString()
  1698. {
  1699. return "|";
  1700. }
  1701. }
  1702. public class TokenKwHash: TokenKw
  1703. {
  1704. public TokenKwHash(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1705. public TokenKwHash(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1706. public override string ToString()
  1707. {
  1708. return "#";
  1709. }
  1710. }
  1711. public class TokenKwAbstract: TokenKw
  1712. {
  1713. public TokenKwAbstract(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1714. public TokenKwAbstract(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1715. public override string ToString()
  1716. {
  1717. return "abstract";
  1718. }
  1719. }
  1720. public class TokenKwBase: TokenKw
  1721. {
  1722. public TokenKwBase(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1723. public TokenKwBase(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1724. public override string ToString()
  1725. {
  1726. return "base";
  1727. }
  1728. }
  1729. public class TokenKwBreak: TokenKw
  1730. {
  1731. public TokenKwBreak(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1732. public TokenKwBreak(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1733. public override string ToString()
  1734. {
  1735. return "break";
  1736. }
  1737. }
  1738. public class TokenKwCase: TokenKw
  1739. {
  1740. public TokenKwCase(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1741. public TokenKwCase(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1742. public override string ToString()
  1743. {
  1744. return "case";
  1745. }
  1746. }
  1747. public class TokenKwCatch: TokenKw
  1748. {
  1749. public TokenKwCatch(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1750. public TokenKwCatch(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1751. public override string ToString()
  1752. {
  1753. return "catch";
  1754. }
  1755. }
  1756. public class TokenKwClass: TokenKw
  1757. {
  1758. public TokenKwClass(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1759. public TokenKwClass(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1760. public override string ToString()
  1761. {
  1762. return "class";
  1763. }
  1764. }
  1765. public class TokenKwConst: TokenKw
  1766. {
  1767. public TokenKwConst(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1768. public TokenKwConst(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1769. public override string ToString()
  1770. {
  1771. return "constant";
  1772. }
  1773. }
  1774. public class TokenKwConstructor: TokenKw
  1775. {
  1776. public TokenKwConstructor(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1777. public TokenKwConstructor(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1778. public override string ToString()
  1779. {
  1780. return "constructor";
  1781. }
  1782. }
  1783. public class TokenKwCont: TokenKw
  1784. {
  1785. public TokenKwCont(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1786. public TokenKwCont(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1787. public override string ToString()
  1788. {
  1789. return "continue";
  1790. }
  1791. }
  1792. public class TokenKwDelegate: TokenKw
  1793. {
  1794. public TokenKwDelegate(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1795. public TokenKwDelegate(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1796. public override string ToString()
  1797. {
  1798. return "delegate";
  1799. }
  1800. }
  1801. public class TokenKwDefault: TokenKw
  1802. {
  1803. public TokenKwDefault(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1804. public TokenKwDefault(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1805. public override string ToString()
  1806. {
  1807. return "default";
  1808. }
  1809. }
  1810. public class TokenKwDestructor: TokenKw
  1811. {
  1812. public TokenKwDestructor(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1813. public TokenKwDestructor(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1814. public override string ToString()
  1815. {
  1816. return "destructor";
  1817. }
  1818. }
  1819. public class TokenKwDo: TokenKw
  1820. {
  1821. public TokenKwDo(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1822. public TokenKwDo(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1823. public override string ToString()
  1824. {
  1825. return "do";
  1826. }
  1827. }
  1828. public class TokenKwElse: TokenKw
  1829. {
  1830. public TokenKwElse(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1831. public TokenKwElse(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1832. public override string ToString()
  1833. {
  1834. return "else";
  1835. }
  1836. }
  1837. public class TokenKwFinal: TokenKw
  1838. {
  1839. public TokenKwFinal(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1840. public TokenKwFinal(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1841. public override string ToString()
  1842. {
  1843. return "final";
  1844. }
  1845. }
  1846. public class TokenKwFinally: TokenKw
  1847. {
  1848. public TokenKwFinally(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1849. public TokenKwFinally(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1850. public override string ToString()
  1851. {
  1852. return "finally";
  1853. }
  1854. }
  1855. public class TokenKwFor: TokenKw
  1856. {
  1857. public TokenKwFor(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1858. public TokenKwFor(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1859. public override string ToString()
  1860. {
  1861. return "for";
  1862. }
  1863. }
  1864. public class TokenKwForEach: TokenKw
  1865. {
  1866. public TokenKwForEach(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1867. public TokenKwForEach(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1868. public override string ToString()
  1869. {
  1870. return "foreach";
  1871. }
  1872. }
  1873. public class TokenKwGet: TokenKw
  1874. {
  1875. public TokenKwGet(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1876. public TokenKwGet(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1877. public override string ToString()
  1878. {
  1879. return "get";
  1880. }
  1881. }
  1882. public class TokenKwIf: TokenKw
  1883. {
  1884. public TokenKwIf(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1885. public TokenKwIf(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1886. public override string ToString()
  1887. {
  1888. return "if";
  1889. }
  1890. }
  1891. public class TokenKwIn: TokenKw
  1892. {
  1893. public TokenKwIn(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1894. public TokenKwIn(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1895. public override string ToString()
  1896. {
  1897. return "in";
  1898. }
  1899. }
  1900. public class TokenKwInterface: TokenKw
  1901. {
  1902. public TokenKwInterface(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1903. public TokenKwInterface(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1904. public override string ToString()
  1905. {
  1906. return "interface";
  1907. }
  1908. }
  1909. public class TokenKwIs: TokenKw
  1910. {
  1911. public TokenKwIs(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1912. public TokenKwIs(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1913. public override string ToString()
  1914. {
  1915. return "is";
  1916. }
  1917. }
  1918. public class TokenKwJump: TokenKw
  1919. {
  1920. public TokenKwJump(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1921. public TokenKwJump(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1922. public override string ToString()
  1923. {
  1924. return "jump";
  1925. }
  1926. }
  1927. public class TokenKwNew: TokenKw
  1928. {
  1929. public TokenKwNew(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1930. public TokenKwNew(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1931. public override string ToString()
  1932. {
  1933. return "new";
  1934. }
  1935. }
  1936. public class TokenKwOverride: TokenKw
  1937. {
  1938. public TokenKwOverride(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1939. public TokenKwOverride(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1940. public override string ToString()
  1941. {
  1942. return "override";
  1943. }
  1944. }
  1945. public class TokenKwPartial: TokenKw
  1946. {
  1947. public TokenKwPartial(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1948. public TokenKwPartial(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1949. public override string ToString()
  1950. {
  1951. return "partial";
  1952. }
  1953. }
  1954. public class TokenKwPrivate: TokenKw
  1955. {
  1956. public TokenKwPrivate(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1957. public TokenKwPrivate(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1958. public override string ToString()
  1959. {
  1960. return "private";
  1961. }
  1962. }
  1963. public class TokenKwProtected: TokenKw
  1964. {
  1965. public TokenKwProtected(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1966. public TokenKwProtected(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1967. public override string ToString()
  1968. {
  1969. return "protected";
  1970. }
  1971. }
  1972. public class TokenKwPublic: TokenKw
  1973. {
  1974. public TokenKwPublic(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1975. public TokenKwPublic(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1976. public override string ToString()
  1977. {
  1978. return "public";
  1979. }
  1980. }
  1981. public class TokenKwRet: TokenKw
  1982. {
  1983. public TokenKwRet(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1984. public TokenKwRet(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1985. public override string ToString()
  1986. {
  1987. return "return";
  1988. }
  1989. }
  1990. public class TokenKwSet: TokenKw
  1991. {
  1992. public TokenKwSet(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1993. public TokenKwSet(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1994. public override string ToString()
  1995. {
  1996. return "set";
  1997. }
  1998. }
  1999. public class TokenKwState: TokenKw
  2000. {
  2001. public TokenKwState(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2002. public TokenKwState(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2003. public override string ToString()
  2004. {
  2005. return "state";
  2006. }
  2007. }
  2008. public class TokenKwStatic: TokenKw
  2009. {
  2010. public TokenKwStatic(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2011. public TokenKwStatic(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2012. public override string ToString()
  2013. {
  2014. return "static";
  2015. }
  2016. }
  2017. public class TokenKwSwitch: TokenKw
  2018. {
  2019. public TokenKwSwitch(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2020. public TokenKwSwitch(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2021. public override string ToString()
  2022. {
  2023. return "switch";
  2024. }
  2025. }
  2026. public class TokenKwThis: TokenKw
  2027. {
  2028. public TokenKwThis(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2029. public TokenKwThis(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2030. public override string ToString()
  2031. {
  2032. return "this";
  2033. }
  2034. }
  2035. public class TokenKwThrow: TokenKw
  2036. {
  2037. public TokenKwThrow(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2038. public TokenKwThrow(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2039. public override string ToString()
  2040. {
  2041. return "throw";
  2042. }
  2043. }
  2044. public class TokenKwTry: TokenKw
  2045. {
  2046. public TokenKwTry(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2047. public TokenKwTry(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2048. public override string ToString()
  2049. {
  2050. return "try";
  2051. }
  2052. }
  2053. public class TokenKwTypedef: TokenKw
  2054. {
  2055. public TokenKwTypedef(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2056. public TokenKwTypedef(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2057. public override string ToString()
  2058. {
  2059. return "typedef";
  2060. }
  2061. }
  2062. public class TokenKwUndef: TokenKw
  2063. {
  2064. public TokenKwUndef(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2065. public TokenKwUndef(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2066. public override string ToString()
  2067. {
  2068. return "undef";
  2069. }
  2070. }
  2071. public class TokenKwVirtual: TokenKw
  2072. {
  2073. public TokenKwVirtual(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2074. public TokenKwVirtual(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2075. public override string ToString()
  2076. {
  2077. return "virtual";
  2078. }
  2079. }
  2080. public class TokenKwWhile: TokenKw
  2081. {
  2082. public TokenKwWhile(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2083. public TokenKwWhile(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2084. public override string ToString()
  2085. {
  2086. return "while";
  2087. }
  2088. }
  2089. /**
  2090. * @brief These static functions attempt to perform arithmetic on two constant
  2091. * operands to generate the resultant constant.
  2092. * Likewise for unary operators.
  2093. *
  2094. * @param left = left-hand value
  2095. * @param right = right-hand value
  2096. * @returns null: not able to perform computation
  2097. * else: resultant value object
  2098. *
  2099. * Note: it is ok for these to throw any exception (such as overflow or div-by-zero),
  2100. * and it will be treated as the 'not able to perform computation' case.
  2101. */
  2102. public class TokenRValConstOps
  2103. {
  2104. public static object Null(object left, object right)
  2105. {
  2106. return null;
  2107. }
  2108. public static object Div(object left, object right)
  2109. {
  2110. double r;
  2111. try
  2112. {
  2113. if ((left is int li) && (right is int ri))
  2114. {
  2115. if(li == -2147483648 && ri == -1)
  2116. return -2147483648;
  2117. return (int)left / (int)right;
  2118. }
  2119. if ((left is double) && (right is int))
  2120. {
  2121. r = (double)left / (int)right;
  2122. if (double.IsNaN(r) || double.IsInfinity(r))
  2123. throw new Exception("Division by Zero");
  2124. return r;
  2125. }
  2126. }
  2127. catch (DivideByZeroException)
  2128. {
  2129. throw new Exception("Division by Zero");
  2130. }
  2131. if ((left is int) && (right is double))
  2132. {
  2133. r = (int)left / (double)right;
  2134. }
  2135. else if((left is double) && (right is double))
  2136. {
  2137. r= (double)left / (double)right;
  2138. }
  2139. else
  2140. return null;
  2141. if (double.IsNaN(r) || double.IsInfinity(r))
  2142. throw new Exception("Division by Zero");
  2143. return r;
  2144. }
  2145. public static object Mod(object left, object right)
  2146. {
  2147. double r;
  2148. try
  2149. {
  2150. if ((left is int li) && (right is int ri))
  2151. {
  2152. if (li == -2147483648 && ri == -1)
  2153. return 0;
  2154. return li % ri;
  2155. }
  2156. if ((left is double) && (right is int))
  2157. {
  2158. r = (double)left % (int)right;
  2159. if (double.IsNaN(r) || double.IsInfinity(r))
  2160. throw new Exception("Division by Zero");
  2161. return r;
  2162. }
  2163. }
  2164. catch (DivideByZeroException)
  2165. {
  2166. throw new Exception("Division by Zero");
  2167. }
  2168. if ((left is int) && (right is double))
  2169. {
  2170. r = (int)left % (double)right;
  2171. }
  2172. else if ((left is double) && (right is double))
  2173. {
  2174. r = (double)left % (double)right;
  2175. }
  2176. else
  2177. return null;
  2178. if (double.IsNaN(r) || double.IsInfinity(r))
  2179. throw new Exception("Division by Zero");
  2180. return r;
  2181. }
  2182. public static object Mul(object left, object right)
  2183. {
  2184. if((left is int) && (right is int))
  2185. {
  2186. return (int)left * (int)right;
  2187. }
  2188. if((left is int) && (right is double))
  2189. {
  2190. return (int)left * (double)right;
  2191. }
  2192. if((left is double) && (right is int))
  2193. {
  2194. return (double)left * (int)right;
  2195. }
  2196. if((left is double) && (right is double))
  2197. {
  2198. return (double)left * (double)right;
  2199. }
  2200. return null;
  2201. }
  2202. public static object And(object left, object right)
  2203. {
  2204. if((left is int) && (right is int))
  2205. {
  2206. return (int)left & (int)right;
  2207. }
  2208. return null;
  2209. }
  2210. public static object LSh(object left, object right)
  2211. {
  2212. if((left is int) && (right is int))
  2213. return (int)left << (int)right;
  2214. return null;
  2215. }
  2216. public static object Or(object left, object right)
  2217. {
  2218. if((left is int) && (right is int))
  2219. return (int)left | (int)right;
  2220. return null;
  2221. }
  2222. public static object RSh(object left, object right)
  2223. {
  2224. if((left is int) && (right is int))
  2225. return (int)left >> (int)right;
  2226. return null;
  2227. }
  2228. public static object Xor(object left, object right)
  2229. {
  2230. if((left is int) && (right is int))
  2231. return (int)left ^ (int)right;
  2232. return null;
  2233. }
  2234. public static object Add(object left, object right)
  2235. {
  2236. if((left is char) && (right is int))
  2237. {
  2238. return (char)((char)left + (int)right);
  2239. }
  2240. if((left is double) && (right is double))
  2241. {
  2242. return (double)left + (double)right;
  2243. }
  2244. if((left is double) && (right is int))
  2245. {
  2246. return (double)left + (int)right;
  2247. }
  2248. if((left is double) && (right is string))
  2249. {
  2250. return TypeCast.FloatToString((double)left) + (string)right;
  2251. }
  2252. if((left is int) && (right is double))
  2253. {
  2254. return (int)left + (double)right;
  2255. }
  2256. if((left is int) && (right is int))
  2257. {
  2258. return (int)left + (int)right;
  2259. }
  2260. if((left is int) && (right is string))
  2261. {
  2262. return TypeCast.IntegerToString((int)left) + (string)right;
  2263. }
  2264. if((left is string) && (right is char))
  2265. {
  2266. return (string)left + (char)right;
  2267. }
  2268. if((left is string) && (right is double))
  2269. {
  2270. return (string)left + TypeCast.FloatToString((double)right);
  2271. }
  2272. if((left is string) && (right is int))
  2273. {
  2274. return (string)left + TypeCast.IntegerToString((int)right);
  2275. }
  2276. if((left is string) && (right is string))
  2277. {
  2278. return (string)left + (string)right;
  2279. }
  2280. return null;
  2281. }
  2282. public static object Sub(object left, object right)
  2283. {
  2284. if((left is char) && (right is int))
  2285. {
  2286. return (char)((char)left - (int)right);
  2287. }
  2288. if((left is int) && (right is int))
  2289. {
  2290. return (int)left - (int)right;
  2291. }
  2292. if((left is int) && (right is double))
  2293. {
  2294. return (int)left - (double)right;
  2295. }
  2296. if((left is double) && (right is int))
  2297. {
  2298. return (double)left - (int)right;
  2299. }
  2300. if((left is double) && (right is double))
  2301. {
  2302. return (double)left - (double)right;
  2303. }
  2304. return null;
  2305. }
  2306. public static object Null(object right)
  2307. {
  2308. return null;
  2309. }
  2310. public static object Neg(object right)
  2311. {
  2312. if(right is int)
  2313. {
  2314. return -(int)right;
  2315. }
  2316. if(right is double)
  2317. {
  2318. return -(double)right;
  2319. }
  2320. return null;
  2321. }
  2322. public static object Not(object right)
  2323. {
  2324. if(right is int)
  2325. {
  2326. return ~(int)right;
  2327. }
  2328. return null;
  2329. }
  2330. public static int binConstCompare(object left, object right)
  2331. {
  2332. double a;
  2333. if (left is bool lb)
  2334. a = lb ? 1.0 : 0.0;
  2335. else if (left is int li)
  2336. a = li;
  2337. else if (left is float lf)
  2338. a = lf;
  2339. else if (left is double ld)
  2340. a = ld;
  2341. else if(left is string ls)
  2342. {
  2343. if(!(right is string rs))
  2344. return -2;
  2345. return ls.CompareTo(rs);
  2346. }
  2347. else
  2348. return -2;
  2349. double b;
  2350. if (right is bool rb)
  2351. b = rb ? 1.0 : 0.0;
  2352. else if (right is int ri)
  2353. b = ri;
  2354. else if (right is float rf)
  2355. b = rf;
  2356. else if (right is double rd)
  2357. b = rd;
  2358. else
  2359. return -2;
  2360. return a.CompareTo(b);
  2361. }
  2362. public static object binConstsLT(object left, object right)
  2363. {
  2364. int res = binConstCompare(left, right);
  2365. if (res == -2)
  2366. return null;
  2367. return (res < 0) ? 1 : 0;
  2368. }
  2369. public static object binConstsLE(object left, object right)
  2370. {
  2371. int res = binConstCompare(left, right);
  2372. if (res == -2)
  2373. return null;
  2374. return (res <= 0) ? 1 : 0;
  2375. }
  2376. public static object binConstsGT(object left, object right)
  2377. {
  2378. int res = binConstCompare(left, right);
  2379. if (res == -2)
  2380. return null;
  2381. return (res > 0) ? 1 : 0;
  2382. }
  2383. public static object binConstsGE(object left, object right)
  2384. {
  2385. int res = binConstCompare(left, right);
  2386. if (res == -2)
  2387. return null;
  2388. return (res >= 0) ? 1 : 0;
  2389. }
  2390. public static object binConstsEQ(object left, object right)
  2391. {
  2392. int res = binConstCompare(left, right);
  2393. if (res == -2)
  2394. return null;
  2395. return (res == 0) ? 1 : 0;
  2396. }
  2397. public static object binConstsNE(object left, object right)
  2398. {
  2399. int res = binConstCompare(left, right);
  2400. if (res == -2)
  2401. return null;
  2402. return (res != 0) ? 1 : 0;
  2403. }
  2404. public static object binConstsLogicAndAnd(object left, object right)
  2405. {
  2406. if ((left is int li) && (right is int ri))
  2407. {
  2408. if (li == 0)
  2409. return 0;
  2410. if (ri == 0)
  2411. return 0;
  2412. return 1;
  2413. }
  2414. return null;
  2415. }
  2416. public static object binConstsLoginOrOr(object left, object right)
  2417. {
  2418. if ((left is int li) && (right is int ri))
  2419. {
  2420. if (li != 0)
  2421. return 1;
  2422. if (ri != 0)
  2423. return 1;
  2424. return 0;
  2425. }
  2426. return null;
  2427. }
  2428. public static object unOpExclam(object left)
  2429. {
  2430. if ((left is int li))
  2431. {
  2432. if (li == 0)
  2433. return 1;
  2434. return 0;
  2435. }
  2436. return null;
  2437. }
  2438. }
  2439. /*
  2440. * Various datatypes.
  2441. */
  2442. public abstract class TokenType: Token
  2443. {
  2444. public TokenType(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2445. public TokenType(Token original) : base(original) { }
  2446. public static TokenType FromSysType(Token original, System.Type typ)
  2447. {
  2448. if(typ == typeof(LSL_List))
  2449. return new TokenTypeList(original);
  2450. if(typ == typeof(LSL_Rotation))
  2451. return new TokenTypeRot(original);
  2452. if(typ == typeof(void))
  2453. return new TokenTypeVoid(original);
  2454. if(typ == typeof(LSL_Vector))
  2455. return new TokenTypeVec(original);
  2456. if(typ == typeof(float))
  2457. return new TokenTypeFloat(original);
  2458. if(typ == typeof(int))
  2459. return new TokenTypeInt(original);
  2460. if(typ == typeof(string))
  2461. return new TokenTypeStr(original);
  2462. if(typ == typeof(double))
  2463. return new TokenTypeFloat(original);
  2464. if(typ == typeof(bool))
  2465. return new TokenTypeBool(original);
  2466. if(typ == typeof(object))
  2467. return new TokenTypeObject(original);
  2468. if(typ == typeof(XMR_Array))
  2469. return new TokenTypeArray(original);
  2470. if(typ == typeof(LSL_Integer))
  2471. return new TokenTypeLSLInt(original);
  2472. if(typ == typeof(LSL_Float))
  2473. return new TokenTypeLSLFloat(original);
  2474. if(typ == typeof(LSL_String))
  2475. return new TokenTypeLSLString(original);
  2476. if(typ == typeof(char))
  2477. return new TokenTypeChar(original);
  2478. if(typ == typeof(Exception))
  2479. return new TokenTypeExc(original);
  2480. throw new Exception("unknown script type " + typ.ToString());
  2481. }
  2482. public static TokenType FromLSLType(Token original, string typ)
  2483. {
  2484. switch(typ)
  2485. {
  2486. case "list":
  2487. return new TokenTypeList(original);
  2488. case "rotation":
  2489. return new TokenTypeRot(original);
  2490. case "vector":
  2491. return new TokenTypeVec(original);
  2492. case "float":
  2493. return new TokenTypeFloat(original);
  2494. case "integer":
  2495. return new TokenTypeInt(original);
  2496. case "key":
  2497. return new TokenTypeKey(original);
  2498. case "string":
  2499. return new TokenTypeStr(original);
  2500. case "object":
  2501. return new TokenTypeObject(original);
  2502. case "array":
  2503. return new TokenTypeArray(original);
  2504. case "bool":
  2505. return new TokenTypeBool(original);
  2506. case "void":
  2507. return new TokenTypeVoid(original);
  2508. case "char":
  2509. return new TokenTypeChar(original);
  2510. case "exception":
  2511. return new TokenTypeExc(original);
  2512. }
  2513. throw new Exception("unknown type " + typ);
  2514. }
  2515. /**
  2516. * @brief Estimate the number of bytes of memory taken by one of these
  2517. * objects. For objects with widely varying size, return the
  2518. * smallest it can be.
  2519. */
  2520. public static int StaticSize(System.Type typ)
  2521. {
  2522. if(typ == typeof(LSL_List))
  2523. return 96;
  2524. if(typ == typeof(LSL_Rotation))
  2525. return 80;
  2526. if(typ == typeof(void))
  2527. return 0;
  2528. if(typ == typeof(LSL_Vector))
  2529. return 72;
  2530. if(typ == typeof(float))
  2531. return 8;
  2532. if(typ == typeof(int))
  2533. return 8;
  2534. if(typ == typeof(string))
  2535. return 40;
  2536. if(typ == typeof(double))
  2537. return 8;
  2538. if(typ == typeof(bool))
  2539. return 8;
  2540. if(typ == typeof(XMR_Array))
  2541. return 96;
  2542. if(typ == typeof(object))
  2543. return 32;
  2544. if(typ == typeof(char))
  2545. return 2;
  2546. if(typ == typeof(LSL_Integer))
  2547. return 32;
  2548. if(typ == typeof(LSL_Float))
  2549. return 32;
  2550. if(typ == typeof(LSL_String))
  2551. return 40;
  2552. throw new Exception("unknown type " + typ.ToString());
  2553. }
  2554. /**
  2555. * @brief Return the corresponding system type.
  2556. */
  2557. public abstract Type ToSysType();
  2558. /**
  2559. * @brief Return the equivalent LSL wrapping type.
  2560. *
  2561. * null: normal
  2562. * else: LSL-style wrapping, ie, LSL_Integer, LSL_Float, LSL_String
  2563. * ToSysType()=System.Int32; lslWrapping=LSL_Integer
  2564. * ToSysType()=System.Float; lslWrapping=LSL_Float
  2565. * ToSysType()=System.String; lslWrapping=LSL_String
  2566. */
  2567. public virtual Type ToLSLWrapType()
  2568. {
  2569. return null;
  2570. }
  2571. /**
  2572. * @brief Assign slots in either the global variable arrays or the script-defined type instance arrays.
  2573. * These only need to be implemented for script-visible types, ie, those that a script writer
  2574. * can actually define a variable as.
  2575. */
  2576. public virtual void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2577. {
  2578. throw new Exception("not implemented for " + ToString() + " (" + GetType() + ")");
  2579. }
  2580. /**
  2581. * @brief Get heap tracking type.
  2582. * null indicates there is no heap tracker for the type.
  2583. */
  2584. public virtual Type ToHeapTrackerType()
  2585. {
  2586. return null;
  2587. }
  2588. public virtual ConstructorInfo GetHeapTrackerCtor()
  2589. {
  2590. throw new ApplicationException("no GetHeapTrackerCtor for " + this.GetType());
  2591. }
  2592. public virtual void CallHeapTrackerPopMeth(Token errorAt, ScriptMyILGen ilGen)
  2593. {
  2594. throw new ApplicationException("no CallHeapTrackerPopMeth for " + this.GetType());
  2595. }
  2596. public virtual void CallHeapTrackerPushMeth(Token errorAt, ScriptMyILGen ilGen)
  2597. {
  2598. throw new ApplicationException("no CallHeapTrackerPushMeth for " + this.GetType());
  2599. }
  2600. }
  2601. public class TokenTypeArray: TokenType
  2602. {
  2603. private static readonly FieldInfo iarArraysFieldInfo = typeof(XMRInstArrays).GetField("iarArrays");
  2604. public TokenTypeArray(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2605. public TokenTypeArray(Token original) : base(original) { }
  2606. public override Type ToSysType()
  2607. {
  2608. return typeof(XMR_Array);
  2609. }
  2610. public override string ToString()
  2611. {
  2612. return "array";
  2613. }
  2614. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2615. {
  2616. declVar.vTableArray = iarArraysFieldInfo;
  2617. declVar.vTableIndex = arSizes.iasArrays++;
  2618. }
  2619. }
  2620. public class TokenTypeBool: TokenType
  2621. {
  2622. public TokenTypeBool(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2623. public TokenTypeBool(Token original) : base(original) { }
  2624. public override Type ToSysType()
  2625. {
  2626. return typeof(bool);
  2627. }
  2628. public override string ToString()
  2629. {
  2630. return "bool";
  2631. }
  2632. }
  2633. public class TokenTypeChar: TokenType
  2634. {
  2635. private static readonly FieldInfo iarCharsFieldInfo = typeof(XMRInstArrays).GetField("iarChars");
  2636. public TokenTypeChar(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2637. public TokenTypeChar(Token original) : base(original) { }
  2638. public override Type ToSysType()
  2639. {
  2640. return typeof(char);
  2641. }
  2642. public override string ToString()
  2643. {
  2644. return "char";
  2645. }
  2646. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2647. {
  2648. declVar.vTableArray = iarCharsFieldInfo;
  2649. declVar.vTableIndex = arSizes.iasChars++;
  2650. }
  2651. }
  2652. public class TokenTypeExc: TokenType
  2653. {
  2654. private static readonly FieldInfo iarObjectsFieldInfo = typeof(XMRInstArrays).GetField("iarObjects");
  2655. public TokenTypeExc(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2656. public TokenTypeExc(Token original) : base(original) { }
  2657. public override Type ToSysType()
  2658. {
  2659. return typeof(Exception);
  2660. }
  2661. public override string ToString()
  2662. {
  2663. return "exception";
  2664. }
  2665. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2666. {
  2667. declVar.vTableArray = iarObjectsFieldInfo;
  2668. declVar.vTableIndex = arSizes.iasObjects++;
  2669. }
  2670. }
  2671. public class TokenTypeFloat: TokenType
  2672. {
  2673. private static readonly FieldInfo iarFloatsFieldInfo = typeof(XMRInstArrays).GetField("iarFloats");
  2674. public TokenTypeFloat(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2675. public TokenTypeFloat(Token original) : base(original) { }
  2676. public override Type ToSysType()
  2677. {
  2678. return typeof(double);
  2679. }
  2680. public override string ToString()
  2681. {
  2682. return "float";
  2683. }
  2684. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2685. {
  2686. declVar.vTableArray = iarFloatsFieldInfo;
  2687. declVar.vTableIndex = arSizes.iasFloats++;
  2688. }
  2689. }
  2690. public class TokenTypeInt: TokenType
  2691. {
  2692. private static readonly FieldInfo iarIntegersFieldInfo = typeof(XMRInstArrays).GetField("iarIntegers");
  2693. public TokenTypeInt(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2694. public TokenTypeInt(Token original) : base(original) { }
  2695. public override Type ToSysType()
  2696. {
  2697. return typeof(int);
  2698. }
  2699. public override string ToString()
  2700. {
  2701. return "integer";
  2702. }
  2703. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2704. {
  2705. declVar.vTableArray = iarIntegersFieldInfo;
  2706. declVar.vTableIndex = arSizes.iasIntegers++;
  2707. }
  2708. }
  2709. public class TokenTypeKey: TokenType
  2710. {
  2711. private static readonly FieldInfo iarStringsFieldInfo = typeof(XMRInstArrays).GetField("iarStrings");
  2712. public TokenTypeKey(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2713. public TokenTypeKey(Token original) : base(original) { }
  2714. public override Type ToSysType()
  2715. {
  2716. return typeof(string);
  2717. }
  2718. public override string ToString()
  2719. {
  2720. return "key";
  2721. }
  2722. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2723. {
  2724. declVar.vTableArray = iarStringsFieldInfo;
  2725. declVar.vTableIndex = arSizes.iasStrings++;
  2726. }
  2727. }
  2728. public class TokenTypeList: TokenType
  2729. {
  2730. private static readonly FieldInfo iarListsFieldInfo = typeof(XMRInstArrays).GetField("iarLists");
  2731. private static readonly ConstructorInfo htListCtor = typeof(HeapTrackerList).GetConstructor(new Type[] { typeof(XMRInstAbstract) });
  2732. public TokenTypeList(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2733. public TokenTypeList(Token original) : base(original) { }
  2734. public override Type ToSysType()
  2735. {
  2736. return typeof(LSL_List);
  2737. }
  2738. public override string ToString()
  2739. {
  2740. return "list";
  2741. }
  2742. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2743. {
  2744. declVar.vTableArray = iarListsFieldInfo;
  2745. declVar.vTableIndex = arSizes.iasLists++;
  2746. }
  2747. public override Type ToHeapTrackerType()
  2748. {
  2749. return typeof(HeapTrackerList);
  2750. }
  2751. public override ConstructorInfo GetHeapTrackerCtor()
  2752. {
  2753. return htListCtor;
  2754. }
  2755. public override void CallHeapTrackerPopMeth(Token errorAt, ScriptMyILGen ilGen)
  2756. {
  2757. HeapTrackerList.GenPop(errorAt, ilGen);
  2758. }
  2759. public override void CallHeapTrackerPushMeth(Token errorAt, ScriptMyILGen ilGen)
  2760. {
  2761. HeapTrackerList.GenPush(errorAt, ilGen);
  2762. }
  2763. }
  2764. public class TokenTypeObject: TokenType
  2765. {
  2766. private static readonly FieldInfo iarObjectsFieldInfo = typeof(XMRInstArrays).GetField("iarObjects");
  2767. private static readonly ConstructorInfo htObjectCtor = typeof(HeapTrackerObject).GetConstructor(new Type[] { typeof(XMRInstAbstract) });
  2768. public TokenTypeObject(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2769. public TokenTypeObject(Token original) : base(original) { }
  2770. public override Type ToSysType()
  2771. {
  2772. return typeof(object);
  2773. }
  2774. public override string ToString()
  2775. {
  2776. return "object";
  2777. }
  2778. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2779. {
  2780. declVar.vTableArray = iarObjectsFieldInfo;
  2781. declVar.vTableIndex = arSizes.iasObjects++;
  2782. }
  2783. public override Type ToHeapTrackerType()
  2784. {
  2785. return typeof(HeapTrackerObject);
  2786. }
  2787. public override ConstructorInfo GetHeapTrackerCtor()
  2788. {
  2789. return htObjectCtor;
  2790. }
  2791. public override void CallHeapTrackerPopMeth(Token errorAt, ScriptMyILGen ilGen)
  2792. {
  2793. HeapTrackerObject.GenPop(errorAt, ilGen);
  2794. }
  2795. public override void CallHeapTrackerPushMeth(Token errorAt, ScriptMyILGen ilGen)
  2796. {
  2797. HeapTrackerObject.GenPush(errorAt, ilGen);
  2798. }
  2799. }
  2800. public class TokenTypeRot: TokenType
  2801. {
  2802. private static readonly FieldInfo iarRotationsFieldInfo = typeof(XMRInstArrays).GetField("iarRotations");
  2803. public TokenTypeRot(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2804. public TokenTypeRot(Token original) : base(original) { }
  2805. public override Type ToSysType()
  2806. {
  2807. return typeof(LSL_Rotation);
  2808. }
  2809. public override string ToString()
  2810. {
  2811. return "rotation";
  2812. }
  2813. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2814. {
  2815. declVar.vTableArray = iarRotationsFieldInfo;
  2816. declVar.vTableIndex = arSizes.iasRotations++;
  2817. }
  2818. }
  2819. public class TokenTypeStr: TokenType
  2820. {
  2821. private static readonly FieldInfo iarStringsFieldInfo = typeof(XMRInstArrays).GetField("iarStrings");
  2822. private static readonly ConstructorInfo htStringCtor = typeof(HeapTrackerString).GetConstructor(new Type[] { typeof(XMRInstAbstract) });
  2823. public TokenTypeStr(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2824. public TokenTypeStr(Token original) : base(original) { }
  2825. public override Type ToSysType()
  2826. {
  2827. return typeof(string);
  2828. }
  2829. public override string ToString()
  2830. {
  2831. return "string";
  2832. }
  2833. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2834. {
  2835. declVar.vTableArray = iarStringsFieldInfo;
  2836. declVar.vTableIndex = arSizes.iasStrings++;
  2837. }
  2838. public override Type ToHeapTrackerType()
  2839. {
  2840. return typeof(HeapTrackerString);
  2841. }
  2842. public override ConstructorInfo GetHeapTrackerCtor()
  2843. {
  2844. return htStringCtor;
  2845. }
  2846. public override void CallHeapTrackerPopMeth(Token errorAt, ScriptMyILGen ilGen)
  2847. {
  2848. HeapTrackerString.GenPop(errorAt, ilGen);
  2849. }
  2850. public override void CallHeapTrackerPushMeth(Token errorAt, ScriptMyILGen ilGen)
  2851. {
  2852. HeapTrackerString.GenPush(errorAt, ilGen);
  2853. }
  2854. }
  2855. public class TokenTypeUndef: TokenType
  2856. { // for the 'undef' constant, ie, null object pointer
  2857. public TokenTypeUndef(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2858. public TokenTypeUndef(Token original) : base(original) { }
  2859. public override Type ToSysType()
  2860. {
  2861. return typeof(object);
  2862. }
  2863. public override string ToString()
  2864. {
  2865. return "undef";
  2866. }
  2867. }
  2868. public class TokenTypeVec: TokenType
  2869. {
  2870. private static readonly FieldInfo iarVectorsFieldInfo = typeof(XMRInstArrays).GetField("iarVectors");
  2871. public TokenTypeVec(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2872. public TokenTypeVec(Token original) : base(original) { }
  2873. public override Type ToSysType()
  2874. {
  2875. return typeof(LSL_Vector);
  2876. }
  2877. public override string ToString()
  2878. {
  2879. return "vector";
  2880. }
  2881. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2882. {
  2883. declVar.vTableArray = iarVectorsFieldInfo;
  2884. declVar.vTableIndex = arSizes.iasVectors++;
  2885. }
  2886. }
  2887. public class TokenTypeVoid: TokenType
  2888. { // used only for function/method return types
  2889. public TokenTypeVoid(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2890. public TokenTypeVoid(Token original) : base(original) { }
  2891. public override Type ToSysType()
  2892. {
  2893. return typeof(void);
  2894. }
  2895. public override string ToString()
  2896. {
  2897. return "void";
  2898. }
  2899. }
  2900. public class TokenTypeLSLFloat: TokenTypeFloat
  2901. {
  2902. public TokenTypeLSLFloat(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2903. public TokenTypeLSLFloat(Token original) : base(original) { }
  2904. public override Type ToLSLWrapType()
  2905. {
  2906. return typeof(LSL_Float);
  2907. }
  2908. }
  2909. public class TokenTypeLSLInt: TokenTypeInt
  2910. {
  2911. public TokenTypeLSLInt(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2912. public TokenTypeLSLInt(Token original) : base(original) { }
  2913. public override Type ToLSLWrapType()
  2914. {
  2915. return typeof(LSL_Integer);
  2916. }
  2917. }
  2918. public class TokenTypeLSLKey: TokenTypeKey
  2919. {
  2920. public TokenTypeLSLKey(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2921. public TokenTypeLSLKey(Token original) : base(original) { }
  2922. public override Type ToLSLWrapType()
  2923. {
  2924. return typeof(LSL_Key);
  2925. }
  2926. }
  2927. public class TokenTypeLSLString: TokenTypeStr
  2928. {
  2929. public TokenTypeLSLString(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2930. public TokenTypeLSLString(Token original) : base(original) { }
  2931. public override Type ToLSLWrapType()
  2932. {
  2933. return typeof(LSL_String);
  2934. }
  2935. }
  2936. }