コード例 #1
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);
        }
コード例 #2
0
ファイル: GrammarDataBuilder.cs プロジェクト: hozuki/irony-vs
        private NonTerminal CreateAugmentedRoot(NonTerminal root)
        {
            var result = new NonTerminal(root.Name + "'", root + _grammar.Eof);

            result.SetFlag(TermFlags.NoAstNode); //mark that we don't need AST node here
            return(result);
        }
コード例 #3
0
ファイル: Grammar.cs プロジェクト: joewan/xenko
 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;
 }
コード例 #4
0
ファイル: Grammar.cs プロジェクト: wanglong/irony
        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
コード例 #5
0
ファイル: Grammar.cs プロジェクト: joewan/xenko
 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; 
 }
コード例 #6
0
ファイル: Grammar.cs プロジェクト: JamesTryand/Pash2
        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
コード例 #7
0
ファイル: GrammarDataBuilder.cs プロジェクト: hozuki/irony-vs
 private static bool ComputeNullability(NonTerminal nonTerminal)
 {
     foreach (var prod in nonTerminal.Productions)
     {
         if (prod.RValues.Count == 0)
         {
             nonTerminal.SetFlag(TermFlags.IsNullable);
             return(true); //decided, Nullable
         }
         //If production has terminals, it is not nullable and cannot contribute to nullability
         if (prod.Flags.IsSet(ProductionFlags.HasTerminals))
         {
             continue;
         }
         //Go through all elements of production and check nullability
         var allNullable = prod.RValues.All(child => child.Flags.IsSet(TermFlags.IsNullable));
         if (allNullable)
         {
             nonTerminal.SetFlag(TermFlags.IsNullable);
             return(true);
         }
     }
     return(false); //cannot decide
 }
コード例 #8
0
ファイル: SqlGrammar.cs プロジェクト: boyangwm/DBScribe-Ext
        public SqlGrammar()
            : base(false)
        {
            //SQL is case insensitive
              //Terminals
              var comment = new CommentTerminal("comment", "/*", "*/");
              var lineComment = new CommentTerminal("line_comment", "--", "\n", "\r\n");
              NonGrammarTerminals.Add(comment);
              NonGrammarTerminals.Add(lineComment);
              var number = new NumberLiteral("number");
              var string_literal = new StringLiteral("string", "'", StringOptions.AllowsDoubledQuote);
              var Id_simple = TerminalFactory.CreateSqlExtIdentifier(this, "id_simple"); //covers normal identifiers (abc) and quoted id's ([abc d], "abc d")
              var comma = ToTerm(",");
              var dot = ToTerm(".");
              var CREATE = ToTerm("CREATE");
              var NULL = ToTerm("NULL");
              var NOT = ToTerm("NOT");
              var UNIQUE = ToTerm("UNIQUE");
              var WITH = ToTerm("WITH");
              var TABLE = ToTerm("TABLE");
              var ALTER = ToTerm("ALTER");
              var ADD = ToTerm("ADD");
              var COLUMN = ToTerm("COLUMN");
              var DROP = ToTerm("DROP");
              var CONSTRAINT = ToTerm("CONSTRAINT");
              var INDEX = ToTerm("INDEX");
              var ON = ToTerm("ON");
              var KEY = ToTerm("KEY");
              var PRIMARY = ToTerm("PRIMARY");
              var INSERT = ToTerm("INSERT");
              var INTO = ToTerm("INTO");
              var UPDATE = ToTerm("UPDATE");
              var SET = ToTerm("SET");
              var VALUES = ToTerm("VALUES");
              var DELETE = ToTerm("DELETE");
              var SELECT = ToTerm("SELECT");
              var FROM = ToTerm("FROM");
              var AS = ToTerm("AS");
              var COUNT = ToTerm("COUNT");
              var JOIN = ToTerm("JOIN");
              var BY = ToTerm("BY");

              //Non-terminals
              var Id = new NonTerminal("Id");
              var stmt = new NonTerminal("stmt");
              var createTableStmt = new NonTerminal("createTableStmt");
              var createIndexStmt = new NonTerminal("createIndexStmt");
              var alterStmt = new NonTerminal("alterStmt");
              var dropTableStmt = new NonTerminal("dropTableStmt");
              var dropIndexStmt = new NonTerminal("dropIndexStmt");
              var selectStmt = new NonTerminal("selectStmt");
              var insertStmt = new NonTerminal("insertStmt");
              var updateStmt = new NonTerminal("updateStmt");
              var deleteStmt = new NonTerminal("deleteStmt");
              var fieldDef = new NonTerminal("fieldDef");
              var fieldDefList = new NonTerminal("fieldDefList");
              var nullSpecOpt = new NonTerminal("nullSpecOpt");
              var typeName = new NonTerminal("typeName");
              var typeSpec = new NonTerminal("typeSpec");
              var typeParamsOpt = new NonTerminal("typeParams");
              var constraintDef = new NonTerminal("constraintDef");
              var constraintListOpt = new NonTerminal("constraintListOpt");
              var constraintTypeOpt = new NonTerminal("constraintTypeOpt");
              var idlist = new NonTerminal("idlist");
              var idlistPar = new NonTerminal("idlistPar");
              var uniqueOpt = new NonTerminal("uniqueOpt");
              var orderList = new NonTerminal("orderList");
              var orderMember = new NonTerminal("orderMember");
              var orderDirOpt = new NonTerminal("orderDirOpt");
              var withClauseOpt = new NonTerminal("withClauseOpt");
              var alterCmd = new NonTerminal("alterCmd");
              var insertData = new NonTerminal("insertData");
              var intoOpt = new NonTerminal("intoOpt");
              var assignList = new NonTerminal("assignList");
              var whereClauseOpt = new NonTerminal("whereClauseOpt");
              var assignment = new NonTerminal("assignment");
              var expression = new NonTerminal("expression");
              var exprList = new NonTerminal("exprList");
              var selRestrOpt = new NonTerminal("selRestrOpt");
              var selList = new NonTerminal("selList");
              var intoClauseOpt = new NonTerminal("intoClauseOpt");
              var fromClauseOpt = new NonTerminal("fromClauseOpt");
              var groupClauseOpt = new NonTerminal("groupClauseOpt");
              var havingClauseOpt = new NonTerminal("havingClauseOpt");
              var orderClauseOpt = new NonTerminal("orderClauseOpt");
              var columnItemList = new NonTerminal("columnItemList");
              var columnItem = new NonTerminal("columnItem");
              var columnSource = new NonTerminal("columnSource");
              var asOpt = new NonTerminal("asOpt");
              var aliasOpt = new NonTerminal("aliasOpt");
              var aggregate = new NonTerminal("aggregate");
              var aggregateArg = new NonTerminal("aggregateArg");
              var aggregateName = new NonTerminal("aggregateName");
              var tuple = new NonTerminal("tuple");
              var joinChainOpt = new NonTerminal("joinChainOpt");
              var joinSubOpt = new NonTerminal("joinSubOpt");
              var joinKindOpt = new NonTerminal("joinKindOpt");
              var term = new NonTerminal("term");
              var subTerm = new NonTerminal("subTerm");
              var unExpr = new NonTerminal("unExpr");
              var unOp = new NonTerminal("unOp");
              var binExpr = new NonTerminal("binExpr");
              var binOp = new NonTerminal("binOp");
              var betweenExpr = new NonTerminal("betweenExpr");
              var inExpr = new NonTerminal("inExpr");
              var parSelectStmt = new NonTerminal("parSelectStmt");
              var notOpt = new NonTerminal("notOpt");
              var funCall = new NonTerminal("funCall");
              var stmtLine = new NonTerminal("stmtLine");
              var semiOpt = new NonTerminal("semiOpt");
              var stmtList = new NonTerminal("stmtList");
              var funArgs = new NonTerminal("funArgs");
              var inStmt = new NonTerminal("inStmt");

              //BNF Rules
              this.Root = stmtList;
              stmtLine.Rule = stmt + semiOpt;
              semiOpt.Rule = Empty | ";";
              stmtList.Rule = MakePlusRule(stmtList, stmtLine);

              //ID
              Id.Rule = MakePlusRule(Id, dot, Id_simple) | "'" + Id + "'";

              stmt.Rule = createTableStmt | createIndexStmt | alterStmt
                | dropTableStmt | dropIndexStmt
                | selectStmt | insertStmt | updateStmt | deleteStmt
                | "GO" ;
              //Create table
              createTableStmt.Rule = CREATE + TABLE + Id + "(" + fieldDefList + ")" + constraintListOpt;
              fieldDefList.Rule = MakePlusRule(fieldDefList, comma, fieldDef);
              fieldDef.Rule = Id + typeName + typeParamsOpt + nullSpecOpt;
              nullSpecOpt.Rule = NULL | NOT + NULL | Empty;
              typeName.Rule = ToTerm("BIT") | "DATE" | "TIME" | "TIMESTAMP" | "DECIMAL" | "REAL" | "FLOAT" | "SMALLINT" | "INTEGER"
                                   | "INTERVAL" | "CHARACTER"
                                   // MS SQL types:
                                   | "DATETIME" | "INT" | "DOUBLE" | "CHAR" | "NCHAR" | "VARCHAR" | "NVARCHAR"
                                   | "IMAGE" | "TEXT" | "NTEXT";
              typeParamsOpt.Rule = "(" + number + ")" | "(" + number + comma + number + ")" | Empty;
              constraintDef.Rule = CONSTRAINT + Id + constraintTypeOpt;
              constraintListOpt.Rule = MakeStarRule(constraintListOpt, constraintDef );
              constraintTypeOpt.Rule = PRIMARY + KEY + idlistPar | UNIQUE + idlistPar | NOT + NULL + idlistPar
                             | "Foreign" + KEY + idlistPar + "References" + Id + idlistPar;
              idlistPar.Rule = Empty | "(" + idlist + ")";
              idlist.Rule = MakePlusRule(idlist, comma, Id);

              //Create Index
              createIndexStmt.Rule = CREATE + uniqueOpt + INDEX + Id + ON + Id + orderList + withClauseOpt;
              uniqueOpt.Rule = Empty | UNIQUE;
              orderList.Rule = MakePlusRule(orderList, comma, orderMember);
              orderMember.Rule = Id + orderDirOpt;
              orderDirOpt.Rule = Empty | "ASC" | "DESC";
              withClauseOpt.Rule = Empty | WITH + PRIMARY | WITH + "Disallow" + NULL | WITH + "Ignore" + NULL;

              //Alter
              alterStmt.Rule = ALTER + TABLE + Id + alterCmd;
              alterCmd.Rule = ADD + COLUMN  + fieldDefList + constraintListOpt
                    | ADD + constraintDef
                    | DROP + COLUMN + Id
                    | DROP + CONSTRAINT + Id;

              //Drop stmts
              dropTableStmt.Rule = DROP + TABLE + Id;
              dropIndexStmt.Rule = DROP + INDEX + Id + ON + Id;

              //Insert stmt
              insertStmt.Rule = INSERT + intoOpt + Id + idlistPar + insertData;
              insertData.Rule = selectStmt | VALUES + "(" + exprList + ")";
              intoOpt.Rule = Empty | INTO; //Into is optional in MSSQL

              //Update stmt
              updateStmt.Rule = UPDATE + Id + SET + assignList + whereClauseOpt;
              assignList.Rule = MakePlusRule(assignList, comma, assignment);
              assignment.Rule = Id + "=" + expression | Id;

              //Delete stmt
              deleteStmt.Rule = DELETE + FROM + Id + whereClauseOpt;

              //Select stmt
              selectStmt.Rule = SELECT + selRestrOpt + selList + intoClauseOpt + fromClauseOpt + whereClauseOpt +
                        groupClauseOpt + havingClauseOpt + orderClauseOpt;
              selRestrOpt.Rule = Empty | "ALL" | "DISTINCT";
              selList.Rule = columnItemList | "*" | Id | number;
              columnItemList.Rule = MakePlusRule(columnItemList, comma, columnItem);
              columnItem.Rule = columnSource + aliasOpt;
              aliasOpt.Rule = Empty | asOpt + Id;
              asOpt.Rule = Empty | AS;
              columnSource.Rule = aggregate | Id;
              aggregate.Rule = aggregateName + "(" + aggregateArg + ")";
              aggregateArg.Rule = expression | "*";
              aggregateName.Rule = COUNT | "Avg" | "Min" | "Max" | "StDev" | "StDevP" | "Sum" | "Var" | "VarP";
              intoClauseOpt.Rule = Empty | INTO + Id;
              fromClauseOpt.Rule = Empty | FROM + idlist + joinChainOpt | FROM + idlist + aliasOpt | FROM + idlist + aliasOpt + joinChainOpt;
              joinChainOpt.Rule = Empty | joinSubOpt | joinSubOpt + aliasOpt;
              joinSubOpt.Rule = Empty | joinKindOpt + JOIN + idlist | joinKindOpt + JOIN + idlist + joinKindOpt + JOIN + idlist | joinKindOpt + JOIN + idlist + ON + Id + "=" + Id;
              joinKindOpt.Rule = Empty | "INNER" | "LEFT" | "RIGHT" | "NATURAL";
              whereClauseOpt.Rule = Empty | "WHERE" + expression;
              groupClauseOpt.Rule = Empty | "GROUP" + BY + idlist;
              havingClauseOpt.Rule = Empty | "HAVING" + expression;
              orderClauseOpt.Rule = Empty | "ORDER" + BY + orderList;

              //Expression
              exprList.Rule = MakePlusRule(exprList, comma, expression);
              expression.Rule = term | unExpr | binExpr;// | betweenExpr; //-- BETWEEN doesn't work - yet; brings a few parsing conflicts
              term.Rule = subTerm | "'"+subTerm+"'";
              subTerm.Rule = Id | string_literal | number | funCall | tuple | parSelectStmt | Id_simple;// | inStmt;
              tuple.Rule = "(" + exprList + ")";
              parSelectStmt.Rule = "(" + selectStmt + ")";
              unExpr.Rule = unOp + term;
              unOp.Rule = NOT | "+" | "-" | "~";
              binExpr.Rule = expression + binOp + expression;
              binOp.Rule = ToTerm("+") | "-" | "*" | "/" | "%" //arithmetic
                 | "&" | "|" | "^"                     //bit
                 | "=" | ">" | "<" | ">=" | "<=" | "<>" | "!=" | "!<" | "!>"
                 | "AND" | "OR" | "LIKE" | NOT + "LIKE" | "IN" | NOT + "IN" ;
              betweenExpr.Rule = expression + notOpt + "BETWEEN" + expression + "AND" + expression;
              notOpt.Rule = Empty | NOT;
              //funCall covers some psedo-operators and special forms like ANY(...), SOME(...), ALL(...), EXISTS(...), IN(...)
              funCall.Rule = Id + "(" + funArgs  + ")";
              funArgs.Rule = selectStmt | exprList | Empty;
              inStmt.Rule = expression + "IN" + "(" + exprList + ")";

              //Operators
              RegisterOperators(10, "*", "/", "%");
              RegisterOperators(9, "+", "-");
              RegisterOperators(8, "=", ">", "<", ">=", "<=", "<>", "!=", "!<", "!>", "LIKE", "IN");
              RegisterOperators(7, "^", "&", "|");
              RegisterOperators(6, NOT);
              RegisterOperators(5, "AND");
              RegisterOperators(4, "OR");

              MarkPunctuation(",", "(", ")");
              MarkPunctuation(asOpt, semiOpt);
              //Note: we cannot declare binOp as transient because it includes operators "NOT LIKE", "NOT IN" consisting of two tokens.
              // Transient non-terminals cannot have more than one non-punctuation child nodes.
              // Instead, we set flag InheritPrecedence on binOp , so that it inherits precedence value from it's children, and this precedence is used
              // in conflict resolution when binOp node is sitting on the stack
              base.MarkTransient(stmt, term, asOpt, aliasOpt, stmtLine, expression, unOp, tuple);
              binOp.SetFlag(TermFlags.InheritPrecedence);
        }
コード例 #9
0
ファイル: SonesGQLGrammar.cs プロジェクト: cosh/sones
        public SonesGQLGrammar(IGraphDB iGraphDb)
            : base(false)
        {
            _iGraphDB = iGraphDb;

            #region SetLanguageFlags

            base.LanguageFlags |= LanguageFlags.CreateAst;
            //this.SetLanguageFlags(LanguageFlags.CreateAst);
            //this.SetLanguageFlags(LanguageFlags.AutoDetectTransient, false);

            #endregion

            #region Terminals

            #region Comments

            //Terminals
            var comment = new CommentTerminal("comment", "/*", "*/");
            var lineComment = new CommentTerminal("line_comment", "--", "\n", "\r\n");
            //TODO: remove block comment, added for testing LUA-style comments
            var blockComment = new CommentTerminal("block_comment", "--[[", "]]");
            NonGrammarTerminals.Add(comment);
            NonGrammarTerminals.Add(lineComment);
            NonGrammarTerminals.Add(blockComment);

            #endregion

            #region Available value defs: Number, String, Name

            var number = new NumberLiteral("number", NumberOptions.AllowSign | NumberOptions.DisableQuickParse);
            number.DefaultIntTypes = new TypeCode[] { TypeCode.UInt64, TypeCode.Int64, NumberLiteral.TypeCodeBigInt };
            var string_literal = new StringLiteral("string", "'", StringOptions.AllowsDoubledQuote | StringOptions.AllowsLineBreak);
            var location_literal = new StringLiteral("file", "'", StringOptions.AllowsDoubledQuote | StringOptions.AllowsLineBreak | StringOptions.NoEscapes);

            var name = new IdentifierTerminal("name", "ִײ�הצ��0123456789_", "ִײ�הצ�0123456789$_");

            #endregion

            //var name_ext            = TerminalFactory.CreateSqlExtIdentifier("name_ext"); //removed, because we do not want to hav types or sth else with whitespaces, otherwise it conflicts with tupleSet

            #region Symbols

            S_CREATE = ToTerm("CREATE");
            S_comma = ToTerm(",");
            S_dot = ToTerm(".");
            S_ASTERISK = ToTerm("*");
            S_EQUALS = ToTerm("=");
            S_QUESTIONMARK_EQUALS = ToTerm("?=");

            S_colon = ToTerm(":");
            S_BRACKET_LEFT = ToTerm(TERMINAL_BRACKET_LEFT);
            S_BRACKET_RIGHT = ToTerm(TERMINAL_BRACKET_RIGHT);
            S_TUPLE_BRACKET_LEFT = ToTerm("[");
            S_TUPLE_BRACKET_RIGHT = ToTerm("]");
            S_edgeInformationDelimiterSymbol = ToTerm(SonesGQLConstants.EdgeInformationDelimiterSymbol);
            S_edgeTraversalDelimiter = ToTerm(SonesGQLConstants.EdgeTraversalDelimiterSymbol);
            S_NULL = ToTerm("NULL");
            S_NOT = ToTerm("NOT");
            S_UNIQUE = ToTerm("UNIQUE");
            S_WITH = ToTerm("WITH");
            S_ALTER = ToTerm("ALTER");
            S_ADD = ToTerm("ADD");
            S_TO = ToTerm("TO");
            S_COLUMN = ToTerm("COLUMN");
            S_DROP = ToTerm("DROP");
            S_RENAME = ToTerm("RENAME");
            S_CONSTRAINT = ToTerm("CONSTRAINT");
            S_INDEX = ToTerm("INDEX");
            S_INDICES = ToTerm("INDICES");
            S_ON = ToTerm("ON");
            S_KEY = ToTerm("KEY");
            S_INSERT = ToTerm("INSERT");
            S_INTO = ToTerm("INTO");
            S_UPDATE = ToTerm("UPDATE");
            S_INSERTORUPDATE = ToTerm("INSERTORUPDATE");
            S_INSERTORREPLACE = ToTerm("INSERTORREPLACE");
            S_REPLACE = ToTerm("REPLACE");
            S_SET = ToTerm(TERMINAL_SET);
            S_REMOVE = ToTerm("REMOVE");
            S_VALUES = ToTerm("VALUES");
            S_DELETE = ToTerm("DELETE");
            S_SELECT = ToTerm("SELECT");
            S_FROM = ToTerm("FROM");
            S_AS = ToTerm("AS");
            S_COUNT = ToTerm("COUNT");
            S_JOIN = ToTerm("JOIN");
            S_BY = ToTerm("BY");
            S_WHERE = ToTerm("WHERE");
            S_TYPE = ToTerm("TYPE");
            S_TYPES = ToTerm("TYPES");
            S_VERTEX = ToTerm("VERTEX");
            S_VERTICES = ToTerm("VERTICES");
            S_EDITION = ToTerm("EDITION");
            S_INDEXTYPE = ToTerm("INDEXTYPE");
            S_LIST = ToTerm(TERMINAL_LIST);
            S_ListTypePrefix = ToTerm(TERMINAL_LT);
            S_ListTypePostfix = ToTerm(TERMINAL_GT);
            S_EXTENDS = ToTerm("EXTENDS");
            S_ATTRIBUTES = ToTerm("ATTRIBUTES");
            S_LIMIT = ToTerm("LIMIT");
            S_DEPTH = ToTerm("DEPTH");
            S_REFERENCE = ToTerm("REFERENCE");
            S_REF = ToTerm("REF");
            S_REFUUID = ToTerm("REFUUID");
            S_REFERENCEUUID = ToTerm("REFERENCEUUID");
            S_LISTOF = ToTerm(SonesGQLConstants.LISTOF);
            S_SETOF = ToTerm(SonesGQLConstants.SETOF);
            S_SETOFUUIDS = ToTerm(SonesGQLConstants.SETOFUUIDS);
            S_UUID = ToTerm("VertexID");
            S_OFFSET = ToTerm("OFFSET");
            S_TRUNCATE = ToTerm("TRUNCATE");
            S_TRUE = ToTerm(TERMINAL_TRUE);
            S_FALSE = ToTerm(TERMINAL_FALSE);
            S_ASC = ToTerm(TERMINAL_ASC);
            S_DESC = ToTerm(TERMINAL_DESC);
            S_QUEUESIZE = ToTerm(TERMINAL_QUEUESIZE);
            S_WEIGHTED = ToTerm(TERMINAL_WEIGHTED);
            S_GET = ToTerm("GET");
            S_ATTRIBUTE = ToTerm("ATTRIBUTE");
            S_DEFAULT = ToTerm("DEFAULT");
            S_INCOMINGEDGE = ToTerm(SonesGQLConstants.INCOMINGEDGE);
            S_INCOMINGEDGES = ToTerm(SonesGQLConstants.INCOMINGEDGES);
            S_DESCRIBE = ToTerm("DESCRIBE");
            S_FUNCTION = ToTerm("FUNCTION");
            S_FUNCTIONS = ToTerm("FUNCTIONS");
            S_AGGREGATE = ToTerm("AGGREGATE");
            S_AGGREGATES = ToTerm("AGGREGATES");
            S_INDICES = ToTerm("INDICES");
            S_EDGE = ToTerm("EDGE");
            S_EDGES = ToTerm("EDGES");
            S_MANDATORY = ToTerm("MANDATORY");
            S_ABSTRACT = ToTerm("ABSTRACT");
            S_BEGIN = ToTerm("BEGIN");
            S_TRANSACTION = ToTerm("TRANSACTION");
            S_TRANSACTDISTRIBUTED = ToTerm(SonesGQLConstants.TRANSACTION_DISTRIBUTED);
            S_TRANSACTLONGRUNNING = ToTerm(SonesGQLConstants.TRANSACTION_LONGRUNNING);
            S_TRANSACTISOLATION = ToTerm(SonesGQLConstants.TRANSACTION_ISOLATION);
            S_TRANSACTNAME = ToTerm(SonesGQLConstants.TRANSACTION_NAME);
            S_TRANSACTTIMESTAMP = ToTerm(SonesGQLConstants.TRANSACTION_TIMESTAMP);
            S_TRANSACTROLLBACK = ToTerm(SonesGQLConstants.TRANSACTION_ROLLBACK);
            S_TRANSACTCOMMIT = ToTerm(SonesGQLConstants.TRANSACTION_COMMIT);
            S_TRANSACTCOMROLLASYNC = ToTerm(SonesGQLConstants.TRANSACTION_COMROLLASYNC);
            S_ADDTOLIST = ToTerm("+=");
            S_REMOVEFROMLIST = ToTerm("-=");
            S_DUMP = ToTerm("DUMP");
            S_EXPORT = ToTerm("EXPORT");
            S_ALL = ToTerm("ALL");
            S_GDDL = ToTerm("GDDL");
            S_GDML = ToTerm("GDML");
            S_GQL = ToTerm("GQL");
            S_CSV = ToTerm("CSV");
            S_COMMENT = ToTerm("COMMENT");
            S_REBUILD = ToTerm("REBUILD");
            S_DEFINE = ToTerm("DEFINE");
            S_UNDEFINE = ToTerm("UNDEFINE");
            S_VIA = ToTerm("VIA");
            S_LINK = ToTerm("LINK");
            S_UNLINK = ToTerm("UNLINK");
            S_USE = ToTerm("USE");

            #region IMPORT

            S_IMPORT = ToTerm("IMPORT");
            S_COMMENTS = ToTerm("COMMENTS");
            S_PARALLELTASKS = ToTerm("PARALLELTASKS");
            S_VERBOSITY = ToTerm("VERBOSITY");
            S_FORMAT = ToTerm("FORMAT");

            #endregion

            #region options

            S_OPTIONS = ToTerm("OPTIONS");

            #endregion

            #endregion

            #endregion

            #region Non-Terminals

            #region ID related

            NT_Id = new NonTerminal("Id", CreateIDNode);
            var Id_simple = new NonTerminal("id_simple", typeof(AstNode));
            var id_typeAndAttribute = new NonTerminal("id_typeAndAttribute");
            var idlist = new NonTerminal("idlist");
            var id_simpleList = new NonTerminal("id_simpleList");
            var id_simpleDotList = new NonTerminal("id_simpleDotList");
            var IdOrFunc = new NonTerminal("IdOrFunc");
            var IdOrFuncList = new NonTerminal("IdOrFuncList", CreateIDNode);
            var IDOrFuncDelimiter = new NonTerminal("IDOrFuncDelimiter");
            var dotWrapper = new NonTerminal("dotWrapper", CreateDotDelimiter);
            var edgeAccessorWrapper = new NonTerminal("edgeAccessorWrapper", CreateEdgeAccessorDelimiter);
            var EdgeInformation = new NonTerminal("EdgeInformation", CreateEdgeInformation);
            var EdgeTraversalWithFunctions = new NonTerminal("EdgeTraversalWithFunctions", CreateEdgeTraversal);
            var EdgeTraversalWithOutFunctions = new NonTerminal("EdgeTraversalWithOutFunctions", CreateEdgeTraversal);

            #endregion

            #region AStatements

            var singlestmt = new NonTerminal("singlestmt");
            var createIndexStmt = new NonTerminal("createIndexStmt", CreateCreateIndexStatementNode);
            var alterVertexTypeStmt = new NonTerminal("alterVertexTypeStmt", CreateAlterVertexTypeStmNode);
            var alterEdgeTypeStmt = new NonTerminal("alterEdgeTypeStmt", CreateAlterEdgeTypeStmNode);
            var dropVertexTypeStmt = new NonTerminal("dropVertexTypeStmt", CreateDropVertexTypeStmNode);
            var dropEdgeTypeStmt = new NonTerminal("dropEdgeTypeStmt", CreateDropEdgeTypeStmNode);
            var dropIndexStmt = new NonTerminal("dropIndexStmt", CreateDropIndexStmNode);
            var InsertStmt = new NonTerminal("InsertStmt", CreateInsertStatementNode);
            var updateStmt = new NonTerminal("updateStmt", CreateUpdateStatementNode);
            var updateEdgesStmt = new NonTerminal("updateStmt", CreateUpdateEdgesStatementNode);
            var deleteStmt = new NonTerminal("deleteStmt", CreateDeleteStatementNode);
            var SelectStmtGraph = new NonTerminal("SelectStmtGraph", CreateSelectStatementNode);
            var parSelectStmt = new NonTerminal("parSelectStmt", CreatePartialSelectStmtNode);
            var createTypesStmt = new NonTerminal("createTypesStmt", CreateCreateVertexTypesStatementNode);
            var createEdgeTypesStmt = new NonTerminal("createEdgeTypeStmt", CreateCreateEdgeTypesStatementNode);
            var insertorupdateStmt = new NonTerminal("insertorupdateStmt", CreateInsertOrUpdateStatementNode);
            var insertorreplaceStmt = new NonTerminal("insertorreplaceStmt", CreateInsertOrReplaceStatementNode);
            var replaceStmt = new NonTerminal("replaceStmt", CreateReplaceStatementNode);
            var transactStmt = new NonTerminal("transactStmt", CreateTransActionStatementNode);
            var commitRollBackTransactStmt = new NonTerminal("commitRollBackTransactStmt", CreateCommitRollbackTransActionNode);
            var linkStmt = new NonTerminal("linkStmt", CreateLinkStmtNode);
            var unlinkStmt = new NonTerminal("unlinkStmt", CreateUnlinkStmt);

            #endregion

            var deleteStmtMember = new NonTerminal("deleteStmtMember");
            var uniqueOpt = new NonTerminal("uniqueOpt", typeof(UniqueOptNode));
            var IndexAttributeList = new NonTerminal("IndexAttributeList", typeof(IndexAttributeListNode));
            var IndexAttributeMember = new NonTerminal("IndexAttributeMember", typeof(IndexAttributeNode));
            var IndexAttributeType = new NonTerminal("IndexAttributeType");
            var orderByAttributeList = new NonTerminal("orderByAttributeList");
            var orderByAttributeListMember = new NonTerminal("orderByAttributeListMember");
            var AttributeOrderDirectionOpt = new NonTerminal("AttributeOrderDirectionOpt");
            NT_IndexTypeOpt = new NonTerminal("indexTypeOpt", typeof(IndexTypeOptNode));
            var indexNameOpt = new NonTerminal("indextNameOpt", typeof(IndexNameOptNode));
            var editionOpt = new NonTerminal("editionOpt", typeof(EditionOptNode));
            var alterVertexTypeCmd = new NonTerminal("alterVertexTypeCmd", typeof(AlterVertexTypeCommandNode));
            var alterVertexTypeCmdList = new NonTerminal("alterVertexTypeCmdList");
            var alterEdgeTypeCmd = new NonTerminal("alterEdgeTypeCmd", typeof(AlterEdgeTypeCommandNode));
            var alterEdgeTypeCmdList = new NonTerminal("alterEdgeTypeCmdList");
            var insertData = new NonTerminal("insertData");
            var intoOpt = new NonTerminal("intoOpt");
            var assignList = new NonTerminal("assignList");
            NT_whereClauseOpt = new NonTerminal("whereClauseOpt", CreateWhereExpressionNode);
            var extendsOpt = new NonTerminal("extendsOpt");
            var abstractOpt = new NonTerminal("abstractOpt");
            var commentOpt = new NonTerminal("CommentOpt");
            var bulkVertexTypeList = new NonTerminal("bulkVertexTypeList");
            var bulkEdgeTypeList = new NonTerminal("bulkEdgeTypeList");
            var vertexTypeAttributesOpt = new NonTerminal("vertexTypeAttributesOpt");
            var edgeTypeAttributesOpt = new NonTerminal("edgeTypeAttributesOpt");
            var insertValuesOpt = new NonTerminal("insertValuesOpt");
            NT_UseIndex = new NonTerminal("useIndexOpt", CreateUseIndexNode);

            #region Expression

            NT_Expression = new NonTerminal("expression", typeof(ExpressionNode));
            var expressionOfAList = new NonTerminal("expressionOfAList", typeof(ExpressionOfAListNode));
            var BNF_ExprList = new NonTerminal("exprList");
            var unExpr = new NonTerminal("unExpr", CreateUnExpressionNode);
            var unOp = new NonTerminal("unOp");
            var binExpr = new NonTerminal("binExpr", CreateBinaryExpressionNode);
            var binOp = new NonTerminal("binOp");
            var inExpr = new NonTerminal("inExpr");

            #endregion

            #region Select

            var selList = new NonTerminal("selList");
            var fromClauseOpt = new NonTerminal("fromClauseOpt");
            var groupClauseOpt = new NonTerminal("groupClauseOpt");
            var havingClauseOpt = new NonTerminal("havingClauseOpt", typeof(HavingExpressionNode));
            var orderClauseOpt = new NonTerminal("orderClauseOpt", typeof(OrderByNode));
            var selectionList = new NonTerminal("selectionList");
            var selectionListElement = new NonTerminal("selectionListElement", typeof(SelectionListElementNode));
            var aliasOpt = new NonTerminal("aliasOpt");
            var aliasOptName = new NonTerminal("aliasOptName");
            var selectOutputOpt = new NonTerminal("selectOutputOpt", typeof(SelectOutputOptNode));

            #endregion

            #region Aggregates & Functions

            NT_Aggregate = new NonTerminal("aggregate", CreateAggregateNode);
            NT_AggregateArg = new NonTerminal("aggregateArg");
            var function = new NonTerminal("function", CreateFunctionCallNode);
            var functionName = new NonTerminal("functionName");
            NT_FunArgs = new NonTerminal("funArgs");
            NT_FuncCall = new NonTerminal("funCall", CreateFunctionCallNode);

            #endregion

            #region Tuple

            var tuple = new NonTerminal("tuple", typeof(TupleNode));
            var bracketLeft = new NonTerminal(SonesGQLConstants.BracketLeft);
            var bracketRight = new NonTerminal(SonesGQLConstants.BracketRight);

            #endregion

            var term = new NonTerminal("term");
            var notOpt = new NonTerminal("notOpt");

            var VertexType = new NonTerminal(SonesGQLConstants.VertexType, CreateVertexTypeNode);
            var EdgeType = new NonTerminal(SonesGQLConstants.EdgeType, CreateEdgeTypeNode);
            var VertexTypeAttributeList = new NonTerminal("VertexTypeAttributeList");
            var VertexTypeAttrDefinition = new NonTerminal("VertexTypeAttrDefinition", CreateVertexTypeAttributeDefinitionNode);
            var EdgeTypeAttributeList = new NonTerminal("EdgeTypeAttributeList");
            var EdgeTypeAttrDefinition = new NonTerminal("EdgeTypeAttrDefinition", CreateEdgeTypeAttributeDefinitionNode);
            var ResultObject = new NonTerminal("ResultObject");
            var ResultList = new NonTerminal("ResultList");
            var PrefixOperation = new NonTerminal("PrefixOperation");
            var ParameterList = new NonTerminal("ParameterList");
            var VertexTypeList = new NonTerminal("TypeList", CreateVertexTypeListNode);
            NT_AType = new NonTerminal("AType", CreateATypeNode);
            NT_VertexType = new NonTerminal("AType", CreateATypeNode);
            var VertexTypeWrapper = new NonTerminal("TypeWrapper");

            #region Attribute changes

            var AttrAssignList = new NonTerminal("AttrAssignList", CreateAttrAssignListNode);
            var AttrUpdateList = new NonTerminal("AttrUpdateList", typeof(AttributeUpdateOrAssignListNode));
            var EdgeAttrUpdateList = new NonTerminal("EdgeAttrUpdateList", typeof(EdgeAttributeUpdateListNode));
            var AttrAssign = new NonTerminal("AttrAssign", typeof(AttributeAssignNode));
            var AttrRemove = new NonTerminal("AttrRemove", typeof(AttributeRemoveNode));
            var ListAttrUpdate = new NonTerminal("AttrUpdate");
            var AddToListAttrUpdate = new NonTerminal("AddToListAttrUpdate", typeof(AddToListAttrUpdateNode));
            var AddToListAttrUpdateAddTo = new NonTerminal("AddToListAttrUpdateAddTo", CreateAddToListAttrUpdateAddToNode);
            var AddToListAttrUpdateOperator = new NonTerminal("AddToListAttrUpdateOperator", CreateAddToListAttrUpdateOperatorNode);
            var RemoveFromListAttrUpdateAddToRemoveFrom = new NonTerminal("RemoveFromListAttrUpdateAddToRemoveFrom", CreateRemoveFromListAttrUpdateAddToRemoveFromNode);
            var RemoveFromListAttrUpdateAddToOperator = new NonTerminal("RemoveFromListAttrUpdateAddToOperator", CreateRemoveFromListAttrUpdateAddToOperatorNode);
            var RemoveFromListAttrUpdateScope = new NonTerminal("RemoveFromListAttrUpdateScope", CreateRemoveFromListAttrUpdateScope);
            var EdgeAttrUpdate = new NonTerminal("EdgeAttrUpdate", typeof(EdgeAttributeUpdateNode));
            var AttrUpdateOrAssign = new NonTerminal("AttrUpdateOrAssign");
            var CollectionOfDBObjects = new NonTerminal("ListOfDBObjects", typeof(CollectionOfDBObjectsNode));
            var CollectionOfEdges = new NonTerminal("ListOfEdges", typeof(CollectionOfEdgesNode));
            var CollectionOfBasicDBObjects = new NonTerminal("ListOfBasicDBObjects", typeof(CollectionOfBasicDBObjectsNode));
            var VertexTypeVertexIDCollection = new NonTerminal("VertexTypeVertexIDCollection", CreateVertexTypeVertexIDCollection);
            var VertexTypeVertexElement = new NonTerminal("VertexTypeVertexElement", CreateVertexTypeVertexElement);
            var CollectionTuple = new NonTerminal("CollectionTuple", typeof(TupleNode));
            var ExtendedExpressionList = new NonTerminal("ExtendedExpressionList");
            var ExtendedExpression = new NonTerminal("ExtendedExpression", typeof(ExpressionOfAListNode));

            #endregion

            var Reference = new NonTerminal("REFERENCE", typeof(SetRefNode));
            var offsetOpt = new NonTerminal("offsetOpt", typeof(OffsetNode));
            var resolutionDepthOpt = new NonTerminal("resolutionDepthOpt");
            var limitOpt = new NonTerminal("limitOpt", typeof(LimitNode));
            var SimpleIdList = new NonTerminal("SimpleIdList");
            var bulkVertexTypeListMember = new NonTerminal("bulkVertexTypeListMember", CreateBulkVertexTypeListMemberNode);
            var bulkEdgeTypeListMember = new NonTerminal("bulkEdgeTypeListMember", CreateBulkEdgeTypeListMemberNode);
            var bulkVertexType = new NonTerminal("bulVertexkType", CreateBulkVertexTypeNode);
            var bulkEdgeType = new NonTerminal("bulkEdgeType", CreateBulkEdgeTypeNode);
            var truncateStmt = new NonTerminal("truncateStmt", CreateTruncateStmNode);
            var uniquenessOpt = new NonTerminal("UniquenessOpt", typeof(UniqueAttributesOptNode));
            var mandatoryOpt = new NonTerminal("MandatoryOpt", typeof(MandatoryOptNode));

            #region Transactions

            var TransactOptions = new NonTerminal("TransactOptions");
            var TransactAttributes = new NonTerminal("TransactAttributes");
            var TransactIsolation = new NonTerminal("TransactIsolation");
            var TransactName = new NonTerminal("TransactName");
            var TransactTimestamp = new NonTerminal("TransactTimestamp");
            var TransactCommitRollbackOpt = new NonTerminal("TransactCommitRollbackOpt");
            var TransactCommitRollbackType = new NonTerminal("TransactCommitRollbackType");

            #endregion

            var KeyValuePair = new NonTerminal("KeyValuePair", CreateKeyValuePairNode);
            NT_KeyValueList = new NonTerminal("ValueList", CreateKeyValueListNode);
            var BooleanVal = new NonTerminal("BooleanVal");
            var Values = new NonTerminal("Values");
            NT_Options = new NonTerminal("Options", CreateOptionsNode);
            var ExtKeyValuePair = new NonTerminal("ExtKeyValuePair", CreateExtendedKeyValuePairNode);
            NT_ExtKeyValueList = new NonTerminal("ExtValueList", CreateExtendedKeyValueListNode);

            var ListType = new NonTerminal("ListType");
            var ListParametersForExpression = new NonTerminal("ListParametersForExpression", typeof(ParametersNode));
            var LinkCondition = new NonTerminal("LinkCondition");

            #region EdgeType

            var EdgeTypeDef = new NonTerminal("EdgeTypeDef", CreateEdgeTypeDefNode);
            var SingleEdgeTypeDef = new NonTerminal("EdgeTypeDef", CreateSingleEdgeTypeDefNode);
            var DefaultValueDef = new NonTerminal("DefaultValueDef", typeof(DefaultValueDefNode));
            var EdgeTypeParams = new NonTerminal("EdgeTypeParams", typeof(EdgeTypeParamsNode));
            var EdgeTypeParam = new NonTerminal("EdgeTypeParamNode", typeof(EdgeTypeParamNode));
            var EdgeType_Sorted = new NonTerminal("ListPropertyAssign_Sorted", typeof(EdgeType_SortedNode));
            var EdgeType_SortedMember = new NonTerminal("ListPropertyAssign_SortedMember");
            var AttrDefaultOpValue = new NonTerminal("AttrDefaultOpValue", CreateAttrDefaultValueNode);

            #endregion

            #region IncomingEdges

            var incomingEdgesOpt = new NonTerminal("IncomingEdges", CreateIncomingEdgesNode);
            var IncomingEdgesSingleDef = new NonTerminal("IncomingEdgesSingleDef", CreateBackwardEdgeNode);
            var IncomingEdgesList = new NonTerminal("IncomingEdgesList");

            #endregion

            #region Index

            var indexOptOnCreateType = new NonTerminal("IndexOptOnCreateType");
            var indexOnCreateType = new NonTerminal("indexOnCreateType", CreateIndexOnCreateType);
            var IndexOptOnCreateTypeMember = new NonTerminal("IndexOptOnCreateTypeMember", CreateIndexOptOnCreateTypeMemberNode);
            var IndexOptOnCreateTypeMemberList = new NonTerminal("IndexOptOnCreateTypeMemberList");
            var IndexDropOnAlterType = new NonTerminal("IndexDropOnAlterType", CreateDropIndicesNode);
            var IndexDropOnAlterTypeMember = new NonTerminal("IndexDropOnAlterTypeMember");
            var IndexDropOnAlterTypeMemberList = new NonTerminal("IndexDropOnAlterTypeMemberList");

            #endregion

            #region Dump/Export

            var dumpStmt = new NonTerminal("Dump", CreateDumpNode);
            var dumpType = new NonTerminal("dumpType", CreateDumpTypeNode);
            var dumpFormat = new NonTerminal("dumpFormat", CreateDumpFormatNode);
            var typeOptionalList = new NonTerminal("typeOptionalList");
            var dumpDestination = new NonTerminal("dumpDestination");

            #endregion

            #region Describe

            var DescrInfoStmt = new NonTerminal("DescrInfoStmt", CreateDescribeNode);
            var DescrArgument = new NonTerminal("DescrArgument");
            var DescrFuncStmt = new NonTerminal("DescrFuncStmt", CreateDescrFunc);
            var DescrFunctionsStmt = new NonTerminal("DescrFunctionsStmt", CreateDescrFunctions);
            var DescrAggrStmt = new NonTerminal("DescrAggrStmt", CreateDescrAggr);
            var DescrAggrsStmt = new NonTerminal("DescrAggrsStmt", CreateDescrAggrs);
            var DescrTypeStmt = new NonTerminal("DescrTypeStmt", CreateDescrType);
            var DescrTypesStmt = new NonTerminal("DescrTypesStmt", CreateDescrTypes);
            var DescrIdxStmt = new NonTerminal("DescrIdxStmt", CreateDescrIdx);
            var DescrIdxsStmt = new NonTerminal("DescrIdxsStmt", CreateDescrIdxs);
            var DescrIdxEdtStmt = new NonTerminal("DescrIdxEdtStmt");
            var DescrDedicatedIdxStmt = new NonTerminal("DescrDedicatedIdxStmt");
            var DescrEdgeStmt = new NonTerminal("DescrEdgeStmt", CreateDescrEdge);
            var DescrEdgesStmt = new NonTerminal("DescrEdgesStmt", CreateDescrEdges);

            #endregion

            #region REBUILD INDICES

            var rebuildIndicesStmt = new NonTerminal("rebuildIndicesStmt", CreateRebuildIndicesNode);
            var rebuildIndicesTypes = new NonTerminal("rebuildIndiceTypes");

            #endregion

            #region Import

            NT_ImportFormat = new NonTerminal("importFormat");
            NT_ImportStmt = new NonTerminal("import", CreateImportNode);
            var paramParallelTasks = new NonTerminal("parallelTasks", CreateParallelTaskNode);
            var paramComments = new NonTerminal("comments", CreateCommentsNode);
            var verbosity = new NonTerminal("verbosity", CreateVerbosityNode);
            var verbosityTypes = new NonTerminal("verbosityTypes");

            #endregion

            #endregion

            #region Statements

            #region GQL root

            //BNF Rules
            this.Root = singlestmt;

            singlestmt.Rule = SelectStmtGraph
                            | InsertStmt
                            | alterVertexTypeStmt
                            | alterEdgeTypeStmt
                            | updateStmt
                            | updateEdgesStmt
                            | dropVertexTypeStmt
                            | dropEdgeTypeStmt
                            | dropIndexStmt
                            | createIndexStmt
                            | createTypesStmt
                            | createEdgeTypesStmt
                            | deleteStmt
                            | truncateStmt
                            | DescrInfoStmt
                            | insertorupdateStmt
                            | insertorreplaceStmt
                            | replaceStmt
                            | dumpStmt
                            | transactStmt
                            | commitRollBackTransactStmt
                            | rebuildIndicesStmt
                            | NT_ImportStmt
                            | linkStmt
                            | unlinkStmt;

            #endregion

            #region misc

            #region ID

            #region wo functions

            Id_simple.Rule = name;

            EdgeTraversalWithOutFunctions.Rule = dotWrapper + Id_simple;

            NT_Id.SetFlag(TermFlags.IsList);
            NT_Id.Rule = Id_simple
                        | NT_Id + EdgeTraversalWithOutFunctions;
            //old
            //Id.Rule = MakePlusRule(Id, dotWrapper, Id_simple);

            idlist.Rule = MakePlusRule(idlist, S_comma, NT_Id);
            id_simpleList.Rule = MakePlusRule(id_simpleList, S_comma, Id_simple);
            id_simpleDotList.Rule = MakePlusRule(id_simpleDotList, S_dot, Id_simple);
            id_typeAndAttribute.Rule = VertexTypeWrapper + S_dot + NT_Id;

            #endregion

            #region ID_or_Func

            IdOrFunc.Rule = name
                            | NT_FuncCall;

            dotWrapper.Rule = S_edgeTraversalDelimiter;

            edgeAccessorWrapper.Rule = S_edgeInformationDelimiterSymbol;

            //IDOrFuncDelimiter.Rule =        dotWrapper
            //                            |   edgeAccessorWrapper;

            EdgeTraversalWithFunctions.Rule = dotWrapper + IdOrFunc;

            EdgeInformation.Rule = edgeAccessorWrapper + Id_simple;

            IdOrFuncList.SetFlag(TermFlags.IsList);
            IdOrFuncList.Rule = IdOrFunc
                                    | IdOrFuncList + EdgeInformation
                                    | IdOrFuncList + EdgeTraversalWithFunctions;

            //old
            //IdOrFuncList.Rule = MakePlusRule(IdOrFuncList, IDOrFuncDelimiter, IdOrFunc);

            #endregion

            #endregion

            #region typeList

            VertexTypeList.Rule = MakePlusRule(VertexTypeList, S_comma, NT_AType);

            NT_AType.Rule = Id_simple + Id_simple
                        | Id_simple;

            NT_VertexType.Rule = Id_simple;

            //AType.Rule = Id + Id_simple
            //                | Id;

            VertexTypeWrapper.Rule = NT_AType;

            #endregion

            #region CreateIndexAttribute

            IndexAttributeList.Rule = MakePlusRule(IndexAttributeList, S_comma, IndexAttributeMember);

            IndexAttributeMember.Rule = IndexAttributeType;// + AttributeOrderDirectionOpt;

            IndexAttributeType.Rule = IdOrFuncList;// Id_simple | id_typeAndAttribute;

            #endregion

            #region OrderDirections

            AttributeOrderDirectionOpt.Rule = Empty
                                                | S_ASC
                                                | S_DESC;

            #endregion

            #region Boolean

            BooleanVal.Rule = S_TRUE | S_FALSE;

            #endregion

            #region KeyValue

            KeyValuePair.Rule = Id_simple + "=" + string_literal
                                | Id_simple + "=" + number
                                | Id_simple + "=" + BooleanVal;

            NT_KeyValueList.Rule = MakePlusRule(NT_KeyValueList, S_comma, KeyValuePair);

            #endregion

            #region ExtendedKeyValue

            ExtKeyValuePair.Rule = Id_simple + "=" + string_literal
                                    | Id_simple + "=" + number
                                    | Id_simple + "=" + BooleanVal
                                    | Id_simple + "=" + CollectionOfBasicDBObjects;

            NT_ExtKeyValueList.Rule = MakePlusRule(NT_ExtKeyValueList, S_comma, ExtKeyValuePair);

            CollectionOfBasicDBObjects.Rule = Empty
                                              | S_SETOF + CollectionTuple
                                              | S_LISTOF + CollectionTuple;

            #endregion

            #region ListType

            ListType.Rule = S_LIST;

            ListParametersForExpression.Rule = Empty
                                         | S_colon + S_BRACKET_LEFT + NT_ExtKeyValueList + S_BRACKET_RIGHT;

            EdgeType_SortedMember.Rule = S_ASC | S_DESC;
            EdgeType_Sorted.Rule = S_SORTED + "=" + EdgeType_SortedMember;

            #endregion

            #region GraphType

            //                 SET<                   WEIGHTED  (Double, DEFAULT=2, SORTED=DESC)<   [idsimple]  >>
            //EdgeTypeDef.Rule = S_SET + S_ListTypePrefix + Id_simple + S_BRACKET_LEFT + EdgeTypeParams + S_BRACKET_RIGHT + S_ListTypePrefix + Id_simple + S_ListTypePostfix + S_ListTypePostfix;
            //                 SET     <                  USER        (                WEIGHTED    )                 >
            EdgeTypeDef.Rule = S_SET + S_ListTypePrefix + Id_simple + S_BRACKET_LEFT + Id_simple + S_BRACKET_RIGHT + S_ListTypePostfix;

            //                       COUNTED        (Integer, DEFAULT=2)                   <   [idsimple]  >
            //SingleEdgeTypeDef.Rule = Id_simple + S_BRACKET_LEFT + EdgeTypeParams + S_BRACKET_RIGHT + S_ListTypePrefix + Id_simple + S_ListTypePostfix;

            //                       USER        (                COUNTED     )
            SingleEdgeTypeDef.Rule = Id_simple + S_BRACKET_LEFT + Id_simple + S_BRACKET_RIGHT;

            EdgeTypeParams.Rule = MakeStarRule(EdgeTypeParams, S_comma, EdgeTypeParam);
            EdgeTypeParam.Rule = Id_simple
                               | DefaultValueDef
                               | EdgeType_Sorted
                               | string_literal;

            EdgeTypeParam.SetFlag(TermFlags.IsTransient, false);

            DefaultValueDef.Rule = S_DEFAULT + "=" + KeyValuePair;

            VertexType.Rule = Id_simple
                                   | S_LIST + S_ListTypePrefix + Id_simple + S_ListTypePostfix
                                   | S_SET + S_ListTypePrefix + Id_simple + S_ListTypePostfix
                                   | EdgeTypeDef
                                   | SingleEdgeTypeDef;

            EdgeType.Rule = Id_simple
                                   | S_LIST + S_ListTypePrefix + Id_simple + S_ListTypePostfix
                                   | S_SET + S_ListTypePrefix + Id_simple + S_ListTypePostfix;

            #endregion

            #region TypeAttributeList

            VertexTypeAttributeList.Rule = MakePlusRule(VertexTypeAttributeList, S_comma, VertexTypeAttrDefinition);

            VertexTypeAttrDefinition.Rule = VertexType + Id_simple + AttrDefaultOpValue;

            EdgeTypeAttributeList.Rule = MakePlusRule(EdgeTypeAttributeList, S_comma, EdgeTypeAttrDefinition);

            EdgeTypeAttrDefinition.Rule = EdgeType + Id_simple + AttrDefaultOpValue;

            #endregion

            #region IncomingEdgesList

            IncomingEdgesList.Rule = MakePlusRule(IncomingEdgesList, S_comma, IncomingEdgesSingleDef);

            IncomingEdgesSingleDef.Rule = Id_simple + S_dot + Id_simple + Id_simple;
            //| Id_simple + S_dot + Id_simple + S_ListTypePrefix + Id_simple + S_BRACKET_LEFT + EdgeTypeParams + S_BRACKET_RIGHT + S_ListTypePostfix + Id_simple;

            #endregion

            #region id_simple list

            SimpleIdList.Rule = MakePlusRule(SimpleIdList, S_comma, Id_simple);

            #endregion

            #region expression

            //Expression
            BNF_ExprList.Rule = MakeStarRule(BNF_ExprList, S_comma, NT_Expression);

            NT_Expression.Rule = term
                                | unExpr
                                | binExpr;

            expressionOfAList.Rule = NT_Expression + ListParametersForExpression;

            term.Rule = IdOrFuncList              //d.Name
                            | string_literal      //'lala'
                            | number              //10
                //|   funcCall          //EXISTS ( SelectStatement )
                            | NT_Aggregate        //COUNT ( SelectStatement )
                            | tuple               //(d.Name, 'Henning', (SelectStatement))
                            | parSelectStmt       //(FROM User u Select u.Name)
                            | S_TRUE
                            | S_FALSE;

            #region Tuple

            tuple.Rule = bracketLeft + expressionOfAList + bracketRight;

            bracketLeft.Rule = S_BRACKET_LEFT | S_TUPLE_BRACKET_LEFT;
            bracketRight.Rule = S_BRACKET_RIGHT | S_TUPLE_BRACKET_RIGHT;

            #endregion

            parSelectStmt.Rule = S_BRACKET_LEFT + SelectStmtGraph + S_BRACKET_RIGHT;

            unExpr.Rule = unOp + term;

            unOp.Rule = S_NOT
                            | "+"
                            | "-"
                            | "~";

            binExpr.Rule = NT_Expression + binOp + NT_Expression
                            | NT_Expression + binOp + NT_Expression + PreferShiftHere() + S_USE + Id_simple;

            NT_UseIndex.Rule = S_USE + Id_simple;

            binOp.Rule = ToTerm("+")
                            | "-"
                            | "*"
                            | "/"
                            | "%" //arithmetic
                            | "&"
                            | "|"
                            | "="
                            | ">"
                            | "<"
                            | ">="
                            | "<="
                            | "<>"
                            | "!="
                            | "AND"
                            | "OR"
                            | "INRANGE"
                            | "LIKE";

            notOpt.Rule = Empty
                            | S_NOT;

            #endregion

            #region Functions & Aggregates

            //funcCall covers some psedo-operators and special forms like ANY(...), SOME(...), ALL(...), EXISTS(...), IN(...)
            //funcCall.Rule = BNF_FuncCallName + S_BRACKET_LEFT + funArgs + S_BRACKET_RIGHT;

            // The grammar will be created by IExtendableGrammer methods
            //BNF_Aggregate.Rule = Empty;
            //BNF_FuncCall.Rule = Empty;

            NT_FunArgs.Rule = SelectStmtGraph
                            | BNF_ExprList;

            #endregion

            #region operators

            //Operators
            RegisterOperators(10, "*", "/", "%");
            RegisterOperators(9, "+", "-");
            RegisterOperators(8, "=", ">", "<", ">=", "<=", "<>", "!=", "INRANGE", "LIKE");
            RegisterOperators(7, "^", "&", "|");
            RegisterOperators(6, "NOT");
            RegisterOperators(5, "AND", "OR");

            #region operators
            // Why this definition was twice in the GraphQL???
            //RegisterOperators(1, Associativity.Neutral, "AND", "OR");
            //RegisterOperators(2, Associativity.Neutral, "=", "!=", ">", ">=", "<", "<=", "<>", "!<", "!>", "IN", "NOTIN", "INRANGE");
            //RegisterOperators(3, "+", "-");
            //RegisterOperators(4, "*", "/");
            RegisterOperators(5, Associativity.Right, "**");
            #endregion

            #endregion

            #region prefixOperation

            PrefixOperation.Rule = Id_simple + S_BRACKET_LEFT + ParameterList + S_BRACKET_RIGHT;

            ParameterList.Rule = ParameterList + S_comma + NT_Expression
                                    | NT_Expression;

            #endregion

            #region options

            NT_Options.Rule = Empty
                                | S_OPTIONS + S_BRACKET_LEFT + NT_KeyValueList + S_BRACKET_RIGHT;

            #endregion

            #endregion

            #region CREATE INDEX

            createIndexStmt.Rule = S_CREATE + S_INDEX + indexNameOpt + editionOpt + S_ON + S_VERTEX + S_TYPE + VertexTypeWrapper + S_BRACKET_LEFT + IndexAttributeList + S_BRACKET_RIGHT + NT_IndexTypeOpt + NT_Options
                                    | S_CREATE + S_INDEX + indexNameOpt + editionOpt + S_ON + VertexTypeWrapper + S_BRACKET_LEFT + IndexAttributeList + S_BRACKET_RIGHT + NT_IndexTypeOpt + NT_Options; // due to compatibility the  + S_TYPE is optional

            uniqueOpt.Rule = Empty | S_UNIQUE;

            editionOpt.Rule = Empty
                                | S_EDITION + Id_simple;

            NT_IndexTypeOpt.Rule = Empty
                                | S_INDEXTYPE + Id_simple;

            indexNameOpt.Rule = Empty
                                | Id_simple;

            #endregion

            #region REBUILD INDICES

            rebuildIndicesStmt.Rule = S_REBUILD + S_INDICES + rebuildIndicesTypes;

            rebuildIndicesTypes.Rule = Empty | VertexTypeList;

            #endregion

            #region CREATE VERTEX TYPE(S)

            createTypesStmt.Rule = S_CREATE + S_VERTEX + S_TYPES + bulkVertexTypeList
                                    | S_CREATE + S_ABSTRACT + S_VERTEX + S_TYPE + bulkVertexType
                                    | S_CREATE + S_VERTEX + S_TYPE + bulkVertexType;

            bulkVertexTypeList.Rule = MakePlusRule(bulkVertexTypeList, S_comma, bulkVertexTypeListMember);

            bulkVertexTypeListMember.Rule = abstractOpt + bulkVertexType;

            bulkVertexType.Rule = Id_simple + extendsOpt + vertexTypeAttributesOpt + incomingEdgesOpt + uniquenessOpt + mandatoryOpt + indexOptOnCreateType + commentOpt;

            commentOpt.Rule = Empty
                                    | S_COMMENT + "=" + string_literal;

            abstractOpt.Rule = S_ABSTRACT
                                | Empty;

            extendsOpt.Rule = Empty
                                    | S_EXTENDS + Id_simple;

            vertexTypeAttributesOpt.Rule = Empty
                                    | S_ATTRIBUTES + S_BRACKET_LEFT + VertexTypeAttributeList + S_BRACKET_RIGHT;

            incomingEdgesOpt.Rule = Empty
                                    | S_INCOMINGEDGES + S_BRACKET_LEFT + IncomingEdgesList + S_BRACKET_RIGHT;

            uniquenessOpt.Rule = Empty
                                    | S_UNIQUE + S_BRACKET_LEFT + id_simpleList + S_BRACKET_RIGHT;

            mandatoryOpt.Rule = Empty
                                    | S_MANDATORY + S_BRACKET_LEFT + id_simpleList + S_BRACKET_RIGHT;

            indexOptOnCreateType.Rule = Empty
                                        | indexOnCreateType;

            indexOnCreateType.Rule = S_INDICES + S_BRACKET_LEFT + IndexOptOnCreateTypeMemberList + S_BRACKET_RIGHT
                                    | S_INDICES + IndexOptOnCreateTypeMember;

            IndexOptOnCreateTypeMemberList.Rule = MakePlusRule(IndexOptOnCreateTypeMemberList, S_comma, IndexOptOnCreateTypeMember);

            IndexOptOnCreateTypeMember.Rule = S_BRACKET_LEFT + indexNameOpt + editionOpt + NT_IndexTypeOpt + S_ON + S_ATTRIBUTES + IndexAttributeList + NT_Options + S_BRACKET_RIGHT
                                            | S_BRACKET_LEFT + indexNameOpt + editionOpt + NT_IndexTypeOpt + S_ON + IndexAttributeList + NT_Options + S_BRACKET_RIGHT // due to compatibility the  + S_ATTRIBUTES is optional
                                            | S_BRACKET_LEFT + IndexAttributeList + NT_Options + S_BRACKET_RIGHT;

            Values.Rule = BooleanVal | number | string_literal;

            AttrDefaultOpValue.Rule = Empty
                                    | "=" + Values;

            #endregion

            #region CREATE EDGE TYPE(s)

            createEdgeTypesStmt.Rule = S_CREATE + S_EDGE + S_TYPE + bulkEdgeType
                                        | S_CREATE + S_EDGE + S_TYPES + bulkEdgeTypeList;

            bulkEdgeType.Rule = Id_simple + extendsOpt + edgeTypeAttributesOpt + commentOpt;

            edgeTypeAttributesOpt.Rule = Empty
                                    | S_ATTRIBUTES + S_BRACKET_LEFT + EdgeTypeAttributeList + S_BRACKET_RIGHT;

            bulkEdgeTypeList.Rule = MakePlusRule(bulkEdgeTypeList, S_comma, bulkEdgeTypeListMember);

            bulkEdgeTypeListMember.Rule = abstractOpt + bulkVertexType;

            #endregion

            #region ALTER VERTEX TYPE

            alterVertexTypeStmt.Rule = S_ALTER + S_VERTEX + S_TYPE + Id_simple + alterVertexTypeCmdList + uniquenessOpt + mandatoryOpt;

            alterVertexTypeCmd.Rule = Empty
                            | S_ADD + S_ATTRIBUTES + S_BRACKET_LEFT + VertexTypeAttributeList + S_BRACKET_RIGHT
                            | S_DROP + S_ATTRIBUTES + S_BRACKET_LEFT + SimpleIdList + S_BRACKET_RIGHT
                            | S_ADD + S_INCOMINGEDGES + S_BRACKET_LEFT + IncomingEdgesList + S_BRACKET_RIGHT
                            | S_DROP + S_INCOMINGEDGES + S_BRACKET_LEFT + SimpleIdList + S_BRACKET_RIGHT
                            | S_ADD + indexOnCreateType
                            | S_DROP + IndexDropOnAlterType
                            | S_RENAME + S_ATTRIBUTE + Id_simple + S_TO + Id_simple
                            | S_RENAME + S_INCOMINGEDGE + Id_simple + S_TO + Id_simple
                            | S_RENAME + S_TO + Id_simple
                            | S_DEFINE + S_ATTRIBUTES + S_BRACKET_LEFT + VertexTypeAttributeList + S_BRACKET_RIGHT
                            | S_UNDEFINE + S_ATTRIBUTES + S_BRACKET_LEFT + SimpleIdList + S_BRACKET_RIGHT
                            | S_DROP + S_UNIQUE + S_ON + Id_simple
                            | S_DROP + S_MANDATORY + S_ON + Id_simple
                            | S_COMMENT + "=" + string_literal;

            alterVertexTypeCmdList.Rule = MakePlusRule(alterVertexTypeCmdList, S_comma, alterVertexTypeCmd);

            IndexDropOnAlterTypeMember.Rule = S_BRACKET_LEFT + SimpleIdList + S_BRACKET_RIGHT;

            IndexDropOnAlterTypeMemberList.Rule = MakePlusRule(IndexDropOnAlterTypeMemberList, S_comma, IndexDropOnAlterTypeMember);

            IndexDropOnAlterType.Rule = S_INDICES + IndexDropOnAlterTypeMember;

            #endregion

            #region ALTER EDGE TYPE

            alterEdgeTypeStmt.Rule = S_ALTER + S_EDGE + S_TYPE + Id_simple + alterEdgeTypeCmdList;

            alterEdgeTypeCmd.Rule = Empty
                            | S_ADD + S_ATTRIBUTES + S_BRACKET_LEFT + EdgeTypeAttributeList + S_BRACKET_RIGHT
                            | S_DROP + S_ATTRIBUTES + S_BRACKET_LEFT + SimpleIdList + S_BRACKET_RIGHT
                            | S_RENAME + S_ATTRIBUTE + Id_simple + S_TO + Id_simple
                            | S_RENAME + S_TO + Id_simple
                //| S_DEFINE + S_ATTRIBUTES + S_BRACKET_LEFT + EdgeTypeAttributeList + S_BRACKET_RIGHT
                //| S_UNDEFINE + S_ATTRIBUTES + S_BRACKET_LEFT + SimpleIdList + S_BRACKET_RIGHT
                            | S_COMMENT + "=" + string_literal;

            alterEdgeTypeCmdList.Rule = MakePlusRule(alterEdgeTypeCmdList, S_comma, alterEdgeTypeCmd);

            #endregion

            #region SELECT

            SelectStmtGraph.Rule = S_FROM +
                                    VertexTypeList +
                                    S_SELECT +
                                    selList +
                                    NT_whereClauseOpt +
                                    groupClauseOpt +
                                    havingClauseOpt +
                                    orderClauseOpt +
                                    offsetOpt +
                                    limitOpt +
                                    resolutionDepthOpt +
                                    selectOutputOpt;

            resolutionDepthOpt.Rule = Empty
                                        | S_DEPTH + number;

            selectOutputOpt.Rule = Empty
                                        | "OUTPUT" + name;

            offsetOpt.Rule = Empty
                            | S_OFFSET + number;

            limitOpt.Rule = Empty
                            | S_LIMIT + number;

            selList.Rule = selectionList;

            selectionList.Rule = MakePlusRule(selectionList, S_comma, selectionListElement);

            selectionListElement.Rule = S_ASTERISK
                                        | NT_Aggregate + aliasOpt
                                        | IdOrFuncList + aliasOpt;

            aliasOptName.Rule = Id_simple | string_literal;

            aliasOpt.Rule = Empty
                            | S_AS + aliasOptName;

            #region Aggregate

            //BNF_Aggregate.Rule = BNF_AggregateName + S_BRACKET_LEFT + name + S_BRACKET_RIGHT;

            NT_AggregateArg.Rule = NT_Id
                                    | S_ASTERISK;
            /*
            aggregateName.Rule =        S_COUNT
                                    |   "AVG"
                                    |   "MIN"
                                    |   "MAX"
                                    |   "STDEV"
                                    |   "STDEVP"
                                    |   "SUM"
                                    |   "VAR"
                                    |   "VARP";
            */
            #endregion

            #region Functions

            //function.Rule           = functionName + S_BRACKET_LEFT + term + S_BRACKET_RIGHT;

            //functionName.Rule       = FUNC_WEIGHT;

            #endregion

            NT_whereClauseOpt.Rule = Empty
                                    | S_WHERE + NT_Expression;

            groupClauseOpt.Rule = Empty
                                    | "GROUP" + S_BY + idlist;

            havingClauseOpt.Rule = Empty
                                    | "HAVING" + NT_Expression;

            orderByAttributeListMember.Rule = NT_Id
                                                | string_literal;

            orderByAttributeList.Rule = MakePlusRule(orderByAttributeList, S_comma, orderByAttributeListMember);

            orderClauseOpt.Rule = Empty
                                    | "ORDER" + S_BY + orderByAttributeList + AttributeOrderDirectionOpt;

            #endregion

            #region INSERT

            InsertStmt.Rule = S_INSERT + S_INTO + Id_simple + insertValuesOpt;

            insertValuesOpt.Rule = Empty
                                    | S_VALUES + S_BRACKET_LEFT + AttrAssignList + S_BRACKET_RIGHT;

            AttrAssignList.Rule = MakePlusRule(AttrAssignList, S_comma, AttrAssign);

            AttrAssign.Rule = NT_Id + "=" + NT_Expression
                                | NT_Id + "=" + Reference
                                | NT_Id + "=" + CollectionOfDBObjects;

            CollectionOfDBObjects.Rule = S_SETOF + CollectionTuple
                                            | S_LISTOF + CollectionTuple
                                            | S_SETOFUUIDS + VertexTypeVertexIDCollection
                                            | S_SETOFUUIDS + "()"
                                            | S_SETOF + "()";

            VertexTypeVertexIDCollection.Rule = MakeStarRule(VertexTypeVertexIDCollection, VertexTypeVertexElement);

            VertexTypeVertexElement.Rule = TERMINAL_LT + Id_simple + TERMINAL_GT + CollectionTuple;

            CollectionTuple.Rule = S_BRACKET_LEFT + ExtendedExpressionList + S_BRACKET_RIGHT;

            ExtendedExpressionList.Rule = MakePlusRule(ExtendedExpressionList, S_comma, ExtendedExpression);

            ExtendedExpression.Rule = NT_Expression + ListParametersForExpression;

            Reference.Rule = S_REFERENCE + tuple + ListParametersForExpression
                            | S_REF + tuple + ListParametersForExpression
                            | S_REFUUID + TERMINAL_LT + Id_simple + TERMINAL_GT + tuple + ListParametersForExpression
                            | S_REFERENCEUUID + TERMINAL_LT + Id_simple + TERMINAL_GT + tuple + ListParametersForExpression;

            //| S_SETREF + tupleRangeSet + ListParametersForExpression;

            #endregion

            #region UPDATE

            updateStmt.Rule = S_UPDATE + Id_simple + S_SET + S_BRACKET_LEFT + AttrUpdateList + S_BRACKET_RIGHT + NT_whereClauseOpt;

            AttrUpdateList.Rule = MakePlusRule(AttrUpdateList, S_comma, AttrUpdateOrAssign);

            AttrUpdateOrAssign.Rule = AttrAssign
                                        | AttrRemove
                                        | ListAttrUpdate;

            AttrRemove.Rule = S_REMOVE + S_ATTRIBUTES + S_BRACKET_LEFT + id_simpleList + S_BRACKET_RIGHT;

            ListAttrUpdate.Rule = AddToListAttrUpdate
                                    | RemoveFromListAttrUpdateAddToRemoveFrom
                                    | RemoveFromListAttrUpdateAddToOperator;

            AddToListAttrUpdate.Rule = AddToListAttrUpdateAddTo
                                        | AddToListAttrUpdateOperator;

            AddToListAttrUpdateAddTo.Rule = S_ADD + S_TO + NT_Id + CollectionOfDBObjects;
            AddToListAttrUpdateOperator.Rule = NT_Id + S_ADDTOLIST + CollectionOfDBObjects;

            RemoveFromListAttrUpdateAddToRemoveFrom.Rule = S_REMOVE + S_FROM + NT_Id + tuple;
            RemoveFromListAttrUpdateAddToOperator.Rule = NT_Id + RemoveFromListAttrUpdateScope;
            RemoveFromListAttrUpdateScope.Rule = S_REMOVEFROMLIST + tuple | S_REMOVEFROMLIST + CollectionOfDBObjects;

            #endregion

            #region UPDATE EDGES

            //                       UPDATE     EDGES     ON      User
            updateEdgesStmt.Rule = S_UPDATE + S_EDGES + S_ON + Id_simple +
                //                                (      Friends = (), Fiends = ()      )       WHERE Name = 'Hans'
                                    S_BRACKET_LEFT + EdgeAttrUpdateList + S_BRACKET_RIGHT + NT_whereClauseOpt;

            //                          Friends = (), Fiends = ()
            EdgeAttrUpdateList.Rule = MakePlusRule(EdgeAttrUpdateList, S_comma, EdgeAttrUpdate);

            //                    Friends  =   (Name = 'Hans' : (Weight = 1.5))
            EdgeAttrUpdate.Rule = NT_Id + "=" + CollectionOfEdges;

            //                       Name = 'Hans' : (Weight = 1.5)
            CollectionOfEdges.Rule = CollectionTuple;

            #endregion

            #region DROP VertexType

            dropVertexTypeStmt.Rule = S_DROP + S_VERTEX + S_TYPE + Id_simple;

            #endregion

            #region DROP EdgeType

            dropEdgeTypeStmt.Rule = S_DROP + S_EDGE + S_TYPE + Id_simple;

            #endregion

            #region DROP INDEX

            dropIndexStmt.Rule = S_FROM + VertexTypeWrapper + S_DROP + S_INDEX + Id_simple + editionOpt;

            #endregion

            #region TRUNCATE

            truncateStmt.Rule = S_TRUNCATE + S_VERTEX + S_TYPE + Id_simple;

            #endregion

            #region DELETE

            deleteStmtMember.Rule = Empty | idlist;
            deleteStmt.Rule = S_FROM + Id_simple + S_DELETE + deleteStmtMember + NT_whereClauseOpt;

            #endregion

            #region DESCRIBE

            DescrInfoStmt.Rule = S_DESCRIBE + DescrArgument;

            DescrArgument.Rule = DescrAggrStmt
                                | DescrAggrsStmt
                                | DescrEdgeStmt
                                | DescrEdgesStmt
                                | DescrTypeStmt
                                | DescrTypesStmt
                                | DescrFuncStmt
                                | DescrFunctionsStmt
                                | DescrIdxStmt
                                | DescrIdxsStmt;

            DescrAggrStmt.Rule = S_AGGREGATE + string_literal;

            DescrAggrsStmt.Rule = S_AGGREGATES;

            DescrEdgeStmt.Rule = S_EDGE + Id_simple;

            DescrEdgesStmt.Rule = S_EDGES;

            DescrTypeStmt.Rule = S_VERTEX + S_TYPE + Id_simple;

            DescrTypesStmt.Rule = S_VERTEX + S_TYPES;

            DescrFuncStmt.Rule = S_FUNCTION + string_literal;

            DescrFunctionsStmt.Rule = S_FUNCTIONS;

            //                            User        [IndexName]             [EDITION default]
            DescrIdxStmt.Rule = S_INDEX + NT_VertexType + DescrDedicatedIdxStmt + DescrIdxEdtStmt;

            DescrDedicatedIdxStmt.Rule = Empty | Id_simple;

            DescrIdxEdtStmt.Rule = Empty
                                    | S_EDITION + Id_simple;

            DescrIdxsStmt.Rule = S_INDICES;

            #endregion

            #region INSERTORUPDATE

            insertorupdateStmt.Rule = S_INSERTORUPDATE + Id_simple + S_VALUES + S_BRACKET_LEFT + AttrUpdateList + S_BRACKET_RIGHT + NT_whereClauseOpt;

            #endregion

            #region INSERTORREPLACE

            insertorreplaceStmt.Rule = S_INSERTORREPLACE + Id_simple + S_VALUES + S_BRACKET_LEFT + AttrAssignList + S_BRACKET_RIGHT + NT_whereClauseOpt;

            #endregion

            #region REPLACE

            replaceStmt.Rule = S_REPLACE + Id_simple + S_VALUES + S_BRACKET_LEFT + AttrAssignList + S_BRACKET_RIGHT + S_WHERE + NT_Expression;

            #endregion

            #region TRANSACTION

            #region BeginTransAction

            transactStmt.Rule = S_BEGIN + TransactOptions + S_TRANSACTION + TransactAttributes;

            TransactOptions.Rule = Empty |
                                S_TRANSACTDISTRIBUTED + S_TRANSACTLONGRUNNING |
                                S_TRANSACTDISTRIBUTED |
                                S_TRANSACTLONGRUNNING;

            TransactAttributes.Rule = Empty |
                                TransactIsolation |
                                TransactName |
                                TransactTimestamp |
                                TransactIsolation + TransactName |
                                TransactIsolation + TransactTimestamp |
                                TransactName + TransactTimestamp |
                                TransactIsolation + TransactName + TransactTimestamp;

            TransactIsolation.Rule = S_TRANSACTISOLATION + "=" + string_literal;

            TransactName.Rule = S_TRANSACTNAME + "=" + string_literal;

            TransactTimestamp.Rule = S_TRANSACTTIMESTAMP + "=" + string_literal;

            #endregion

            #region CommitRollbackTransAction

            commitRollBackTransactStmt.Rule = TransactCommitRollbackType + S_TRANSACTION + TransactCommitRollbackOpt;

            TransactCommitRollbackType.Rule = S_TRANSACTCOMMIT | S_TRANSACTROLLBACK;

            TransactCommitRollbackOpt.Rule = Empty |
                                        TransactName |
                                        S_TRANSACTCOMROLLASYNC |
                                        TransactName + S_TRANSACTCOMROLLASYNC;

            #endregion

            #endregion

            #region EXPORT/DUMP

            dumpType.Rule = Empty | S_ALL | S_GDDL | S_GDML;      // If empty => create both
            dumpFormat.Rule = Empty | S_AS + S_GQL;                 // If empty => create GQL
            typeOptionalList.Rule = Empty | S_VERTEX + S_TYPES + id_simpleList;

            dumpDestination.Rule = Empty | S_INTO + location_literal | S_TO + location_literal;

            dumpStmt.Rule = S_DUMP + typeOptionalList + dumpType + dumpFormat + dumpDestination
                                    | S_EXPORT + typeOptionalList + dumpType + dumpFormat + dumpDestination;

            #endregion

            #region IMPORT

            paramComments.Rule = S_COMMENTS + tuple | Empty;
            paramParallelTasks.Rule = S_PARALLELTASKS + "(" + number + ")" | Empty;
            verbosityTypes.Rule = ToTerm(VerbosityTypes.Silent.ToString()) | ToTerm(VerbosityTypes.Errors.ToString()) | ToTerm(VerbosityTypes.Full.ToString());
            verbosity.Rule = S_VERBOSITY + verbosityTypes | Empty;

            //BNF_ImportFormat.Rule = Empty;

            NT_ImportStmt.Rule = S_IMPORT + S_FROM + location_literal + S_FORMAT + NT_ImportFormat + paramParallelTasks + paramComments + offsetOpt + limitOpt + verbosity + NT_Options;

            #endregion

            #region LINK

            // Semantic Web Yoda-Style and human language style
            linkStmt.Rule = S_LINK + VertexTypeWrapper + CollectionTuple + S_VIA + NT_Id + S_TO + LinkCondition |
                            S_LINK + VertexTypeWrapper + CollectionTuple + S_TO + LinkCondition + S_VIA + NT_Id;

            LinkCondition.Rule = VertexTypeWrapper + CollectionTuple;

            #endregion

            #region UNLINK

            unlinkStmt.Rule = S_UNLINK + VertexTypeWrapper + CollectionTuple + S_VIA + NT_Id + S_FROM + LinkCondition |
                              S_UNLINK + VertexTypeWrapper + CollectionTuple + S_FROM + LinkCondition + S_VIA + NT_Id;

            #endregion

            #endregion

            #region Misc

            #region punctuation

            MarkPunctuation(",", S_BRACKET_LEFT.ToString(), S_BRACKET_RIGHT.ToString(), "[", "]");
            //RegisterPunctuation(",", S_BRACKET_LEFT.Symbol, S_BRACKET_RIGHT.Symbol, S_TUPLE_BRACKET_LEFT.Symbol, S_TUPLE_BRACKET_RIGHT.Symbol);
            //RegisterPunctuation(",");
            //RegisterBracePair(_S_BRACKET_LEFT.Symbol, S_BRACKET_RIGHT.Symbol);
            //RegisterBracePair(_S_TUPLE_BRACKET_LEFT.Symbol, S_TUPLE_BRACKET_RIGHT.Symbol);
            //RegisterBracePair(_S_TUPLE_BRACKET_LEFT_EXCLUSIVE.Symbol, S_TUPLE_BRACKET_RIGHT.Symbol);
            //RegisterBracePair(_S_TUPLE_BRACKET_LEFT.Symbol, S_TUPLE_BRACKET_RIGHT_EXCLUSIVE.Symbol);
            //RegisterBracePair(_S_TUPLE_BRACKET_LEFT_EXCLUSIVE.Symbol, S_TUPLE_BRACKET_RIGHT_EXCLUSIVE.Symbol);

            #endregion

            base.MarkTransient(
                singlestmt, Id_simple, selList, /* selectionSource, */NT_Expression, term, NT_FunArgs
                , unOp, /*binOp, */ /*aliasOpt, */ aliasOptName, orderByAttributeListMember
                //, KeyValuePair
                //, EdgeTypeParam
                , EdgeType_SortedMember, AttrUpdateOrAssign, ListAttrUpdate, DescrArgument,
                VertexTypeWrapper //is used as a wrapper for AType
                , IdOrFunc //, IdOrFuncList
                , BNF_ExprList, NT_AggregateArg,
                //ExtendedExpressionList,
                NT_ImportFormat, NT_FuncCall, NT_Aggregate, verbosityTypes/*,
                vertexType, BNF_VertexTypes*/);

            #endregion
        }
コード例 #10
0
ファイル: Grammar.cs プロジェクト: adrobyazko-softheme/PQL
 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;
 }
コード例 #11
0
        public ExpressionGrammar()
            : base(false)
        {
            //SQL is case insensitive
            //Terminals
            var comment = new CommentTerminal("comment", "/*", "*/");
            var lineComment = new CommentTerminal("line_comment", "--", "\n", "\r\n");
            NonGrammarTerminals.Add(comment);
            NonGrammarTerminals.Add(lineComment);
            var numberLiteral = new NumberLiteral("number", NumberOptions.AllowSign | NumberOptions.AllowStartEndDot) {DefaultIntTypes = new [] {TypeCode.Int32, TypeCode.Int64 }};
            var stringLiteral = new StringLiteral("string", "'", StringOptions.AllowsDoubledQuote | StringOptions.AllowsLineBreak | StringOptions.AllowsAllEscapes);
            var idSimple = CreateSqlExtIdentifier("id_simple"); //covers normal identifiers (abc) and quoted id's ([abc d], "abc d")
            var commaTerm = ToTerm(",");
            var dotTerm = ToTerm(".");
            var notTerm = ToTerm("NOT");

            //Non-terminals
            var id = new NonTerminal("Id");
            var idlist = new NonTerminal("idlist");
            var idlistPar = new NonTerminal("idlistPar");
            var tuple = new NonTerminal("tuple");
            var expression = new NonTerminal("expression");
            var exprList = new NonTerminal("exprList");
            var caseStmt = new NonTerminal("case");
            var caseVariable = new NonTerminal("caseVariable");
            var caseWhenList = new NonTerminal("caseWhenList");
            var caseWhenThen = new NonTerminal("caseWhenThen");
            var caseDefaultOpt = new NonTerminal("caseDefault");
            var term = new NonTerminal("term");
            var unExpr = new NonTerminal("unExpr");
            var unOp = new NonTerminal("unOp");
            var binExpr = new NonTerminal("binExpr");
            var binOp = new NonTerminal("binOp");
            var betweenExpr = new NonTerminal("betweenExpr");
            //var inExpr = new NonTerminal("inExpr");
            var notOpt = new NonTerminal("notOpt");
            var funCall = new NonTerminal("funCall");
            var funArgs = new NonTerminal("funArgs");
            //var inStmt = new NonTerminal("inStmt");

            //BNF Rules
            Root = expression;

            //ID
            id.Rule = MakePlusRule(id, dotTerm, idSimple);

            idlistPar.Rule = "(" + idlist + ")";
            idlist.Rule = MakePlusRule(idlist, commaTerm, id);

            caseWhenThen.Rule = "WHEN" + exprList + "THEN" + expression;
            caseWhenList.Rule = MakePlusRule(caseWhenList, caseWhenThen);
            caseDefaultOpt.Rule = Empty | "ELSE" + expression;
            caseVariable.Rule = Empty | expression;
            caseStmt.Rule = "CASE" + caseVariable + caseWhenList + caseDefaultOpt + "END";

            //Expression
            exprList.Rule = MakePlusRule(exprList, commaTerm, expression);
            expression.Rule = term | unExpr | binExpr | caseStmt | betweenExpr; //-- BETWEEN brings a few parsing conflicts, use parentheses
            tuple.Rule = "(" + exprList + ")";
            term.Rule = id | stringLiteral | numberLiteral | funCall | tuple;// | inStmt;
            unExpr.Rule = unOp + term | term + "IS" + "NULL" | term + "IS" + "NOT" + "NULL";
            unOp.Rule = notTerm | "+" | "-" | "~";
            binExpr.Rule = expression + binOp + expression;
            binOp.Rule = ToTerm("+") | "-" | "*" | "/" | "%" //arithmetic
                        | "&" | "|" | "^"                     //bit
                        | "=" | ">" | "<" | ">=" | "<=" | "<>" | "!=" | "!<" | "!>"
                        | "AND" | "OR" | "XOR" | "LIKE" | notTerm + "LIKE" | "IN" | notTerm + "IN";
            betweenExpr.Rule = expression + notOpt + "BETWEEN" + expression + "AND" + expression;
            notOpt.Rule = Empty | notTerm;
            //funCall covers some psedo-operators and special forms like ANY(...), SOME(...), ALL(...), EXISTS(...), IN(...)
            funCall.Rule = id + "(" + funArgs + ")";
            funArgs.Rule = Empty | exprList;
            //inStmt.Rule = expression + "IN" + "(" + exprList + ")";

            //Operators
            RegisterOperators(10, "*", "/", "%");
            RegisterOperators(9, "+", "-");
            RegisterOperators(8, "=", ">", "<", ">=", "<=", "<>", "!=", "!<", "!>", "LIKE", "IN", "BETWEEN");
            RegisterOperators(7, "^", "&", "|");
            RegisterOperators(6, notTerm);
            RegisterOperators(5, "AND");
            RegisterOperators(4, "OR", "XOR");

            MarkPunctuation(",", "(", ")");
            //Note: we cannot declare binOp as transient because it includes operators "NOT LIKE", "NOT IN" consisting of two tokens.
            // Transient non-terminals cannot have more than one non-punctuation child nodes.
            // Instead, we set flag InheritPrecedence on binOp , so that it inherits precedence value from it's children, and this precedence is used
            // in conflict resolution when binOp node is sitting on the stack
            MarkTransient(term, expression, unOp);
            binOp.SetFlag(TermFlags.InheritPrecedence);

            SnippetRoots.Add(expression);
        }
コード例 #12
0
ファイル: Grammar.cs プロジェクト: h78hy78yhoi8j/xenko
 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;
 }
コード例 #13
0
ファイル: Grammar.cs プロジェクト: h78hy78yhoi8j/xenko
 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;
 }
コード例 #14
0
ファイル: Grammar.cs プロジェクト: h78hy78yhoi8j/xenko
 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; 
 }
コード例 #15
0
        protected NonTerminal SqlExpression()
        {
            if (sqlExpression != null)
                return sqlExpression;

            sqlExpression = new NonTerminal("sql_expression");

            var sqlUnaryExpression = new NonTerminal("sql_unary_expression", typeof(SqlUnaryExpressionNode));
            var sqlBinaryExpression = new NonTerminal("sql_binary_expression", typeof(SqlBinaryExpressionNode));
            var sqlBetweenExpression = new NonTerminal("sql_between_expression", typeof(SqlBetweenExpressionNode));
            var sqlCaseExpression = new NonTerminal("sql_case_expression", typeof(SqlCaseExpressionNode));
            var sqlReferenceExpression = new NonTerminal("sql_reference_expression", typeof(SqlReferenceExpressionNode));
            var term = new NonTerminal("term");
            var sqlSimpleExpression = new NonTerminal("sql_simple_expression");
            var unaryOp = new NonTerminal("unary_op");
            var binaryOp = new NonTerminal("binary_op");
            var binaryOpSimple = new NonTerminal("binary_op_simple");
            var logicalOp = new NonTerminal("logical_op");
            var subqueryOp = new NonTerminal("subquery_op");
            var caseTestExpressionOpt = new NonTerminal("case_test_expression_opt");
            var caseWhenThenList = new NonTerminal("case_when_then_list");
            var caseWhenThen = new NonTerminal("case_when_then", typeof(CaseSwitchNode));
            var caseElseOpt = new NonTerminal("case_else_opt");
            var sqlVarefExpression = new NonTerminal("sql_varef_expression", typeof(SqlVariableRefExpressionNode));
            var sqlConstantExpression = new NonTerminal("sql_constant_expression", typeof(SqlConstantExpressionNode));
            var functionCallExpression = new NonTerminal("function_call_expression", typeof(SqlFunctionCallExpressionNode));
            var functionCallArgsOpt = new NonTerminal("function_call_args_opt");
            var functionCallArgsList = new NonTerminal("function_call_args_list");
            var notOpt = new NonTerminal("not_opt");
            var grouped = new NonTerminal("grouped");
            var anyOp = new NonTerminal("any_op");
            var allOp = new NonTerminal("all_op");

            sqlExpression.Rule = sqlSimpleExpression |
                                  sqlBetweenExpression |
                                  sqlCaseExpression |
                                  SqlQueryExpression();
            sqlConstantExpression.Rule = StringLiteral | NumberLiteral | Key("TRUE") | Key("FALSE") | Key("NULL");
            sqlSimpleExpression.Rule = term  | sqlBinaryExpression | sqlUnaryExpression;
            term.Rule = sqlReferenceExpression |
                        sqlVarefExpression |
                        sqlConstantExpression |
                        functionCallExpression |
                        grouped;
            sqlReferenceExpression.Rule = ObjectName();
            grouped.Rule = ImplyPrecedenceHere(30) + "(" + sqlExpression + ")";
            sqlUnaryExpression.Rule = unaryOp + term;
            unaryOp.Rule = Key("NOT") | "+" | "-" | "~";
            sqlBinaryExpression.Rule = sqlSimpleExpression + binaryOp + sqlSimpleExpression;
            binaryOpSimple.Rule = ToTerm("+") | "-" | "*" | "/" | "%" | ">" | "<" | "=" | "<>";
            binaryOp.Rule = binaryOpSimple | allOp | anyOp | logicalOp | subqueryOp;
            logicalOp.Rule = Key("AND") | Key("OR") | Key("IS") | Key("IS") + Key("NOT") + "&" | "|";
            subqueryOp.Rule = Key("IN") | Key("NOT") + Key("IN");
            anyOp.Rule = Key("ANY") + binaryOpSimple;
            allOp.Rule = Key("ALL") + binaryOpSimple;
            sqlBetweenExpression.Rule = sqlSimpleExpression + notOpt + Key("BETWEEN") + sqlSimpleExpression + Key("AND") +
                                        sqlSimpleExpression;
            sqlCaseExpression.Rule = Key("CASE") + caseTestExpressionOpt + caseWhenThenList + caseElseOpt + Key("END");
            caseTestExpressionOpt.Rule = Empty | sqlExpression;
            caseElseOpt.Rule = Empty | Key("ELSE") + sqlExpression;
            caseWhenThenList.Rule = MakePlusRule(caseWhenThenList, caseWhenThen);
            caseWhenThen.Rule = Key("WHEN") + sqlExpression + Key("THEN") + sqlExpression;

            functionCallExpression.Rule = ObjectName() + functionCallArgsOpt;
            functionCallArgsOpt.Rule = Empty | "(" + functionCallArgsList + ")";
            functionCallArgsList.Rule = MakeStarRule(functionCallArgsList, Comma, sqlExpression);

            sqlVarefExpression.Rule = Colon + Identifier;

            notOpt.Rule = Empty | Key("NOT");

            MarkTransient(sqlExpression, term, sqlSimpleExpression, grouped, functionCallArgsOpt);

            binaryOp.SetFlag(TermFlags.InheritPrecedence);
            binaryOpSimple.SetFlag(TermFlags.InheritPrecedence);
            logicalOp.SetFlag(TermFlags.InheritPrecedence);
            subqueryOp.SetFlag(TermFlags.InheritPrecedence);
            unaryOp.SetFlag(TermFlags.InheritPrecedence);

            return sqlExpression;
        }
コード例 #16
0
ファイル: ID3SQLGrammar.cs プロジェクト: murrple-1/ID3SQL
        private ID3SQLGrammar() : base(false)
        {
            Terminal numberTerm = new NumberLiteral(NumberTermName);
            Terminal stringLiteralTerm = new StringLiteral(StringLiteralTermName, "'", StringOptions.AllowsDoubledQuote);
            Terminal idTerm = TerminalFactory.CreateSqlExtIdentifier(this, IdTermName);

            NonTerminal statementNonTerm = new NonTerminal(StatementNonTermName);
            NonTerminal selectStatementNonTerm = new NonTerminal(SelectStatementNonTermName);
            NonTerminal updateStatementNonTerm = new NonTerminal(UpdateStatementNonTermName);
            NonTerminal deleteStatementNonTerm = new NonTerminal(DeleteStatementNonTermName);
            NonTerminal assignListNonTerm = new NonTerminal(AssignListNonTermName);
            NonTerminal whereClauseNonTerm = new NonTerminal(WhereClauseNonTermName);
            NonTerminal assignmentNonTerm = new NonTerminal(AssignmentNonTermName);
            NonTerminal expressionNonTerm = new NonTerminal(ExpressionNonTermName);
            NonTerminal expressionListNonTerm = new NonTerminal(ExpressionListNonTermName);
            NonTerminal selectListNonTerm = new NonTerminal(SelectListNonTermName);
            NonTerminal columnItemListNonTerm = new NonTerminal(ColumnItemListNonTermName);
            NonTerminal termNonTerm = new NonTerminal(TermNonTermName);
            NonTerminal unaryExpressionNonTerm = new NonTerminal(UnaryExpressionNonTermName);
            NonTerminal unaryOperatorNonTerm = new NonTerminal(UnaryOperatorNonTermName);
            NonTerminal binaryExpressionNonTerm = new NonTerminal(BinaryExpressionNonTermName);
            NonTerminal binaryOperatorNonTerm = new NonTerminal(BinaryOperatorNonTermName);
            NonTerminal notOperatorNonTerm = new NonTerminal(NotOperatorNonTermName);
            NonTerminal inStatementNonTerm = new NonTerminal(InStatementNonTermName);

            this.Root = statementNonTerm;

            statementNonTerm.Rule = selectStatementNonTerm | updateStatementNonTerm | deleteStatementNonTerm;

            //Select statement
            selectStatementNonTerm.Rule = ToTerm("SELECT") + selectListNonTerm + whereClauseNonTerm;
            selectListNonTerm.Rule = columnItemListNonTerm | "*";
            columnItemListNonTerm.Rule = MakePlusRule(columnItemListNonTerm, ToTerm(","), idTerm);
            whereClauseNonTerm.Rule = Empty | "WHERE" + expressionNonTerm;

            //Update statement
            updateStatementNonTerm.Rule = ToTerm("UPDATE") + "SET" + assignListNonTerm + whereClauseNonTerm;
            assignListNonTerm.Rule = MakePlusRule(assignListNonTerm, ToTerm(","), assignmentNonTerm);
            assignmentNonTerm.Rule = idTerm + "=" + expressionNonTerm;

            //Delete statement
            deleteStatementNonTerm.Rule = ToTerm("DELETE") + whereClauseNonTerm;
 
            //Expression
            expressionListNonTerm.Rule = MakePlusRule(expressionListNonTerm, ToTerm(","), expressionNonTerm);
            expressionNonTerm.Rule = termNonTerm | unaryExpressionNonTerm | binaryExpressionNonTerm;
            termNonTerm.Rule = idTerm | stringLiteralTerm | numberTerm;
            unaryExpressionNonTerm.Rule = unaryOperatorNonTerm + termNonTerm;
            unaryOperatorNonTerm.Rule = ToTerm("NOT") | "-";
            binaryExpressionNonTerm.Rule = expressionNonTerm + binaryOperatorNonTerm + expressionNonTerm;
            binaryOperatorNonTerm.Rule = ToTerm("=") | ">" | "<" | ">=" | "<=" | "!="
                        | "AND" | "OR" | "LIKE" | "NOT" + "LIKE" | "IN" | "NOT" + "IN";
            notOperatorNonTerm.Rule = Empty | "NOT";
            inStatementNonTerm.Rule = expressionNonTerm + "IN" + "(" + expressionListNonTerm + ")";

            //Operators
            RegisterOperators(10, "*", "/", "%");
            RegisterOperators(9, "+", "-");
            RegisterOperators(8, "=", ">", "<", ">=", "<=", "<>", "!=", "!<", "!>", "LIKE", "IN");
            RegisterOperators(7, "^", "&", "|");
            RegisterOperators(6, "NOT");
            RegisterOperators(5, "AND");
            RegisterOperators(4, "OR");

            MarkPunctuation(",", "(", ")");
            //Note: we cannot declare binOp as transient because it includes operators "NOT LIKE", "NOT IN" consisting of two tokens. 
            // Transient non-terminals cannot have more than one non-punctuation child nodes.
            // Instead, we set flag InheritPrecedence on binOp , so that it inherits precedence value from it's children, and this precedence is used
            // in conflict resolution when binOp node is sitting on the stack
            base.MarkTransient(statementNonTerm, termNonTerm, expressionNonTerm, unaryOperatorNonTerm);
            binaryOperatorNonTerm.SetFlag(TermFlags.InheritPrecedence);
        }
コード例 #17
0
ファイル: STL.cs プロジェクト: cubean/CG
        public STLGrammar()
            : base(false)
        {
            #region Letters and Digits
            /*
            letter	        A | B | .. | Z | a | b | .. |z
            digit	        0 | 1 | .. | 9
            bit digit	    0|1| .. |7
            binary digit	0 | 1 | _
            hex digit	    digit | A | .. | F | a | .. | f | _
            character	    letter | ASCII 128 | .. | ASCII 255 | _
            first identifier character	character | space
            other identifier character	character | digit | space
            Local Variables (Local ToTerms)	[ # ] identifier
            */
            var semi = ToTerm(";", "semi");
            var semi_opt = new NonTerminal("semi?", Empty | semi);
            var dot = ToTerm(".", "dot");
            var comma = ToTerm(",", "comma");
            var comma_opt = new NonTerminal("comma_opt", Empty | comma);
            var equal = ToTerm("=", "equal");

            var digits = new NumberLiteral("decimal", NumberOptions.IntOnly | NumberOptions.DisableQuickParse);
            var binarys = new NumberLiteral("binary", NumberOptions.IntOnly | NumberOptions.DisableQuickParse | NumberOptions.Binary | NumberOptions.AllowUnderscore);
            var octals = new NumberLiteral("octal", NumberOptions.IntOnly | NumberOptions.DisableQuickParse | NumberOptions.Octal);
            var hexs = new NumberLiteral("hex", NumberOptions.IntOnly | NumberOptions.DisableQuickParse | NumberOptions.Hex | NumberOptions.AllowUnderscore);
            var identifier = TerminalFactory.CreateCSharpIdentifier("identifier");
            var global_variable = new NonTerminal("global_variable", typeof(Variable));
            var local_variable = new NonTerminal("local_variable", typeof(Variable));
            KeyTerm colon = ToTerm(":", "colon");

            binarys.AddPrefix("2#", NumberOptions.Binary);
            hexs.AddPrefix("16#", NumberOptions.Hex);
            global_variable.SetFlag(TermFlags.IsConstant);
            local_variable.SetFlag(TermFlags.IsConstant);

            global_variable.Rule = identifier;
            local_variable.Rule = "#" + identifier;
            #endregion

            #region Program Comments
            /*
            comment characters	printable character CR
            comment	            // { comment characters } CR
            */
            var comment = new CommentTerminal("comment", "//", "\r", "\n");
            var comment_opt = new NonTerminal("comment?");
            var line_comment = new NonTerminal("line_comment");
            var multi_line_comment = new NonTerminal("multi_line_comment");
            var empty_line = new NonTerminal("empty_line");
            var empty_lines = new NonTerminal("empty_line+");
            var empty_lines_opt = new NonTerminal("empty_line*");

            multi_line_comment.SetFlag(TermFlags.IsList);
            empty_lines.SetFlag(TermFlags.IsList);
            empty_lines_opt.SetFlag(TermFlags.IsListContainer);

            comment_opt.Rule = comment | Empty;
            line_comment.Rule = comment + NewLine;
            multi_line_comment.Rule = multi_line_comment + line_comment | line_comment;
            empty_line.Rule = NewLine | line_comment;
            empty_lines.Rule = empty_lines + empty_line | empty_line;
            empty_lines_opt.Rule = empty_lines | Empty;
            #endregion

            #region Instruction mnemonic terminal
            // Bit logic
            var bit_logic_mnemonic = new NonTerminal("bit_logic_mnemonic");
            var clock_mnemonic = new NonTerminal("clock_mnemonic");
            var communication_mnemonic = new NonTerminal("communication_mnemonic");
            var compare_mnemonic = new NonTerminal("compare_mnemonic");
            var convert_mnemonic = new NonTerminal("convert_mnemonic");
            var counter_mnemonic = new NonTerminal("counter_mnemonic");
            var floatpoint_math_mnemonic = new NonTerminal("floatpoint_math_mnemonic");
            var integer_math_mnemonic = new NonTerminal("integer_math_mnemonic");
            var logical_mnemonic = new NonTerminal("logical_mnemonic");
            var move_mnemonic = new NonTerminal("move_mnemonic");
            var program_control_mnemonic = new NonTerminal("program_control_mnemonic");
            var shift_rotate_mnemonic = new NonTerminal("shift_rotate_mnemonic");
            var string_mnemonic = new NonTerminal("string_mnemonic");
            var table_mnemonic = new NonTerminal("table_mnemonic");
            var timer_mnemonic = new NonTerminal("timer_mnemonic");
            var subroutine_mnemonic = new NonTerminal("subroutine_mnemonic");

            bit_logic_mnemonic.Rule =
                ToTerm("LD") | "A" | "O" |
                "LDN" | "AN" | "ON" |
                "LDI" | "AI" | "OI" |
                "LDNI" | "ANI" | "ONI" |
                "NOT" | "EU" | "ED" | "ALD" | "OLD" |
                "LPS" | "LDS" | "LRD" | "LPP" | "=" | "=I" |
                "S" | "SI" | "R" | "RI" | "AENO" | "NOP";
            clock_mnemonic.Rule =
                ToTerm("TODR") | "TODW" | "TODRX" | "TODWX";
            communication_mnemonic.Rule =
                ToTerm("XMT") | "RCV" | "NETR" | "NETW" | "GPA" | "SPA";
            compare_mnemonic.Rule =
                ToTerm("LDB=") | "AB=" | "OB=" |
                "LDB<>" | "AB<>" | "OB<>" |
                "LDB>=" | "AB>=" | "OB>=" |
                "LDB<=" | "AB<=" | "OB<=" |
                "LDB>" | "AB>" | "OB>" |
                "LDB<" | "AB<" | "OB<" |
                "LDW=" | "AW=" | "OW=" |
                "LDW<>" | "AW<>" | "OW<>" |
                "LDW>=" | "AW>=" | "OW>=" |
                "LDW<=" | "AW<=" | "OW<=" |
                "LDW>" | "AW>" | "OW>" |
                "LDW<" | "AW<" | "OW<" |
                "LDD=" | "AD=" | "OD=" |
                "LDD<>" | "AD<>" | "OD<>" |
                "LDD>=" | "AD>=" | "OD>=" |
                "LDD<=" | "AD<=" | "OD<=" |
                "LDD>" | "AD>" | "OD>" |
                "LDD<" | "AD<" | "OD<" |
                "LDR=" | "AR=" | "OR=" |
                "LDR<>" | "AR<>" | "OR<>" |
                "LDR>=" | "AR>=" | "OR>=" |
                "LDR<=" | "AR<=" | "OR<=" |
                "LDR>" | "AR>" | "OR>" |
                "LDR<" | "AR<" | "OR<" |
                "LDS=" | "AS=" | "OS=" |
                "LDS<>" | "AS<>" | "OS<>";
            convert_mnemonic.Rule =
                ToTerm("BTI") | "ITB" | "ITD" | "ITS" |
                "DTI" | "DTR" | "DTS" |
                "ROUND" | "TRUNC" | "RTS" |
                "BCDI" | "IBCD" |
                "ITA" | "DTA" | "RTA" | "ATH" | "HTA" |
                "STI" | "STD" | "STR" |
                "DECO" | "Encoder" | "SEG";
            counter_mnemonic.Rule =
                ToTerm("CTU") | "CTD" | "CTUD" | "HDEF" | "HSC" | "PLS";
            floatpoint_math_mnemonic.Rule =
                ToTerm("+R") | "-R" | "*R" | "/R" |
                "SQRT" | "SIN" | "COS" | "TAN" | "LN" | "EXP" | "PID";
            integer_math_mnemonic.Rule =
                ToTerm("+I") | "-I" | "*I" | "/I" |
                "+D" | "-D" | "*D" | "/D" |
                "MUL" | "DIV" |
                "INCB" | "INCW" | "INCD" |
                "DECB" | "DECW" | "DECD";
            logical_mnemonic.Rule =
                ToTerm("INVB") | "INVW" | "INVD" |
                "ANDB" | "ANDW" | "ANDD" |
                "ORB" | "ORW" | "ORD" |
                "XORB" | "XORW" | "XORD";
            move_mnemonic.Rule =
                ToTerm("MOVB") | "MOVW" | "MOVD" | "MOVR" |
                "BMB" | "BMW" | "BMD" |
                "SWAP" | "BIR" | "BIW";
            program_control_mnemonic.Rule =
                ToTerm("FOR") | "NEXT" | "JMP" | "LBL" |
                "LSCR" | "SCRT" | "SCRE" | "CSCRE" |
                "END" | "STOP" | "WDR" | "DLED";
            shift_rotate_mnemonic.Rule =
                ToTerm("SLB") | "SLW" | "SLD" |
                "SRB" | "SRW" | "SRD" |
                "RLB" | "RLW" | "RLD" |
                "RRB" | "RRW" | "RRD" | "SHRB";
            string_mnemonic.Rule =
                ToTerm("SLEN") | "SCPY" | "SSCPY" | "SCAT" | "SFND" | "CFND";
            table_mnemonic.Rule =
                ToTerm("FILL") | "ATT" | "FND=" | "FND<>" | "FND<" | "FND>" | "LIFO" | "FIFO";
            timer_mnemonic.Rule =
                ToTerm("TON") | "TONR" | "TOF" | "BITIM" | "CITIM";
            subroutine_mnemonic.Rule =
                ToTerm("CALL") | "ENI" | "ENS";
            #endregion

            #region Constants
            /*
            Boolean constant	        TRUE | FALSE | ON | OFF                        Note: Case insensitive
            constant descriptor     	B# | BYTE# | W# | WORD# | DW# | DWORD#         Note: Case insensitive
            unsigned integer	        [constant descriptor]digit {digit}
            number	                    digit {digit}
            signed number	            [ + | - ] number
            signed integer	            [constant descriptor]signed number
            binary integer	            [constant descriptor]2# binary digit { binary digit }
            hex integer	                [constant descriptor]16# hex digit { hex digit }
            exponent	                ( E | e ) signed number
            real constant	            signed number . {exponent}
            real constant	            number {exponent}
            real constant	            signed number . number {exponent}
            printable character	        ASCII 32 | .. | ASCII 255 excluding DEL and ?
            two character hex	        hex digit  hex digit
            character representation	printable character | $$ | $ | $L | $l | $N | $n | $P | $p | $R | $r | $T | $t | $?| $"
                $two character hex
                    Note: The leading $ sign is a control character          (Also known as an escape code)
                Escape Code	    Interpretation
                $$	            Single dollar sign
                $?              Single quotation mark character
                $"	            Double quotation mark character
                $L or $l	    A line feed character
                $N or $n	    A new line character
                $P or $p	    Form feed, new page
                $R or $r	    Carriage return character
                $T or $t	    Tab character

            ASCII character constant	[constant descriptor]'character representation'
            ASCII string constant	    "character representation"
            constant	                Boolean constant | binary digit | unsigned integer |
                                        signed integer | binary integer | hex integer |
                                        real constant | ASCII constant
            */
            var real = new NumberLiteral("Real", NumberOptions.AllowSign);
            var bool_constant = new NonTerminal("bool_constant", typeof(BoolConstrant));
            var constant_descriptor = new NonTerminal("constant_descriptor", typeof(Descriptor));
            var unsigned_integer = new NonTerminal("unsigned_integer", typeof(NumberConstrant));
            var signed_number = new NumberLiteral("decimal", NumberOptions.IntOnly|NumberOptions.AllowSign);
            var signed_integer = new NonTerminal("signed_integer", typeof(NumberConstrant));
            var binary_integer = new NonTerminal("binary_integer", typeof(NumberConstrant));
            var hex_integer = new NonTerminal("hex_integer", typeof(NumberConstrant));
            var real_constant = new NonTerminal("real_constant", typeof(NumberConstrant));
            var character_representation = new StringLiteral("character_representation", "'");
            var ascii_constant = new NonTerminal("ascii_constant");
            var string_constant = new StringLiteral("string_constant", "\"");
            var constant = new NonTerminal("Constant");

            bool_constant.Rule = ToTerm("TRUE") | "FALSE" | "ON" | "OFF";
            constant_descriptor.Rule = (ToTerm("B") | "BYTE" | "W" | "WORD" | "D" | "DWORD") + "#" | Empty;
            unsigned_integer.Rule = constant_descriptor + digits;
            signed_integer.Rule = constant_descriptor + signed_number;
            binary_integer.Rule = constant_descriptor + binarys;
            hex_integer.Rule = constant_descriptor + hexs;
            real_constant.Rule = real;
            ascii_constant.Rule = constant_descriptor + character_representation;
            constant.Rule = bool_constant |  unsigned_integer | signed_integer |
                            binary_integer | hex_integer | real_constant |
                            ascii_constant | string_constant;
            #endregion

            #region Addressing
            /*Addressing
            discrete input	I | E	Note: Case insensitive
            discrete output	Q | A	Note: Case insensitive
            analog input	AI | AE	Note: Case insensitive
            analog output	AQ | AA	Note: Case insensitive
            db memory	    DB	Note: Case insensitive
            variable memory	V	Note: Case insensitive
            flag memory	    M	Note: Case insensitive
            system memory	SM	Note: Case insensitive
            Stage memory	S	Note: Case insensitive
            accumulator	    AC	Note: Case insensitive
            Timer	        T	Note: Case insensitive
            counter	        C | Z	Note: Case insensitive
            high speed counter	HC | HZ	Note: Case insensitive
            data block	    DB	Note: Case insensitive
            local memory	L	Note: Case insensitive
            bit point	    unsigned number . 0 | 1 | ?| 7
            size prefix	    B | W | D                                       Note: Case insensitive
            Direct prefix	        discrete input | discrete output | variable memory | flag memory | system memory | stage memory
            peripheral prefix	    analog input | analog output
            timer counter prefix	timer | counter
            bit address	            direct prefix [X] bit point
            byte word dword address	direct prefix size prefix unsigned number
            peripheral address	    peripheral prefix [W] unsigned number
            timer counter address	timer counter prefix ((X unsigned number) | unsigned number)
            high speed counter address	high speed counter  unsigned number
            accumulator address	    accumulator [size prefix] unsigned number
            db number	            DB unsigned number
            db address	            [db number .] data block ([X] bit point) | (size prefix  unsigned number)
            Direct address	        bit address | byte word dword address | peripheral address |timer counter address | high speed counter address | accumulator address |db address
            indirect address	    * ((accumulator [ D| d ]) | (variable memory D | d ) | (local memory D | d) | ([db number .] data block D | d)) unsigned number
            address of	            & (variable memory | discrete input | discrete output | timer | counter | flag memory | system memory ([db number.] data block) size prefix unsigned number
            */
            var address_term = new AddressTerm("address_term");
            var address = new NonTerminal("address", typeof(Address));

            address.Rule = address_term;
            #endregion

            #region Local Variable Declaration
            /*
            ob declaration	        [var declaration]
            int declaration	        [var declaration]
            sbr declaration	        [io var declaration] ob declarations
            io var declaration	    [var input declaration] [var in out declaration] [var output declaration]
            var input declaration	VAR_INPUT  CR decl_list END_VAR  CR
            var output declaration	VAR_OUTPUT  CR decl_list END_VAR CR
            var in out declaration	VAR_IN_OUT  CR decl_list END_VAR  CR
            var declaration	        VAR  CR decl_list END_VAR  CR
            decl list	            {identifier : complex type }; {comment}
            Type	                Base type | user type | string type
            complex type	        Base type | array type | struct type | user type | string type
            init value	            constant | integer ( init value ) | init value , init value
            base type	            BOOL | BYTE | WORD | DWORD | CHAR | INT | DINT | REAL |
            */
            var base_type = new NonTerminal("base_type");
            var init_value = new NonTerminal("init_value");
            var complex_type = new NonTerminal("complex_type");
            var type = new NonTerminal("type");
            var decl = new NonTerminal("decl", typeof(Declaration));
            var decl_line = new NonTerminal("decl_line");
            var decl_list = new NonTerminal("decl+");
            var decl_list_opt = new NonTerminal("decl*");
            var var_input_decl = new NonTerminal("var_input_decl", typeof(VarDecl));
            var var_output_decl = new NonTerminal("var_output_decl", typeof(VarDecl));
            var var_in_out_decl = new NonTerminal("var_in_out_decl", typeof(VarDecl));
            var var_decl = new NonTerminal("var_decl", typeof(VarDecl));
            var var_input_decl_opt = new NonTerminal("var_input_decl?");
            var var_output_decl_opt = new NonTerminal("var_output_decl?");
            var var_in_out_decl_opt = new NonTerminal("var_in_out_decl?");
            var var_decl_opt = new NonTerminal("var_decl?");
            var var_decl_suffix = new NonTerminal("var_decl_suffix");
            var io_var_decl = new NonTerminal("io_var_decl");

            decl_list.SetFlag(TermFlags.IsList);
            decl_list_opt.SetFlag(TermFlags.IsListContainer);
            MarkTransient(decl_line, complex_type, base_type,
                var_input_decl_opt, var_output_decl_opt, var_in_out_decl_opt);

            base_type.Rule = ToTerm("BOOL") | "BYTE" | "WORD" | "DWORD" | "CHAR" | "INT" | "DINT" | "REAL";
            init_value.Rule = init_value + comma + constant | constant | ToTerm("integer") + "(" + constant + ")";
            complex_type.Rule = base_type;
            type.Rule = base_type;
            decl.Rule = identifier + ":" + complex_type + ";" + comment_opt + NewLine;
            decl_line.Rule = decl | empty_line;
            decl_list.Rule = decl_list + decl_line | decl_line;
            decl_list_opt.Rule = decl_list | Empty;
            var_decl_suffix.Rule = NewLine + decl_list_opt + "END_VAR" + NewLine;
            var_input_decl.Rule = "VAR_INPUT" + var_decl_suffix;
            var_output_decl.Rule = "VAR_OUTPUT" + var_decl_suffix;
            var_in_out_decl.Rule = "VAR_IN_OUT" + var_decl_suffix;
            var_decl.Rule = "VAR" + var_decl_suffix;
            var_input_decl_opt.Rule = var_input_decl | Empty;
            var_output_decl_opt.Rule = var_output_decl | Empty;
            var_in_out_decl_opt.Rule = var_in_out_decl | Empty;
            var_decl_opt.Rule = var_decl | Empty;
            io_var_decl.Rule = var_input_decl_opt + var_output_decl_opt + var_in_out_decl_opt;
            #endregion

            #region Program Structure
            /*Note:
            Keywords are case insensitive unless otherwise noted.

            Block title	    { white space } (TITLE =  comment characters CR | comment)
            Block comment	{comment}
            network title	{ white space } (TITLE =  comment characters CR | comment)
            network comment	{comment}
            line comment	{comment}
            code comment	{comment}
            network number	{ space | unsigned number }
            operand	        { white space } global variable | local variable | constant | direct address | indirect address | address of
            instruction mnemonic	(letter | digit | _ ) { letter | digit | _ }
            instruction	            instruction mnemonic [(white space) { white space } operand {(,| white space) { white space } operand}] ; code comment
            statement list	        {instruction | line comment}
            network	                NETWORK network number (CR | [network title] [network comment]) statement list
            ob number	            OB unsigned number
            organization block	    ORGANIZATION_BLOCK (ob number) (CR | [block title] [block comment])ob declarations BEGIN [network] END_ORGANIZATION_BLOCK CR
            sbr number	            SBR unsigned number
            subroutine block	    SUBROUTINE_BLOCK (sbr number) (CR [block title] [block comment])sbr declarations BEGIN [network] END_SUBROUTINE_BLOCK CR
            int number	            INT unsigned_number
            interrupt block	        INTERRUPT_BLOCK (int number) (CR [block title] [block comment]) int declarations BEGIN [network] END_INTERRUPT_BLOCK CR
             */
            var title_content = new FreeTextLiteral("Title", "\r", "\n");

            var title = new NonTerminal("title");
            var title_opt = new NonTerminal("title?");
            var network_number = new NonTerminal("network_number");
            var mnemonic = new NonTerminal("mnemonic");
            var operand = new NonTerminal("operand");
            var operand_list = new NonTerminal("operand+");
            var operand_list_opt = new NonTerminal("operand*");
            var instruction = new NonTerminal("instruction", typeof(Instruction));
            var statement = new NonTerminal("statement");
            var statement_list = new NonTerminal("statement_list");
            var statement_list_opt = new NonTerminal("statement*");
            var network = new NonTerminal("network", typeof(Network));
            var network_list = new NonTerminal("network+");
            var network_list_opt = new NonTerminal("network*", typeof(NodeList));
            var ob_number = new NonTerminal("ob_number");
            var block_1 = new NonTerminal("block_1");
            var block_2 = new NonTerminal("block_2");
            var organization_block = new NonTerminal("organization_block", typeof(POU));
            var sbr_number = new NonTerminal("sbr_number");
            var subroutine_block = new NonTerminal("subroutine_block", typeof(POU));
            var int_number = new NonTerminal("int_number");
            var interrupt_block = new NonTerminal("interrupt_block", typeof(POU));
            var subroutine_block_list = new NonTerminal("subroutine_block+");
            var interrupt_block_list = new NonTerminal("interrupt_block+");
            var subroutine_block_list_opt = new NonTerminal("subroutine_block*", typeof(NodeList));
            var interrupt_block_list_opt = new NonTerminal("interrupt_block*", typeof(NodeList));
            var program = new NonTerminal("program", typeof(Block));

            operand_list.SetFlag(TermFlags.IsList);
            statement_list.SetFlag(TermFlags.IsList);
            network_list.SetFlag(TermFlags.IsList);
            subroutine_block_list.SetFlag(TermFlags.IsList);
            interrupt_block_list.SetFlag(TermFlags.IsList);
            operand_list_opt.SetFlag(TermFlags.IsListContainer);
            statement_list_opt.SetFlag(TermFlags.IsListContainer);
            network_list_opt.SetFlag(TermFlags.IsListContainer);
            subroutine_block_list_opt.SetFlag(TermFlags.IsListContainer);
            interrupt_block_list_opt.SetFlag(TermFlags.IsListContainer);
            MarkTransient(constant, mnemonic, operand, statement);

            mnemonic.Rule = bit_logic_mnemonic | clock_mnemonic | communication_mnemonic |
                compare_mnemonic | convert_mnemonic | counter_mnemonic | floatpoint_math_mnemonic |
                integer_math_mnemonic | logical_mnemonic | move_mnemonic | program_control_mnemonic |
                shift_rotate_mnemonic | string_mnemonic | table_mnemonic | timer_mnemonic | subroutine_mnemonic;
            title.Rule = ToTerm("TITLE") + "=" + title_content + NewLine;
            title_opt.Rule = title | Empty;
            operand.Rule = global_variable | local_variable | constant | address;
            operand_list.Rule = operand_list + comma + operand | operand;
            operand_list_opt.Rule = operand_list | Empty;
            instruction.Rule = mnemonic + operand_list_opt + semi_opt + comment_opt + NewLine;
            statement.Rule = instruction | line_comment | NewLine;
            statement_list.Rule = statement_list + statement | statement;
            statement_list_opt.Rule = statement_list | Empty;
            network_number.Rule = digits | Empty;
            network.Rule = "NETWORK" + network_number + comment_opt + NewLine + title_opt + statement_list_opt;
            network_list.Rule = network_list + network | network;
            network_list_opt.Rule = network_list | Empty;
            block_1.Rule = identifier + ":" + identifier + NewLine + title_opt + empty_lines_opt;
            block_2.Rule = "BEGIN" + NewLine + network_list_opt;
            organization_block.Rule =
                "ORGANIZATION_BLOCK" + block_1 + var_decl_opt + block_2 + "END_ORGANIZATION_BLOCK" + NewLine;
            subroutine_block.Rule =
                "SUBROUTINE_BLOCK" + block_1 + io_var_decl + var_decl_opt + block_2 + "END_SUBROUTINE_BLOCK" + NewLine;
            interrupt_block.Rule =
                "INTERRUPT_BLOCK" + block_1 + var_decl_opt + block_2 + "END_INTERRUPT_BLOCK" + NewLine;
            subroutine_block_list.Rule = subroutine_block_list + subroutine_block | subroutine_block;
            interrupt_block_list.Rule = interrupt_block_list + interrupt_block | interrupt_block;
            subroutine_block_list_opt.Rule = subroutine_block_list | Empty;
            interrupt_block_list_opt.Rule = interrupt_block_list | Empty;
            program.Rule = organization_block + subroutine_block_list_opt + interrupt_block_list_opt;
            #endregion

            //Set grammar root
            this.Root = program;
            this.WhitespaceChars = " \t\v";

            MarkPunctuation("(", ")", ":", ";", ".", ",");
            MarkPunctuation(semi_opt, comma_opt,
                comment, comment_opt, line_comment, empty_line, empty_lines, empty_lines_opt);

            this.LanguageFlags = LanguageFlags.NewLineBeforeEOF |
                LanguageFlags.CreateAst;
        }
コード例 #18
0
ファイル: Grammar.cs プロジェクト: 201123065/Irony
 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;
 }
コード例 #19
0
ファイル: SpecParser.cs プロジェクト: mirhagk/IronTuring
        public SpecParser()
        {
            //Expr -> n | v | Expr BinOp Expr | UnOP Expr | ( Expr )
            //BinOp -> + | - | * | / | **
            //UnOp -> -
            //ExprLine -> Expr EOF

            //1. Terminals
            //Terminal num = new NumberLiteral("number");
            Terminal id = new IdentifierTerminal("id");
            //Terminal stringLiteral = TerminalFactory.CreateCSharpString("stringLiteral");
            CommentTerminal SingleLineComment = new CommentTerminal("SingleLineComment", "%", "\r", "\n", "\u2085", "\u2028", "\u2029");
            CommentTerminal DelimitedComment = new CommentTerminal("DelimitedComment", "/*", "*/");
            NonGrammarTerminals.Add(SingleLineComment);
            NonGrammarTerminals.Add(DelimitedComment);

            //2. Non-Terminals
            //Programs and declarations
            var program = new NonTerminal("program");
            var declarationOrStatementsInMainProgram = new NonTerminal("declarationOrStatementsInMainProgram");
            var declaration = new NonTerminal("declaration");
            var constantDeclaration = new NonTerminal("constantDeclaration");
            var initializingValue = new NonTerminal("initializingValue");
            var variableDeclaration = new NonTerminal("variableDeclaration");

            //Types
            var typeDeclaration = new NonTerminal("typeDeclaration");
            var typeSpec = new NonTerminal("typeSpec");
            var standardType = new NonTerminal("standardType");
            var subrangeType = new NonTerminal("subrangeType");
            var arrayType = new NonTerminal("arrayType");
            var indexType = new NonTerminal("indexType");
            var recordType = new NonTerminal("recordType");
            var namedType = new NonTerminal("namedType");

            //subprograms
            var subprogramDeclaration = new NonTerminal("subprogramDeclaration");
            var subprogramHeader = new NonTerminal("subprogramHeader");
            var parameterDeclaration = new NonTerminal("parameterDeclaration");
            var parameterType = new NonTerminal("parameterType");
            var subprogramBody = new NonTerminal("subprogramBody");

            //statements and input/output
            var declarationsAndStatements = new NonTerminal("declarationsAndStatements");
            var declarationOrStatement = new NonTerminal("declarationOrStatement");
            var statement = new NonTerminal("statement");
            var procedureCall = new NonTerminal("procedureCall");
            var ifStatement = new NonTerminal("ifStatement");
            var loopStatement = new NonTerminal("loopStatement");
            var caseStatement = new NonTerminal("caseStatement");
            var forStatement = new NonTerminal("forStatement");
            var putStatement = new NonTerminal("putStatement");
            var putItem = new NonTerminal("putItem");
            var getStatement = new NonTerminal("getStatement");
            var getItem = new NonTerminal("getItem");
            var openStatement = new NonTerminal("openStatement");
            var capability = new NonTerminal("capability");
            var closeStatement = new NonTerminal("closeStatement");
            var streamNumber = new NonTerminal("streamNumber");
            var widthExpn = new NonTerminal("widthExpn");
            var fractionWidth = new NonTerminal("fractionWidth");
            var exponentWidth = new NonTerminal("exponentWidth");
            var fileNumber = new NonTerminal("fileNumber");
            var fileNumberVariable = new NonTerminal("fileNumberVariable");//this was not defined in the spec. The behaviour should conform to how the language works, but it's not guaranteed
            var fileName = new NonTerminal("fileName"); //above is a variable declared of int type, and this is either string constant or variable

            //References and Expressions
            var variableReference = new NonTerminal("variableReference");
            var reference = new NonTerminal("reference");
            var componentSelector = new NonTerminal("componentSelector");
            var booleanExpr = new NonTerminal("booleanExpr");
            var compileTimeExpn = new NonTerminal("compileTimeExpn");
            var expn = new NonTerminal("expn");
            var explicitConstant = new NonTerminal("explicitConstant");
            var infixOperator = new NonTerminal("infixOperator");
            var prefixOperator = new NonTerminal("prefixOperator");
            var substring = new NonTerminal("substring");
            var substringPosition = new NonTerminal("substringPosition");

            //Explicit Constants
            Terminal explicitStringConstant = TerminalFactory.CreateCSharpString("explicitStringConstant");//new StringLiteral("explicitStringConstant");//new NonTerminal("explicitStringConstant");
            Terminal explicitUnsignedRealConstant = new NumberLiteral("explicitUnsignedRealConstant", NumberOptions.Default);//new NonTerminal("explicitUnsignedRealConstant");
            Terminal explicitUnsignedIntegerConstant = new NumberLiteral("explicitUnsignedIntegerConstant", NumberOptions.IntOnly | NumberOptions.NoDotAfterInt);//new NonTerminal("explicitUnsignedIntegerConstant");

            //3. BNF Rules
            //Programs and declarations
            program.Rule = MakeStarRule(program, declarationOrStatementsInMainProgram);
            declarationOrStatementsInMainProgram.Rule = declaration | statement | subprogramDeclaration;
            declaration.Rule = constantDeclaration | variableDeclaration | typeDeclaration;
            constantDeclaration.Rule = ToTerm("const") + id + ":=" + expn
                                       | "const" + id + ":" + typeSpec + ":=" + initializingValue;
            initializingValue.Rule = expn | "init" + "(" + MakePlusRule(initializingValue, ToTerm(","), initializingValue) + ")";
            variableDeclaration.Rule = ToTerm("var") + MakePlusRule(variableDeclaration, ToTerm(","), id) + ":=" + expn
                                       | "var" + MakePlusRule(variableDeclaration, ToTerm(","), id) + ":" + typeSpec + (":=" + initializingValue | Empty);

            //Types
            typeDeclaration.Rule = ToTerm("type") + id + ":" + typeSpec;
            typeSpec.Rule = standardType | subrangeType | arrayType | recordType | namedType;
            standardType.Rule = ToTerm("int") | "real" | "boolean" | "string" + ("(" + compileTimeExpn + ")" | Empty);
            subrangeType.Rule = compileTimeExpn + ".." + expn;
            arrayType.Rule = ToTerm("array") + MakePlusRule(arrayType, ToTerm(","), indexType) + "of" + typeSpec;
            indexType.Rule = subrangeType | namedType;
            recordType.Rule = ToTerm("record") + MakePlusRule(recordType, MakePlusRule(recordType, ToTerm(","), id) + ":" + typeSpec) + "end" + "record";
            namedType.Rule = id;

            //Subprograms
            subprogramDeclaration.Rule = subprogramHeader + subprogramBody;
            subprogramHeader.Rule = ToTerm("procedure") + id + ("(" + MakePlusRule(subprogramHeader, ToTerm(","), parameterDeclaration) + ")" | Empty)
                                  | "function" + id + ("(" + MakePlusRule(subprogramHeader, ToTerm(","), parameterDeclaration) + ")" | Empty) + ":" + typeSpec;
            parameterDeclaration.Rule = (ToTerm("var") | Empty) + MakePlusRule(parameterDeclaration, ToTerm(","), id) + ":" + parameterType;
            parameterType.Rule = typeSpec | "string" + "(" + "*" + ")"
                               | "array" + MakePlusRule(parameterType, ToTerm(","), compileTimeExpn + ".." + "*") + "of" + typeSpec
                               | "array" + MakePlusRule(parameterType, ToTerm(","), compileTimeExpn + ".." + "*") + "of" + "string" + "(" + "*" + ")";
            subprogramBody.Rule = declarationsAndStatements + "end" + id;

            //Statements and Input/Output
            declarationsAndStatements.Rule = MakePlusRule(declarationsAndStatements, declarationOrStatement);
            declarationOrStatement.Rule = declaration | statement;
            statement.Rule = variableReference + ":=" + expn
                            | procedureCall
                            | "assert" + booleanExpr
                            | "result" + expn
                            | ifStatement
                            | loopStatement
                            | "exit" + ("when" + booleanExpr | Empty)
                            | caseStatement
                            | forStatement
                            | putStatement
                            | getStatement
                            | openStatement
                            | closeStatement;
            procedureCall.Rule = reference;
            ifStatement.Rule = ToTerm("if") + booleanExpr + "then" + declarationsAndStatements + MakeStarRule(ifStatement, ToTerm("elsif") + booleanExpr + "then" + declarationsAndStatements) + ("else" + declarationsAndStatements | Empty) + "end" + "if";
            loopStatement.Rule = ToTerm("loop") + declarationsAndStatements + "end" + "loop";
            caseStatement.Rule = ToTerm("case") + expn + "of" + MakePlusRule(caseStatement, ToTerm("label") + MakePlusRule(caseStatement, ToTerm(","), compileTimeExpn) + ":" + declarationsAndStatements) + ("label" + ":" + declarationsAndStatements | Empty) + "end" + "case";
            forStatement.Rule = ToTerm("for") + (id | Empty) + ":" + expn + ".." + expn + ("by" + expn | Empty) + declarationsAndStatements + "end" + "for"
                                | "for" + "decreasing" + (id | Empty) + ":" + expn + ".." + expn + ("by" + expn | Empty) + declarationsAndStatements + "end" + "for";
            putStatement.Rule = ToTerm("put") + (":" + streamNumber + "," | Empty) + MakePlusRule(putStatement, ToTerm(","), putItem) + (".." | Empty);
            putItem.Rule = expn + (":" + widthExpn + (":" + fractionWidth + (":" + exponentWidth | Empty) | Empty) | Empty) | "skip";
            getStatement.Rule = ToTerm("get") + (":" + streamNumber + "," | Empty) + MakePlusRule(getStatement, ToTerm(","), getItem);
            getItem.Rule = variableReference | "skip" | variableReference + ":" + "*" | variableReference + ":" + widthExpn;
            openStatement.Rule = ToTerm("open") + ":" + fileNumberVariable + "," + fileName + "," + MakePlusRule(openStatement, ToTerm(","), capability);
            capability.Rule = ToTerm("put") | "get";
            closeStatement.Rule = ToTerm("close") + ":" + fileNumber;
            streamNumber.Rule = widthExpn.Rule = fractionWidth.Rule = exponentWidth.Rule = fileNumber.Rule = expn;

            //Following are guesses as to the rules, since the spec does not state the rules for them
            fileNumberVariable.Rule = variableReference;
            fileName.Rule = explicitStringConstant | variableReference;

            //References and Expressions
            variableReference.Rule = reference;
            reference.Rule = id | reference + componentSelector;
            componentSelector.Rule = "(" + MakePlusRule(componentSelector, ToTerm(","), expn) + ")" | "." + id;
            booleanExpr.Rule = compileTimeExpn.Rule = expn;
            expn.Rule = reference | explicitConstant | substring | expn + infixOperator + expn | prefixOperator + expn | "(" + expn + ")";
            expn.SetFlag(TermFlags.InheritPrecedence);
            explicitConstant.Rule = explicitUnsignedIntegerConstant | explicitUnsignedRealConstant | explicitStringConstant | "true" | "false";
            infixOperator.Rule = ToTerm("+") | "-" | "*" | "/" | "div" | "mod" | "**" | "<" | ">" | "=" | "<=" | ">=" | "not=" | "and" | "or";
            //prefixOperator.Precedence = 70;
            prefixOperator.Rule = ToTerm("+") | "-" | "not";
            substring.Rule = reference + "(" + substringPosition + (".." + substringPosition | Empty) + ")";
            substringPosition.Rule = expn | "*" + ("-" + expn | Empty);

            this.Root = program;

            //4. Set operator precendence and associativity
            RegisterOperators(80, Associativity.Left, "**");//this is VERY odd, but Turing simplifies associativity by saying it's all left associative
            RegisterOperators(60, "*","/","div","mod");
            RegisterOperators(50, "+", "-");
            RegisterOperators(40, "<", ">", "=", "<=", ">=", "not=");
            RegisterOperators(30, "not");
            RegisterOperators(20, "and");
            RegisterOperators(10, "or");

            //5. Register Parenthesis as punctuation symbols so they will not appear in the syntax tree
            MarkPunctuation("(", ")", ",");
            RegisterBracePair("(", ")");
            //MarkTransient(Expr, BinOp, ParExpr);

            this.LanguageFlags = LanguageFlags.NewLineBeforeEOF;
        }