コード例 #1
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);
        }
コード例 #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);
        }
コード例 #3
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);
        }
コード例 #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);
        }
コード例 #5
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);
        }
コード例 #6
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);
        }
コード例 #7
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);
        }
コード例 #8
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);
        }
コード例 #9
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);
        }
コード例 #10
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);
        }