예제 #1
0
파일: Parser.cs 프로젝트: Silica/CsPSL
 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);
 }
예제 #2
0
파일: Parser.cs 프로젝트: Silica/CsPSL
 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, ";");
 }
예제 #3
0
파일: Parser.cs 프로젝트: Silica/CsPSL
 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));
 }