Esempio n. 1
0
        static NicodemGrammarProductions()
        {
            DecimalNumberLiteral.SetProduction(DecimalNumberLiteralToken);
            CharacterLiteral.SetProduction(CharacterLiteralToken);
            StringLiteral.SetProduction(StringLiteralToken);
            BooleanLiteral.SetProduction(BooleanLiteralToken);
            Literals.SetProduction(DecimalNumberLiteral + CharacterLiteral + StringLiteral + BooleanLiteral);

            Program.SetProduction((Function + RecordTypeDeclaration).Star * Eof);
            RecordTypeDeclaration.SetProduction(TypeSpecifier * "{" * RecordTypeFieldsDeclarationList * "}");
            RecordTypeFieldsDeclarationList.SetProduction(RecordTypeFieldDeclaration.Star * RecordTypeFieldDeclaration);
            RecordTypeFieldDeclaration.SetProduction(ObjectDeclaration * ";");
            Function.SetProduction(ObjectName * "(" * ParametersList * ")" * "->" * TypeSpecifier * Expression);
            ParametersList.SetProduction(((ObjectDeclaration * ",").Star * ObjectDeclaration).Optional);
            ObjectDeclaration.SetProduction(TypeSpecifier * ObjectName);
            TypeSpecifier.SetProduction(TypeName * ("mutable".Optional() * "[" * Expression.Optional * "]").Star * "mutable".Optional());
            Expression.SetProduction(RecordVariableDefinitionExpression + RecordFieldAccessExpression + OperatorExpression);
            RecordFieldAccessExpression.SetProduction(ObjectName * "[" * ObjectName * "]");
            OperatorExpression.SetProduction(Operator19Expression);
            Operator19Expression.SetProduction(ObjectDefinitionExpression + Operator18Expression);
            ObjectDefinitionExpression.SetProduction(TypeSpecifier * ObjectName * "=" * Expression);  // NOTE: "=" is _not_ an assignment operator here
            RecordVariableDefinitionExpression.SetProduction(TypeSpecifier * ObjectName * "{" * RecordInitializationList * "}");
            RecordInitializationList.SetProduction((RecordInitializationField * ",").Star * RecordInitializationField);
            RecordInitializationField.SetProduction(ObjectName * "=" * Expression);
            Operator18Expression.SetProduction(IfExpression + WhileExpression + Operator17Expression);
            IfExpression.SetProduction("if" * Expression * Expression * ("else" * Expression).Optional);
            WhileExpression.SetProduction("while" * Expression * Expression * ("else" * Expression).Optional);
            Operator17Expression.SetProduction(Operator16Expression);
            Operator16Expression.SetProduction(Operator15Expression);
            Operator15Expression.SetProduction(MakeInfixOperatorExpressionRegex(Operator14Expression, "= += -= *= /= %= <<= >>= &= ^= |=".Split(' ')));
            Operator14Expression.SetProduction(MakeInfixOperatorExpressionRegex(Operator13Expression, "||"));
            Operator13Expression.SetProduction(MakeInfixOperatorExpressionRegex(Operator12Expression, "&&"));
            Operator12Expression.SetProduction(MakeInfixOperatorExpressionRegex(Operator11Expression, "|"));
            Operator11Expression.SetProduction(MakeInfixOperatorExpressionRegex(Operator10Expression, "^"));
            Operator10Expression.SetProduction(MakeInfixOperatorExpressionRegex(Operator9Expression, "&"));
            Operator9Expression.SetProduction(MakeInfixOperatorExpressionRegex(Operator8Expression, "==", "!="));
            Operator8Expression.SetProduction(MakeInfixOperatorExpressionRegex(Operator7Expression, "< <= > >=".Split(' ')));
            Operator7Expression.SetProduction(MakeInfixOperatorExpressionRegex(Operator6Expression, "<< >>".Split(' ')));
            Operator6Expression.SetProduction(MakeInfixOperatorExpressionRegex(Operator5Expression, "+ -".Split(' ')));
            Operator5Expression.SetProduction(MakeInfixOperatorExpressionRegex(Operator4Expression, "* / %".Split(' ')));
            Operator4Expression.SetProduction(Operator3Expression);
            Operator3Expression.SetProduction(RegexSymbol.MakeUnion("++ -- + - ! ~".Split(' ')).Star *Operator2Expression);
            Operator2Expression.SetProduction(Operator1Expression * (RegexSymbol.MakeUnion("++", "--") + ("(" * (Expression * ",").Star * Expression.Optional * ")") + ("[" * Expression * "]") + ("[" * Expression.Optional * ".." * Expression.Optional * "]")).Star);
            Operator1Expression.SetProduction(Operator0Expression);
            Operator0Expression.SetProduction(AtomicExpression + ("(" * Expression * ")"));
            AtomicExpression.SetProduction(
                BlockExpression +
                ArrayLiteralExpression +
                ObjectUseExpression +
                LoopControlExpression
                );
            BlockExpression.SetProduction("{" * (Expression * ";").Star * "}");               // No left-recursion thanks to '{'
            ArrayLiteralExpression.SetProduction("[" * (Expression * ",").Star * Expression.Optional * "]");
            ObjectUseExpression.SetProduction(ObjectName + Literals);
            LoopControlExpression.SetProduction(("break".Token() + "continue") * (Expression * DecimalNumberLiteral.Optional).Optional);
        }
Esempio n. 2
0
 private static void SetProduction(this UniversalSymbol that, RegexSymbol regexSymbol)
 {
     Productions.Add(that, regexSymbol);
 }
Esempio n. 3
0
        private static RegexSymbol MakeInfixOperatorExpressionRegex(UniversalSymbol operatorExpression, params string[] operators)
        {
            var operatorsRegex = RegexSymbol.MakeUnion(operators);

            return(operatorExpression * (operatorsRegex * operatorExpression).Star);
        }
Esempio n. 4
0
 public abstract void Apply(RegexSymbol regexSymbol);