public SpeechExpression()
        {
            FreeTextLiteral text = new FreeTextLiteral(TextLiteralName, FreeTextOptions.AllowEof, AliasSymbol, VarSymbol, OpenBracketSymbol, ArgSeparatorSymbol, CloseBracketSymbol);
            IdentifierTerminal name = TerminalFactory.CreateCSharpIdentifier(NameLiteralName);

            NonTerminal root = new NonTerminal(RootExpressionName);
            NonTerminal expression = new NonTerminal(ExpressionLiteralName);
            NonTerminal argumentList = new NonTerminal(ArgumentListLiteralName);
            NonTerminal alias = new NonTerminal(AliasLiteralName);
            NonTerminal variable = new NonTerminal(VariableLiteralName);

            argumentList.Rule = MakePlusRule(argumentList, ToTerm(ArgSeparatorSymbol), root);
            alias.Rule = AliasSymbol + name + OpenBracketSymbol + argumentList + CloseBracketSymbol | AliasSymbol + name;
            variable.Rule = VarSymbol + name;

            expression.Rule = text | variable | alias;
            root.Rule = MakeStarRule(root, expression);

            Root = root;

            text.Escapes.Add("\\" + AliasSymbol, AliasSymbol);
            text.Escapes.Add("\\" + VarSymbol, VarSymbol);
            text.Escapes.Add("\\" + OpenBracketSymbol, OpenBracketSymbol);
            text.Escapes.Add("\\" + CloseBracketSymbol, CloseBracketSymbol);
            text.Escapes.Add("\\" + ArgSeparatorSymbol, ArgSeparatorSymbol);

            MarkTransient(root, expression);
            RegisterBracePair(OpenBracketSymbol, CloseBracketSymbol);
        }
Beispiel #2
0
        public ListRules(PieGrammar grammar)
        {
            this.grammar = grammar;

            StarIdentifierList = new NonTerminal("star_identifer_list");
            PlusIdentifierList = new NonTerminal("plus_identfier_list");
        }
        public FabricGrammar(): base(false) // case non-sensitive
        {
            // Terminal Definitions
            RegexBasedTerminal number = new RegexBasedTerminal("number", "[0-9]+");

            // Non-Terminal Definitions
            NonTerminal program = new NonTerminal("program"),
                createStatement = new NonTerminal("createStatement"),
                startStatement = new NonTerminal("startStatement"),
                moveStatements = new NonTerminal("moveStatements"),
                moveStatement = new NonTerminal("moveStatement"),
                direction = new NonTerminal("direction");

            // Relation Definitions
            program.Rule = createStatement + startStatement + moveStatements;
            createStatement.Rule = ToTerm("Create") + "a" + number + "by" + number + "grid";
            startStatement.Rule = ToTerm("Start") + "at" + "location" + number + "," + number;
            moveStatements.Rule = MakePlusRule(moveStatements, moveStatement);
            moveStatement.Rule = ToTerm("Move") + direction + number;
            direction.Rule = ToTerm("up") | "down" | "right" | "left";

            // Set the Root
            this.Root = program;

            // Set the Markup Register
            MarkPunctuation("Create", "a", "grid", "by", "Start", "at", "location", ",", "Move");
        }
Beispiel #4
0
        public ExceptionRules(PieGrammar grammar)
        {
            this.grammar = grammar;

            ExceptionHandlingBlock = new NonTerminal("exception_handling_block");
            ThrowStatement = new NonTerminal("throw_statement");
        }
            public ExpressionGrammar()
            {
                var Number = new NumberLiteral("Number");
                var Var = new IdentifierTerminal("Var");
                var conditional_expression = new NonTerminal("conditional_expression");

                //conditional_expression.Rule = expression + PreferShiftHere() + qmark + expression + colon + expression;
                //NonTerminal DataType = new NonTerminal("DataType");

                NonTerminal DecSt = new NonTerminal("DecSt");
                DecSt.Rule = "int" + Var + "=" + Number + ";" | "int" + Var + ";";

                NonTerminal PrintSt = new NonTerminal("PrintSt");
                PrintSt.Rule = "cout <<" + Var;

                //NonTerminal IF = new NonTerminal("IF");
                //IF.Rule = "if( + ;

                NonTerminal stmt = new NonTerminal("stmt");
                stmt.Rule = PrintSt | DecSt;

                NonTerminal stmt1 = new NonTerminal("stmt");
                stmt1.Rule = "begin{" + stmt + "}end;";

                this.Root = DecSt;
            }
Beispiel #6
0
        protected override NonTerminal MakeRoot()
        {
            var root = new NonTerminal("root");
            Productions(root);

            return root;
        }
Beispiel #7
0
        public E2Grammar()
        {
            LineTerminators = "\r\n";
            var program = new NonTerminal("Program");
            var directiveList = new NonTerminal("DirectiveList");
            var directive = new NonTerminal("Directive");
            var directiveName = new IdentifierTerminal("DirectiveName");
            var directiveBody = new NonTerminal("DirectiveBody");
            var statementList = new NonTerminal("StatementList");
            var statement = new NonTerminal("Statement");
            var assignment = new NonTerminal("Assignment");
            var expression = new NonTerminal("Expression");
            var parenExpression = new NonTerminal("ParenExpression");
            var methodCall = new NonTerminal("MethodCall");
            var argumentList = new NonTerminal("ArgumentList");
            var argumentTail = new NonTerminal("ArgumentTail");
            var @operator = new NonTerminal("Operator");
            var operation = new NonTerminal("Operation");
            var identifier = new IdentifierTerminal("Identifier");
            var @string = new StringLiteral("String", "\"");
            var number = new NumberLiteral("Number");
            var ifStatement = new NonTerminal("IfStatement");
            var whileStatement = new NonTerminal("WhileStatement");
            var comment = new CommentTerminal("comment", "#", new[] {"\n"});
            var dcom = new CommentTerminal("commentCheat", "@", new[] {"\n"});

            Root = program;

            NonGrammarTerminals.Add(comment);
            NonGrammarTerminals.Add(dcom);

            RegisterBracePair("{", "}");

            program.Rule = /* directiveList + */statementList;

            //directiveList.Rule = MakePlusRule(directiveList, null, directive);
            //directiveBody.Rule = new CommentTerminal()
            //directive.Rule = ToTerm("@") + directiveName + directiveBody;

            statementList.Rule = MakePlusRule(statementList, null, statement);
            statement.Rule = methodCall | assignment;

            expression.Rule = operation | @string | number | methodCall | identifier;

            parenExpression.Rule = ToTerm("(") + expression + ")";

            methodCall.Rule = expression + ":" + identifier + "(" + argumentList + ")";

            argumentList.Rule = MakeStarRule(argumentList, ToTerm(","), expression);

            operation.Rule = expression + @operator + expression;

            @operator.Rule = ToTerm("+") | "-" | "*" | "/" | "&" | "|";

            assignment.Rule = identifier + "=" + expression;

            ifStatement.Rule = ToTerm("if") + parenExpression + "{" + statementList + "}";

            whileStatement.Rule = ToTerm("while") + parenExpression + "{" + statementList + "}";
        }
Beispiel #8
0
        public WhileLoopRules(PieGrammar grammar)
        {
            this.grammar = grammar;

            SimpleWhileLoop = new NonTerminal("simple_while_loop");
            BodiedWhileLoop = new NonTerminal("bodied_while_loop");
        }
Beispiel #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Parser"/> class.
        /// </summary>
        /// <param name="language">The language.</param>
        /// <param name="scanner">The scanner.</param>
        /// <param name="root">The root.</param>
        /// <exception cref="Exception">
        ///   </exception>
        public Parser(LanguageData language, Scanner scanner, NonTerminal root)
        {
            Language = language;
            Context  = new ParsingContext(this);
            Scanner  = scanner ?? language.CreateScanner();

            if (Scanner != null)
            {
                Scanner.Initialize(this);
            }
            else
            {
                Language.Errors.Add(GrammarErrorLevel.Error, null, "Scanner is not initialized for this grammar");
            }
            CoreParser = new CoreParser(this);
            Root       = root;
            if (Root == null)
            {
                Root         = Language.Grammar.Root;
                InitialState = Language.ParserData.InitialState;
            }
            else
            {
                if (Root != Language.Grammar.Root && !Language.Grammar.SnippetRoots.Contains(Root))
                {
                    throw new Exception(string.Format(Resources.ErrRootNotRegistered, root.Name));
                }

                InitialState = Language.ParserData.InitialStates[Root];
            }
        }
Beispiel #10
0
        public ProjectsGrammar()
        {
            // Todo
            // Fix Note to work actually right, just take the rest of the text

            // Define Terminals
            var taskName = new TaskTerminal("TaskName");
            var projectName = new ProjectTerminal("ProjectName");
            var noteText = new NoteTerminal("NoteText");

            // Define Non-Terminals
            var notes = new NonTerminal("Notes", typeof(StatementListNode));
            var project = new NonTerminal("Project", typeof (StatementListNode));
            var task = new NonTerminal("Task", typeof (StatementListNode));
            var tasks = new NonTerminal("Tasks", typeof (StatementListNode));

            var program = new NonTerminal("ProgramLine", typeof(StatementListNode));

            // Define Rules
            notes.Rule = MakeStarRule(notes, noteText);
            task.Rule = taskName + notes;
            tasks.Rule = MakeStarRule(tasks, task);
            project.Rule = projectName +notes + tasks;
            program.Rule = MakeStarRule(program, project);

            Root = program;
            LanguageFlags = LanguageFlags.CreateAst
                            | LanguageFlags.CanRunSample;
        }
 public override void ForCircleDefinition(NonTerminal circleDef, NonTerminal coordSet)
 {
     AstBuilder(circleDef, (context, node) =>
     {
         throw new InvalidOperationException("SqlGeometryParser cannot handle circle-like structures if the output style is set to GeometryCollection");
     });
 }
        public XamlMarkupExtensionGrammar()
        {
            // Non Terminals
            var markupExtension = new NonTerminal(MarkupExtensionTerm);
            var arguments = new NonTerminal("Arguments");
            var namedArgs = new NonTerminal("NamedArgs");
            var namedArg = new NonTerminal(NamedArgumentTerm);
            var positionalArgs = new NonTerminal("PositionalArgs");
            var argument = new NonTerminal("Argument");

            // Terminals
            var typeName = new TypeNameTerminal(TypeNameTerm);
            var memberName = new MemberNameTerminal(MemberNameTerm);
            var @string = new StringTerminal(StringTerm);
            var startExtension = this.ToTransientTerm("{");
            var endExtension = this.ToTransientTerm("}");
            var namedArgumentSeparator = this.ToTransientTerm("=");
            var argumentSeparator = this.ToTransientTerm(",");

            // Setup rules
            markupExtension.Rule = (startExtension + typeName + endExtension)
                | (startExtension + typeName + arguments + endExtension);

            arguments.Rule = namedArgs | positionalArgs | (positionalArgs + argumentSeparator + namedArgs);
            namedArgs.Rule = namedArg | (namedArg + argumentSeparator + namedArgs);
            namedArg.Rule = (memberName + namedArgumentSeparator + argument);
            positionalArgs.Rule = namedArgs | argument | (argument + argumentSeparator + positionalArgs);
            argument.Rule = markupExtension | @string;

            this.Root = markupExtension;
            this.MarkTransient(arguments, argument);
        }
Beispiel #13
0
    public JsonGrammar() {
      //Terminals
      var jstring = new StringLiteral("string", "\"");
      var jnumber = new NumberLiteral("number");
      var comma = ToTerm(","); 
      
      //Nonterminals
      var jobject = new NonTerminal("Object"); 
      var jobjectBr = new NonTerminal("ObjectBr");
      var jarray = new NonTerminal("Array"); 
      var jarrayBr = new NonTerminal("ArrayBr");
      var jvalue = new NonTerminal("Value");
      var jprop = new NonTerminal("Property"); 

      //Rules
      jvalue.Rule = jstring | jnumber | jobjectBr | jarrayBr | "true" | "false" | "null";
      jobjectBr.Rule = "{" + jobject + "}";
      jobject.Rule = MakeStarRule(jobject, comma, jprop);
      jprop.Rule = jstring + ":" + jvalue;
      jarrayBr.Rule = "[" + jarray + "]";
      jarray.Rule = MakeStarRule(jarray, comma, jvalue);

      //Set grammar root
      this.Root = jvalue;
      MarkPunctuation("{", "}", "[", "]", ":", ",");
      this.MarkTransient(jvalue, jarrayBr, jobjectBr);

    }//constructor
Beispiel #14
0
        public void Define()
        {
            /* case <expression>:
             *      <expression>
             */
            var caseBlock = new NonTerminal("case_block");
            caseBlock.Rule = grammar.Keywords.Case
                + grammar.expression
                + grammar.ToTerm(":")
                + grammar.Eos
                + grammar.MethodDeclarations.OptionalMethodBody;

            // List of case block expressions.
            var caseBlockList = new NonTerminal("case_block_list");
            caseBlockList.Rule = grammar.MakeStarRule(caseBlockList, caseBlock);

            // The list of case block expressions is optional.
            var caseBlockListOpt = new NonTerminal("case_block_list_opt");
            caseBlockListOpt.Rule = (grammar.Indent + caseBlockList +grammar.Dedent) | grammar.Empty;

            /* switch <expression>:
             *      case <expression>:
             *              <expression>
             */
            SwitchBlock.Rule = grammar.Keywords.Switch
                + grammar.expression
                + grammar.ToTerm(":")
                + grammar.Eos
                + caseBlockListOpt;
        }
        //#AS:2012/12/08: grammar is case-insensitive
        public CameraControlGrammar()
            : base(caseSensitive: false)
        {
            var program = new NonTerminal("program");
            var cameraSize = new NonTerminal("cameraSize");
            var cameraPosition = new NonTerminal("cameraPosition");
            var commandList = new NonTerminal("commandList");
            var command = new NonTerminal("command");
            var direction = new NonTerminal("direction");
            var number = new NumberLiteral("number");
            this.Root = program;
            //Grammar production rules in bnf form
            // <Program> ::= <CameraSize> <CameraPosition> <CommandList>
            program.Rule = cameraSize + cameraPosition + commandList;

            // <CameraSize> ::= "set" "camera" "size" ":" <number> "by" <number> "pixels" "."
            cameraSize.Rule = ToTerm("set") + "camera" + "size" + ":" +
                              number + "by" + number + "pixels" + ".";

            // <CameraPosition> ::= "set" "camera" "position" ":" <number> "," <number> "."
            cameraPosition.Rule = ToTerm("set") + "camera" + "position" +
                                  ":" + number + "," + number + ".";

            // <CommandList> ::= <Command>+
            commandList.Rule = MakePlusRule(commandList, null, command);

            // <Command> ::= "move" <number> "pixels" <Direction> "."
            command.Rule = ToTerm("move") + number + "pixels" + direction + ".";

            // <Direction> ::= "up" | "down" | "left" | "right"
            direction.Rule = ToTerm("up") | "down" | "left" | "right";

            //#AS:2012/12/08: these symbols are defined as puntuation, so they will not be included in the ast
            this.MarkPunctuation("set", ("camera"), "size", ":", "by", "pixels", ".", "position", ",", "move");
        }
Beispiel #16
0
 public TestGrammar()
 {
     var root = new NonTerminal("root");
       root.Rule = Empty;
       this.Root = root;
       this.Delimiters = ",;(){}"; //important for quick-parse tests
 }
Beispiel #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Parser"/> class.
        /// </summary>
        /// <param name="language">The language.</param>
        /// <param name="scanner">The scanner.</param>
        /// <param name="root">The root.</param>
        /// <exception cref="Exception">
        ///   </exception>
        public Parser(LanguageData language, Scanner scanner, NonTerminal root)
        {
            Language = language;
            Context = new ParsingContext(this);
            Scanner = scanner ?? language.CreateScanner();

            if (Scanner != null)
            {
                Scanner.Initialize(this);
            } 
            else
            {
                Language.Errors.Add(GrammarErrorLevel.Error, null, "Scanner is not initialized for this grammar");
            }
            CoreParser = new CoreParser(this);
            Root = root;
            if (Root == null)
            {
                Root = Language.Grammar.Root;
                InitialState = Language.ParserData.InitialState;
            }
            else
            {
                if (Root != Language.Grammar.Root && !Language.Grammar.SnippetRoots.Contains(Root))
                {
                    throw new Exception(string.Format(Resources.ErrRootNotRegistered, root.Name));
                }

                InitialState = Language.ParserData.InitialStates[Root];
            }
        }
Beispiel #18
0
        public static BnfExpression MakeStarRule(NonTerminal listNonTerminal, BnfTerm delimiter, BnfTerm listMember, TermListOptions options)
        {
            bool allowTrailingDelimiter = (options & TermListOptions.AllowTrailingDelimiter) != 0;

            if (delimiter == null)
            {
                //it is much simpler case
                listNonTerminal.SetFlag(TermFlags.IsList);
                listNonTerminal.Rule = _currentGrammar.Empty | listNonTerminal + listMember;
                return(listNonTerminal.Rule);
            }
            //Note that deceptively simple version of the star-rule
            //       Elem* -> Empty | Elem | Elem* + delim + Elem
            //  does not work when you have delimiters. This simple version allows lists starting with delimiters -
            // which is wrong. The correct formula is to first define "Elem+"-list, and then define "Elem*" list
            // as "Elem* -> Empty|Elem+"
            NonTerminal plusList = new NonTerminal(listMember.Name + "+");

            plusList.Rule = MakePlusRule(plusList, delimiter, listMember);
            plusList.SetFlag(TermFlags.NoAstNode); //to allow it to have AstNodeType not assigned
            if (allowTrailingDelimiter)
            {
                listNonTerminal.Rule = _currentGrammar.Empty | plusList | plusList + delimiter;
            }
            else
            {
                listNonTerminal.Rule = _currentGrammar.Empty | plusList;
            }
            listNonTerminal.SetFlag(TermFlags.IsListContainer);
            return(listNonTerminal.Rule);
        }
Beispiel #19
0
        public GridWorldGrammar()
        {
            this.GrammarComments = "A grammar for GridWorld";

            //Terminals
            RegexBasedTerminal number = new RegexBasedTerminal("number", "[0-9]+");

            //Non terminals
            NonTerminal program = new NonTerminal("program");
            NonTerminal createStatement = new NonTerminal("createStatement", typeof(StartNode));
            NonTerminal startStatement = new NonTerminal("startStatement", typeof(StartNode));
            NonTerminal moveStatements = new NonTerminal("moveStatements", typeof(MovesNode));
            NonTerminal moveStatement = new NonTerminal("moveStatement", typeof(MoveNode));
            NonTerminal direction = new NonTerminal("direction", typeof(DirectionNode));

            //BNF rules
            program.Rule = createStatement + startStatement + moveStatements;
            createStatement.Rule = ToTerm("Create") + "a" + number + "by" + number + "grid" + ".";
            startStatement.Rule = ToTerm("Start") + "at" + "location" + number + "," + number + ".";
            moveStatements.Rule = MakePlusRule(moveStatements, moveStatement);
            moveStatement.Rule = "Move" + direction + number + ".";
            direction.Rule = ToTerm("up") | "down" | "right" | "left";
            this.Root = program;
            this.LanguageFlags = LanguageFlags.CreateAst;
            MarkPunctuation("Create", "a", "grid", "by", "Start", "at","location", ",", ".", "Move");
        }
Beispiel #20
0
        public ForLoopRules(PieGrammar grammar)
        {
            this.grammar = grammar;

            SimpleForLoop = new NonTerminal("simple_for_loop");
            BodiedForLoop = new NonTerminal("bodied_for_loop");
        }
Beispiel #21
0
    public GrammarExL514() {
      NonTerminal A = new NonTerminal("A");
      Terminal a = new Terminal("a");

      A.Rule = "(" + A + ")" | a; 
      this.Root = A;
    }//method
        public ASLGrammar()
            : base(true)
        {
            var string_lit = TerminalFactory.CreateCSharpString("string");
            var number = TerminalFactory.CreateCSharpNumber("number");
            var identifier = TerminalFactory.CreateCSharpIdentifier("identifier");
            var code = new CustomTerminal("code", MatchCodeTerminal);

            var single_line_comment = new CommentTerminal("SingleLineComment", "//", "\r", "\n", "\u2085", "\u2028", "\u2029");
            var delimited_comment = new CommentTerminal("DelimitedComment", "/*", "*/");
            NonGrammarTerminals.Add(single_line_comment);
            NonGrammarTerminals.Add(delimited_comment);

            var state = new KeyTerm("state", "state");
            var init = new KeyTerm("init", "init");
            var exit = new KeyTerm("exit", "exit");
            var update = new KeyTerm("update", "update");
            var start = new KeyTerm("start", "start");
            var split = new KeyTerm("split", "split");
            var reset = new KeyTerm("reset", "reset");
            var startup = new KeyTerm("startup", "startup");
            var shutdown = new KeyTerm("shutdown", "shutdown");
            var isLoading = new KeyTerm("isLoading", "isLoading");
            var gameTime = new KeyTerm("gameTime", "gameTime");
            var comma = ToTerm(",", "comma");
            var semi = ToTerm(";", "semi");

            var root = new NonTerminal("root");
            var state_def = new NonTerminal("stateDef");
            var version = new NonTerminal("version");
            var state_list = new NonTerminal("stateList");
            var method_list = new NonTerminal("methodList");
            var var_list = new NonTerminal("varList");
            var var = new NonTerminal("var");
            var module = new NonTerminal("module");
            var method = new NonTerminal("method");
            var offset_list = new NonTerminal("offsetList");
            var offset = new NonTerminal("offset");
            var method_type = new NonTerminal("methodType");

            root.Rule = state_list + method_list;
            version.Rule = (comma + string_lit) | Empty;
            state_def.Rule = state + "(" + string_lit + version + ")" + "{" + var_list + "}";
            state_list.Rule = MakeStarRule(state_list, state_def);
            method_list.Rule = MakeStarRule(method_list, method);
            var_list.Rule = MakeStarRule(var_list, semi, var);
            module.Rule = (string_lit + comma) | Empty;
            var.Rule = (identifier + identifier + ":" + module + offset_list) | Empty;
            method.Rule = (method_type + "{" + code + "}") | Empty;
            offset_list.Rule = MakePlusRule(offset_list, comma, offset);
            offset.Rule = number;
            method_type.Rule = init | exit | update | start | split | isLoading | gameTime | reset | startup | shutdown;

            Root = root;

            MarkTransient(var_list, method_list, offset, method_type);

            LanguageFlags = LanguageFlags.NewLineBeforeEOF;
        }
Beispiel #23
0
        public KISGrammer()
        {
            var number = new NumberLiteral("number");
            var text = new StringLiteral("string", "\"");

            number.DefaultIntTypes = new TypeCode[] { TypeCode.Int32, TypeCode.Int64, NumberLiteral.TypeCodeBigInt };
            var identifier = new IdentifierTerminal("identifier");
            var comment = new CommentTerminal("comment", "#", "\n", "\r");
            base.NonGrammarTerminals.Add(comment);

            var Code = new NonTerminal("code");
            var Statments = new NonTerminal("statments");
            var Value = new NonTerminal("value");
            var ValueString = TerminalFactory.CreateCSharpString("valuestring");

            var SetStmt = new NonTerminal("setstmt");
            var CallStmt = new NonTerminal("callstmt");
            var FnStmt = new NonTerminal("fnstmt");

            var CallPath = new NonTerminal("callpath");
            var CallPerams = new NonTerminal("callperams");

            var fullstop = new NonTerminal("fullstop");
            var comma = new NonTerminal("comma");
            var openb = new NonTerminal("openb");
            var closeb = new NonTerminal("closeb");
            openb.Rule = "{";
            closeb.Rule = "}";
            fullstop.Rule = ".";
            comma.Rule = ",";

            CallPath.Rule = MakePlusRule(CallPath, fullstop, identifier);
            CallPerams.Rule = MakePlusRule(CallPerams, comma, Value);

            var Semicolon = ToTerm(";");

            //StateMents:
            SetStmt.Rule = identifier + "=" + Value + Semicolon;
            CallStmt.Rule = (CallPath | identifier) + "(" + (CallPerams | Empty) + ")" + Semicolon;
            FnStmt.Rule = "function" + identifier + "(" + (CallPerams | Empty) + ")";

            Statments.Rule = SetStmt | CallStmt | FnStmt | openb | closeb | Empty;

            var Exspr = new NonTerminal("exspr");
            var Operator = new NonTerminal("operator");
            var ExsprStmt = new NonTerminal("exsprstmt");

            Operator.Rule = ToTerm("/") | "*" | "-" | "+";

            ExsprStmt.Rule = Value + Operator + Value;

            Exspr.Rule = MakePlusRule(Exspr, Operator, ExsprStmt);

            Value.Rule = number | ValueString | identifier | "true" | "false" | Exspr /* | text */;
            Code.Rule = MakePlusRule(Code, NewLine, Statments);
            LanguageFlags = LanguageFlags.NewLineBeforeEOF;
            //code := Statment {statment}
            this.Root = Code;
        }
Beispiel #24
0
 public static BnfExpression MakePlusRule(NonTerminal listNonTerminal, BnfTerm delimiter, BnfTerm listMember) {
   if (delimiter == null)
     listNonTerminal.Rule = listMember | listNonTerminal + listMember;
   else 
     listNonTerminal.Rule = listMember | listNonTerminal + delimiter + listMember;
   listNonTerminal.SetFlag(TermFlags.IsList);
   return listNonTerminal.Rule;
 }
 public override void ForGeometryCollection(NonTerminal geometryCollection, NonTerminal geometryDef)
 {
     AstBuilder(geometryCollection, (context, node) =>
     {
         var geometries = GetAllAstNodesOf<GeoJSONObject>(node, geometryDef);
         node.AstNode = new GeometryCollection(geometries.OfType<IGeometryObject>().ToList());
     });
 }
Beispiel #26
0
        private NonTerminal Alter()
        {
            var alterCommand = new NonTerminal("alter_command");

            alterCommand.Rule = AlterTable() | AlterUser();

            return alterCommand;
        }
 public override void ForGeometryCollection(NonTerminal geometryCollection, NonTerminal geometryDef)
 {
     AstBuilder(geometryCollection, (context, node) =>
     {
         var geometries = GetAllAstNodesOf<Feature>(node, geometryDef).ToList();
         node.AstNode = new FeatureCollection(geometries);
     });
 }
Beispiel #28
0
 public IntegrationTestGrammar() {
   var comment = new CommentTerminal("comment", "/*", "*/");
   base.NonGrammarTerminals.Add(comment);
   var str = new StringLiteral("str", "'", StringOptions.AllowsLineBreak);
   var stmt = new NonTerminal("stmt");
   stmt.Rule = str | Empty;
   this.Root = stmt; 
 }
        /// <summary>
        /// Class constructor and grammar definition
        /// </summary>
        public FtpGrammar()
            : base(false)
        {
            // declare keywords
            var openKeyword = ToTerm("open");
            var changeDirKeyword = ToTerm("cd");
            var dirKeyword = ToTerm("dir");
            var listKeyword = ToTerm("ls");
            var closeKeyword = ToTerm("close");
            var getKeyword = ToTerm("get");
            var byeKeyword = ToTerm("bye");
            var backfolderKeyword = ToTerm("..");
            var rootfolderKeyword = ToTerm(@"\");

            // declare non-terminals
            var program = new NonTerminal("program");
            var commandList = new NonTerminal("commandList");
            var command = new NonTerminal("command");
            var openCommand = new NonTerminal("open");
            var changeDirCommand = new NonTerminal("cd");
            var dirCommand = new NonTerminal("dir");
            var closeCommand = new NonTerminal("close");
            var getCommand = new NonTerminal("get");
            var byeCommand = new NonTerminal("byeCommand");
            var url = new NonTerminal("url");
            var folderName = new NonTerminal("folderName");

            var quotedUrl = new StringLiteral("quotedUrl", "\"");
            var unquotedUrl = new IdentifierTerminal("unquotedUrl");
            var quotedIdentifier = new StringLiteral("quotedIdentifier", "\"");
            var unquotedIdentifier = new IdentifierTerminal("unquotedIdentifier");
            var filename = new RegexBasedTerminal("filename", @"[a-zA-Z0-9\.\-_]+"); // note: space not allowed.

            // grammar rules
            program.Rule = commandList;
            commandList.Rule = this.MakePlusRule(commandList, null, command);
            command.Rule = openCommand | changeDirCommand | dirCommand | closeCommand | getCommand | byeCommand;

            openCommand.Rule = openKeyword + url + this.NewLine; // string_literal + string_literal +
            changeDirCommand.Rule = changeDirKeyword + rootfolderKeyword + this.NewLine | changeDirKeyword + backfolderKeyword + this.NewLine | changeDirKeyword + folderName + this.NewLine;
            dirCommand.Rule = (dirKeyword | listKeyword) + this.NewLine;
            closeCommand.Rule = closeKeyword + this.NewLine;
            getCommand.Rule = getKeyword + unquotedIdentifier + this.NewLine; // vai ser preciso usar uma regex para o nome do ficheiro
            byeCommand.Rule = byeKeyword + this.NewLine;

            //// string regex = @"^[a-zA-Z0-9\.-_ ]+$" (cuidado com ., .., ...) e os espaços
            //// inválidos: \/:*?"<>|

            url.Rule = quotedUrl | unquotedUrl;
            folderName.Rule = quotedIdentifier | filename;

            // remove these notes as children in the AST
            this.MarkPunctuation("open", "dir", "ls", "close", "get", "cd", "bye");
            this.Root = program;

            // LanguageFlags |= LanguageFlags.CreateAst;
        }
Beispiel #30
0
        public IfBlockRules(PieGrammar grammar)
        {
            this.grammar = grammar;

            SimpleIfBlock = new NonTerminal("simple_if_block");
            BodiedIfBlock = new NonTerminal("bodied_if_block");
            SimpleElseBlock = new NonTerminal("simple_else_block");
            BodiedElseBlock = new NonTerminal("bodied_else_block");
        }
Beispiel #31
0
        public PowerPCGrammar()
            : base(false)
        {
            var number = new NumberLiteral("number", NumberOptions.Default);
            var REGCHAR = ToTerm("r");
            REGCHAR.AllowAlphaAfterKeyword = true;
            var register = new NonTerminal("register");
            register.Rule = REGCHAR + number;

            var program = new NonTerminal("program");
            var statementList = new NonTerminal("statementList");
            var statement = new NonTerminal("statement");
            var comma = ",";

            var li = new NTerminal("li");
            var add = new NTerminal("add");
            var addi = new NTerminal("addi");
            var addc = new NTerminal("addc");
            var and = new NTerminal("and");
            var andc = new NTerminal("andc");
            var andi = new NTerminal("andi");
            var andis = new NTerminal("andis");
            var cmp = new NTerminal("cmp");
            var sub = new NTerminal("sub");
            var subi = new NTerminal("subi");
            var print = new NTerminal("print");

            li.Rule = li.term + register + comma + number;
            add.Rule = add.term + register + comma + register + comma + register;
            addi.Rule = addi.term + register + comma + register + comma + number;
            addc.Rule = addc.term + register + comma + register + comma + register;
            and.Rule = and.term + register + comma + register + comma + register;
            andc.Rule = andc.term + register + comma + register + comma + register;
            andi.Rule = andi.term + register + comma + register + comma + number;
            andis.Rule = andis.term + register + comma + register + comma + number;
            cmp.Rule = cmp.term + register + comma + register;
            sub.Rule = sub.term + register + comma + register + comma + register;
            subi.Rule = subi.term + register + comma + register + comma + number;

            print.Rule = print.term | print.term + register | print.term + register + "..." + register;

            program.Rule = statementList;
            statementList.Rule = MakeStarRule(statementList, NewLine, statement);

            this.MarkPunctuation(comma, ";", "...");

            foreach (NTerminal n in NTerminal.termList)
            {
                if (statement.Rule == null)
                    statement.Rule = n.keyTerm;
                else
                    statement.Rule = statement.Rule | n.keyTerm;
                MarkPunctuation(n.term);
            }

            this.Root = program;
        }
Beispiel #32
0
        protected override NonTerminal MakeRoot()
        {
            Semicolon = ToTerm(".");

            var root = new NonTerminal("root");
            Productions(root);

            return root;
        }
 public override void ForGeometry(NonTerminal geometryDef)
 {
     AstBuilder(geometryDef, (context, node) =>
     {
         node.AstNode = node.ChildNodes.Count == 1
             ? node.ChildNodes[0].AstNode
             : new Feature(new GeometryCollection(node.ChildNodes.Select(ptn => ptn.AstNode).OfType<IGeometryObject>().ToList()));
     });
 }
Beispiel #34
0
 public NonTerminal Star()
 {
     if (_star != null)
     {
         return(_star);
     }
     _star      = new NonTerminal(this.Name + "*");
     _star.Rule = Grammar.MakeStarRule(_star, this);
     return(_star);
 }
Beispiel #35
0
 public NonTerminal Plus()
 {
     if (_plus != null)
     {
         return(_plus);
     }
     _plus      = new NonTerminal(this.Name + "+");
     _plus.Rule = Grammar.MakePlusRule(_plus, this);
     return(_plus);
 }
Beispiel #36
0
 NonTerminal _q, _plus, _star; //cash them
 public NonTerminal Q()
 {
     if (_q != null)
     {
         return(_q);
     }
     _q      = new NonTerminal(this.Name + "?");
     _q.Rule = this | Grammar.CurrentGrammar.Empty;
     return(_q);
 }
Beispiel #37
0
 public static BnfExpression MakePlusRule(NonTerminal listNonTerminal, BnfTerm delimiter, BnfTerm listMember, TermListOptions options) {
    bool allowTrailingDelimiter = (options & TermListOptions.AllowTrailingDelimiter) != 0;
   if (delimiter == null || !allowTrailingDelimiter)
     return MakePlusRule(listNonTerminal, delimiter, listMember); 
   //create plus list
   var plusList = new NonTerminal(listMember.Name + "+"); 
   plusList.Rule = MakePlusRule(listNonTerminal, delimiter, listMember);
   listNonTerminal.Rule = plusList | plusList + delimiter; 
   listNonTerminal.SetFlag(TermFlags.IsListContainer); 
   return listNonTerminal.Rule; 
 }
Beispiel #38
0
        protected BnfExpression MakeListRule(NonTerminal list, BnfTerm delimiter, BnfTerm listMember, TermListOptions options = TermListOptions.PlusList)
        {
            //If it is a star-list (allows empty), then we first build plus-list
            var isPlusList         = !options.IsSet(TermListOptions.AllowEmpty);
            var allowTrailingDelim = options.IsSet(TermListOptions.AllowTrailingDelimiter) && delimiter != null;
            //"plusList" is the list for which we will construct expression - it is either extra plus-list or original list.
            // In the former case (extra plus-list) we will use it later to construct expression for list
            NonTerminal plusList = isPlusList ? list : new NonTerminal(listMember.Name + "+");

            plusList.SetFlag(TermFlags.IsList);
            plusList.Rule = plusList; // rule => list
            if (delimiter != null)
            {
                plusList.Rule += delimiter; // rule => list + delim
            }
            if (options.IsSet(TermListOptions.AddPreferShiftHint))
            {
                plusList.Rule += PreferShiftHere(); // rule => list + delim + PreferShiftHere()
            }
            plusList.Rule += listMember;            // rule => list + delim + PreferShiftHere() + elem
            plusList.Rule |= listMember;            // rule => list + delim + PreferShiftHere() + elem | elem
            if (isPlusList)
            {
                // if we build plus list - we're almost done; plusList == list
                // add trailing delimiter if necessary; for star list we'll add it to final expression
                if (allowTrailingDelim)
                {
                    plusList.Rule |= list + delimiter; // rule => list + delim + PreferShiftHere() + elem | elem | list + delim
                }
            }
            else
            {
                // Setup list.Rule using plus-list we just created
                list.Rule = Empty | plusList;
                if (allowTrailingDelim)
                {
                    list.Rule |= plusList + delimiter | delimiter;
                }
                plusList.SetFlag(TermFlags.NoAstNode);
                list.SetFlag(TermFlags.IsListContainer); //indicates that real list is one level lower
            }
            return(list.Rule);
        }//method
Beispiel #39
0
 public Parser(LanguageData language, NonTerminal root)
 {
     Language = language;
     Data     = Language.ParserData;
     _grammar = Language.Grammar;
     Context  = new ParsingContext(this);
     Scanner  = new Scanner(this);
     Root     = root;
     if (Root == null)
     {
         Root         = Language.Grammar.Root;
         InitialState = Language.ParserData.InitialState;
     }
     else
     {
         if (Root != Language.Grammar.Root && !Language.Grammar.SnippetRoots.Contains(Root))
         {
             throw new Exception(string.Format(Resources.ErrRootNotRegistered, root.Name));
         }
         InitialState = Language.ParserData.InitialStates[Root];
     }
 }
Beispiel #40
0
        protected BnfExpression MakeListRule(NonTerminal list, BnfTerm delimiter, BnfTerm listMember, TermListOptions options = TermListOptions.PlusList)
        {
            //If it is a star-list (allows empty), then we first build plus-list
            var         isStarList = options.IsSet(TermListOptions.AllowEmpty);
            NonTerminal plusList   = isStarList ? new NonTerminal(listMember.Name + "+") : list;

            //"list" is the real list for which we will construct expression - it is either extra plus-list or original listNonTerminal.
            // In the latter case we will use it later to construct expression for listNonTerminal
            plusList.Rule = plusList; // rule => list
            if (delimiter != null)
            {
                plusList.Rule += delimiter; // rule => list + delim
            }
            if (options.IsSet(TermListOptions.AddPreferShiftHint))
            {
                plusList.Rule += PreferShiftHere(); // rule => list + delim + PreferShiftHere()
            }
            plusList.Rule += listMember;            // rule => list + delim + PreferShiftHere() + elem
            plusList.Rule |= listMember;            // rule => list + delim + PreferShiftHere() + elem | elem
            //trailing delimiter
            if (options.IsSet(TermListOptions.AllowTrailingDelimiter) & delimiter != null)
            {
                plusList.Rule |= list + delimiter; // => list + delim + PreferShiftHere() + elem | elem | list + delim
            }
            // set Rule value
            plusList.SetFlag(TermFlags.IsList);
            //If we do not use exra list - we're done, return list.Rule
            if (plusList == list)
            {
                return(list.Rule);
            }
            // Let's setup listNonTerminal.Rule using plus-list we just created
            //If we are here, TermListOptions.AllowEmpty is set, so we have star-list
            list.Rule = Empty | plusList;
            plusList.SetFlag(TermFlags.NoAstNode);
            list.SetFlag(TermFlags.IsListContainer); //indicates that real list is one level lower
            return(list.Rule);
        }//method
Beispiel #41
0
 public ParseTreeNode(NonTerminal term, SourceSpan span)
     : this()
 {
     Term = term;
     Span = span;
 }
Beispiel #42
0
 public static BnfExpression MakeStarRule(NonTerminal listNonTerminal, BnfTerm listMember)
 {
     return(MakeStarRule(listNonTerminal, null, listMember, TermListOptions.None));
 }
Beispiel #43
0
 public override void Modify(NonTerminal node)
 {
     Grammar.MarkTransient(node);
 }
Beispiel #44
0
 public Production(NonTerminal lvalue)
 {
     LValue = lvalue;
 }
Beispiel #45
0
 public override void Modify(NonTerminal node)
 {
     node.Flags = TermFlags.None;
     node.AstConfig.NodeCreator = _nodeCreator;
 }
Beispiel #46
0
 public static BnfExpression MakePlusRule(NonTerminal listNonTerminal, BnfTerm listMember)
 {
     return(MakePlusRule(listNonTerminal, null, listMember));
 }
Beispiel #47
0
 public static BnfExpression MakeStarRule(NonTerminal listNonTerminal, BnfTerm delimiter, BnfTerm listMember) {
   return MakeStarRule(listNonTerminal, delimiter, listMember, TermListOptions.None); 
 }
Beispiel #48
0
        internal readonly Construction.LR0ItemList LR0Items = new Construction.LR0ItemList(); //LR0 items based on this production

        public Production(NonTerminal lvalue)
        {
            LValue = lvalue;
        }//constructor
Beispiel #49
0
 public BnfExpression MakeStarRule(NonTerminal listNonTerminal, BnfTerm delimiter, BnfTerm listMember)
 {
     return(MakeListRule(listNonTerminal, delimiter, listMember, TermListOptions.StarList));
 }
Beispiel #50
0
 public BnfExpression MakePlusRule(NonTerminal listNonTerminal, BnfTerm delimiter, BnfTerm listMember)
 {
     return(MakeListRule(listNonTerminal, delimiter, listMember));
 }
Beispiel #51
0
 public virtual void Modify(NonTerminal nt)
 {
     _modify(nt);
 }