Ejemplo n.º 1
0
        bool TestlistComp(out AST.ProgObj obj)
        {
            if (Test(out obj))
            {
                goto _1;
            }
            obj = null;
            return(false);

_1:
            //if (scan.Lexeme == Lexeme.Comma) {
            //    scan.Next();
            //    goto _2;
            //}
            goto _end;
            //_2:
            //    if (Test()) {
            //        goto _3;
            //    }
            //    goto _end;
            //_3:
            //    if (scan.Lexeme == Lexeme.Comma) {
            //        scan.Next();
            //        goto _2;
            //    }
            //    CompilationError(ErrorType.InvalidSyntax);
_end:
            return(true);
        }
Ejemplo n.º 2
0
        bool ArithExpr(out AST.ProgObj expr)
        {
            string name;

            if (Term(out expr))
            {
                goto _2;
            }
            return(false);

_1:
            if (Term(out var right))
            {
                expr = new AST.FuncCall(name, expr, right);
                goto _2;
            }
            throw new CompilationError(ErrorType.InvalidSyntax);
_2:
            if (scan.Lexeme == Lexeme.Plus)
            {
                name = "__add__";
                scan.Next();
                goto _1;
            }
            if (scan.Lexeme == Lexeme.Minus)
            {
                name = "__sub__";
                scan.Next();
                goto _1;
            }
            goto _end;
_end:
            return(true);
        }
Ejemplo n.º 3
0
        bool AndExpr(out AST.ProgObj expr)
        {
            if (ShiftExpr(out expr))
            {
                goto _2;
            }
            return(false);

_1:
            if (ShiftExpr(out var right))
            {
                expr = new AST.FuncCall("__bitand__", expr, right);
                goto _2;
            }
            throw new CompilationError(ErrorType.InvalidSyntax);
_2:
            if (scan.Lexeme == Lexeme.BitAnd)
            {
                scan.Next();
                goto _1;
            }
            goto _end;
_end:
            return(true);
        }
Ejemplo n.º 4
0
        bool ShiftExpr(out AST.ProgObj expr)
        {
            string name;

            if (ArithExpr(out expr))
            {
                goto _2;
            }
            return(false);

_1:
            if (ArithExpr(out var right))
            {
                expr = new AST.FuncCall(name, expr, right);
                goto _2;
            }
            throw new CompilationError(ErrorType.InvalidSyntax);
_2:
            if (scan.Lexeme == Lexeme.LeftShift)
            {
                name = "__lshift__";
                scan.Next();
                goto _1;
            }
            if (scan.Lexeme == Lexeme.RightShift)
            {
                name = "__rshift__";
                scan.Next();
                goto _1;
            }
            goto _end;
_end:
            return(true);
        }
Ejemplo n.º 5
0
        bool OrTest(out AST.ProgObj expr)
        {
            if (AndTest(out expr))
            {
                goto _2;
            }
            return(false);

_1:
            if (AndTest(out var right))
            {
                expr = new AST.FuncCall("__or__", expr, right);
                goto _2;
            }
            throw new CompilationError(ErrorType.InvalidSyntax);
_2:
            if (scan.Lexeme == Lexeme.KwOr)
            {
                scan.Next();
                goto _1;
            }
            goto _end;
_end:
            return(true);
        }
Ejemplo n.º 6
0
        bool Trailer(AST.ProgObj atom, out AST.ProgObj expr)
        {
            if (scan.Lexeme == Lexeme.LeftParenthesis)
            {
                scan.Next();
                goto _1;
            }
            expr = null;
            return(false);

_1:
            if (Arglist(out var args))
            {
                expr = new AST.FuncCall(atom, args);
                goto _2;
            }
            expr = new AST.FuncCall(atom);
            goto _2;
_2:
            if (scan.Lexeme == Lexeme.RightParenthesis)
            {
                scan.Next();
                goto _end;
            }
            throw new CompilationError(ErrorType.InvalidSyntax);
_end:
            return(true);
        }
Ejemplo n.º 7
0
        bool Power(out AST.ProgObj expr)
        {
            if (AtomExpr(out expr))
            {
                goto _1;
            }
            expr = null;
            return(false);

_1:
            if (scan.Lexeme == Lexeme.Power)
            {
                scan.Next();
                goto _2;
            }
            goto _end;
_2:
            if (Factor(out var right))
            {
                expr = new AST.FuncCall("__pow__", expr, right);
                goto _end;
            }
            throw new CompilationError(ErrorType.InvalidSyntax);
_end:
            return(true);
        }
Ejemplo n.º 8
0
        bool Atom(out AST.ProgObj obj)
        {
            if (scan.Lexeme == Lexeme.LeftParenthesis)
            {
                scan.Next();
                goto _1;
            }
            if (scan.Lexeme == Lexeme.Id)
            {
                obj = new AST.NameObj(scan.TextValue());
                scan.Next();
                goto _end;
            }
            if (scan.Lexeme == Lexeme.Int)
            {
                obj = new AST.ConstInt(scan.ToInt());
                scan.Next();
                goto _end;
            }
            if (scan.Lexeme == Lexeme.Float)
            {
                obj = new AST.ConstFloat(scan.ToSingle());
                scan.Next();
                goto _end;
            }
            if (scan.Lexeme == Lexeme.KwTrue)
            {
                obj = new AST.ConstBool(true);
                scan.Next();
                goto _end;
            }
            if (scan.Lexeme == Lexeme.KwFalse)
            {
                obj = new AST.ConstBool(false);
                scan.Next();
                goto _end;
            }
            obj = null;
            return(false);

_1:
            if (TestlistComp(out obj))
            {
                goto _2;
            }
            obj = new AST.Tuple();
            goto _2;
_2:
            if (scan.Lexeme == Lexeme.RightParenthesis)
            {
                scan.Next();
                goto _end;
            }
            throw new CompilationError(ErrorType.InvalidSyntax);
_end:
            return(true);
        }
Ejemplo n.º 9
0
 public Function(TypeObj retType, string name, params TypeObj[] paramTypes)
 {
     Name    = name;
     BuiltIn = true;
     RetType = retType;
     for (var i = 0; i < paramTypes.Length; i += 1)
     {
         Parameters.Add(new Parameter(i, paramTypes[i]));
     }
 }
Ejemplo n.º 10
0
        bool Test(out AST.ProgObj expr)
        {
            if (OrTest(out expr))
            {
                goto _1;
            }
            return(false);

_1:
            goto _end;
_end:
            return(true);
        }
Ejemplo n.º 11
0
        bool Term(out AST.ProgObj expr)
        {
            string name;

            if (Factor(out expr))
            {
                goto _2;
            }
            expr = null;
            return(false);

_1:
            if (Factor(out var right))
            {
                expr = new AST.FuncCall(name, expr, right);
                goto _2;
            }
            throw new CompilationError(ErrorType.InvalidSyntax);
_2:
            if (scan.Lexeme == Lexeme.Star)
            {
                name = "__mul__";
                scan.Next();
                goto _1;
            }
            if (scan.Lexeme == Lexeme.Slash)
            {
                name = "__truediv__";
                scan.Next();
                goto _1;
            }
            if (scan.Lexeme == Lexeme.Percent)
            {
                name = "__mod__";
                scan.Next();
                goto _1;
            }
            if (scan.Lexeme == Lexeme.DoubleSlash)
            {
                name = "__floordiv__";
                scan.Next();
                goto _1;
            }
            goto _end;
_end:
            return(true);
        }
Ejemplo n.º 12
0
        bool Comparison(out AST.ProgObj expr)
        {
            string name;

            AST.ProgObj left;
            var         chained = false;

            if (Expr(out expr))
            {
                left = expr;
                goto _2;
            }
            return(false);

_1:
            if (Expr(out var right))
            {
                var comp = new AST.FuncCall(name, left, right);
                left = right;
                if (chained)
                {
                    expr = new AST.FuncCall("__and__", expr, comp);
                }
                else
                {
                    expr    = comp;
                    chained = true;
                }
                goto _2;
            }
            throw new CompilationError(ErrorType.InvalidSyntax);
_2:
            if (CompOp(out name))
            {
                goto _1;
            }
            goto _end;
_end:
            return(true);
        }
Ejemplo n.º 13
0
        bool Factor(out AST.ProgObj expr)
        {
            string name;

            if (Power(out expr))
            {
                goto _end;
            }
            if (scan.Lexeme == Lexeme.Plus)
            {
                name = "__pos__";
                scan.Next();
                goto _1;
            }
            if (scan.Lexeme == Lexeme.Minus)
            {
                name = "__neg__";
                scan.Next();
                goto _1;
            }
            if (scan.Lexeme == Lexeme.BitNot)
            {
                name = "__invert__";
                scan.Next();
                goto _1;
            }
            expr = null;
            return(false);

_1:
            if (Factor(out var right))
            {
                expr = new AST.FuncCall(name, right);
                goto _end;
            }
            throw new CompilationError(ErrorType.InvalidSyntax);
_end:
            return(true);
        }
Ejemplo n.º 14
0
        bool TestlistStarExpr(out AST.ProgObj expr)
        {
            if (Test(out expr))
            {
                goto _1;
            }
            return(false);

_1:
            //if (scan.Lexeme == Lexeme.Comma) {
            //    scan.Next();
            //    goto _2;
            //}
            goto _end;
            //_2:
            //    if (Test()) {
            //        goto _1;
            //    }
            //    goto _end;
_end:
            return(true);
        }
Ejemplo n.º 15
0
        bool Argument(out AST.ProgObj expr)
        {
            if (Test(out expr))
            {
                goto _1;
            }
            return(false);

_1:
            //if (scan.Lexeme == Lexeme.Assignment) {
            //    scan.Next();
            //    goto _2;
            //}
            goto _end;
            //_2:
            //    if (Test()) {
            //        goto _end;
            //    }
            //    CompilationError(ErrorType.InvalidSyntax);
_end:
            return(true);
        }
Ejemplo n.º 16
0
        bool NotTest(out AST.ProgObj expr)
        {
            if (scan.Lexeme == Lexeme.KwNot)
            {
                scan.Next();
                goto _1;
            }
            if (Comparison(out expr))
            {
                goto _end;
            }
            return(false);

_1:
            if (NotTest(out var right))
            {
                expr = new AST.FuncCall("__not__", right);
                goto _end;
            }
            throw new CompilationError(ErrorType.InvalidSyntax);
_end:
            return(true);
        }
Ejemplo n.º 17
0
        bool AtomExpr(out AST.ProgObj expr)
        {
            if (Atom(out expr))
            {
                goto _2;
            }
            expr = null;
            return(false);

            //_1:
            //    if (Atom()) {
            //        goto _2;
            //    }
            //    throw new CompilationError(ErrorType.InvalidSyntax);
_2:
            if (Trailer(expr, out var trailer))
            {
                expr = trailer;
                goto _2;
            }
            goto _end;
_end:
            return(true);
        }
Ejemplo n.º 18
0
 public FuncCall(string name, params ProgObj[] args)
 {
     Func = new NameObj(name);
     Args.AddRange(args);
 }
Ejemplo n.º 19
0
 public FuncCall(ProgObj func, List <ProgObj> args)
 {
     Func = func;
     Args.AddRange(args);
 }
Ejemplo n.º 20
0
 public FuncCall(ProgObj func)
 {
     Func = func;
 }