Advertisement
Guest User

Untitled

a guest
Oct 5th, 2010
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 46.51 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Collections.Specialized;
  5. using System.Text;
  6. using ICSharpCode.NRefactory.Parser;
  7. using ICSharpCode.NRefactory.Ast;
  8. using ASTAttribute = ICSharpCode.NRefactory.Ast.Attribute;
  9. using Types = ICSharpCode.NRefactory.Ast.ClassType;
  10.  
  11. COMPILER Andromeda
  12.  
  13. /*------------------------------------------------------------------------*
  14. *----- LEXER TOKEN LIST ------------------------------------------------*
  15. *------------------------------------------------------------------------*/
  16.  
  17. /* START AUTOGENERATED TOKENS SECTION */
  18. TOKENS
  19. /* Terminal classes. */
  20. /* EOF is 0 */
  21. ident
  22. Literal
  23.  
  24. /* Special characters. */
  25. "="
  26. "+"
  27. "-"
  28. "*"
  29. "/"
  30. "%"
  31. ":"
  32. "::"
  33. ";"
  34. "?"
  35. "??"
  36. ","
  37. "."
  38. "{"
  39. "}"
  40. "["
  41. "]"
  42. "("
  43. ")"
  44. ">"
  45. "<"
  46. "!"
  47. "&&"
  48. "||"
  49. "~"
  50. "&"
  51. "|"
  52. "^"
  53. "++"
  54. "--"
  55. "=="
  56. "!="
  57. ">="
  58. "<="
  59. "<<"
  60. "+="
  61. "-="
  62. "*="
  63. "/="
  64. "%="
  65. "&="
  66. "|="
  67. "^="
  68. "<<="
  69. "->"
  70.  
  71. /* Keywords. */
  72. "abilcmd"
  73. "abstract"
  74. "actor"
  75. "actorscope"
  76. "aifilter"
  77. "bank"
  78. "bool"
  79. "break"
  80. "byte"
  81. "camerainfo"
  82. "case"
  83. "catch"
  84. "class"
  85. "color"
  86. "const"
  87. "continue"
  88. "default"
  89. "do"
  90. "doodad"
  91. "else"
  92. "enrich"
  93. "extends"
  94. "false"
  95. "final"
  96. "finally"
  97. "fixed"
  98. "for"
  99. "if"
  100. "implements"
  101. "import"
  102. "include"
  103. "inline"
  104. "instance"
  105. "int"
  106. "interface"
  107. "internal"
  108. "is"
  109. "iskey"
  110. "keyof"
  111. "marker"
  112. "namespace"
  113. "native"
  114. "new"
  115. "null"
  116. "order"
  117. "out"
  118. "override"
  119. "package"
  120. "playergroup"
  121. "point"
  122. "private"
  123. "protected"
  124. "public"
  125. "readonly"
  126. "revealer"
  127. "ref"
  128. "return"
  129. "setinstancelimit"
  130. "sound"
  131. "soundlink"
  132. "stackalloc"
  133. "static"
  134. "string"
  135. "struct"
  136. "super"
  137. "switch"
  138. "text"
  139. "this"
  140. "throws"
  141. "throw"
  142. "timer"
  143. "transient"
  144. "transmissionsource"
  145. "trigger"
  146. "true"
  147. "try"
  148. "typedef"
  149. "typeof"
  150. "unit"
  151. "unitfilter"
  152. "unitgroup"
  153. "unitref"
  154. "uses"
  155. "virtual"
  156. "volatile"
  157. "void"
  158. "wave"
  159. "waveinfo"
  160. "wavetarget"
  161. "while"
  162. "get"
  163. "set"
  164. /* END AUTOGENERATED TOKENS SECTION */
  165.  
  166. /*------------------------------------------------------------------------*
  167. *----- PARSER -----------------------------------------------------------*
  168. *------------------------------------------------------------------------*/
  169.  
  170. PRODUCTIONS
  171.  
  172. Andromeda
  173. (. lexer.NextToken(); /* get the first token */ .)
  174. =
  175. { NamespaceMemberDecl }
  176. EOF
  177. .
  178.  
  179. NamespaceMemberDecl
  180. (.
  181. ModifierList m = new ModifierList();
  182. string qualident;
  183. .)
  184. = /*--- namespace declaration: */
  185. "package" (. Location startPos = t.Location; .)
  186. Qualident<out qualident> (. INode node = new NamespaceDeclaration(qualident);
  187. node.StartLocation = startPos;
  188. compilationUnit.AddChild(node);
  189. compilationUnit.BlockStart(node);
  190. .)
  191. ";"
  192. { NamespaceMemberDecl }
  193. [ ";" ] (. node.EndLocation = t.EndLocation;
  194. compilationUnit.BlockEnd();
  195. .)
  196. /*--- type declaration: */
  197. |
  198. { TypeModifier<m> }
  199. TypeDecl<m>
  200. .
  201.  
  202. TypeDecl<ModifierList m>
  203. (.
  204. List<TypeReference> names;
  205. List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
  206. List<TemplateDefinition> templates;
  207. .)
  208. = /*--- class declaration: */ (. m.Check(Modifiers.Classes); .)
  209. "class" (. TypeDeclaration newType = new TypeDeclaration(m.Modifier, new List<AttributeSection>());
  210. templates = newType.Templates;
  211. compilationUnit.AddChild(newType);
  212. compilationUnit.BlockStart(newType);
  213. newType.StartLocation = m.GetDeclarationLocation(t.Location);
  214.  
  215. newType.Type = Types.Class;
  216. .)
  217. Identifier (. newType.Name = t.val; .)
  218.  
  219. [ ClassBase<out names> (. newType.BaseTypes = names; .) ]
  220.  
  221. (. newType.BodyStartLocation = t.EndLocation; .)
  222. ClassBody
  223. [ ";" ] (. newType.EndLocation = t.Location;
  224. compilationUnit.BlockEnd();
  225. .)
  226. | /*--- enrichment declaration: */
  227. "enrich" (. TypeDeclaration newType = new TypeDeclaration(m.Modifier, new List<AttributeSection>());
  228. templates = newType.Templates;
  229. compilationUnit.AddChild(newType);
  230. compilationUnit.BlockStart(newType);
  231. newType.StartLocation = m.GetDeclarationLocation(t.Location);
  232. newType.Type = Types.Enrichment;
  233. .)
  234. Identifier (. newType.Name = t.val; .)
  235.  
  236. [ ClassBae<out names> (. newType.BsaeTypes = names; .) ]
  237.  
  238. (. newType.BodyStartLocation = t.EndLocation; .)
  239. ClassBody
  240. [ ";" ] (. newType.EndLocation = t.Location;
  241. compilationUnit.BlockEnd();
  242. .)
  243. | /*--- interface declaration: */
  244. "interface" (. TypeDeclaration newType = new TypeDeclaration(m.Modifier, new List<AttributeSection>());
  245. templates = newType.Templates;
  246. compilationUnit.AddChild(newType);
  247. compilationUnit.BlockStart(newType);
  248. newType.StartLocation = m.GetDeclarationLocation(t.Location);
  249. newType.Type = Types.Interface;
  250. .)
  251. Identifier (. newType.Name = t.val; .)
  252.  
  253. [ ClassBase<out names> (. newType.BaseTypes = names; .) ]
  254.  
  255. (. newType.BodyStartLocation = t.EndLocation; .)
  256. ClassBody
  257. [ ";" ] (. newType.EndLocation = t.Location;
  258. compilationUnit.BlockEnd();
  259. .)
  260. .
  261.  
  262. Qualident<out string qualident>
  263. =
  264. ident (. string str = ""; qualidentBuilder.Length = 0; qualidentBuilder.Append(t.val); .)
  265. { IF (DotAndIdent()) "." IdentifierTimes<out str> (. qualidentBuilder.Append('.');
  266. qualidentBuilder.Append(str);
  267. .)
  268. } (. qualident = qualidentBuilder.ToString(); .)
  269. .
  270.  
  271. IdentifierTimes<out string str>
  272. (. str = ""; .)
  273. =
  274. ident (. str = t.val; .) | "*" (.str = "*"; .)
  275. .
  276.  
  277. ClassBase<out List<TypeReference> names>
  278. (.
  279. TypeReference typeRef;
  280. names = new List<TypeReference>();
  281. TypeReferenceKind kind = TypeReferenceKind.Extends;
  282. .)
  283. =
  284. {"extends" ClassType<out typeRef> (. if (typeRef != null) { kind = TypeReferenceKind.Extends; typeRef.Kind = kind; names.Add(typeRef); } .) }
  285. {"implements" ClassType<out typeRef> (. if (typeRef != null) { kind = TypeReferenceKind.Implements; typeRef.Kind = kind; names.Add(typeRef); } .) }
  286. { "," TypeName<out typeRef> (. if (typeRef != null) { typeRef.Kind = kind; names.Add(typeRef); } .) }
  287. .
  288.  
  289. ClassBody
  290. =
  291. "{"
  292. { (.ModifierList m = new ModifierList(); .)
  293. ClassMemberDecl<m>
  294. }
  295. "}"
  296. .
  297.  
  298. Type<out TypeReference type>
  299. =
  300. TypeWithRestriction<out type>
  301. .
  302.  
  303. TypeWithRestriction<out TypeReference type>
  304. (.
  305. string name;
  306. type = null;
  307. .)
  308. =
  309. ( ClassType<out type>
  310. | SimpleType<out name> (. type = new TypeReference(name); .)
  311. | "void" (. type = new TypeReference("void"); .)
  312. ) (. List<int> r = new List<int>(); .)
  313.  
  314. { IF (IsPointerOrDims()) (. int i = 0; .)
  315. ( "[" { "," (. ++i; .) } "]" (. r.Add(i); .) )
  316. }
  317.  
  318. (. if (type != null) {
  319. type.RankSpecifier = r.ToArray();
  320. }
  321. .)
  322. .
  323.  
  324.  
  325. NonArrayType<out TypeReference type>
  326. (.
  327. string name;
  328. type = null;
  329. .)
  330. =
  331. ( ClassType<out type>
  332. | SimpleType<out name> (. type = new TypeReference(name); .)
  333. | "void" (. type = new TypeReference("void"); .)
  334. )
  335. .
  336.  
  337. SimpleType<out string name>
  338. (. name = String.Empty; .)
  339. =
  340. IntegralType<out name>
  341. | "abilcmd" (. name = "abilcmd"; .)
  342. | "actor" (. name = "actor"; .)
  343. | "actorscope" (. name = "actorscope"; .)
  344. | "aifilter" (. name = "aifilter"; .)
  345. | "bank" (. name = "bank"; .)
  346. | "bool" (. name = "bool"; .)
  347. | "byte" (. name = "byte"; .)
  348. | "camerainfo" (. name = "camerainfo"; .)
  349. | "color" (. name = "color"; .)
  350. | "doodad" (. name = "doodad"; .)
  351. | "fixed" (. name = "fixed"; .)
  352. | "int" (. name = "int"; .)
  353. | "marker" (. name = "marker"; .)
  354. | "order" (. name = "order"; .)
  355. | "playergroup" (. name = "playergroup"; .)
  356. | "point" (. name = "point"; .)
  357. | "revealer" (. name = "revealer"; .)
  358. | "sound" (. name = "sound"; .)
  359. | "soundlink" (. name = "soundlink"; .)
  360. | "string" (. name = "string"; .)
  361. | "text" (. name = "text"; .)
  362. | "timer" (. name = "timer"; .)
  363. | "transmissionsource" (. name = "transmissionsource"; .)
  364. | "trigger" (. name = "trigger"; .)
  365. | "unit" (. name = "unit"; .)
  366. | "unitfilter" (. name = "unitfilter"; .)
  367. | "unitgroup" (. name = "unitgroup"; .)
  368. | "unitref" (. name = "unitref"; .)
  369. | "void" (. name = "void"; .)
  370. | "wave" (. name = "wave"; .)
  371. | "waveinfo" (. name = "waveinfo"; .)
  372. | "wavetarget" (. name = "wavetarget"; .)
  373. .
  374.  
  375.  
  376. FormalParameterList<List<ParameterDeclarationExpression> parameter>
  377. (.
  378. ParameterDeclarationExpression p;
  379. .)
  380. =
  381. (
  382. FixedParameter<out p> (.
  383. p.Attributes = new List<AttributeSection>();
  384. parameter.Add(p);
  385. .)
  386. {
  387. ","
  388. (
  389. FixedParameter<out p> (. p.Attributes = new List<AttributeSection>(); parameter.Add(p); .)
  390. )
  391. }
  392. )
  393. .
  394.  
  395. FixedParameter<out ParameterDeclarationExpression p>
  396. (.
  397. TypeReference type;
  398. ParameterModifiers mod = ParameterModifiers.In;
  399. Location start = t.Location;
  400. bool final = false;
  401. .)
  402. =
  403. [ "final" (. final = true; .) ]
  404. Type<out type> ident (. if (final) { mod = mod | ParameterModifiers.Final; } p = new ParameterDeclarationExpression(type, t.val, mod); p.StartLocation = start; p.EndLocation = t.Location; .)
  405. ArrayRank<type>
  406. .
  407.  
  408. TypeModifier<ModifierList m>
  409. =
  410. "new" (. m.Add(Modifiers.New, t.Location); .)
  411. | "public" (. m.Add(Modifiers.Public, t.Location); .)
  412. | "protected" (. m.Add(Modifiers.Protected, t.Location); .)
  413. | "private" (. m.Add(Modifiers.Private, t.Location); .)
  414. | "abstract" (. m.Add(Modifiers.Abstract, t.Location); .)
  415. | "static" (. m.Add(Modifiers.Static, t.Location); .)
  416. | "final" (. m.Add(Modifiers.Final, t.Location); .)
  417. .
  418.  
  419. ClassType<out TypeReference typeRef>
  420. (. TypeReference r; typeRef = null; .)
  421. =
  422. TypeName<out r> (. typeRef = r; .)
  423. .
  424.  
  425. IntegralType<out string name> (. name = ""; .)
  426. =
  427. "abilcmd" (. name = "abilcmd"; .)
  428. | "actor" (. name = "actor"; .)
  429. | "actorscope" (. name = "actorscope"; .)
  430. | "aifilter" (. name = "aifilter"; .)
  431. | "bank" (. name = "bank"; .)
  432. | "bool" (. name = "bool"; .)
  433. | "byte" (. name = "byte"; .)
  434. | "camerainfo" (. name = "camerainfo"; .)
  435. | "color" (. name = "color"; .)
  436. | "doodad" (. name = "doodad"; .)
  437. | "fixed" (. name = "fixed"; .)
  438. | "int" (. name = "int"; .)
  439. | "marker" (. name = "marker"; .)
  440. | "order" (. name = "order"; .)
  441. | "playergroup" (. name = "playergroup"; .)
  442. | "point" (. name = "point"; .)
  443. | "revealer" (. name = "revealer"; .)
  444. | "sound" (. name = "sound"; .)
  445. | "soundlink" (. name = "soundlink"; .)
  446. | "string" (. name = "string"; .)
  447. | "text" (. name = "text"; .)
  448. | "timer" (. name = "timer"; .)
  449. | "transmissionsource" (. name = "transmissionsource"; .)
  450. | "trigger" (. name = "trigger"; .)
  451. | "unit" (. name = "unit"; .)
  452. | "unitfilter" (. name = "unitfilter"; .)
  453. | "unitgroup" (. name = "unitgroup"; .)
  454. | "unitref" (. name = "unitref"; .)
  455. | "void" (. name = "void"; .)
  456. | "wave" (. name = "wave"; .)
  457. | "waveinfo" (. name = "waveinfo"; .)
  458. | "wavetarget" (. name = "wavetarget"; .)
  459. .
  460.  
  461. MemberModifiers<ModifierList m>
  462. =
  463. {
  464. "abstract" (. m.Add(Modifiers.Abstract, t.Location); .)
  465. | "new" (. m.Add(Modifiers.New, t.Location); .)
  466. | "private" (. m.Add(Modifiers.Private, t.Location); .)
  467. | "protected" (. m.Add(Modifiers.Protected, t.Location); .)
  468. | "public" (. m.Add(Modifiers.Public, t.Location); .)
  469. | "final" (. m.Add(Modifiers.Final, t.Location); .)
  470. | "static" (. m.Add(Modifiers.Static, t.Location); .)
  471. | "volatile" (. m.Add(Modifiers.Volatile, t.Location); .)
  472. | "transient" (. m.Add(Modifiers.Transient, t.Location); .)
  473. | "native" (. m.Add(Modifiers.Native, t.Location); .)
  474. }
  475. .
  476.  
  477. StructMemberDecl<ModifierList m>
  478. (.
  479. string qualident = null;
  480. TypeReference type;
  481. Expression expr;
  482. List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
  483. Statement stmt = null;
  484. List<VariableDeclaration> variableDeclarators = new List<VariableDeclaration>();
  485. List<TemplateDefinition> templates = new List<TemplateDefinition>();
  486. TypeReference explicitInterface = null;
  487. .)
  488. =
  489. /*--- constant declaration: */ (. m.Check(Modifiers.Constants); .)
  490. "const" (.Location startPos = t.Location; .)
  491. Type<out type> ident (. FieldDeclaration fd = new FieldDeclaration(new List<AttributeSection>(), type, m.Modifier | Modifiers.Const);
  492. fd.StartLocation = m.GetDeclarationLocation(startPos);
  493. VariableDeclaration f = new VariableDeclaration(t.val);
  494. fd.Fields.Add(f);
  495. .)
  496. "=" Expr<out expr> (. f.Initializer = expr; .)
  497. { "," ident (. f = new VariableDeclaration(t.val);
  498. fd.Fields.Add(f);
  499. .)
  500. "=" Expr<out expr> (. f.Initializer = expr; .)
  501. } ";" (. fd.EndLocation = t.EndLocation; compilationUnit.AddChild(fd); .)
  502.  
  503.  
  504. | /*--- void method (procedure) declaration: */
  505. IF (NotVoidPointer()) (. m.Check(Modifiers.PropertysEventsMethods); .)
  506. "void" (. Location startPos = t.Location; .)
  507. ( IF (IsExplicitInterfaceImplementation())
  508. TypeName<out explicitInterface>
  509. (.if (la.kind != Tokens.Dot || Peek(1).kind != Tokens.This) {
  510. qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface);
  511. } .)
  512. | Identifier (. qualident = t.val; .)
  513. )
  514. "("
  515. [ FormalParameterList<p> ] ")"
  516. (. MethodDeclaration methodDeclaration = new MethodDeclaration(qualident,
  517. m.Modifier,
  518. new TypeReference("void"),
  519. p,
  520. new List<AttributeSection>());
  521. methodDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
  522. methodDeclaration.EndLocation = t.EndLocation;
  523. methodDeclaration.Templates = templates;
  524. if (explicitInterface != null)
  525. methodDeclaration.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident));
  526. compilationUnit.AddChild(methodDeclaration);
  527. compilationUnit.BlockStart(methodDeclaration);
  528. .)
  529. [ Throws<methodDeclaration.Throws> ]
  530.  
  531. ( Block<out stmt> | ";" ) (. compilationUnit.BlockEnd();
  532. methodDeclaration.Body = (BlockStatement)stmt;
  533. .) [";"]
  534.  
  535. | /*--- constructor or static contructor declaration: */
  536. IF (IdentAndLPar()) (. m.Check(Modifiers.Constructors | Modifiers.StaticConstructors); .)
  537. Identifier (. string name = t.val; Location startPos = t.Location; .) "(" [ (. m.Check(Modifiers.Constructors); .)
  538. FormalParameterList<p>
  539. ]
  540. ")" (. m.Check(Modifiers.Constructors); .)
  541. (.
  542. ConstructorDeclaration cd = new ConstructorDeclaration(name, m.Modifier, p, null, new List<AttributeSection>());
  543. cd.StartLocation = startPos;
  544. cd.EndLocation = t.EndLocation;
  545. .)
  546. [ Throws<cd.Throws> ]
  547. ( "{" ConstructorBlock<out stmt,cd> | ";" ) "}"
  548. (.
  549. cd.Body = (BlockStatement)stmt; compilationUnit.AddChild(cd);
  550. .)
  551. [";"]
  552. |
  553. "{" (. ConstructorDeclaration cd = new ConstructorDeclaration("InitializerBlock", Modifiers.Public, null, null, null); .)
  554. ( ConstructorBlock<out stmt,cd> | ";" ) (. cd.Body = (BlockStatement)stmt; compilationUnit.AddChild(cd); .)
  555. "}"
  556. | /*--- inner type declaration: */
  557. TypeDecl<m>
  558.  
  559. | Type<out type> (. Location startPos = t.Location; .)
  560. (
  561. /*--- field declaration: */
  562. IF (IsVarDecl())
  563. (. m.Check(Modifiers.Fields);
  564. FieldDeclaration fd = new FieldDeclaration(new List<AttributeSection>(), type, m.Modifier);
  565. fd.StartLocation = m.GetDeclarationLocation(startPos);
  566. .)
  567. ( IF (m.Contains(Modifiers.Fixed))
  568. VariableDeclarator<variableDeclarators,type>
  569. "["
  570. Expr<out expr> (. if (variableDeclarators.Count > 0)
  571. variableDeclarators[variableDeclarators.Count-1].FixedArrayInitialization = expr; .)
  572. "]"
  573. { ","
  574. VariableDeclarator<variableDeclarators,type>
  575. "["
  576. Expr<out expr> (. if (variableDeclarators.Count > 0)
  577. variableDeclarators[variableDeclarators.Count-1].FixedArrayInitialization = expr; .)
  578. "]"
  579. }
  580. | /* non-fixed field */
  581. VariableDeclarator<variableDeclarators,type>
  582. { "," VariableDeclarator<variableDeclarators,type> }
  583. )
  584. ";" (. fd.EndLocation = t.EndLocation; fd.Fields = variableDeclarators; compilationUnit.AddChild(fd); .)
  585. [";"]
  586. | IF (IsIdentifierToken(la))
  587. ( IF (IsExplicitInterfaceImplementation())
  588. TypeName<out explicitInterface>
  589. (.if (la.kind != Tokens.Dot || Peek(1).kind != Tokens.This) {
  590. qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface);
  591. } .)
  592. | Identifier (. qualident = t.val; .)
  593. )
  594. (. Location qualIdentEndLocation = t.EndLocation; .)
  595.  
  596. (
  597. /*--- "not void" method (function) declaration: */
  598. ( (. m.Check(Modifiers.PropertysEventsMethods); .)
  599. "(" [ FormalParameterList<p> ] ")" (.
  600. MethodDeclaration methodDeclaration = new MethodDeclaration(qualident,
  601. m.Modifier,
  602. type,
  603. p,
  604. new List<AttributeSection>());
  605. if (explicitInterface != null)
  606. methodDeclaration.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident));
  607. methodDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
  608. methodDeclaration.EndLocation = t.EndLocation;
  609. methodDeclaration.Templates = templates;
  610. compilationUnit.AddChild(methodDeclaration);
  611. .)
  612. [ Throws<methodDeclaration.Throws> ]
  613. ( Block<out stmt> | ";" ) (. methodDeclaration.Body = (BlockStatement)stmt; .)
  614. [";"]
  615. )
  616. )
  617. )
  618. .
  619.  
  620. Throws<List<TypeReference> types >
  621. (. TypeReference throwsTypeRef; .)
  622. =
  623. "throws" TypeName<out throwsTypeRef> (. types.Add(throwsTypeRef); .)
  624. { "," TypeName<out throwsTypeRef> (. types.Add(throwsTypeRef); .) }
  625. .
  626.  
  627. ClassMemberDecl<ModifierList m>
  628. (. Statement stmt = null; .)
  629. =
  630. IF (StaticConstructor())
  631. "static" (. ConstructorDeclaration cd = new ConstructorDeclaration("static", Modifiers.Static, null, null, null); .)
  632. ( Block<out stmt> | ";" ) (. cd.Body = (BlockStatement)stmt; compilationUnit.AddChild(cd); .)
  633. | MemberModifiers<m>
  634. StructMemberDecl<m>
  635. | /*--- destructor declaration: */ (. m.Check(Modifiers.Destructors); Location startPos = t.Location; .)
  636. "~" Identifier (. DestructorDeclaration d = new DestructorDeclaration(t.val, m.Modifier, null);
  637. d.Modifier = m.Modifier;
  638. d.StartLocation = m.GetDeclarationLocation(startPos);
  639. .)
  640. "(" ")" (. d.EndLocation = t.EndLocation; .) ( Block<out stmt> | ";" ) (.
  641. d.Body = (BlockStatement)stmt;
  642. compilationUnit.AddChild(d);
  643. .)
  644. .
  645.  
  646. VariableDeclarator<List<VariableDeclaration> fieldDeclaration,TypeReference type>
  647. (. Expression expr = null; .)
  648. =
  649. Identifier (. VariableDeclaration f = new VariableDeclaration(t.val); .)
  650. ArrayRank<type>
  651. [ "=" VariableInitializer<out expr> (. f.Initializer = expr; .) ] (. fieldDeclaration.Add(f); .)
  652. .
  653.  
  654. Block<out Statement stmt> /* not BlockStatement because of EmbeddedStatement */
  655. =
  656. "{" (. BlockStatement blockStmt = new BlockStatement();
  657. blockStmt.StartLocation = t.Location;
  658. compilationUnit.BlockStart(blockStmt);
  659. if (!ParseMethodBodies) lexer.SkipCurrentBlock(0);
  660. .)
  661. { AndromedaStatement }
  662. "}" (.
  663. stmt = blockStmt;
  664. blockStmt.EndLocation = t.EndLocation;
  665. compilationUnit.BlockEnd();
  666. .)
  667. [";"]
  668. .
  669.  
  670. ConstructorBlock<out Statement stmt,ConstructorDeclaration cd>
  671. =
  672. (. BlockStatement blockStmt = new BlockStatement();
  673. blockStmt.StartLocation = t.EndLocation;
  674. compilationUnit.BlockStart(blockStmt);
  675. if (!ParseMethodBodies) lexer.SkipCurrentBlock(0);
  676. .)
  677. [IF (ConstructorInitializer()) ConstructorInitializer<cd>]
  678. { AndromedaStatement }
  679. (.
  680. stmt = blockStmt;
  681. blockStmt.EndLocation = t.EndLocation;
  682. compilationUnit.BlockEnd();
  683. .)
  684. .
  685.  
  686. ConstructorInitializer<ConstructorDeclaration cd>
  687. (. Expression expr; cd.ConstructorInitializer = new ConstructorInitializer(); ConstructorInitializer ci = cd.ConstructorInitializer; .)
  688. =
  689. ("super" (. ci.ConstructorInitializerType = ConstructorInitializerType.Base; .)
  690. | "this" (. ci.ConstructorInitializerType = ConstructorInitializerType.This; .) )
  691. "("
  692. [ Argument<out expr> (. if (expr != null) { ci.Arguments.Add(expr); } .) { "," Argument<out expr> (. if (expr != null) { ci.Arguments.Add(expr); } .) } ]
  693. ")" ";"
  694. .
  695.  
  696. VariableInitializer<out Expression initializerExpression>
  697. (. initializerExpression = null; .)
  698. =
  699. Expr<out initializerExpression>
  700. | CollectionInitializer<out initializerExpression>
  701. | IF (la.kind == Tokens.Void) ( PrimaryExpr<out initializerExpression> )
  702. .
  703.  
  704. Argument<out Expression argumentexpr>
  705. (.
  706. Expression expr = null;
  707. FieldDirection fd = FieldDirection.None;
  708. .)
  709. =
  710. Expr<out expr>
  711. (. argumentexpr = fd != FieldDirection.None ? argumentexpr = new DirectionExpression(fd, expr) : expr; .)
  712. .
  713.  
  714. AssignmentOperator<out AssignmentOperatorType op>
  715. (. op = AssignmentOperatorType.None; .)
  716. =
  717. "=" (. op = AssignmentOperatorType.Assign; .)
  718. | "+=" (. op = AssignmentOperatorType.Add; .)
  719. | "-=" (. op = AssignmentOperatorType.Subtract; .)
  720. | "*=" (. op = AssignmentOperatorType.Multiply; .)
  721. | "/=" (. op = AssignmentOperatorType.Divide; .)
  722. | "%=" (. op = AssignmentOperatorType.Modulus; .)
  723. | "&=" (. op = AssignmentOperatorType.BitwiseAnd; .)
  724. | "|=" (. op = AssignmentOperatorType.BitwiseOr; .)
  725. | "^=" (. op = AssignmentOperatorType.ExclusiveOr; .)
  726. | "<<=" (. op = AssignmentOperatorType.ShiftLeft; .)
  727. | IF (la.kind == Tokens.GreaterThan && Peek(1).kind == Tokens.GreaterEqual)
  728. ">" ">=" (. op = AssignmentOperatorType.ShiftRight; .)
  729. .
  730.  
  731. CollectionInitializer<out Expression outExpr>
  732. (.
  733. Expression expr = null;
  734. CollectionInitializerExpression initializer = new CollectionInitializerExpression();
  735. .)
  736. =
  737. "{"
  738. [ VariableInitializer<out expr>
  739. (. if (expr != null) { initializer.CreateExpressions.Add(expr); } .)
  740. { IF (NotFinalComma())
  741. "," VariableInitializer<out expr>
  742. (. if (expr != null) { initializer.CreateExpressions.Add(expr); } .)
  743. }
  744. [ "," ]
  745. ]
  746. "}" (. outExpr = initializer; .)
  747. .
  748.  
  749. LocalVariableDecl<out Statement stmt>
  750. (.
  751. TypeReference type;
  752. VariableDeclaration var = null;
  753. LocalVariableDeclaration localVariableDeclaration;
  754. bool final = false;
  755. .)
  756. =
  757. ["final" (. final = true; .) ]
  758. Type<out type> (. localVariableDeclaration = new LocalVariableDeclaration(type); if (final) { localVariableDeclaration.Modifier = localVariableDeclaration.Modifier | Modifiers.Final; } localVariableDeclaration.StartLocation = t.Location; .)
  759. LocalVariableDeclarator<out var,type> (. localVariableDeclaration.Variables.Add(var); .)
  760. { "," LocalVariableDeclarator<out var,type> (. localVariableDeclaration.Variables.Add(var); .) }
  761. (. stmt = localVariableDeclaration; .)
  762. .
  763.  
  764. LocalVariableDeclarator<out VariableDeclaration var,TypeReference type>
  765. (. Expression expr = null; .)
  766. =
  767. Identifier (. var = new VariableDeclaration(t.val); .)
  768. ArrayRank<type>
  769. [ "=" VariableInitializer<out expr> (. var.Initializer = expr; .) ]
  770. .
  771. /*
  772. LocalVariableInitializer<out Expression expr>
  773. (. expr = null; .)
  774. =
  775. Expr<out expr>
  776. | CollectionInitializer<out expr>
  777. .
  778. */
  779. Statement
  780. (.
  781. TypeReference type;
  782. Expression expr;
  783. Statement stmt = null;
  784. Location startPos = la.Location;
  785. List<TypeReference> names;
  786. .)
  787. =
  788. (
  789. /*--- labeled statement: */
  790. IF (IsLabel()) Identifier (. compilationUnit.AddChild(new LabelStatement(t.val)); .)
  791. ":" AndromedaStatement
  792. /*--- local constant declaration: */
  793. | "const" Type<out type> (. LocalVariableDeclaration var = new LocalVariableDeclaration(type, Modifiers.Const); string ident = null; var.StartLocation = t.Location; .)
  794. ident (. ident = t.val; .)
  795. "=" Expr<out expr> (. var.Variables.Add(new VariableDeclaration(ident, expr)); .)
  796. { "," ident (. ident = t.val; .) "=" Expr<out expr> (. var.Variables.Add(new VariableDeclaration(ident, expr)); .) }
  797. ";" (. compilationUnit.AddChild(var); .)
  798. | "class" (. TypeDeclaration newType = new TypeDeclaration(Modifiers.None, new List<AttributeSection>());
  799. stmt = new ClassDeclarationStatement(newType);
  800. newType.Type = Types.Class;
  801. compilationUnit.BlockStart(newType);
  802. .)
  803. ident (. newType.Name = t.val; .)
  804. [ ClassBase<out names> (. newType.BaseTypes = names; .) ]
  805. ClassBody [ ";" ] (. newType.EndLocation = t.Location; compilationUnit.BlockEnd(); compilationUnit.AddChild(stmt); .)
  806. /*--- local variable declaration: */
  807. | EmbeddedStatement<out stmt> (. compilationUnit.AddChild(stmt); .)
  808. /* LL(1) confict: LocalVariableDecl *
  809. * <-> StatementExpr *
  810. * ident {"." ident} { "[" Expr ... */
  811. )
  812. (.
  813. if (stmt != null) {
  814. stmt.StartLocation = startPos;
  815. stmt.EndLocation = t.EndLocation;
  816. }
  817. .)
  818. .
  819.  
  820. EmbeddedStatement<out Statement statement>
  821. (.
  822. Expression expr = null;
  823. Statement embeddedStatement = null;
  824. statement = null;
  825. .)
  826. =
  827. Block<out statement>
  828. /*--- empty statement: */
  829. | ";" (. statement = new EmptyStatement(); .)
  830. /*--- selection statements (if, switch): */
  831. | "if" (. Statement elseStatement = null; .)
  832. "(" Expr<out expr> ")"
  833. EmbeddedStatement<out embeddedStatement>
  834. [ "else" EmbeddedStatement<out elseStatement> ]
  835. (. statement = elseStatement != null ? new IfElseStatement(expr, embeddedStatement, elseStatement) : new IfElseStatement(expr, embeddedStatement); .)
  836. (. if (elseStatement is IfElseStatement && (elseStatement as IfElseStatement).TrueStatement.Count == 1) {
  837. /* else if-section (otherwise we would have a BlockStatment) */
  838. (statement as IfElseStatement).ElseIfSections.Add(
  839. new ElseIfSection((elseStatement as IfElseStatement).Condition,
  840. (elseStatement as IfElseStatement).TrueStatement[0]));
  841. (statement as IfElseStatement).ElseIfSections.AddRange((elseStatement as IfElseStatement).ElseIfSections);
  842. (statement as IfElseStatement).FalseStatement = (elseStatement as IfElseStatement).FalseStatement;
  843. } .)
  844. | "switch" (. List<SwitchSection> switchSections = new List<SwitchSection>(); .)
  845. "(" Expr<out expr> ")"
  846. "{" SwitchSections<switchSections>
  847. "}" (. statement = new SwitchStatement(expr, switchSections); .)
  848. /*--- iteration statements (while, do, for, foreach): */
  849. | "while" "(" Expr<out expr> ")"
  850.  
  851. EmbeddedStatement<out embeddedStatement> (. statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.Start);.)
  852. | "do" EmbeddedStatement<out embeddedStatement> "while"
  853. "(" Expr<out expr> ")" ";" (. statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.End); .)
  854. | "for" (. List<Statement> initializer = null; List<Statement> iterator = null; .)
  855. "(" ["final"] [ ForInitializer<out initializer> ] ";"
  856. [ Expr<out expr> ] ";"
  857. [ ForIterator<out iterator> ] ")"
  858. EmbeddedStatement<out embeddedStatement> (. statement = new ForStatement(initializer, expr, iterator, embeddedStatement); .)
  859. /*--- jump statements (break, contine, goto, return, throw): */
  860. | "break" (. statement = new BreakStatement(); .)
  861. [ident (. ((BreakStatement)statement).Label = t.val; .) ]
  862. ";"
  863. | "continue" (. statement = new ContinueStatement(); .)
  864. [ident (. ((ContinueStatement)statement).Label = t.val; .) ]
  865. ";"
  866. | "return" [ Expr<out expr> ] ";" (. statement = new ReturnStatement(expr); .)
  867. | "throw" [ Expr<out expr> ] ";" (. statement = new ThrowStatement(expr); .)
  868.  
  869. /*--- expression statement: */
  870. | StatementExpr<out statement> ";"
  871. /*--- try statement: */
  872. | TryStatement<out statement>
  873. EmbeddedStatement<out embeddedStatement> (. statement = new LockStatement(expr, embeddedStatement); .)
  874. .
  875.  
  876. ForInitializer<out List<Statement> initializer>
  877. (.
  878. Statement stmt;
  879. initializer = new List<Statement>();
  880. .)
  881. =
  882. IF (IsLocalVarDecl()) LocalVariableDecl<out stmt> (. initializer.Add(stmt);.)
  883. | StatementExpr<out stmt> (.initializer.Add(stmt);.) { "," StatementExpr<out stmt> (. initializer.Add(stmt);.) }
  884. .
  885.  
  886. ForIterator<out List<Statement> iterator>
  887. (.
  888. Statement stmt;
  889. iterator = new List<Statement>();
  890. .)
  891. =
  892. StatementExpr<out stmt> (. iterator.Add(stmt);.) { "," StatementExpr<out stmt> (. iterator.Add(stmt); .) }
  893. .
  894.  
  895. SwitchSections<List<SwitchSection> switchSections>
  896. (.
  897. SwitchSection switchSection = new SwitchSection();
  898. CaseLabel label;
  899. .)
  900. =
  901. SwitchLabel<out label> (. if (label != null) { switchSection.SwitchLabels.Add(label); } .)
  902. (. compilationUnit.BlockStart(switchSection); .)
  903. {
  904. ( SwitchLabel<out label>
  905. (. if (label != null) {
  906. if (switchSection.Children.Count > 0) {
  907. // open new section
  908. compilationUnit.BlockEnd(); switchSections.Add(switchSection);
  909. switchSection = new SwitchSection();
  910. compilationUnit.BlockStart(switchSection);
  911. }
  912. switchSection.SwitchLabels.Add(label);
  913. }
  914. .)
  915. | AndromedaStatement)
  916. }
  917. (. compilationUnit.BlockEnd(); switchSections.Add(switchSection); .)
  918. .
  919.  
  920. SwitchLabel<out CaseLabel label>
  921. (. Expression expr = null; label = null; .)
  922. =
  923. "case" Expr<out expr> ":" (. label = new CaseLabel(expr); .)
  924. | "default" ":" (. label = new CaseLabel(); .)
  925. .
  926.  
  927. TryStatement<out Statement tryStatement>
  928. (.
  929. Statement blockStmt = null, finallyStmt = null;
  930. List<CatchClause> catchClauses = null;
  931. .)
  932. =
  933. "try" Block<out blockStmt>
  934. (
  935. CatchClauses<out catchClauses> [ "finally" Block<out finallyStmt> ]
  936. | "finally" Block<out finallyStmt>
  937. )
  938. (.
  939. tryStatement = new TryCatchStatement(blockStmt, catchClauses, finallyStmt);
  940.  
  941. .)
  942. .
  943.  
  944. CatchClauses<out List<CatchClause> catchClauses>
  945. (.
  946. catchClauses = new List<CatchClause>();
  947. .)
  948. =
  949. "catch" (. string identifier;
  950. Statement stmt;
  951. TypeReference typeRef;
  952. .)
  953. /*--- general catch clause (as only catch clause) */
  954. (
  955. Block<out stmt> (. catchClauses.Add(new CatchClause(stmt)); .)
  956. /*--- specific catch clause */
  957. | "(" ["final"] ClassType<out typeRef> (. identifier = null; .)
  958. [ ident (. identifier = t.val; .) ]
  959. ")" Block<out stmt>
  960. (. catchClauses.Add(new CatchClause(typeRef, identifier, stmt)); .)
  961. { IF (IsTypedCatch()) "catch" "(" ["final"] ClassType<out typeRef> (. identifier = null; .)
  962. [ ident (. identifier = t.val; .) ]
  963. ")" Block<out stmt>
  964. (. catchClauses.Add(new CatchClause(typeRef, identifier, stmt)); .) }
  965. /*--- general catch clause (after specific catch clauses, optional) */
  966. [ "catch" Block<out stmt> (. catchClauses.Add(new CatchClause(stmt)); .) ]
  967. )
  968. .
  969.  
  970. StatementExpr<out Statement stmt>
  971. (. Expression expr; .)
  972. =
  973. Expr<out expr>
  974. /* The grammar allows only assignments or method invocations here, */
  975. /* but we don't enforce that here */
  976. (. stmt = new ExpressionStatement(expr); .)
  977. .
  978.  
  979. Expr<out Expression expr>
  980. (. expr = null; Expression expr1 = null, expr2 = null; AssignmentOperatorType op; .)
  981. =
  982. IF(la.kind == Tokens.Void) ( PrimaryExpr<out expr> )
  983. | UnaryExpr<out expr>
  984. /*--- conditional expression: */
  985. (
  986. ( AssignmentOperator<out op> Expr<out expr1> (. expr = new AssignmentExpression(expr, op, expr1); .) )
  987. | IF (la.kind == Tokens.GreaterThan && Peek(1).kind == Tokens.GreaterEqual)
  988. ( AssignmentOperator<out op> Expr<out expr1> (. expr = new AssignmentExpression(expr, op, expr1); .) )
  989. | (
  990. ConditionalOrExpr<ref expr>
  991. [ "??" Expr<out expr1> (. expr = new BinaryOperatorExpression(expr, BinaryOperatorType.NullCoalescing, expr1); .) ]
  992. [ "?" Expr<out expr1> ":" Expr<out expr2> (. expr = new ConditionalExpression(expr, expr1, expr2); .) ]
  993. )
  994. )
  995. .
  996.  
  997.  
  998. UnaryExpr<out Expression uExpr>
  999. (.
  1000. TypeReference type = null;
  1001. Expression expr;
  1002. ArrayList expressions = new ArrayList();
  1003. uExpr = null;
  1004. .)
  1005. =
  1006. {
  1007. /* IF (Tokens.UnaryOp[la.kind] || IsTypeCast()) */
  1008. (
  1009. "+" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Plus)); .)
  1010. | "-" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Minus)); .)
  1011. | "!" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Not)); .)
  1012. | "~" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.BitNot)); .)
  1013. | "*" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Star)); .)
  1014. | "++" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Increment)); .)
  1015. | "--" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Decrement)); .)
  1016. | "&" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.BitWiseAnd)); .)
  1017.  
  1018. /*--- cast expression: */
  1019. /* Problem: "(" Type ")" from here and *
  1020. * "(" Expr ")" from PrimaryExpr *
  1021. * Solution: (in IsTypeCast()) */
  1022. | IF (IsTypeCast()) "(" Type<out type> ")" (. expressions.Add(new CastExpression(type)); .)
  1023. )
  1024. }
  1025.  
  1026. PrimaryExpr<out expr> (. for (int i = 0; i < expressions.Count; ++i) {
  1027. Expression nextExpression = i + 1 < expressions.Count ? (Expression)expressions[i + 1] : expr;
  1028. if (expressions[i] is CastExpression) {
  1029. ((CastExpression)expressions[i]).Expression = nextExpression;
  1030. } else {
  1031. ((UnaryOperatorExpression)expressions[i]).Expression = nextExpression;
  1032. }
  1033. }
  1034. if (expressions.Count > 0) {
  1035. uExpr = (Expression)expressions[0];
  1036. } else {
  1037. uExpr = expr;
  1038. }
  1039. .)
  1040. .
  1041.  
  1042.  
  1043. PrimaryExpr<out Expression pexpr>
  1044. (.
  1045. TypeReference type = null;
  1046. Expression expr;
  1047. pexpr = null;
  1048. .)
  1049. =
  1050. (
  1051. "true" (.pexpr = new PrimitiveExpression(true, "true"); .)
  1052. | "false" (.pexpr = new PrimitiveExpression(false, "false"); .)
  1053. | "null" (.pexpr = new PrimitiveExpression(null, "null"); .) /* from literal token */
  1054. | Literal (.pexpr = new PrimitiveExpression(t.literalValue, t.val); .)
  1055. | "void" (. type = new TypeReference("void"); pexpr = new TypeReferenceExpression(type); .) "." "class" (. type.Kind = TypeReferenceKind.DotClass; .)
  1056. | IF (IsTypeReferenceWithDotClassOrThis())
  1057. (
  1058. Type<out type> (. pexpr = new TypeReferenceExpression(type); .) "."
  1059. (
  1060. "class" (. type.Kind = TypeReferenceKind.DotClass; .)
  1061. | "this" (. type.Kind = TypeReferenceKind.DotThis; .)
  1062. )
  1063. )
  1064. /*--- simple name: */
  1065. | ident (. pexpr = new IdentifierExpression(t.val); .)
  1066. /*--- parenthesized expression: */
  1067. | "(" Expr<out expr> ")" (. pexpr = new ParenthesizedExpression(expr); .)
  1068. | /*--- predefined type member access: */
  1069. (. string val = null; .)
  1070. (
  1071. "abilcmd" (. val = "abilcmd"; .)
  1072. | "actor" (. val = "actor"; .)
  1073. | "actorscope" (. val = "actorscope"; .)
  1074. | "aifilter" (. val = "aifilter"; .)
  1075. | "bank" (. val = "bank"; .)
  1076. | "bool" (. val = "bool"; .)
  1077. | "byte" (. val = "byte"; .)
  1078. | "camerainfo" (. val = "camerainfo"; .)
  1079. | "color" (. val = "color"; .)
  1080. | "doodad" (. val = "doodad"; .)
  1081. | "fixed" (. val = "fixed"; .)
  1082. | "int" (. val = "int"; .)
  1083. | "marker" (. val = "marker"; .)
  1084. | "order" (. val = "order"; .)
  1085. | "playergroup" (. val = "playergroup"; .)
  1086. | "point" (. val = "point"; .)
  1087. | "revealer" (. val = "revealer"; .)
  1088. | "sound" (. val = "sound"; .)
  1089. | "soundlink" (. val = "soundlink"; .)
  1090. | "string" (. val = "string"; .)
  1091. | "text" (. val = "text"; .)
  1092. | "timer" (. val = "timer"; .)
  1093. | "transmissionsource" (. val = "transmissionsource"; .)
  1094. | "trigger" (. val = "trigger"; .)
  1095. | "unit" (. val = "unit"; .)
  1096. | "unitfilter" (. val = "unitfilter"; .)
  1097. | "unitgroup" (. val = "unitgroup"; .)
  1098. | "unitref" (. val = "unitref"; .)
  1099. | "void" (. val = "void"; .)
  1100. | "wave" (. val = "wave"; .)
  1101. | "waveinfo" (. val = "waveinfo"; .)
  1102. | "wavetarget" (. val = "wavetarget"; .)
  1103. ) (. t.val = ""; .) "." ident (. pexpr = new FieldReferenceExpression(new TypeReferenceExpression(val), t.val); .)
  1104. /*--- this access: */
  1105. | "this" (. pexpr = new ThisReferenceExpression(); .)
  1106. /*--- base access: */
  1107. | "super" (. Expression retExpr = new BaseReferenceExpression(); .)
  1108. (
  1109. "." Identifier (. retExpr = new FieldReferenceExpression(retExpr, t.val); .)
  1110. | "[" Expr<out expr> (. List<Expression> indices = new List<Expression>(); if (expr != null) { indices.Add(expr); } .)
  1111. { "," Expr<out expr> (. if (expr != null) { indices.Add(expr); } .) }
  1112. "]" (. retExpr = new IndexerExpression(retExpr, indices); .)
  1113. ) (. pexpr = retExpr; .)
  1114. | "new" NonArrayType<out type>
  1115. (. List<Expression> parameters = new List<Expression>(); .)
  1116. /*--- delegate / object creation expression: */
  1117. /* Note: a delegate creation expression allow only a single Expr */
  1118. /* not an argument list, but this is not distinguished here */
  1119. (
  1120. "(" (. ObjectCreateExpression oce = new ObjectCreateExpression(type, parameters); .)
  1121. [ Argument<out expr> (. if (expr != null) { parameters.Add(expr); } .)
  1122. { "," Argument<out expr> (. if (expr != null) { parameters.Add(expr); } .) }
  1123. ]
  1124. ")" (. pexpr = oce; .)
  1125. [
  1126.  
  1127. (.
  1128. ModifierList m = new ModifierList();
  1129. TypeDeclaration newType = new TypeDeclaration(Modifiers.Public, null);
  1130.  
  1131. compilationUnit.BlockStart(newType);
  1132. newType.Type = Types.Class;
  1133. newType.Name = t.val;
  1134. .)
  1135. ClassBody
  1136. (.
  1137. compilationUnit.BlockEnd();
  1138. oce.AnonymousClass = newType;
  1139. .)
  1140. ]
  1141. | "[" /*--- array creation expression: */
  1142. (. ArrayCreateExpression ace = new ArrayCreateExpression(type); pexpr = ace; .)
  1143. (. int dims = 0; List<int> ranks = new List<int>(); .)
  1144. (
  1145. { "," (. dims += 1; .) }
  1146. "]" (. ranks.Add(dims); dims = 0; .)
  1147. { "[" { "," (. ++dims; .) } "]" (. ranks.Add(dims); dims = 0; .) }
  1148. (. ace.CreateType.RankSpecifier = ranks.ToArray(); .)
  1149. CollectionInitializer<out expr> (. ace.ArrayInitializer = (CollectionInitializerExpression)expr; .)
  1150. | Expr<out expr> (. if (expr != null) parameters.Add(expr); .)
  1151. "]" (. ace.Arguments = parameters; .)
  1152. { "[" (. dims++; expr = null; .)
  1153. [ [Expr<out expr>] (. if (expr != null) parameters.Add(expr); else parameters.RemoveRange(1, parameters.Count - 1);.) ]
  1154. "]" (. ranks.Add(0); dims = 0; .)
  1155. } (. ranks.Add(dims); .)
  1156. (. ace.CreateType.RankSpecifier = ranks.ToArray(); .)
  1157. [ CollectionInitializer<out expr> (. ace.ArrayInitializer = (CollectionInitializerExpression)expr; .) ]
  1158. )
  1159. )
  1160. | "typeof" "("
  1161. (
  1162. IF (NotVoidPointer()) "void" (. type = new TypeReference("void"); .)
  1163. | TypeWithRestriction<out type>
  1164. ) ")" (. pexpr = new TypeOfExpression(type); .)
  1165.  
  1166. | "default" "(" Type<out type> ")" (. pexpr = new DefaultValueExpression(type); .)
  1167. )
  1168. {
  1169. (
  1170. "++" (. pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostIncrement); .)
  1171. | "--" (. pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostDecrement); .)
  1172. )
  1173. /*--- member access */
  1174. | "." Identifier (. pexpr = new FieldReferenceExpression(pexpr, t.val);.)
  1175. /*--- invocation expression: */
  1176. | "(" (. List<Expression> parameters = new List<Expression>(); .)
  1177. [ Argument<out expr> (. if (expr != null) {parameters.Add(expr);} .)
  1178. { "," Argument<out expr> (. if (expr != null) {parameters.Add(expr);} .)
  1179. } ] ")" (. pexpr = new InvocationExpression(pexpr, parameters); .)
  1180. /*--- element access */
  1181. | (. /*if (isArrayCreation) Error("element access not allow on array creation");*/
  1182. List<Expression> indices = new List<Expression>();
  1183. .)
  1184. "[" Expr<out expr> (. if (expr != null) { indices.Add(expr); } .)
  1185. { "," Expr<out expr> (. if (expr != null) { indices.Add(expr); } .)
  1186. } "]" (. pexpr = new IndexerExpression(pexpr, indices); .)
  1187. }
  1188. .
  1189.  
  1190. ConditionalOrExpr<ref Expression outExpr>
  1191. (. Expression expr; .)
  1192. =
  1193. ConditionalAndExpr<ref outExpr> { "||" UnaryExpr<out expr> ConditionalAndExpr<ref expr> (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.LogicalOr, expr); .) }
  1194. .
  1195.  
  1196. ConditionalAndExpr<ref Expression outExpr>
  1197. (. Expression expr; .)
  1198. =
  1199. InclusiveOrExpr<ref outExpr> { "&&" UnaryExpr<out expr> InclusiveOrExpr<ref expr> (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.LogicalAnd, expr); .) }
  1200. .
  1201.  
  1202. InclusiveOrExpr<ref Expression outExpr>
  1203. (. Expression expr; .)
  1204. =
  1205. ExclusiveOrExpr<ref outExpr> { "|" UnaryExpr<out expr> ExclusiveOrExpr<ref expr> (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.BitwiseOr, expr); .) }
  1206. .
  1207.  
  1208. ExclusiveOrExpr<ref Expression outExpr>
  1209. (. Expression expr; .)
  1210. =
  1211. AndExpr<ref outExpr> { "^" UnaryExpr<out expr> AndExpr<ref expr> (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.ExclusiveOr, expr); .) }
  1212. .
  1213.  
  1214. AndExpr<ref Expression outExpr>
  1215. (. Expression expr; .)
  1216. =
  1217. EqualityExpr<ref outExpr> { "&" UnaryExpr<out expr> EqualityExpr<ref expr> (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.BitwiseAnd, expr); .) }
  1218. .
  1219.  
  1220. EqualityExpr<ref Expression outExpr>
  1221. (.
  1222. Expression expr;
  1223. BinaryOperatorType op = BinaryOperatorType.None;
  1224. .)
  1225. =
  1226. RelationalExpr<ref outExpr>
  1227. {
  1228. (
  1229. "!=" (. op = BinaryOperatorType.InEquality; .)
  1230. | "==" (. op = BinaryOperatorType.Equality; .)
  1231. )
  1232. UnaryExpr<out expr> RelationalExpr<ref expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
  1233. }
  1234. .
  1235.  
  1236. RelationalExpr<ref Expression outExpr>
  1237. (.
  1238. TypeReference type;
  1239. Expression expr;
  1240. BinaryOperatorType op = BinaryOperatorType.None;
  1241. .)
  1242. =
  1243. ShiftExpr<ref outExpr>
  1244. {
  1245. ( "<" (. op = BinaryOperatorType.LessThan; .)
  1246. | ">" (. op = BinaryOperatorType.GreaterThan; .)
  1247. | "<=" (. op = BinaryOperatorType.LessThanOrEqual; .)
  1248. | ">=" (. op = BinaryOperatorType.GreaterThanOrEqual; .)
  1249. )
  1250. UnaryExpr<out expr>
  1251. ShiftExpr<ref expr>
  1252. (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
  1253. |
  1254. (
  1255. TypeWithRestriction<out type>
  1256. (. outExpr = new TypeOfIsExpression(outExpr, type); .)
  1257. )
  1258. }
  1259. .
  1260.  
  1261. ShiftExpr<ref Expression outExpr>
  1262. (.
  1263. Expression expr;
  1264. BinaryOperatorType op = BinaryOperatorType.None;
  1265. .)
  1266. =
  1267. AdditiveExpr<ref outExpr>
  1268. {
  1269. ( "<<" (. op = BinaryOperatorType.ShiftLeft; .)
  1270. | IF (IsShiftRight()) (
  1271. ">" ">" (. op = BinaryOperatorType.ShiftRight; .)
  1272. [">" (. op = BinaryOperatorType.UnsignedShiftRight; .)
  1273. | ">=" (. op = BinaryOperatorType.UnsignedShiftRightAssign; .)]
  1274. )
  1275. )
  1276. UnaryExpr<out expr> AdditiveExpr<ref expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
  1277. }
  1278. .
  1279.  
  1280. AdditiveExpr<ref Expression outExpr>
  1281. (.
  1282. Expression expr;
  1283. BinaryOperatorType op = BinaryOperatorType.None;
  1284. .)
  1285. =
  1286. MultiplicativeExpr<ref outExpr>
  1287. {
  1288. (
  1289. "+" (. op = BinaryOperatorType.Add; .)
  1290. | "-" (. op = BinaryOperatorType.Subtract; .)
  1291. )
  1292. UnaryExpr<out expr> MultiplicativeExpr<ref expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
  1293. }
  1294. .
  1295.  
  1296. MultiplicativeExpr<ref Expression outExpr>
  1297. (.
  1298. Expression expr;
  1299. BinaryOperatorType op = BinaryOperatorType.None;
  1300. .)
  1301. =
  1302. {
  1303. (
  1304. "*" (. op = BinaryOperatorType.Multiply; .)
  1305. | "/" (. op = BinaryOperatorType.Divide; .)
  1306. | "%" (. op = BinaryOperatorType.Modulus; .)
  1307. )
  1308. UnaryExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
  1309. }
  1310. .
  1311.  
  1312. TypeName<out TypeReference typeRef>
  1313. (.
  1314. string qualident;
  1315. .)
  1316. =
  1317. Qualident<out qualident>
  1318. (.
  1319. typeRef = new TypeReference(qualident, new List<TypeReference>());
  1320. .)
  1321. { IF (DotAndIdent())
  1322. "."
  1323. Qualident<out qualident>
  1324. }
  1325. .
  1326.  
  1327. Identifier
  1328. =
  1329. ident
  1330. .
  1331.  
  1332.  
  1333. ArrayRank<TypeReference type>
  1334. =
  1335. [
  1336. (. List<int> r = new List<int>(); int i = -1;.)
  1337. { "[" (. ++i; .) "]" } (. r.Add(i); .)
  1338. (. type.RankSpecifier = r.ToArray(); .)
  1339. ]
  1340. .
  1341.  
  1342. AndromedaStatement
  1343. (.
  1344. Statement stmt = null;
  1345. .)
  1346. =
  1347. IF (IsLocalVarDecl()) ( LocalVariableDecl<out stmt> ";" ) (. compilationUnit.AddChild(stmt); .)
  1348. | "final" ( LocalVariableDecl<out stmt> ";" ) (. compilationUnit.AddChild(stmt); .)
  1349. | Statement
  1350. .
  1351.  
  1352. END Andromeda.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement