Exemplo n.º 1
0
 private void getexp1(Code c, bool l = false)
 {
     if (!l)
         getTerm(c);
     while (t.checkNext() != "")
     {
         switch (t.checkNext())
         {
             case "*":
                 t.getNext();
                 getTerm(c);
                 c.PushCode(new Mul());
                 break;
             case "/":
                 t.getNext();
                 getTerm(c);
                 c.PushCode(new Div());
                 break;
             case "%":
                 t.getNext();
                 getTerm(c);
                 c.PushCode(new Mod());
                 break;
             default:
                 return;
         }
     }
 }
Exemplo n.º 2
0
 public bool Parse(Variable v)
 {
     var c = new Code();
     c.PushCode(new PushVariable("arg"));
     c.PushCode(new Argument());
     while (t.checkNext() != "")
         ParseStatement(v, c);
     v.setCode(c);
     return error != 0;
 }
Exemplo n.º 3
0
 private void getexp12(Code c, bool l = false)
 {
     getexp11(c, l);
     while (t.checkNext() != "")
     {
         if (t.checkNext() != ",")
             break;
         t.getNext();
         getexp11(c);
         c.PushCode(new List());
     }
 }
Exemplo n.º 4
0
 private void ParseIf(Variable v, Code c)
 {
     var i = new Code();
     if (t.checkNext() != "(")
         Error();
     else
         t.getNext();
     ParseExpression(i, ")");
     OpCode oc = null;
     int l = i.Length;
     if (l > 0)
     {
         oc = new Jrf(0);
         i.PushCode(oc);
         l = i.Length;
     }
     else
         Error();
     ParseStatement(v, i);
     if (t.checkNext() == "identifier" && t.nstr == "else")
     {
         t.getNext();
         if (oc != null)
             oc.Set(i.Length + 1 - l);
         oc = new Jr(0);
         i.PushCode(oc);
         l = i.Length;
         ParseStatement(v, i);
         oc.Set(i.Length - l);
     }
     else
     {
         if (oc != null)
             oc.Set(i.Length - l);
     }
     c.PushCodes(i);
 }
Exemplo n.º 5
0
 private void getexp3(Code c, bool l = false)
 {
     getexp2(c, l);
     while (t.checkNext() != "")
     {
         switch (t.checkNext())
         {
             case "<<":
                 t.getNext();
                 getexp2(c);
                 c.PushCode(new Shl());
                 break;
             case ">>":
                 t.getNext();
                 getexp2(c);
                 c.PushCode(new Shr());
                 break;
             default:
                 return;
         }
     }
 }
Exemplo n.º 6
0
Arquivo: Code.cs Projeto: Silica/CsPSL
 public void PushCodes(Code c)
 {
     code = code.Concat(c.code).ToList<OpCode>();
 }
Exemplo n.º 7
0
 public virtual void setCode(Code c)
 {
 }
Exemplo n.º 8
0
 public FunctionScope(Code c)
     : base(c)
 {
 }
Exemplo n.º 9
0
 public LoopScope(Code c, int i)
     : base(c)
 {
     cline = i;
 }
Exemplo n.º 10
0
 private void getexp9(Code c, bool l = false)
 {
     getexp8(c, l);
 }
Exemplo n.º 11
0
 private void getexp8(Code c, bool l = false)
 {
     getexp7(c, l);
     while (t.checkNext() != "")
     {
         switch (t.checkNext())
         {
             case "==":
                 t.getNext();
                 getexp7(c);
                 c.PushCode(new Eq());
                 break;
             case "!=":
                 t.getNext();
                 getexp7(c);
                 c.PushCode(new Ne());
                 break;
             default:
                 return;
         }
     }
 }
Exemplo n.º 12
0
 private void getexp7(Code c, bool l = false)
 {
     getexp6(c, l);
     while (t.checkNext() != "")
     {
         switch (t.checkNext())
         {
             case "<":
                 t.getNext();
                 getexp6(c);
                 c.PushCode(new Lt());
                 break;
             case ">":
                 t.getNext();
                 getexp6(c);
                 c.PushCode(new Gt());
                 break;
             case "<=":
                 t.getNext();
                 getexp6(c);
                 c.PushCode(new Le());
                 break;
             case ">=":
                 t.getNext();
                 getexp6(c);
                 c.PushCode(new Ge());
                 break;
             default:
                 return;
         }
     }
 }
Exemplo n.º 13
0
 private void getexp6(Code c, bool l = false)
 {
     getexp5(c, l);
     while (t.checkNext() != "")
     {
         if (t.checkNext() != "|")
             break;
         t.getNext();
         getexp5(c);
         c.PushCode(new Or());
     }
 }
Exemplo n.º 14
0
 private void getexp4(Code c, bool l = false)
 {
     getexp3(c, l);
     while (t.checkNext() != "")
     {
         if (t.checkNext() != "&")
             break;
         t.getNext();
         getexp3(c);
         c.PushCode(new And());
     }
 }
Exemplo n.º 15
0
 private void ParseStatement(Variable v, Code c)
 {
     var n = t.checkNext();
     if (n == ";")
     {
         t.getNext();
         return;
     }
     if (n == "{")
     {
         t.getNext();
         var x = new Code();
         ParseBlock(v, x);
         c.PushCodes(x);
         return;
     }
     if (n == "identifier")
     {
         if (t.nstr == "if")
         {
             t.getNext();
             ParseIf(v, c);
             return;
         }
         else if (t.nstr == "for")
         {
             t.getNext();
             ParseFor(v, c);
             return;
         }
     }
     c.PushCode(new Pop());
     ParseExpression(c, ";");
 }
Exemplo n.º 16
0
 private void getexp11(Code c, bool l = false)
 {
     getexp10(c, l);
 }
Exemplo n.º 17
0
 private void getSuffOp(Code c)
 {
     while (t.checkNext() != "")
     {
         switch (t.checkNext())
         {
             case "++":
                 t.getNext();
                 break;
             case "--":
                 t.getNext();
                 break;
             case "(":
                 t.getNext();
                 if (t.checkNext() == ")")
                 {
                     t.getNext();
                     c.PushCode(new PushNull());
                 }
                 else
                 {
                     ParseExpression(c, ")");
                 }
                 c.PushCode(new Call());
                 break;
             case "[":
                 t.getNext();
                 break;
             case ".":
                 t.getNext();
                 break;
             case "`":
                 t.getNext();
                 break;
             default:
                 return;
         }
     }
 }
Exemplo n.º 18
0
 private void getexp13(Code c, bool l = false)
 {
     getexp12(c, l);
     while (t.checkNext() != "")
     {
         switch (t.checkNext())
         {
             case "=":
                 t.getNext();
                 getexp13(c);
                 c.PushCode(new Substitution());
                 break;
             case ":=":
                 t.getNext();
                 getexp13(c);
                 c.PushCode(new Assignment());
                 break;
             case "+=":
                 t.getNext();
                 getexp13(c);
                 c.PushCode(new SAdd());
                 break;
             case "-=":
                 t.getNext();
                 getexp13(c);
                 c.PushCode(new SSub());
                 break;
             case "*=":
                 t.getNext();
                 getexp13(c);
                 c.PushCode(new SMul());
                 break;
             case "/=":
                 t.getNext();
                 getexp13(c);
                 c.PushCode(new SDiv());
                 break;
             case "%=":
                 t.getNext();
                 getexp13(c);
                 c.PushCode(new SMod());
                 break;
             case "&=":
                 t.getNext();
                 getexp13(c);
                 c.PushCode(new SAnd());
                 break;
             case "|=":
                 t.getNext();
                 getexp13(c);
                 c.PushCode(new SOr());
                 break;
             case "^=":
                 t.getNext();
                 getexp13(c);
                 c.PushCode(new SXor());
                 break;
             case "<<=":
                 t.getNext();
                 getexp13(c);
                 c.PushCode(new SShl());
                 break;
             case ">>=":
                 t.getNext();
                 getexp13(c);
                 c.PushCode(new SShr());
                 break;
             default:
                 return;
         }
     }
 }
Exemplo n.º 19
0
 private void getTerm(Code c)
 {
     switch (t.checkNext())
     {
         case "(":
             t.getNext();
             ParseExpression(c, ")");
             break;
         case "+":
             t.getNext();
             getTerm(c);
             break;
         case "-":
             t.getNext();
             getTerm(c);
             c.PushCode(new Minus());
             break;
         case "!":
             t.getNext();
             getTerm(c);
             c.PushCode(new Not());
             break;
         case "~":
             t.getNext();
             getTerm(c);
             c.PushCode(new Compl());
             break;
         case "*":
             t.getNext();
             getTerm(c);
             break;
         case "&":
             t.getNext();
             getTerm(c);
             break;
         case "$":
             t.getNext();
             getTerm(c);
             break;
         case "++":
             t.getNext();
             getTerm(c);
             break;
         case "--":
             t.getNext();
             getTerm(c);
             break;
         case "identifier":
             t.getNext();
             c.PushCode(new PushVariable(t.nstr));
             getSuffOp(c);
             break;
         case "int":
             t.getNext();
             c.PushCode(new PushInt(t.nint));
             getSuffOp(c);
             break;
         case "string":
             t.getNext();
             c.PushCode(new PushString(t.nstr));
             getSuffOp(c);
             break;
         default:
             Error();
             break;
     }
 }
Exemplo n.º 20
0
 public Scope(Code c)
 {
     code = c;
 }
Exemplo n.º 21
0
 private void ParseBlock(Variable v, Code c)
 {
     while (t.checkNext() != "")
     {
         if (t.checkNext() == "}")
         {
             t.getNext();
             return;
         }
         ParseStatement(v, c);
     }
     Error();
 }
Exemplo n.º 22
0
 internal void setCode(Code c)
 {
     x.setCode(c);
 }
Exemplo n.º 23
0
 private void ParseExpression(Code c, string e, bool l = false)
 {
     getexp13(c, l);
     if (t.checkNext() == e)
         t.getNext();
     else
         Error();
 }
Exemplo n.º 24
0
 public override void setCode(Code c)
 {
     code = c;
 }
Exemplo n.º 25
0
 private void ParseFor(Variable v, Code c)
 {
     var f = new Code();
     if (t.checkNext() != "(")
         Error();
     else
         t.getNext();
     int l = 0;
     if (t.checkNext() != ";")
     {
         f.PushCode(new Pop());
         ParseExpression(f, ";");
         l = f.Length;
     }
     else
         t.getNext();
     OpCode oc = null;
     if (t.checkNext() != ";")
     {
         ParseExpression(f, ";");
         if (f.Length - l > 0)
         {
             oc = new Jf(f.Length);
             f.PushCode(oc);
         }
     }
     else
         t.getNext();
     var x = new Code();
     if (t.checkNext() != ")")
         ParseExpression(x, ")");
     else
         t.getNext();
     ParseStatement(v, f);
     int cline = f.Length;
     if (x.Length > 0)
     {
         f.PushCode(new Pop());
         f.PushCodes(x);
     }
     f.PushCode(new Jmp(l));
     if (oc != null)
         oc.Set(f.Length);
     c.PushCode(new For(f, cline));
 }
Exemplo n.º 26
0
Arquivo: Code.cs Projeto: Silica/CsPSL
 public For(Code c, int i)
 {
     code = c; cline = i;
 }
Exemplo n.º 27
0
 private void getexp2(Code c, bool l = false)
 {
     getexp1(c, l);
     while (t.checkNext() != "")
     {
         switch (t.checkNext())
         {
             case "+":
                 t.getNext();
                 getexp1(c);
                 c.PushCode(new Add());
                 break;
             case "-":
                 t.getNext();
                 getexp1(c);
                 c.PushCode(new Sub());
                 break;
             default:
                 return;
         }
     }
 }