Hex Artifact Content
Not logged in

Artifact a264a204623245e6e81a67148bec76050d38adec:


0000: ef bb bf 2f 2a 0d 0a 20 2a 20 41 75 74 68 6f 72  .../*.. * Author
0010: 73 3a 20 6b 2e 69 6e 61 62 61 0d 0a 20 2a 20 4c  s: k.inaba.. * L
0020: 69 63 65 6e 73 65 3a 20 4e 59 53 4c 20 30 2e 39  icense: NYSL 0.9
0030: 39 38 32 20 68 74 74 70 3a 2f 2f 77 77 77 2e 6b  982 http://www.k
0040: 6d 6f 6e 6f 73 2e 6e 65 74 2f 6e 79 73 6c 2f 0d  monos.net/nysl/.
0050: 0a 20 2a 0d 0a 20 2a 20 53 79 6e 74 61 78 20 74  . *.. * Syntax t
0060: 72 65 65 20 66 6f 72 20 50 6f 6c 65 6d 79 20 70  ree for Polemy p
0070: 72 6f 67 72 61 6d 6d 69 6e 67 20 6c 61 6e 67 75  rogramming langu
0080: 61 67 65 2e 0d 0a 20 2a 2f 0d 0a 6d 6f 64 75 6c  age... */..modul
0090: 65 20 70 6f 6c 65 6d 79 2e 61 73 74 3b 0d 0a 69  e polemy.ast;..i
00a0: 6d 70 6f 72 74 20 70 6f 6c 65 6d 79 2e 5f 63 6f  mport polemy._co
00b0: 6d 6d 6f 6e 3b 0d 0a 69 6d 70 6f 72 74 20 70 6f  mmon;..import po
00c0: 6c 65 6d 79 2e 6c 65 78 20 3a 20 4c 65 78 50 6f  lemy.lex : LexPo
00d0: 73 69 74 69 6f 6e 3b 0d 0a 0d 0a 61 6c 69 61 73  sition;....alias
00e0: 20 53 74 61 74 65 6d 65 6e 74 5b 5d 20 50 72 6f   Statement[] Pro
00f0: 67 72 61 6d 3b 0d 0a 0d 0a 61 62 73 74 72 61 63  gram;....abstrac
0100: 74 20 63 6c 61 73 73 20 53 74 61 74 65 6d 65 6e  t class Statemen
0110: 74 0d 0a 7b 0d 0a 09 69 6d 6d 75 74 61 62 6c 65  t..{...immutable
0120: 20 4c 65 78 50 6f 73 69 74 69 6f 6e 20 70 6f 73   LexPosition pos
0130: 3b 0d 0a 09 6d 69 78 69 6e 20 53 69 6d 70 6c 65  ;...mixin Simple
0140: 43 6f 6e 73 74 72 75 63 74 6f 72 3b 0d 0a 7d 0d  Constructor;..}.
0150: 0a 0d 0a 63 6c 61 73 73 20 44 65 63 6c 53 74 61  ...class DeclSta
0160: 74 65 6d 65 6e 74 20 3a 20 53 74 61 74 65 6d 65  tement : Stateme
0170: 6e 74 0d 0a 7b 0d 0a 09 73 74 72 69 6e 67 20 20  nt..{...string  
0180: 20 20 20 76 61 72 3b 0d 0a 09 45 78 70 72 65 73     var;...Expres
0190: 73 69 6f 6e 20 65 78 70 72 3b 0d 0a 09 6d 69 78  sion expr;...mix
01a0: 69 6e 20 53 69 6d 70 6c 65 43 6f 6e 73 74 72 75  in SimpleConstru
01b0: 63 74 6f 72 3b 0d 0a 09 6d 69 78 69 6e 20 53 69  ctor;...mixin Si
01c0: 6d 70 6c 65 43 6f 6d 70 61 72 65 3b 20 2f 2f 20  mpleCompare; // 
01d0: 64 6f 20 6e 6f 74 20 74 61 6b 65 20 22 70 6f 73  do not take "pos
01e0: 22 20 69 6e 74 6f 20 61 63 63 6f 75 6e 74 0d 0a  " into account..
01f0: 7d 0d 0a 0d 0a 63 6c 61 73 73 20 45 78 70 72 53  }....class ExprS
0200: 74 61 74 65 6d 65 6e 74 20 3a 20 53 74 61 74 65  tatement : State
0210: 6d 65 6e 74 0d 0a 7b 0d 0a 09 45 78 70 72 65 73  ment..{...Expres
0220: 73 69 6f 6e 20 65 78 70 72 3b 0d 0a 09 6d 69 78  sion expr;...mix
0230: 69 6e 20 53 69 6d 70 6c 65 43 6f 6e 73 74 72 75  in SimpleConstru
0240: 63 74 6f 72 3b 0d 0a 09 6d 69 78 69 6e 20 53 69  ctor;...mixin Si
0250: 6d 70 6c 65 43 6f 6d 70 61 72 65 3b 20 2f 2f 20  mpleCompare; // 
0260: 64 6f 20 6e 6f 74 20 74 61 6b 65 20 22 70 6f 73  do not take "pos
0270: 22 20 69 6e 74 6f 20 61 63 63 6f 75 6e 74 0d 0a  " into account..
0280: 7d 0d 0a 0d 0a 61 62 73 74 72 61 63 74 20 63 6c  }....abstract cl
0290: 61 73 73 20 45 78 70 72 65 73 73 69 6f 6e 0d 0a  ass Expression..
02a0: 7b 0d 0a 09 69 6d 6d 75 74 61 62 6c 65 20 4c 65  {...immutable Le
02b0: 78 50 6f 73 69 74 69 6f 6e 20 70 6f 73 3b 0d 0a  xPosition pos;..
02c0: 09 6d 69 78 69 6e 20 53 69 6d 70 6c 65 43 6f 6e  .mixin SimpleCon
02d0: 73 74 72 75 63 74 6f 72 3b 0d 0a 09 6d 69 78 69  structor;...mixi
02e0: 6e 20 53 69 6d 70 6c 65 43 6f 6d 70 61 72 65 3b  n SimpleCompare;
02f0: 20 2f 2f 20 64 6f 20 6e 6f 74 20 74 61 6b 65 20   // do not take 
0300: 22 70 6f 73 22 20 69 6e 74 6f 20 61 63 63 6f 75  "pos" into accou
0310: 6e 74 0d 0a 7d 0d 0a 0d 0a 63 6c 61 73 73 20 53  nt..}....class S
0320: 74 72 4c 69 74 65 72 61 6c 45 78 70 72 65 73 73  trLiteralExpress
0330: 69 6f 6e 20 3a 20 45 78 70 72 65 73 73 69 6f 6e  ion : Expression
0340: 0d 0a 7b 0d 0a 09 73 74 72 69 6e 67 20 64 61 74  ..{...string dat
0350: 61 3b 0d 0a 09 6d 69 78 69 6e 20 53 69 6d 70 6c  a;...mixin Simpl
0360: 65 43 6f 6e 73 74 72 75 63 74 6f 72 3b 0d 0a 09  eConstructor;...
0370: 6d 69 78 69 6e 20 53 69 6d 70 6c 65 43 6f 6d 70  mixin SimpleComp
0380: 61 72 65 3b 20 2f 2f 20 64 6f 20 6e 6f 74 20 74  are; // do not t
0390: 61 6b 65 20 22 70 6f 73 22 20 69 6e 74 6f 20 61  ake "pos" into a
03a0: 63 63 6f 75 6e 74 0d 0a 7d 0d 0a 0d 0a 63 6c 61  ccount..}....cla
03b0: 73 73 20 49 6e 74 4c 69 74 65 72 61 6c 45 78 70  ss IntLiteralExp
03c0: 72 65 73 73 69 6f 6e 20 3a 20 45 78 70 72 65 73  ression : Expres
03d0: 73 69 6f 6e 0d 0a 7b 0d 0a 09 42 69 67 49 6e 74  sion..{...BigInt
03e0: 20 64 61 74 61 3b 0d 0a 09 6d 69 78 69 6e 20 53   data;...mixin S
03f0: 69 6d 70 6c 65 43 6f 6e 73 74 72 75 63 74 6f 72  impleConstructor
0400: 3b 0d 0a 09 6d 69 78 69 6e 20 53 69 6d 70 6c 65  ;...mixin Simple
0410: 43 6f 6d 70 61 72 65 3b 20 2f 2f 20 64 6f 20 6e  Compare; // do n
0420: 6f 74 20 74 61 6b 65 20 22 70 6f 73 22 20 69 6e  ot take "pos" in
0430: 74 6f 20 61 63 63 6f 75 6e 74 0d 0a 7d 0d 0a 0d  to account..}...
0440: 0a 63 6c 61 73 73 20 56 61 72 45 78 70 72 65 73  .class VarExpres
0450: 73 69 6f 6e 20 3a 20 45 78 70 72 65 73 73 69 6f  sion : Expressio
0460: 6e 0d 0a 7b 0d 0a 09 73 74 72 69 6e 67 20 76 61  n..{...string va
0470: 72 3b 0d 0a 09 6d 69 78 69 6e 20 53 69 6d 70 6c  r;...mixin Simpl
0480: 65 43 6f 6e 73 74 72 75 63 74 6f 72 3b 0d 0a 09  eConstructor;...
0490: 6d 69 78 69 6e 20 53 69 6d 70 6c 65 43 6f 6d 70  mixin SimpleComp
04a0: 61 72 65 3b 20 2f 2f 20 64 6f 20 6e 6f 74 20 74  are; // do not t
04b0: 61 6b 65 20 22 70 6f 73 22 20 69 6e 74 6f 20 61  ake "pos" into a
04c0: 63 63 6f 75 6e 74 0d 0a 7d 0d 0a 0d 0a 63 6c 61  ccount..}....cla
04d0: 73 73 20 41 73 73 69 67 6e 45 78 70 72 65 73 73  ss AssignExpress
04e0: 69 6f 6e 20 3a 20 45 78 70 72 65 73 73 69 6f 6e  ion : Expression
04f0: 0d 0a 7b 0d 0a 09 45 78 70 72 65 73 73 69 6f 6e  ..{...Expression
0500: 20 6c 68 73 3b 0d 0a 09 45 78 70 72 65 73 73 69   lhs;...Expressi
0510: 6f 6e 20 72 68 73 3b 0d 0a 09 6d 69 78 69 6e 20  on rhs;...mixin 
0520: 53 69 6d 70 6c 65 43 6f 6e 73 74 72 75 63 74 6f  SimpleConstructo
0530: 72 3b 0d 0a 09 6d 69 78 69 6e 20 53 69 6d 70 6c  r;...mixin Simpl
0540: 65 43 6f 6d 70 61 72 65 3b 20 2f 2f 20 64 6f 20  eCompare; // do 
0550: 6e 6f 74 20 74 61 6b 65 20 22 70 6f 73 22 20 69  not take "pos" i
0560: 6e 74 6f 20 61 63 63 6f 75 6e 74 0d 0a 7d 0d 0a  nto account..}..
0570: 0d 0a 63 6c 61 73 73 20 46 75 6e 63 61 6c 6c 45  ..class FuncallE
0580: 78 70 72 65 73 73 69 6f 6e 20 3a 20 45 78 70 72  xpression : Expr
0590: 65 73 73 69 6f 6e 0d 0a 7b 0d 0a 09 45 78 70 72  ession..{...Expr
05a0: 65 73 73 69 6f 6e 20 20 20 66 75 6e 3b 0d 0a 09  ession   fun;...
05b0: 45 78 70 72 65 73 73 69 6f 6e 5b 5d 20 61 72 67  Expression[] arg
05c0: 73 3b 0d 0a 09 74 68 69 73 28 69 6d 6d 75 74 61  s;...this(immuta
05d0: 62 6c 65 20 4c 65 78 50 6f 73 69 74 69 6f 6e 20  ble LexPosition 
05e0: 70 6f 73 2c 20 45 78 70 72 65 73 73 69 6f 6e 20  pos, Expression 
05f0: 66 75 6e 2c 20 45 78 70 72 65 73 73 69 6f 6e 5b  fun, Expression[
0600: 5d 20 61 72 67 73 2e 2e 2e 29 0d 0a 09 09 7b 20  ] args...)....{ 
0610: 73 75 70 65 72 28 70 6f 73 29 3b 20 74 68 69 73  super(pos); this
0620: 2e 66 75 6e 3d 66 75 6e 3b 20 74 68 69 73 2e 61  .fun=fun; this.a
0630: 72 67 73 3d 61 72 67 73 2e 64 75 70 3b 20 7d 0d  rgs=args.dup; }.
0640: 0a 09 6d 69 78 69 6e 20 53 69 6d 70 6c 65 43 6f  ..mixin SimpleCo
0650: 6d 70 61 72 65 3b 20 2f 2f 20 64 6f 20 6e 6f 74  mpare; // do not
0660: 20 74 61 6b 65 20 22 70 6f 73 22 20 69 6e 74 6f   take "pos" into
0670: 20 61 63 63 6f 75 6e 74 0d 0a 7d 0d 0a 0d 0a 63   account..}....c
0680: 6c 61 73 73 20 46 75 6e 4c 69 74 65 72 61 6c 45  lass FunLiteralE
0690: 78 70 72 65 73 73 69 6f 6e 20 3a 20 45 78 70 72  xpression : Expr
06a0: 65 73 73 69 6f 6e 0d 0a 7b 0d 0a 09 73 74 72 69  ession..{...stri
06b0: 6e 67 5b 5d 20 70 61 72 61 6d 73 3b 0d 0a 09 50  ng[] params;...P
06c0: 72 6f 67 72 61 6d 20 20 66 75 6e 62 6f 64 79 3b  rogram  funbody;
06d0: 0d 0a 09 6d 69 78 69 6e 20 53 69 6d 70 6c 65 43  ...mixin SimpleC
06e0: 6f 6e 73 74 72 75 63 74 6f 72 3b 0d 0a 09 6d 69  onstructor;...mi
06f0: 78 69 6e 20 53 69 6d 70 6c 65 43 6f 6d 70 61 72  xin SimpleCompar
0700: 65 3b 20 2f 2f 20 64 6f 20 6e 6f 74 20 74 61 6b  e; // do not tak
0710: 65 20 22 70 6f 73 22 20 69 6e 74 6f 20 61 63 63  e "pos" into acc
0720: 6f 75 6e 74 0d 0a 7d 0d 0a                       ount..}..