Hex Artifact Content
Not logged in

Artifact f03af1208bc8c4340244f99c7e3f6f054dc2fcc5:


0000: ef bb bf 2f 2a 2a 0a 20 2a 20 41 75 74 68 6f 72  .../**. * Author
0010: 73 3a 20 6b 2e 69 6e 61 62 61 0a 20 2a 20 4c 69  s: k.inaba. * Li
0020: 63 65 6e 73 65 3a 20 4e 59 53 4c 20 30 2e 39 39  cense: NYSL 0.99
0030: 38 32 20 68 74 74 70 3a 2f 2f 77 77 77 2e 6b 6d  82 http://www.km
0040: 6f 6e 6f 73 2e 6e 65 74 2f 6e 79 73 6c 2f 0a 20  onos.net/nysl/. 
0050: 2a 0a 20 2a 20 53 79 6e 74 61 78 20 74 72 65 65  *. * Syntax tree
0060: 20 66 6f 72 20 50 6f 6c 65 6d 79 20 70 72 6f 67   for Polemy prog
0070: 72 61 6d 6d 69 6e 67 20 6c 61 6e 67 75 61 67 65  ramming language
0080: 2e 0a 20 2a 2f 0a 6d 6f 64 75 6c 65 20 70 6f 6c  .. */.module pol
0090: 65 6d 79 2e 61 73 74 3b 0a 69 6d 70 6f 72 74 20  emy.ast;.import 
00a0: 70 6f 6c 65 6d 79 2e 5f 63 6f 6d 6d 6f 6e 3b 0a  polemy._common;.
00b0: 69 6d 70 6f 72 74 20 70 6f 6c 65 6d 79 2e 6c 65  import polemy.le
00c0: 78 3b 0d 0a 0d 0a 61 6c 69 61 73 20 53 74 61 74  x;....alias Stat
00d0: 65 6d 65 6e 74 5b 5d 20 50 72 6f 67 72 61 6d 3b  ement[] Program;
00e0: 0a 0a 61 62 73 74 72 61 63 74 20 63 6c 61 73 73  ..abstract class
00f0: 20 53 74 61 74 65 6d 65 6e 74 0a 7b 0a 09 69 6d   Statement.{..im
0100: 6d 75 74 61 62 6c 65 20 4c 65 78 50 6f 73 69 74  mutable LexPosit
0110: 69 6f 6e 20 70 6f 73 3b 0a 09 6d 69 78 69 6e 20  ion pos;..mixin 
0120: 53 69 6d 70 6c 65 43 6f 6e 73 74 72 75 63 74 6f  SimpleConstructo
0130: 72 3b 0a 7d 0a 0a 63 6c 61 73 73 20 44 65 63 6c  r;.}..class Decl
0140: 53 74 61 74 65 6d 65 6e 74 20 3a 20 53 74 61 74  Statement : Stat
0150: 65 6d 65 6e 74 0a 7b 0a 09 73 74 72 69 6e 67 20  ement.{..string 
0160: 20 20 20 20 76 61 72 3b 0a 09 45 78 70 72 65 73      var;..Expres
0170: 73 69 6f 6e 20 65 78 70 72 3b 0a 09 6d 69 78 69  sion expr;..mixi
0180: 6e 20 53 69 6d 70 6c 65 43 6c 61 73 73 3b 0d 0a  n SimpleClass;..
0190: 7d 0a 0a 63 6c 61 73 73 20 45 78 70 72 53 74 61  }..class ExprSta
01a0: 74 65 6d 65 6e 74 20 3a 20 53 74 61 74 65 6d 65  tement : Stateme
01b0: 6e 74 0a 7b 0a 09 45 78 70 72 65 73 73 69 6f 6e  nt.{..Expression
01c0: 20 65 78 70 72 3b 0a 09 6d 69 78 69 6e 20 53 69   expr;..mixin Si
01d0: 6d 70 6c 65 43 6c 61 73 73 3b 0d 0a 7d 0a 0a 61  mpleClass;..}..a
01e0: 62 73 74 72 61 63 74 20 63 6c 61 73 73 20 45 78  bstract class Ex
01f0: 70 72 65 73 73 69 6f 6e 0a 7b 0a 09 69 6d 6d 75  pression.{..immu
0200: 74 61 62 6c 65 20 4c 65 78 50 6f 73 69 74 69 6f  table LexPositio
0210: 6e 20 70 6f 73 3b 0a 09 6d 69 78 69 6e 20 53 69  n pos;..mixin Si
0220: 6d 70 6c 65 43 6f 6e 73 74 72 75 63 74 6f 72 3b  mpleConstructor;
0230: 0a 7d 0a 0a 63 6c 61 73 73 20 53 74 72 4c 69 74  .}..class StrLit
0240: 65 72 61 6c 45 78 70 72 65 73 73 69 6f 6e 20 3a  eralExpression :
0250: 20 45 78 70 72 65 73 73 69 6f 6e 0a 7b 0a 09 73   Expression.{..s
0260: 74 72 69 6e 67 20 64 61 74 61 3b 0a 09 6d 69 78  tring data;..mix
0270: 69 6e 20 53 69 6d 70 6c 65 43 6c 61 73 73 3b 0d  in SimpleClass;.
0280: 0a 7d 0a 0a 63 6c 61 73 73 20 49 6e 74 4c 69 74  .}..class IntLit
0290: 65 72 61 6c 45 78 70 72 65 73 73 69 6f 6e 20 3a  eralExpression :
02a0: 20 45 78 70 72 65 73 73 69 6f 6e 0a 7b 0a 09 42   Expression.{..B
02b0: 69 67 49 6e 74 20 64 61 74 61 3b 0a 09 6d 69 78  igInt data;..mix
02c0: 69 6e 20 53 69 6d 70 6c 65 43 6c 61 73 73 3b 0d  in SimpleClass;.
02d0: 0a 7d 0a 0a 63 6c 61 73 73 20 56 61 72 45 78 70  .}..class VarExp
02e0: 72 65 73 73 69 6f 6e 20 3a 20 45 78 70 72 65 73  ression : Expres
02f0: 73 69 6f 6e 0a 7b 0a 09 73 74 72 69 6e 67 20 76  sion.{..string v
0300: 61 72 3b 0a 09 6d 69 78 69 6e 20 53 69 6d 70 6c  ar;..mixin Simpl
0310: 65 43 6c 61 73 73 3b 0d 0a 7d 0a 0a 63 6c 61 73  eClass;..}..clas
0320: 73 20 41 73 73 69 67 6e 45 78 70 72 65 73 73 69  s AssignExpressi
0330: 6f 6e 20 3a 20 45 78 70 72 65 73 73 69 6f 6e 0a  on : Expression.
0340: 7b 0a 09 45 78 70 72 65 73 73 69 6f 6e 20 6c 68  {..Expression lh
0350: 73 3b 0a 09 45 78 70 72 65 73 73 69 6f 6e 20 72  s;..Expression r
0360: 68 73 3b 0a 09 6d 69 78 69 6e 20 53 69 6d 70 6c  hs;..mixin Simpl
0370: 65 43 6c 61 73 73 3b 0d 0a 7d 0a 0a 63 6c 61 73  eClass;..}..clas
0380: 73 20 46 75 6e 63 61 6c 6c 45 78 70 72 65 73 73  s FuncallExpress
0390: 69 6f 6e 20 3a 20 45 78 70 72 65 73 73 69 6f 6e  ion : Expression
03a0: 0a 7b 0a 09 45 78 70 72 65 73 73 69 6f 6e 20 20  .{..Expression  
03b0: 20 66 75 6e 3b 0a 09 45 78 70 72 65 73 73 69 6f   fun;..Expressio
03c0: 6e 5b 5d 20 61 72 67 73 3b 0a 09 74 68 69 73 28  n[] args;..this(
03d0: 69 6d 6d 75 74 61 62 6c 65 20 4c 65 78 50 6f 73  immutable LexPos
03e0: 69 74 69 6f 6e 20 70 6f 73 2c 20 45 78 70 72 65  ition pos, Expre
03f0: 73 73 69 6f 6e 20 66 75 6e 2c 20 45 78 70 72 65  ssion fun, Expre
0400: 73 73 69 6f 6e 5b 5d 20 61 72 67 73 2e 2e 2e 29  ssion[] args...)
0410: 0a 09 09 7b 20 73 75 70 65 72 28 70 6f 73 29 3b  ...{ super(pos);
0420: 20 74 68 69 73 2e 66 75 6e 3d 66 75 6e 3b 20 74   this.fun=fun; t
0430: 68 69 73 2e 61 72 67 73 3d 61 72 67 73 2e 64 75  his.args=args.du
0440: 70 3b 20 7d 0a 09 6d 69 78 69 6e 20 53 69 6d 70  p; }..mixin Simp
0450: 6c 65 43 6c 61 73 73 3b 0d 0a 7d 0a 0a 63 6c 61  leClass;..}..cla
0460: 73 73 20 46 75 6e 4c 69 74 65 72 61 6c 45 78 70  ss FunLiteralExp
0470: 72 65 73 73 69 6f 6e 20 3a 20 45 78 70 72 65 73  ression : Expres
0480: 73 69 6f 6e 0a 7b 0a 09 73 74 72 69 6e 67 5b 5d  sion.{..string[]
0490: 20 70 61 72 61 6d 73 3b 0a 09 50 72 6f 67 72 61   params;..Progra
04a0: 6d 20 20 66 75 6e 62 6f 64 79 3b 0d 0a 09 6d 69  m  funbody;...mi
04b0: 78 69 6e 20 53 69 6d 70 6c 65 43 6c 61 73 73 3b  xin SimpleClass;
04c0: 0a 7d 0a 0d 0a 2f 2f 2f 20 48 61 6e 64 79 20 47  .}.../// Handy G
04d0: 65 6e 65 72 61 74 6f 72 20 66 6f 72 20 41 53 54  enerator for AST
04e0: 20 6e 6f 64 65 73 2e 20 54 6f 20 75 73 65 20 74   nodes. To use t
04f0: 68 69 73 2c 20 6d 69 78 69 6e 20 45 61 73 79 41  his, mixin EasyA
0500: 73 74 3b 0d 0a 0d 0a 2f 2a 6d 69 78 69 6e 2a 2f  st;..../*mixin*/
0510: 0d 0a 74 65 6d 70 6c 61 74 65 20 45 61 73 79 41  ..template EasyA
0520: 73 74 28 29 0d 0a 7b 0d 0a 09 74 65 6d 70 6c 61  st()..{...templa
0530: 74 65 20 67 65 6e 45 61 73 74 28 54 29 0d 0a 09  te genEast(T)...
0540: 09 7b 20 54 20 67 65 6e 45 61 73 74 28 50 2e 2e  .{ T genEast(P..
0550: 2e 29 28 50 20 70 73 29 20 7b 20 72 65 74 75 72  .)(P ps) { retur
0560: 6e 20 6e 65 77 20 54 28 4c 65 78 50 6f 73 69 74  n new T(LexPosit
0570: 69 6f 6e 2e 64 75 6d 6d 79 2c 20 70 73 29 3b 20  ion.dummy, ps); 
0580: 7d 20 7d 0d 0a 0d 0a 09 61 6c 69 61 73 20 67 65  } }.....alias ge
0590: 6e 45 61 73 74 21 44 65 63 6c 53 74 61 74 65 6d  nEast!DeclStatem
05a0: 65 6e 74 20 64 65 63 6c 3b 0d 0a 09 61 6c 69 61  ent decl;...alia
05b0: 73 20 67 65 6e 45 61 73 74 21 45 78 70 72 53 74  s genEast!ExprSt
05c0: 61 74 65 6d 65 6e 74 20 65 78 70 72 3b 0d 0a 09  atement expr;...
05d0: 61 6c 69 61 73 20 67 65 6e 45 61 73 74 21 56 61  alias genEast!Va
05e0: 72 45 78 70 72 65 73 73 69 6f 6e 20 76 61 72 3b  rExpression var;
05f0: 0d 0a 09 61 6c 69 61 73 20 67 65 6e 45 61 73 74  ...alias genEast
0600: 21 46 75 6e 63 61 6c 6c 45 78 70 72 65 73 73 69  !FuncallExpressi
0610: 6f 6e 20 66 75 6e 63 61 6c 6c 3b 0d 0a 09 61 6c  on funcall;...al
0620: 69 61 73 20 67 65 6e 45 61 73 74 21 49 6e 74 4c  ias genEast!IntL
0630: 69 74 65 72 61 6c 45 78 70 72 65 73 73 69 6f 6e  iteralExpression
0640: 20 69 6e 74 6c 3b 0d 0a 09 61 6c 69 61 73 20 67   intl;...alias g
0650: 65 6e 45 61 73 74 21 53 74 72 4c 69 74 65 72 61  enEast!StrLitera
0660: 6c 45 78 70 72 65 73 73 69 6f 6e 20 73 74 72 6c  lExpression strl
0670: 3b 0d 0a 09 61 6c 69 61 73 20 67 65 6e 45 61 73  ;...alias genEas
0680: 74 21 46 75 6e 4c 69 74 65 72 61 6c 45 78 70 72  t!FunLiteralExpr
0690: 65 73 73 69 6f 6e 20 66 75 6e 3b 0d 0a 7d 0d 0a  ession fun;..}..