Ejemplo n.º 1
0
        public KeywordRules(PieGrammar grammar)
        {
            this.grammar = grammar;

            Partial = grammar.ToTerm("partial");

            Import = grammar.ToTerm("import");

            Public = grammar.ToTerm("public");

            Private = grammar.ToTerm("private");

            Internal = grammar.ToTerm("internal");

            Protected = grammar.ToTerm("protected");

            Final = grammar.ToTerm("final");

            NamespaceKeyword = grammar.ToTerm("namespace");

            Module = grammar.ToTerm("module");

            Class = grammar.ToTerm("class");

            Struct = grammar.ToTerm("struct");

            Enum = grammar.ToTerm("enum");

            As = grammar.ToTerm("as");

            Of = grammar.ToTerm("of");

            Abstract = grammar.ToTerm("abstract");

            And = grammar.ToTerm("&&");

            Or = grammar.ToTerm("||");

            If = grammar.ToTerm("if");

            Else = grammar.ToTerm("else");

            Shared = grammar.ToTerm("shared");

            Def = grammar.ToTerm("def");

            Virtual = grammar.ToTerm("virtual");

            Override = grammar.ToTerm("override");

            For  = grammar.ToTerm("for");
            Step = grammar.ToTerm("step");

            While = grammar.ToTerm("while");

            In = grammar.ToTerm("in");
            To = grammar.ToTerm("to");

            True  = grammar.ToTerm("true");
            False = grammar.ToTerm("false");

            Ref = grammar.ToTerm("ref");
            Out = grammar.ToTerm("out");

            New   = grammar.ToTerm("new");
            Super = grammar.ToTerm("super");

            Get = grammar.ToTerm("get");
            Set = grammar.ToTerm("set");

            Value = grammar.ToTerm("value");

            Try     = grammar.ToTerm("try");
            Catch   = grammar.ToTerm("catch");
            Finally = grammar.ToTerm("finally");
            Throw   = grammar.ToTerm("throw");

            Switch = grammar.ToTerm("switch");
            Case   = grammar.ToTerm("case");
            Break  = grammar.ToTerm("break");

            Delegate = grammar.ToTerm("delegate");
            Event    = grammar.ToTerm("event");

            Interface = grammar.ToTerm("interface");

            Var = grammar.ToTerm("var");

            // Mark them as "reserved" so that the parser can tell the syntax highlighter how to color them in the IDE.
            grammar.MarkReservedWords("partial", "import", "public", "private", "internal", "protected", "def", "shared", "virtual", "enum");
            grammar.MarkReservedWords("final", "namespace", "class", "module", "struct", "as", "of", "abstract", "and", "or", "if", "else");
            grammar.MarkReservedWords("for", "step", "true", "false", "in", "to", "while", "const", "new", "base", "this");
            grammar.MarkReservedWords("override", "get", "set", "value", "try", "catch", "finally", "throw", "switch", "case", "break");
            grammar.MarkReservedWords("delegate", "event", "interface", "var");
        }
Ejemplo n.º 2
0
        public KeywordRules(PieGrammar grammar)
        {
            this.grammar = grammar;

            Partial = grammar.ToTerm("partial");

            Import = grammar.ToTerm("import");

            Public = grammar.ToTerm("public");

            Private = grammar.ToTerm("private");

            Internal = grammar.ToTerm("internal");

            Protected = grammar.ToTerm("protected");

            Final = grammar.ToTerm("final");

            NamespaceKeyword = grammar.ToTerm("namespace");

            Module = grammar.ToTerm("module");

            Class = grammar.ToTerm("class");

            Struct = grammar.ToTerm("struct");

            Enum = grammar.ToTerm("enum");

            As = grammar.ToTerm("as");

            Of = grammar.ToTerm("of");

            Abstract = grammar.ToTerm("abstract");

            And = grammar.ToTerm("&&");

            Or = grammar.ToTerm("||");

            If = grammar.ToTerm("if");

            Else = grammar.ToTerm("else");

            Shared = grammar.ToTerm("shared");

            Def = grammar.ToTerm("def");

            Virtual = grammar.ToTerm("virtual");

            Override = grammar.ToTerm("override");

            For = grammar.ToTerm("for");
            Step = grammar.ToTerm("step");

            While = grammar.ToTerm("while");

            In = grammar.ToTerm("in");
            To = grammar.ToTerm("to");

            True = grammar.ToTerm("true");
            False = grammar.ToTerm("false");

            Ref = grammar.ToTerm("ref");
            Out = grammar.ToTerm("out");

            New = grammar.ToTerm("new");
            Super = grammar.ToTerm("super");

            Get = grammar.ToTerm("get");
            Set = grammar.ToTerm("set");

            Value = grammar.ToTerm("value");

            Try = grammar.ToTerm("try");
            Catch = grammar.ToTerm("catch");
            Finally = grammar.ToTerm("finally");
            Throw = grammar.ToTerm("throw");

            Switch = grammar.ToTerm("switch");
            Case = grammar.ToTerm("case");
            Break = grammar.ToTerm("break");

            Delegate = grammar.ToTerm("delegate");
            Event = grammar.ToTerm("event");

            Interface = grammar.ToTerm("interface");

            Var = grammar.ToTerm("var");

            // Mark them as "reserved" so that the parser can tell the syntax highlighter how to color them in the IDE.
            grammar.MarkReservedWords("partial", "import", "public", "private", "internal", "protected", "def", "shared", "virtual", "enum");
            grammar.MarkReservedWords("final", "namespace", "class", "module", "struct", "as", "of", "abstract", "and", "or", "if", "else");
            grammar.MarkReservedWords("for", "step", "true", "false", "in", "to", "while", "const", "new", "base", "this");
            grammar.MarkReservedWords("override", "get", "set", "value", "try", "catch", "finally", "throw", "switch", "case", "break");
            grammar.MarkReservedWords("delegate", "event", "interface", "var");
        }
Ejemplo n.º 3
0
        public void Define()
        {
            // The rule describing all valid binary operators.
            ValidBinaryOperators.Rule = Add
                                        | Modulo
                                        | Divide
                                        | LessOrEqual
                                        | Less
                                        | Greater
                                        | GreaterOrEqual
                                        | Equal
                                        | NotEqual
                                        | grammar.Keywords.And
                                        | grammar.Keywords.Or
                                        | BitwiseShiftRight
                                        | BitwiseShiftLeft
                                        | BitwiseOr
                                        | BitwiseAnd
                                        | BitwiseXor
                                        | Subtract
                                        | Multiply
                                        | As;
            grammar.MarkTransient(ValidBinaryOperators);

            // Set operators precedence and associativity, in increasing order of precedence.
            int precedence = 1;

            grammar.RegisterOperators(precedence += 1, Associativity.Right, "=", "+=", "-=", "/=", "*=", "|=", "&=", "^=");
            grammar.RegisterOperators(precedence += 1, Associativity.Left, "||");
            grammar.RegisterOperators(precedence += 1, Associativity.Left, "&&");
            grammar.RegisterOperators(precedence += 1, Associativity.Left, "|");
            grammar.RegisterOperators(precedence += 1, Associativity.Left, "^");
            grammar.RegisterOperators(precedence += 1, Associativity.Left, "&");
            grammar.RegisterOperators(precedence += 1, Associativity.Left, "==", "!=");
            grammar.RegisterOperators(precedence += 1, Associativity.Left, "<", ">", ">=", "<=");
            grammar.RegisterOperators(precedence += 1, Associativity.Left, "<<", ">>");
            grammar.RegisterOperators(precedence += 1, Associativity.Left, "+", "-");
            grammar.RegisterOperators(precedence += 1, Associativity.Left, "*", "/", "%");
            grammar.RegisterOperators(precedence += 1, Associativity.Right, "!", "-");
            grammar.RegisterOperators(precedence += 1, As); // Casting

            // Set comma and closing brace as operators so that lists can continue on the next line.
            grammar.RegisterOperators(0, grammar.ToTerm("}"));
            grammar.RegisterOperators(0, grammar.ToTerm(","));

            // An operator expression: two expressions with the operator between
            BinaryOperator.Rule = grammar.expression + ValidBinaryOperators + grammar.expression;

            // The list of valid assignment operators: +=, -=, *=, /=, |*, &=, ^=
            var validAssigments = new NonTerminal("valid_assigments");

            validAssigments.Rule = EqualsAssignment
                                   | AddAssignment
                                   | SubtractAssignment
                                   | MultiplyAssignment
                                   | DivideAssignment
                                   | OrAssignment
                                   | AndAssignment
                                   | XorAssignment;
            grammar.MarkTransient(validAssigments);

            // Assignment expression is an expression that can be assigned to, the operator, and the assigned expression.
            Assignment.Rule = grammar.Assignable + validAssigments + grammar.expression + (grammar.Empty | grammar.Eos);

            // Valid unary operators.
            ValidUnaryOperators.Rule = Not | Negate;

            // Unary operator + expression
            UnaryOperator.Rule = ValidUnaryOperators + grammar.expression + (grammar.Empty | grammar.Eos);

            grammar.MarkReservedWords("As");
        }