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

            Root = program;

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

            RegisterBracePair("{", "}");

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

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

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

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

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

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

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

            operation.Rule = expression + @operator + expression;

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

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

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

            whileStatement.Rule = ToTerm("while") + parenExpression + "{" + statementList + "}";
        }
        public ASLGrammar()
            : base(true)
        {
            var string_lit = TerminalFactory.CreateCSharpString("string");
            var number = TerminalFactory.CreateCSharpNumber("number");
            var identifier = TerminalFactory.CreateCSharpIdentifier("identifier");
            var code = new CustomTerminal("code", MatchCodeTerminal);

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

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

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

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

            Root = root;

            MarkTransient(var_list, method_list, offset, method_type);

            LanguageFlags = LanguageFlags.NewLineBeforeEOF;
        }
Exemplo n.º 3
0
        public KISGrammer()
        {
            var number = new NumberLiteral("number");
            var text = new StringLiteral("string", "\"");

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

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

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

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

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

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

            var Semicolon = ToTerm(";");

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

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

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

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

            ExsprStmt.Rule = Value + Operator + Value;

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

            Value.Rule = number | ValueString | identifier | "true" | "false" | Exspr /* | text */;
            Code.Rule = MakePlusRule(Code, NewLine, Statments);
            LanguageFlags = LanguageFlags.NewLineBeforeEOF;
            //code := Statment {statment}
            this.Root = Code;
        }
Exemplo n.º 4
0
 public IntegrationTestGrammar() {
   var comment = new CommentTerminal("comment", "/*", "*/");
   base.NonGrammarTerminals.Add(comment);
   var str = new StringLiteral("str", "'", StringOptions.AllowsLineBreak);
   var stmt = new NonTerminal("stmt");
   stmt.Rule = str | Empty;
   this.Root = stmt; 
 }
Exemplo n.º 5
0
        private readonly TerminalSet mSkipTokensInPreview = new TerminalSet(); //used in token preview for conflict resolution

        #endregion Fields

        #region Constructors

        public JavaGrammar()
        {
            GrammarComments = "NOTE: This grammar does not parse hex floating point literals.";

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

            MarkPunctuation(";", ",", "(", ")", "{", "}", "[", "]", ":", "@");

            InitializeSyntax();
        }
Exemplo n.º 6
0
        public LinearProgrammingGrammar()
        {
            var comment = new CommentTerminal("comment", "#", "\n", "\r");
            NonGrammarTerminals.Add(comment);

            var identifier = new IdentifierTerminal("appIdentifier");
            var variable = new IdentifierTerminal("variable");

            var number = new NumberLiteral("number", NumberOptions.AllowSign);

            var lpProgram = new NonTerminal("lpApp");
            var lpAppName = new NonTerminal("lpAppName");
            var lpModel = new NonTerminal("lpModel");

            var lpGoal = new NonTerminal("lpGoal");
            var lpPolynomial = new NonTerminal("lpPolynomial");
            var lpConstraints = new NonTerminal("lpConstraints");
            var lpConstraint = new NonTerminal("lpConstraints");
            var lpOperator = new NonTerminal("lpOperator", "lp Operation symbol");
            var lpBinOp = new NonTerminal("lpBinOp", "lp Binary Operation symbol");
            var lpMonomial = new NonTerminal("Monomial");
            var lpNumber = new NonTerminal("lpNumber");

            lpProgram.Rule = lpAppName + "{" + lpModel + "}" + ";";

            lpAppName.Rule = ToTerm("lpmodel") + identifier;

            lpModel.Rule = lpGoal + ToTerm("subject to") +":" + lpConstraints;

            lpGoal.Rule = ToTerm("max") + lpPolynomial | ToTerm("min") + lpPolynomial;

            lpConstraints.Rule = MakePlusRule(lpConstraints, null, lpConstraint);

            //ReduceHere();
            lpConstraint.Rule = lpPolynomial + lpOperator + lpPolynomial + ";";

            lpOperator.Rule = ToTerm("<") | "==" | ">" | "<=" | ">=";

            lpPolynomial.Rule = lpMonomial | lpMonomial + lpBinOp + lpPolynomial  | lpNumber |
                                lpNumber + lpBinOp + lpPolynomial;

            lpMonomial.Rule = variable | lpNumber + ToTerm("*") + variable;

            lpBinOp.Rule = ToTerm("+") | "-";
            lpNumber.Rule = number | lpBinOp + number;

            MarkReservedWords("max", "min", "lpmodel", "subject to");

               // ReduceIf("");
            Root = lpProgram;
        }
        public NumericalSchemeGrammar()
        {
            this.GrammarComments = "";

            //Symbols
            var whitespace = new NonTerminal("WhiteSpace", Empty | " " | "\t");
            // Comments
            var singleLineComment = new CommentTerminal("SingleLineComment", "//", "\r", "\n", "\u2085", "\u2028", "\u2029");
            var multiLineComment = new CommentTerminal("DelimitedComment", "/*", "*/");
            NonGrammarTerminals.Add(singleLineComment);
            NonGrammarTerminals.Add(multiLineComment);

            //Terminals
            var semicolon = ToTerm(";", "Semicolon");
            var ofString = new StringLiteral("String", "\"");
            var ofNumber = new NumberLiteral("Number", NumberOptions.AllowSign);
            var ofIdentifier = TerminalFactory.CreateCSharpIdentifier("Identifier");
            var ofArrayTerm = new IdentifierTerminal("SchemeTerm", "(),|*.+-/%^~!&");

            //Non-terminals
            var ofValue = new NonTerminal("Value");

            var ofDictionary = new NonTerminal("Dictionary");
            var ofDictionaryContent = new NonTerminal("DictionaryContent");
            var ofDictionaryContentWrapper = new NonTerminal("DictionaryContentWrapper");
            var ofDictEntry = new NonTerminal("DictEntry");

            var ofArrayEntry = new NonTerminal("ArrayEntry");
            var ofArray = new NonTerminal("Array");
            var ofArrayWrapper = new NonTerminal("ArrayWrapper");

            //BNF
            ofValue.Rule = ofIdentifier | ofArrayTerm | ofString | ofNumber;

            ofDictEntry.Rule = ofArrayWrapper | ofDictionary;
            ofDictionaryContent.Rule = MakeStarRule(ofDictionaryContent, whitespace, ofDictEntry);
            ofDictionaryContentWrapper.Rule = "{" + ofDictionaryContent + "}";
            ofDictionary.Rule = ofIdentifier + whitespace + ofDictionaryContentWrapper;

            ofArrayEntry.Rule = ofValue;
            ofArray.Rule = MakeStarRule(ofArray, whitespace, ofArrayEntry);
            ofArrayWrapper.Rule = ofArray + semicolon;

            //Set grammar root
            this.Root = ofDictionaryContent;
            MarkPunctuation("{", "}");
            MarkTransient(ofValue, ofDictionaryContentWrapper);
        }
        public ASLGrammar()
            : base(true)
        {
            var stringLit = TerminalFactory.CreateCSharpString("string");
            var number = TerminalFactory.CreateCSharpNumber("number");
            var identifier = TerminalFactory.CreateCSharpIdentifier("identifier");
            var code = new CustomTerminal("code", MatchCodeTerminal);
            var singleLineComment = new CommentTerminal("SingleLineComment", "//", "\r", "\n", "\u2085", "\u2028", "\u2029");
            var delimitedComment = new CommentTerminal("DelimitedComment", "/*", "*/");
            NonGrammarTerminals.Add(singleLineComment);
            NonGrammarTerminals.Add(delimitedComment);

            var state = new KeyTerm("state", "state");
            var start = new KeyTerm("start", "start");
            var split = new KeyTerm("split", "split");
            var reset = new KeyTerm("reset", "reset");
            var isLoading = new KeyTerm("isLoading", "isLoading");
            var gameTime = new KeyTerm("gameTime", "gameTime");
            var comma = ToTerm(",", "comma");
            var semi = ToTerm(";", "semi");

            var root = new NonTerminal("root");
            var stateDef = new NonTerminal("stateDef");
            var methodList = new NonTerminal("methodList");
            var varList = new NonTerminal("varList");
            var var = new NonTerminal("var");
            var method = new NonTerminal("method");
            var offsetList = new NonTerminal("offsetList");
            var offset = new NonTerminal("offset");
            var methodType = new NonTerminal("methodType");

            root.Rule = stateDef + methodList;
            stateDef.Rule = state + "(" + stringLit + ")" + "{" + varList + "}";
            methodList.Rule = MakeStarRule(methodList, method);
            varList.Rule = MakeStarRule(varList, semi, var);
            var.Rule = (identifier + identifier + ":" + stringLit + comma + offsetList) | Empty;
            method.Rule = (methodType + "{" + code + "}") | Empty;
            offsetList.Rule = MakePlusRule(offsetList, comma, offset);
            offset.Rule = number;
            methodType.Rule = start | split | isLoading | gameTime | reset;

            this.Root = root;

            MarkTransient(varList, methodList, offset, methodType);

            this.LanguageFlags = LanguageFlags.NewLineBeforeEOF;
        }
Exemplo n.º 9
0
        /// <summary>
        /// 使うな
        /// </summary>
        public Kbtter3QueryGrammar()
            : base()
        {
            //コメント
            var comment = new CommentTerminal("Comment", "/*", "*/");
            NonGrammarTerminals.Add(comment);

            //リテラル
            var number = new NumberLiteral("Number", NumberOptions.AllowSign | NumberOptions.AllowStartEndDot);
            var str = new StringLiteral("String", "\"");
            var regex = new RegexLiteral("Regex", '/', '\\');
            var ident = new IdentifierTerminal("Identifer");

            //非終端
            var Value = new NonTerminal("Value");
            var Term = new NonTerminal("Term");
            var Expression = new NonTerminal("Expression");
            var BinExpression = new NonTerminal("BinExpression");
            var ParExpression = new NonTerminal("ParExpression");
            var PostfixExpression = new NonTerminal("PostfixExpression");
            var Operator = new NonTerminal("Operator");

            //非終端定義
            Value.Rule = number | str | ident | regex | "null" | "true" | "false";
            Term.Rule = Value | ParExpression;
            Operator.Rule = ToTerm("==") | "!=" | ">" | "<" | ">=" | "<=" | "match" | "&&" | "||" | "+" | "-" | "*" | "/" | "%" | "&" | "|" | "^" | ".";
            BinExpression.Rule = Expression + Operator + Expression;
            PostfixExpression.Rule = (ToTerm("+") + Term) | ("-" + Term) | ("!" + Term);
            Expression.Rule = BinExpression | Term | PostfixExpression;
            ParExpression.Rule = ToTerm("(") + Expression + ")";

            RegisterOperators(10, ".");
            RegisterOperators(9, "*", "/", "%");
            RegisterOperators(8, "+", "-");
            RegisterOperators(7, ">", "<", ">=", "<=", "match");
            RegisterOperators(6, "==", "!=");
            RegisterOperators(5, "&");
            RegisterOperators(4, "^");
            RegisterOperators(3, "|");
            RegisterOperators(2, "&&");
            RegisterOperators(1, "||");

            Root = Expression;
            MarkPunctuation("(", ")");
            MarkTransient(Expression, ParExpression, Value, Operator, Term);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 新しいインスタンスを以下略
        /// </summary>
        public Kb10uyConfigGrammar()
            : base()
        {
            var Number = new NumberLiteral("Number");
            var String = new StringLiteral("String", "\"", StringOptions.AllowsAllEscapes);
            var CommentLine = new CommentTerminal("Comment", "#", "\n", "\r");
            var CommentBlock = new CommentTerminal("Comment", "#<", ">");
            //数値設定
            Number.DefaultIntTypes = new[] { TypeCode.Int32 };
            Number.DefaultFloatType = TypeCode.Double;
            String.EscapeChar = '\\';
            NonGrammarTerminals.Add(CommentBlock);
            NonGrammarTerminals.Add(CommentLine);

            var Value = new NonTerminal("Value");
            var Values = new NonTerminal("Value\'s\'");
            var ValueSet = new NonTerminal("Array");
            var Property = new NonTerminal("Property");
            var Prefix = new NonTerminal("Prefix");
            var Node = new NonTerminal("Node");
            var Nodes = new NonTerminal("Nodes");
            //var PropertySet = new NonTerminal("PropertySet");
            var Group = new NonTerminal("Group");
            var ConfigRoot = new NonTerminal("Root");

            Value.Rule = Number | String | ValueSet;
            Values.Rule = MakeStarRule(Values, ToTerm(","), Value);
            ValueSet.Rule = ToTerm("[") + Values + "]";
            Prefix.Rule = ToTerm("Number") | "String" | "Array" ;
            Property.Rule = Prefix + ":" + String + "=" + Value + ";";
            Node.Rule = Property | Group;
            Nodes.Rule = MakeStarRule(Nodes, Node);
            Group.Rule = String + ":" + "{" +Nodes+ "}";
            ConfigRoot.Rule = MakeStarRule(ConfigRoot, Group);
            Root = ConfigRoot;

            MarkPunctuation("[", "]", ",", "{", "}",":",";","=");
        }
Exemplo n.º 11
0
    // It is loosely based on R6RS specs.  
    // See Grammar Errors tab in GrammarExplorer for remaining conflicts.
    public SchemeGrammar() {

      #region Terminals
      ConstantTerminal Constant = new ConstantTerminal("Constant");
      Constant.Add("#T", 1);
      Constant.Add("#t", 1);
      Constant.Add("#F", null);
      Constant.Add("#f", null);
      Constant.Add("'()", null);
      Constant.Add(@"#\nul", '\u0000');
      Constant.Add(@"#\alarm", '\u0007');
      Constant.Add(@"#\backspace", '\b');
      Constant.Add(@"#\tab", '\t');
      Constant.Add(@"#\linefeed", '\n');
      Constant.Add(@"#\vtab", '\v');
      Constant.Add(@"#\page", '\f');
      Constant.Add(@"#\return", '\r');
      Constant.Add(@"#\esc", '\u001B');
      Constant.Add(@"#\space", ' ');
      Constant.Add(@"#\delete", '\u007F');

      // TODO: build SchemeCharLiteral
      // the following is nonsense, just to put something there
      var charLiteral = new StringLiteral("Char", "'", StringOptions.None); 
      var stringLiteral = new StringLiteral("String", "\"", StringOptions.AllowsAllEscapes);
      //Identifiers. Note: added "-", just to allow IDs starting with "->" 
      var SimpleIdentifier = new IdentifierTerminal("SimpleIdentifier", "_+-*/.@?!<>=", "_+-*/.@?!<>=$%&:^~");
      //                                                           name                extraChars      extraFirstChars  
      var Number = TerminalFactory.CreateSchemeNumber("Number");
      var Byte = new NumberLiteral("Byte", NumberOptions.IntOnly); 

      //Comments
      Terminal Comment = new CommentTerminal("Comment", "#|", "|#");
      Terminal LineComment = new CommentTerminal("LineComment", ";", "\n");
      NonGrammarTerminals.Add(Comment); //add comments explicitly to this list as it is not reachable from Root
      NonGrammarTerminals.Add(LineComment);
      #endregion

      #region NonTerminals
      var Module = new NonTerminal("Module");
      var Library = new NonTerminal("Library");
      var LibraryList = new NonTerminal("Library+");
      var Script = new NonTerminal("Script");

      var Abbreviation = new NonTerminal("Abbreviation");
      var Vector = new NonTerminal("Vector");
      var ByteList = new NonTerminal("ByteList");
      var ByteVector = new NonTerminal("ByteVector");
      var Datum = new NonTerminal("Datum"); //Datum in R6RS terms
      var DatumOpt = new NonTerminal("DatumOpt"); //Datum in R6RS terms
      var DatumList = new NonTerminal("Datum+");
      var DatumListOpt = new NonTerminal("Datum*");
      var Statement = new NonTerminal("Statement");
      var Atom = new NonTerminal("Atom");
      var CompoundDatum = new NonTerminal("CompoundDatum");
      var AbbrevPrefix = new NonTerminal("AbbrevPrefix");

      var LibraryName = new NonTerminal("LibraryName");
      var LibraryBody = new NonTerminal("LibraryBody");
      var ImportSection = new NonTerminal("ImportSection");
      var ExportSection = new NonTerminal("ExportSection");
      var ImportSpec = new NonTerminal("ImportSpec");
      var ImportSpecList = new NonTerminal("ImportSpecList");
      var ExportSpec = new NonTerminal("ExportSpec");
      var ExportSpecList = new NonTerminal("ExportSpecList");
      var LP = new NonTerminal("LP"); //"(" or "["
      var RP = new NonTerminal("RP"); // ")" or "]"
      var Identifier = new NonTerminal("Identifier");
      var IdentifierList = new NonTerminal("IdentifierList");
      var IdentifierListOpt = new NonTerminal("IdentifierListOpt");
      var PeculiarIdentifier = new NonTerminal("PeculiarIdentifier");
      var LibraryVersion = new NonTerminal("LibraryVersion");
      var VersionListOpt = new NonTerminal("VersionListOpt");

      var FunctionCall = new NonTerminal("FunctionCall");
      var FunctionRef = new NonTerminal("FunctionRef");
      var SpecialForm = new NonTerminal("SpecialForm");
      var DefineVarForm = new NonTerminal("DefineVarForm");
      var DefineFunForm = new NonTerminal("DefineFunForm");
      var LambdaForm = new NonTerminal("LambdaForm");
      var IfForm = new NonTerminal("IfForm");
      var CondForm = new NonTerminal("CondForm");
      var CondClause = new NonTerminal("CondClause");
      var CondClauseList = new NonTerminal("CondClauseList");
      var CondElseOpt = new NonTerminal("CondElseOpt");
      var BeginForm = new NonTerminal("BeginForm");
      var LetForm = new NonTerminal("LetForm"); //not implemented
      var LetRecForm = new NonTerminal("LetRecForm"); //not implemented
      var LetPair = new NonTerminal("LetPair");
      var LetPairList = new NonTerminal("LetPairList");
      #endregion

      #region Rules
      base.Root = Module; 

      LP.Rule = ToTerm("(") | "[";  //R6RS allows mix & match () and []
      RP.Rule = ToTerm(")") | "]";

      // Module.Rule = LibraryListOpt + Script; -- this brings conflicts
      Module.Rule = LibraryList + Script | Script;
      LibraryList.Rule = MakePlusRule(LibraryList, Library);
      Script.Rule = ImportSection + DatumList | DatumList; 

      //Library
      // the following doesn't work - brings conflicts that incorrectly resolved by default shifting
      //Library.Rule = LP + "library" + LibraryName + ExportSectionOpt + ImportSectionOpt + DatumListOpt + RP;
      Library.Rule = LP + "library" + LibraryName + LibraryBody + RP;
      //Note - we should be using DatumListOpt, but that brings 2 conflicts, so for now it is just DatumList
      //Note that the following style of BNF expressions is strongly discouraged - all productions should be of the same length, 
      // so that the process of mapping child nodes to parent's properties is straightforward.
      LibraryBody.Rule = ExportSection + ImportSection + DatumList
                       | ExportSection + DatumList
                       | ImportSection + DatumList
                       | DatumList; 
      LibraryName.Rule = LP + IdentifierList + LibraryVersion.Q() + RP;
      LibraryVersion.Rule = LP + VersionListOpt + RP; //zero or more subversion numbers
      VersionListOpt.Rule = MakeStarRule(VersionListOpt, Number);
      ExportSection.Rule = LP + "export" + ExportSpecList + RP;
      ImportSection.Rule = LP + "import" + ImportSpecList + RP;
      ExportSpecList.Rule = MakePlusRule(ExportSpecList, ExportSpec);
      ImportSpecList.Rule = MakePlusRule(ImportSpecList, ImportSpec);
      ExportSpec.Rule = Identifier | LP + "rename"  +  LP + Identifier + Identifier + RP + RP;
      ImportSpec.Rule = LP + Identifier + RP;   // - much more complex in R6RS

      //Datum
      Datum.Rule = Atom | CompoundDatum;
      DatumOpt.Rule = Empty | Datum;
      DatumList.Rule = MakePlusRule(DatumList, Datum);
      DatumListOpt.Rule = MakeStarRule(DatumListOpt, Datum);
      Atom.Rule = Number | Identifier | stringLiteral | Constant | charLiteral | ".";
      CompoundDatum.Rule = Statement | Abbreviation | Vector | ByteVector;
      Identifier.Rule = SimpleIdentifier | PeculiarIdentifier;
      IdentifierList.Rule = MakePlusRule(IdentifierList, Identifier);
      IdentifierListOpt.Rule = MakeStarRule(IdentifierListOpt, Identifier);

      //TODO: create PeculiarIdentifier custom terminal instead of var 
      // or just custom SchemeIdentifier terminal
      PeculiarIdentifier.Rule = ToTerm("+") | "-" | "..."; // |"->" + subsequent; (should be!) 
      Abbreviation.Rule = AbbrevPrefix + Datum;
      AbbrevPrefix.Rule = ToTerm("'") | "`" | ",@" | "," | "#'" | "#`" | "#,@" | "#,";
      Vector.Rule = "#(" + DatumListOpt + ")";
      ByteVector.Rule = "#vu8(" + ByteList + ")";
      ByteList.Rule = MakeStarRule(ByteList, Byte);

      Statement.Rule = FunctionCall | SpecialForm;

      FunctionCall.Rule = LP + FunctionRef + DatumListOpt + RP;
      FunctionRef.Rule = Identifier | Statement;

      SpecialForm.Rule = DefineVarForm | DefineFunForm | LambdaForm | IfForm | CondForm | BeginForm | LetForm | LetRecForm;
      DefineVarForm.Rule = LP + "define" + Identifier + Datum + RP;
      DefineFunForm.Rule = LP + "define" + LP + Identifier + IdentifierListOpt + RP + DatumList + RP;
      LambdaForm.Rule = LP + "lambda" + LP + IdentifierListOpt + RP + DatumList + RP;
      IfForm.Rule = LP + "if" + Datum + Datum + DatumOpt + RP;

      CondForm.Rule = LP + "cond" + CondClauseList + CondElseOpt + RP;
      CondClauseList.Rule = MakePlusRule(CondClauseList, CondClause);
      CondClause.Rule = LP + Datum + DatumList + RP;
      CondElseOpt.Rule = Empty | LP + "else" + DatumList + RP;
      LetForm.Rule = LP + "let" + LP + LetPairList + RP + DatumList + RP;
      LetRecForm.Rule = LP + "letrec" + LP + LetPairList + RP + DatumList + RP;
      BeginForm.Rule = LP + "begin" + DatumList + RP;
      LetPairList.Rule = MakePlusRule(LetPairList, LetPair);
      LetPair.Rule = LP + Identifier + Datum + RP;
      #endregion 

      //Register brace  pairs
      RegisterBracePair("(", ")"); 
      RegisterBracePair("[", "]");

      MarkPunctuation(LP, RP);
      MarkTransient(Datum, CompoundDatum, Statement, SpecialForm, Atom); 

      //Scheme is tail-recursive language
      base.LanguageFlags |= LanguageFlags.TailRecursive; 

    }//constructor
Exemplo n.º 12
0
        // BASIC is not case sensitive...
        public GWBasicGrammar()
            : base(false)
        {
            this.GrammarComments = "This grammar uses one new Irony feature - Scanner-Parser link. Parser helps Scanner to disambiguate " +
                             "similar but different token types when more than one terminal matches the current input char.\r\n" +
                             "See comments in GwBasicGrammar.cs file.";
              /*
               Scanner-Parser link.
               The grammar defines 3 terminals for numbers: number, lineNumber and fileNumber. All three return decimal
               digits in GetFirsts() method. So when current input is a digit, the scanner has 3 potential candidate terminals
               to match the input. However, because each of the 3 terminals can appear in specific "places" in grammar,
               the parser is able to assist scanner to pick the correct terminal, depending on the current parser state.
               The disambiguation happens in Scanner.SelectTerminals method. When the terminal list for current input char
               has more than 1 terminal, the scanner code gets the current parser state from core parser (through compilerContext),
               and then checks the terminals agains the ExpectedTerms set in the parser state.
               As you might see in Grammar Explorer, the conflict is resolved successfully.
               */

            //Terminals
            var lineNumber = new NumberLiteral("LINE_NUMBER", NumberOptions.IntOnly);
            var fileNumber = new NumberLiteral("FILE_NUMBER", NumberOptions.IntOnly);

            var number = new NumberLiteral("NUMBER", NumberOptions.AllowStartEndDot);
            //ints that are too long for int32 are converted to int64
            number.DefaultIntTypes = new TypeCode[] {TypeCode.Int32, TypeCode.Int64};
            number.AddExponentSymbols("eE", TypeCode.Single);
            number.AddExponentSymbols("dD", TypeCode.Double);
            number.AddSuffix("!", TypeCode.Single);
            number.AddSuffix("#", TypeCode.Double);

            var variable = new IdentifierTerminal("Identifier");
            variable.AddSuffix("$", TypeCode.String);
            variable.AddSuffix("%", TypeCode.Int32);
            variable.AddSuffix("!", TypeCode.Single);
            variable.AddSuffix("#", TypeCode.Double);

            var stringLiteral = new StringLiteral("STRING", "\"", StringOptions.None);
            //Important: do not add comment term to base.NonGrammarTerminals list - we do use this terminal in grammar rules
            var userFunctionName = variable;
            var comment = new CommentTerminal("Comment", "REM", "\n");
            var short_comment = new CommentTerminal("ShortComment", "'", "\n");
            var line_cont = new LineContinuationTerminal("LineContinuation", "_");
            var comma = ToTerm(",", "comma");
            var colon = ToTerm(":", "colon");

            var comma_opt = new NonTerminal("comma_opt");
            comma_opt.Rule = Empty | ",";
            var semi_opt = new NonTerminal("semi_opt");
            semi_opt.Rule = Empty | ";";
            var pound_opt = new NonTerminal("pound_opt");
            pound_opt.Rule = Empty | "#";

            // Non-terminals
            var PROGRAM = new NonTerminal("PROGRAM");
            var LINE = new NonTerminal("LINE");
            var LINE_CONTENT_OPT = new NonTerminal("LINE_CONTENT_OPT");
            var COMMENT_OPT = new NonTerminal("COMMENT_OPT");
            var STATEMENT_LIST = new NonTerminal("STATEMENT_LIST");
            var STATEMENT = new NonTerminal("STATEMENT");
            var PRINT_STMT = new NonTerminal("PRINT_STMT");
            var PRINT_LIST = new NonTerminal("PRINT_LIST");
            var PRINT_ARG = new NonTerminal("PRINT_ARG");
            var OPEN_STMT = new NonTerminal("OPEN_STMT");
            var OPEN_STMT_MODE = new NonTerminal("OPEN_STMT_MODE");
            var OPEN_STMT_ACCESS = new NonTerminal("OPEN_STMT_ACCESS");
            var CLOSE_STMT = new NonTerminal("CLOSE_STMT");
            var INPUT_STMT = new NonTerminal("INPUT_STMT");
            var VARIABLES = new NonTerminal("VARIABLES");
            var IF_STMT = new NonTerminal("IF_STMT");
            var THEN_CLAUSE = new NonTerminal("THEN_CLAUSE");
            var ELSE_CLAUSE_OPT = new NonTerminal("ELSE_CLAUSE_OPT"); //, typeof(AstNode));
            var EXPR = new NonTerminal("EXPRESSION");
            var EXPR_LIST = new NonTerminal("EXPRESSION_LIST");
            var BINARY_OP = new NonTerminal("BINARY_OP", "operator");
            var BINARY_EXPR = new NonTerminal("BINARY_EXPR");
            var UNARY_EXPR = new NonTerminal("UNARY_EXPR");
            var SIGN = new NonTerminal("SIGN");
            var ASSIGN_STMT = new NonTerminal("ASSIGN_STMT");
            var FOR_STMT = new NonTerminal("FOR_STMT");
            var STEP_OPT = new NonTerminal("STEP_OPT");
            var NEXT_STMT = new NonTerminal("NEXT_STMT");
            var LOCATE_STMT = new NonTerminal("LOCATE_STMT");
            var WHILE_STMT = new NonTerminal("WHILE_STMT");
            var WEND_STMT = new NonTerminal("WEND_STMT");
            var SWAP_STMT = new NonTerminal("SWAP_STMT");
            var FUN_CALL = new NonTerminal("FUN_CALL");
            var VARIABLE_OR_FUNCTION_EXPR = new NonTerminal("VARIABLE_OR_FUNCTION_EXPR");
            var ARG_LIST = new NonTerminal("ARG_LIST");
            var LINE_INPUT_STMT = new NonTerminal("LINE_INPUT_STMT");
            var LINE_INPUT_POUND_STMT = new NonTerminal("LINE_INPUT_POUND_STMT");
            var END_STMT = new NonTerminal("END_STMT");
            var CLS_STMT = new NonTerminal("CLS_STMT");
            var CLEAR_STMT = new NonTerminal("CLEAR_STMT");
            var DIM_STMT = new NonTerminal("DIM_STMT");
            var DEF_FN_STMT = new NonTerminal("DEF_FN_STMT");
            var GOTO_STMT = new NonTerminal("GOTO_STMT");
            var GOSUB_STMT = new NonTerminal("GOSUB_STMT");
            var RETURN_STMT = new NonTerminal("RETURN_STMT");
            var ON_STMT = new NonTerminal("ON_STMT");
            var LINE_NUMBERS = new NonTerminal("LINE_NUMBERS");
            var RANDOMIZE_STMT = new NonTerminal("RANDOMIZE_STMT");

            // set the PROGRAM to be the root node of BASIC programs.
            this.Root = PROGRAM;

            // BNF Rules
            PROGRAM.Rule = MakePlusRule(PROGRAM, LINE);

            // A line can be an empty line, or it's a number followed by a statement list ended by a new-line.
            LINE.Rule = NewLine | lineNumber + LINE_CONTENT_OPT + COMMENT_OPT + NewLine | SyntaxError + NewLine;
            LINE.NodeCaptionTemplate = "Line #{0}";

            // A statement list is 1 or more statements separated by the ':' character
            LINE_CONTENT_OPT.Rule = Empty | IF_STMT | STATEMENT_LIST;
            STATEMENT_LIST.Rule = MakePlusRule(STATEMENT_LIST, colon, STATEMENT);
            COMMENT_OPT.Rule = short_comment | comment | Empty;

            // A statement can be one of a number of types
            STATEMENT.Rule = ASSIGN_STMT | PRINT_STMT | INPUT_STMT | OPEN_STMT | CLOSE_STMT
                | LINE_INPUT_POUND_STMT | LINE_INPUT_STMT
                | LOCATE_STMT | CLS_STMT
                | END_STMT | CLEAR_STMT | DIM_STMT | DEF_FN_STMT
                | SWAP_STMT | RANDOMIZE_STMT
                | GOSUB_STMT | RETURN_STMT | GOTO_STMT | ON_STMT
                | FOR_STMT | NEXT_STMT | WHILE_STMT | WEND_STMT;

            // The different statements are defined here
            PRINT_STMT.Rule = "print" + PRINT_LIST;
            PRINT_LIST.Rule = MakeStarRule(PRINT_LIST, null, PRINT_ARG);
            PRINT_ARG.Rule = EXPR + semi_opt;
            INPUT_STMT.Rule = "input" + semi_opt + stringLiteral + ";" + VARIABLES;
            OPEN_STMT.Rule = "open" + EXPR + (Empty | "for" + OPEN_STMT_MODE) +
                (Empty | "access" + OPEN_STMT_ACCESS) + "as" + pound_opt + fileNumber;
            OPEN_STMT_ACCESS.Rule = "read" + (Empty | "write") | "write";
            OPEN_STMT_MODE.Rule = ToTerm("o") | "i" | "a" | "output" | "input" | "append";
            CLOSE_STMT.Rule = "close" + pound_opt + fileNumber;
            LINE_INPUT_STMT.Rule = ToTerm("line") + "input" + semi_opt + stringLiteral + ";" + VARIABLE_OR_FUNCTION_EXPR;
            LINE_INPUT_POUND_STMT.Rule = ToTerm("line") + "input" + ToTerm("#") + fileNumber + comma + VARIABLE_OR_FUNCTION_EXPR;
            DIM_STMT.Rule = "dim" + VARIABLES;
            DEF_FN_STMT.Rule = "def" + userFunctionName + (Empty | "(" + ARG_LIST + ")") + "=" + EXPR;
            VARIABLES.Rule = VARIABLE_OR_FUNCTION_EXPR | VARIABLE_OR_FUNCTION_EXPR + "," + VARIABLES;

            IF_STMT.Rule = "if" + EXPR + THEN_CLAUSE + ELSE_CLAUSE_OPT;
            THEN_CLAUSE.Rule = "then" + STATEMENT_LIST | GOTO_STMT;

            //Inject PreferShift hint here to explicitly set shift as preferred action. Suppresses warning message about conflict.
            ELSE_CLAUSE_OPT.Rule = Empty | PreferShiftHere()  + "else" + STATEMENT_LIST;

            GOTO_STMT.Rule = "goto" + lineNumber;
            GOSUB_STMT.Rule = "gosub" + lineNumber;
            RETURN_STMT.Rule = "return";
            ON_STMT.Rule = "on" + EXPR + (ToTerm("goto") | "gosub") + LINE_NUMBERS;
            LINE_NUMBERS.Rule = MakePlusRule(LINE_NUMBERS, comma, lineNumber);
            ASSIGN_STMT.Rule = VARIABLE_OR_FUNCTION_EXPR + "=" + EXPR;
            LOCATE_STMT.Rule = "locate" + EXPR + comma + EXPR;
            SWAP_STMT.Rule = "swap" + EXPR + comma + EXPR;
            END_STMT.Rule = "end";
            CLS_STMT.Rule = "cls";
            CLEAR_STMT.Rule = ToTerm("clear") + comma + (Empty | number) + (Empty | comma + number) | "clear" + number | "clear";
            RANDOMIZE_STMT.Rule = "randomize" + EXPR;

            // An expression is a number, or a variable, a string, or the result of a binary comparison.
            EXPR.Rule = number | variable | FUN_CALL | stringLiteral | BINARY_EXPR
                      | "(" + EXPR + ")" | UNARY_EXPR;
            BINARY_EXPR.Rule = EXPR + BINARY_OP + EXPR;
            UNARY_EXPR.Rule = SIGN + EXPR;
            SIGN.Rule = ToTerm("-") | "+";

            //Inject PreferShift hint here to explicitly set shift as preferred action. Suppresses warning message about conflict.
            //The conflict arises from PRINT statement, when there may be ambigous interpretations for expression like
            //  PRINT F (X) -- either function call or identifier followed by expression
            FUN_CALL.Rule = variable + PreferShiftHere() + "(" + ARG_LIST + ")";
            VARIABLE_OR_FUNCTION_EXPR.Rule = variable | FUN_CALL;

            BINARY_OP.Rule = ToTerm("+") | "^" | "-" | "*" | "/" | "=" | "<=" | ">=" | "<" | ">" | "<>" | "and" | "or";
            //let's do operator precedence right here
            RegisterOperators(60, "^");
            RegisterOperators(50, "*", "/");
            RegisterOperators(40, "+", "-");
            RegisterOperators(30, "=", "<=", ">=", "<", ">", "<>");
            RegisterOperators(20, "and", "or");

            EXPR_LIST.Rule = MakeStarRule(EXPR_LIST, EXPR);

            FOR_STMT.Rule = "for" + ASSIGN_STMT + "to" + EXPR + STEP_OPT;
            STEP_OPT.Rule = Empty | "step" + EXPR;
            NEXT_STMT.Rule = "next" + VARIABLES | "next";
            WHILE_STMT.Rule = "while" + EXPR;
            WEND_STMT.Rule = "wend";

            //TODO: check number of arguments for particular function in node constructor
            ARG_LIST.Rule = MakePlusRule(ARG_LIST, comma, EXPR);

            //Punctuation and Transient elements
            MarkPunctuation("(", ")", ",");
            MarkTransient(EXPR, STATEMENT, LINE_CONTENT_OPT, VARIABLE_OR_FUNCTION_EXPR, COMMENT_OPT);
            NonGrammarTerminals.Add(line_cont);

            this.LanguageFlags = LanguageFlags.NewLineBeforeEOF;

            lineNumber.ValidateToken += lineNumber_ValidateToken;
        }
Exemplo n.º 13
0
        public KinectitudeGrammar()
        {
            Number.DefaultFloatType = TypeCode.Double;
            Number.DefaultIntTypes =  new TypeCode [] { TypeCode.Int64 };

            CommentTerminal lineComment = new CommentTerminal("Line Comment", "//", "\r\n", "\n");
            CommentTerminal blockComment = new CommentTerminal("Block Comment", "/*", "*/");
            NonGrammarTerminals.Add(lineComment);
            NonGrammarTerminals.Add(blockComment);

            #region constants
            Constants.Add("true", ConstantReader.TrueValue);
            Constants.Add("false",ConstantReader.FalseValue);
            Constants.Add("True", ConstantReader.TrueValue);
            Constants.Add("False", ConstantReader.FalseValue);
            Constants.Add("Pi", new ConstantReader(Math.PI));
            Constants.Add("E", new ConstantReader(Math.E));
            #endregion

            Constants.Priority = Identifier.Priority + 1;

            #region operator terminals
            Terminal openBrace = ToTerm("{");
            Terminal closeBrace = ToTerm("}");
            Terminal colon = ToTerm(":");
            Terminal comma = ToTerm(",");
            Terminal openBrac = ToTerm("(");
            Terminal closeBrac = ToTerm(")");
            Becomes = ToTerm("=", "Becomes");
            Eql = ToTerm("==", "Eql");
            Lt = ToTerm("<", "Lt");
            Gt = ToTerm(">", "Gt");
            Le = ToTerm("<=", "Le");
            Ge = ToTerm(">=", "Ge");
            Neq = ToTerm("!=", "ne");
            Plus = ToTerm("+", "Plus");
            Minus = ToTerm("-", "Minus");
            Mult = ToTerm("*", "Mult");
            Div = ToTerm("/", "Div");
            Rem = ToTerm("%", "Rem");
            Pow = ToTerm("**", "Pow");
            And = new RegexBasedTerminal("And", @"(&&)|(and)");
            Or = new RegexBasedTerminal("Or", @"(\|\|)|(or)");
            Not = new RegexBasedTerminal("Not", @"!|(not)");
            LeftShift = ToTerm("<<", "leftShitf");
            RightShift = ToTerm(">>", "RightShift");
            BPlus = ToTerm("+=", "Plus Equals");
            BMinus = ToTerm("-=", "Minus Equals");
            BMult = ToTerm("*=", "Mult Equals");
            BDiv = ToTerm("/=", "Div Equals");
            BRem = ToTerm("%=", "Rem Equals");
            BPow = ToTerm("^=", "Pow Equals");
            BAnd = ToTerm("&=", "And Equals");
            BOr = ToTerm("|=", "Or Equals");
            BLeftShift = ToTerm("<<=", "LShift Equals");
            BRightShift = ToTerm(">>=", "RShift Equals");

            NonTerminal becomesExpr = new NonTerminal("Becomes expr");
            becomesExpr.Rule = BPlus | BMinus | BDiv | BMult | BRem | BPow | BAnd | BOr | BLeftShift | BRightShift | Becomes;

            OpLookup[Plus] = OpLookup[BPlus] = OpCode.Plus;
            OpLookup[Minus] = OpLookup[BMinus] = OpCode.Minus;
            OpLookup[Div] = OpLookup[BDiv] = OpCode.Div;
            OpLookup[Mult] = OpLookup[BMult] = OpCode.Mult;
            OpLookup[Rem] = OpLookup[BRem] = OpCode.Rem;
            OpLookup[Pow] = OpLookup[BPow] = OpCode.Pow;
            OpLookup[And] = OpLookup[BAnd] = OpCode.And;
            OpLookup[Or] = OpLookup[BOr] = OpCode.Or;
            OpLookup[LeftShift] = OpLookup[BLeftShift] = OpCode.LeftShift;
            OpLookup[RightShift] = OpLookup[BRightShift] = OpCode.RightShift;
            OpLookup[Becomes] = OpCode.Becomes;

            OpLookup[Lt] = OpCode.Lt;
            OpLookup[Le] = OpCode.Le;
            OpLookup[Gt] = OpCode.Gt;
            OpLookup[Ge] = OpCode.Ge;
            OpLookup[Neq] = OpCode.Neq;
            OpLookup[Eql] = OpCode.Eql;
            #endregion

            #region values
            //NonTerminal value = new NonTerminal("value");
            NonTerminal exactValue = new NonTerminal("exactValue", "exactValue");
            #endregion

            #region value rules
            ThreeVal.Rule = Identifier + "." + Identifier + "." + Identifier;
            TwoVal.Rule = Identifier + "." + Identifier;
            IsType.Rule = "$" + Identifier;
            RegisterBracePair("(", ")");
            RegisterBracePair("{", "}");
            IsExactType.Rule = "#" + Identifier;
            ParentVal.Rule =  "^" + Identifier + "." + Identifier | "^" + Identifier + "." + Identifier + "." + Identifier;
            exactValue.Rule = Identifier | TwoVal | ThreeVal | ParentVal;
            TypeMatcher.Rule = IsType | IsExactType| IsType + Plus + TypeMatcher | IsExactType + Plus + TypeMatcher;
            Argument.Rule = Expr | Expr + "," + Argument;
            Function.Rule = Identifier + ToTerm("(") +")" | Identifier + "(" + Argument + ")";
            #endregion

            #region expressions
            NonTerminal term = new NonTerminal("term");
            Expr.Rule = Expr + BinOp + Expr | UniOp + Expr | term;
            BinOp.Rule = Plus | Minus | Div | Mult | Rem | Pow | And | Or | Eql | Neq | Gt | Ge | Lt | Le | LeftShift | RightShift;
            UniOp.Rule = Not | Minus;
            term.Rule = Number | Str | openBrac + Expr + closeBrac | exactValue | Constants | Function;
            #endregion

            #region operator precedence
            /* NOTE: Order is taken from C++/C# order with power added in.
             * Higher number = more important
             * Increments are by 10 to allow easy adding of new terms
             * Power is not in C++/C#, but has been added where is seems to fit
             */
            RegisterOperators(10, Associativity.Right, Becomes);
            RegisterOperators(20, Associativity.Left, Or);
            RegisterOperators(30, Associativity.Left, And);
            RegisterOperators(40, Associativity.Left, Eql, Neq);
            RegisterOperators(50, Associativity.Left, Eql, Neq);
            RegisterOperators(60, Associativity.Left, Ge, Le, Lt, Gt);
            RegisterOperators(70, Associativity.Left, LeftShift, RightShift);
            RegisterOperators(70, Associativity.Left, Plus, Minus);
            RegisterOperators(80, Associativity.Left, Div, Mult, Rem);
            RegisterOperators(90, Associativity.Left, Pow);
            RegisterOperators(100, Associativity.Left, Not);

            #endregion

            #region game creation rules
            NonTerminal IsPrototype = new NonTerminal("IsPrototype", "IsPrototype");

            value.Rule = TypeMatcher | Expr;

            Names.Rule = Identifier + comma + Names | Identifier;
            IsPrototype.Rule = colon + Names | Empty;

            NonTerminal optionalProperties = new NonTerminal("optionalProperties", "optionalProperties");
            optionalProperties.Rule = Properties | Empty;
            Properties.Rule = Identifier + Becomes + value | Identifier + Becomes + value + comma + optionalProperties;

            BasicDefinition.Rule = openBrac + optionalProperties + closeBrac;

            NonTerminal optionalComponent = new NonTerminal("optionalComponent", "optionalComponent");
            optionalComponent.Rule = Component | Empty;
            Component.Rule = "Component" + Identifier + BasicDefinition + optionalComponent;

            NonTerminal optionalPrototype = new NonTerminal("optionalPrototype", "optionalPrototype");
            optionalPrototype.Rule = Prototype | Empty;
            Prototype.Rule = "Prototype" + Identifier + EntityDefinition + optionalPrototype;

            NonTerminal optionalManager = new NonTerminal("optionalManager", "optionalManager");
            optionalManager.Rule = Manager | Empty;
            Manager.Rule = "Manager" + Identifier + BasicDefinition + optionalManager;

            NonTerminal optionalService = new NonTerminal("optionalService", "optionalService");
            optionalService.Rule = Service | Empty;
            Service.Rule = "Service" + Identifier + BasicDefinition + optionalService;

            Else.Rule = ToTerm("else") + "if" + openBrac + Expr + closeBrac + openBrace + Actions + closeBrace + Else |
                ToTerm("else") + "if" + openBrac + Expr + closeBrac + openBrace + Actions + closeBrace |
                 "else" + openBrace + Actions + closeBrace + Else |
                 "else" + openBrace + Actions + closeBrace;

            Condition.Rule = "if" + openBrac + Expr + closeBrac + openBrace + Actions + closeBrace + Else |
                "if" + openBrac + Expr + closeBrac + openBrace + Actions + closeBrace;

            NonTerminal optionalAssignment = new NonTerminal("optionalAssignment", "optionalAssignment");
            optionalAssignment.Rule = Assignment | Empty;
            Loop.Rule = "while" + openBrac + Expr + closeBrac + openBrace + Actions + closeBrace |
                "for" + openBrac + optionalAssignment + ";" + Expr + ";" + Assignment + closeBrac + openBrace + Actions + closeBrace;

            NonTerminal optionalActions = new NonTerminal("OptionalActions", "OptionalActions");

            Action.Rule = Identifier + BasicDefinition;

            Assignment.Rule = exactValue + becomesExpr + Expr;

            Actions.Rule = Condition + optionalActions | Action + optionalActions | Assignment + optionalActions | Loop + optionalActions;
            optionalActions.Rule = Actions | Empty;

            NonTerminal optionalEvt = new NonTerminal("optionalEvt", "optionalEvt");
            optionalEvt.Rule = Evt | Empty;
            Evt.Rule = "Event" + Identifier + BasicDefinition + openBrace + optionalActions + closeBrace + optionalEvt;

            EntityDefinition.Rule = IsPrototype + BasicDefinition + openBrace + optionalComponent + optionalEvt + closeBrace;

            NonTerminal optionalEntity = new NonTerminal("optionalEntity", "optionalEntity");
            optionalEntity.Rule = Entity | Empty;

            NonTerminal optionalIdentifier = new NonTerminal("optionalIdentifier", "optionalIdentifier");
            optionalIdentifier.Rule = Identifier | Empty;
            Entity.Rule = "Entity" + optionalIdentifier + EntityDefinition + optionalEntity;

            NonTerminal optionalScene = new NonTerminal("optionalScene", "optionalScene");
            optionalScene.Rule = Scene | Empty;
            Scene.Rule = "Scene" + Identifier + BasicDefinition + openBrace + optionalManager + optionalEntity + closeBrace + optionalScene;

            NonTerminal optionalDefinitions = new NonTerminal("optionalDefinitions", "optionalDefinitions");
            optionalDefinitions.Rule = Definitions | Empty;
            Definitions.Rule = "define" + Identifier + "as" + ClassName + optionalDefinitions;

            NonTerminal optionalUses = new NonTerminal("optionalUses", "optionalUses");
            optionalUses.Rule = Uses | Empty;
            Uses.Rule = "using" + ClassName + openBrace + Definitions + closeBrace + optionalUses;

            Game.Rule = optionalUses + "Game" + BasicDefinition + openBrace + optionalPrototype + optionalService + Scene + closeBrace;
            #endregion

            Root = Game;
            //Removes from the tree, we don't care about having these there
            MarkPunctuation("{", "}", "(", ")", ":", "$", "@", "#", "^", "Game", "using", "define", "Scene", "Entity",
                 ",", "if", "Component", "Manager", "Prototype", "=", ".", "as", "Event", "else", "Service", ";", "while", "for");
            MarkReservedWords("using", "define", "if", "else", "while", "for");
            MarkTransient(BasicDefinition, value, IsPrototype, term, exactValue, optionalActions, optionalEvt, optionalComponent,
                optionalProperties, optionalManager, optionalPrototype, optionalService, optionalUses, optionalDefinitions,
                optionalEntity, optionalScene, optionalIdentifier, optionalAssignment, becomesExpr);
        }
        //case-sensitive
        public CoffeescriptGrammar()
            : base(false)
        {
            // ReSharper disable InconsistentNaming

            //Terminals
            var NUMBER = new NumberLiteral("Number");
            var IDENTIFIER = new IdentifierTerminal("Identifier");
            var STATEMENT = ToTerm("break") | "continue" | "debugger";
            var STRING = new StringLiteral("String", "\"", StringOptions.AllowsAllEscapes);

            var comment = new CommentTerminal("comment", "#", "\n", "\r");

            NonGrammarTerminals.Add(comment);

            var BOOL = ToTerm("true") | "false" | "null" | "undefined";
            var CLASS = ToTerm("class");
            var EXTENDS = ToTerm("extends");
            var PARAM_START = ToTerm("(") | Empty;
            var PARAM_END = ToTerm(")") | Empty;
            var FUNC_GLYPH = ToTerm("=>") | ToTerm("->");
            var COMMA = ToTerm(",");
            var OPT_COMMA = ToTerm(",") | Empty;
            var INDEX_START = ToTerm("[");
            var INDEX_END = ToTerm("]");
            var INDEX_SOAK = ToTerm("?");
            var INDEX_PROTO = ToTerm("::");
            var SUPER = ToTerm("super");
            var FUNC_EXIST = ToTerm("?");
            var CALL_START = ToTerm("(");
            var CALL_END = ToTerm(")");
            var THIS = ToTerm("this");
            var TRY = ToTerm("try");
            var FINALLY = ToTerm("finally");
            var CATCH = ToTerm("catch");
            var THROW = ToTerm("throw");
            var WHILE = ToTerm("while");
            var WHEN = ToTerm("when");
            var UNTIL = ToTerm("until");
            var LOOP = ToTerm("loop");
            var FOR = ToTerm("for");
            var OWN = ToTerm("own");
            var FORIN = ToTerm("in");
            var FOROF = ToTerm("of");
            var BY = ToTerm("by");
            var SWITCH = ToTerm("switch");
            var ELSE = ToTerm("else");
            var LEADING_WHEN = ToTerm("When");
            var IF = ToTerm("IF");
            var POST_IF = ToTerm("if");

            #region Non Terminals
            var Body = new NonTerminal("Body", CreateBlock);
            var UnaryOp = new NonTerminal("UnaryOp");
            var Statement = new NonTerminal("Statement");
            var Expression = new NonTerminal("Expression");
            var Line = new NonTerminal("Line");
            var Return = new NonTerminal("Return");
            var Throw = new NonTerminal("Throw");
            var Comment = new NonTerminal("Comment");
            var Value = new NonTerminal("Value");
            var Invocation = new NonTerminal("Invocation");
            var Code = new NonTerminal("Code");
            var Operation = new NonTerminal("Operation");
            var Assign = new NonTerminal("Assign",typeof(AssignmentNode));
            var If = new NonTerminal("If");
            var Try = new NonTerminal("Try");
            var While = new NonTerminal("While");
            var For = new NonTerminal("For");
            var Switch = new NonTerminal("Switch");
            var Class = new NonTerminal("Class");
            var Block = new NonTerminal("Block",CreateBlock);
            var AlphaNumeric = new NonTerminal("AlphaNumeric");
            var Literal = new NonTerminal("Literal");
            var Assignable = new NonTerminal("Assignable");
            var AssignObj = new NonTerminal("AssignObj");
            var ObjAssignable = new NonTerminal("ObjAssignable");
            var ThisProperty = new NonTerminal("ThisProperty");
            var ParamList = new NonTerminal("ParamList");
            var Param = new NonTerminal("Param");
            var ParamVar = new NonTerminal("ParamVar");
            var ArrayNonTerm = new NonTerminal("Array");
            var ObjectNonTerm = new NonTerminal("Object");
            var Splat = new NonTerminal("Splat");
            var SimpleAssignable = new NonTerminal("SimpleAssignable");
            var Accessor = new NonTerminal("Accessor");
            var Parenthetical = new NonTerminal("Parenthetical");
            var This = new NonTerminal("This");
            var Range = new NonTerminal("Range");
            var Index = new NonTerminal("Index");
            var Slice = new NonTerminal("Slice");
            var AssignList = new NonTerminal("AssignList");
            var OptFuncExist = new NonTerminal("OptFuncExist");
            var Arguments = new NonTerminal("Arguments");
            var ArgList = new NonTerminal("ArgList");
            var RangeDots = new NonTerminal("RangeDots");
            var Arg = new NonTerminal("Arg");
            var SimpleArgs = new NonTerminal("SimpleArgs");
            var Catch = new NonTerminal("Catch");
            var WhileSource = new NonTerminal("WhileSource");
            var Loop = new NonTerminal("Loop");
            var ForBody = new NonTerminal("ForBody");
            var ForStart = new NonTerminal("ForStart");
            var ForSource = new NonTerminal("ForSource");
            var ForVariables = new NonTerminal("ForVariables");
            var ForValue = new NonTerminal("ForValue");
            var Whens = new NonTerminal("Whens");
            var When = new NonTerminal("When");
            var IfBlock = new NonTerminal("IfBlock");
            var BinaryOp = new NonTerminal("BinaryOp");
            var BinExpr = new NonTerminal("BinExpr",typeof(BinaryOperationNode));
            var CompoundAssignOp = new NonTerminal("CompoundAssign");

            #endregion

            #region Production rules

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

            Body.Rule = MakePlusRule(Body, Line);
            Line.Rule = Expression + Eos | Statement + Eos;

            Statement.Rule = STATEMENT;

            Expression.Rule = Value | BinExpr | Assign;

            BinExpr.Rule = Value + BinaryOp + Value;

            Assign.Rule = (Assignable + "=" + Expression)
                        | (Assignable + "=" + Indent + Expression + Dedent);

            SimpleAssignable.Rule = IDENTIFIER;

            Assignable.Rule = SimpleAssignable;

            Value.Rule = Assignable | Literal;

            AlphaNumeric.Rule = NUMBER | STRING;
            Literal.Rule = AlphaNumeric;

            #endregion

            MarkTransient(Line);

            Root = Body;

            LanguageFlags = LanguageFlags.CreateAst;

            // ReSharper enable InconsistentNaming
        }
Exemplo n.º 15
0
    public MiniPythonGrammar() : base(caseSensitive: true) {

      // 1. Terminals
      var number = TerminalFactory.CreatePythonNumber("number");
      var identifier = TerminalFactory.CreatePythonIdentifier("identifier");
      var comment = new CommentTerminal("comment", "#", "\n", "\r");
      //comment must to be added to NonGrammarTerminals list; it is not used directly in grammar rules,
      // so we add it to this list to let Scanner know that it is also a valid terminal. 
      base.NonGrammarTerminals.Add(comment);
      var comma = ToTerm(",");
      var colon = ToTerm(":");

      // 2. Non-terminals
      var Expr = new NonTerminal("Expr");
      var Term = new NonTerminal("Term");
      var BinExpr = new NonTerminal("BinExpr", typeof(BinaryOperationNode));
      var ParExpr = new NonTerminal("ParExpr");
      var UnExpr = new NonTerminal("UnExpr", typeof(UnaryOperationNode));
      var UnOp = new NonTerminal("UnOp", "operator");
      var BinOp = new NonTerminal("BinOp", "operator");
      var AssignmentStmt = new NonTerminal("AssignmentStmt", typeof(AssignmentNode));
      var Stmt = new NonTerminal("Stmt");
      var ExtStmt = new NonTerminal("ExtStmt");
      //Just as a test for NotSupportedNode
      var ReturnStmt = new NonTerminal("return", typeof(NotSupportedNode));
      var Block = new NonTerminal("Block");
      var StmtList = new NonTerminal("StmtList", typeof(StatementListNode));

      var ParamList = new NonTerminal("ParamList", typeof(ParamListNode));
      var ArgList = new NonTerminal("ArgList", typeof(ExpressionListNode));
      var FunctionDef = new NonTerminal("FunctionDef", typeof(FunctionDefNode));
      var FunctionCall = new NonTerminal("FunctionCall", typeof(FunctionCallNode));


      // 3. BNF rules
      Expr.Rule = Term | UnExpr | BinExpr;
      Term.Rule = number | ParExpr | identifier | FunctionCall;
      ParExpr.Rule = "(" + Expr + ")";
      UnExpr.Rule = UnOp + Term;
      UnOp.Rule = ToTerm("+") | "-";
      BinExpr.Rule = Expr + BinOp + Expr;
      BinOp.Rule = ToTerm("+") | "-" | "*" | "/" | "**";
      AssignmentStmt.Rule = identifier + "=" + Expr;
      Stmt.Rule = AssignmentStmt | Expr | ReturnStmt | Empty;
      ReturnStmt.Rule = "return" + Expr; //Not supported for execution! - we associate NotSupportedNode with ReturnStmt
      //Eos is End-Of-Statement token produced by CodeOutlineFilter
      ExtStmt.Rule = Stmt + Eos | FunctionDef;
      Block.Rule = Indent + StmtList + Dedent;
      StmtList.Rule = MakePlusRule(StmtList, ExtStmt);

      ParamList.Rule = MakeStarRule(ParamList, comma, identifier);
      ArgList.Rule = MakeStarRule(ArgList, comma, Expr);
      FunctionDef.Rule = "def" + identifier + "(" + ParamList + ")" + colon + Eos + Block;
      FunctionDef.NodeCaptionTemplate = "def #{1}(...)"; 
      FunctionCall.Rule = identifier + "(" + ArgList + ")";
      FunctionCall.NodeCaptionTemplate = "call #{0}(...)";

      this.Root = StmtList;       // Set grammar root

      // 4. Token filters - created in a separate method CreateTokenFilters
      //    we need to add continuation symbol to NonGrammarTerminals because it is not used anywhere in grammar
      NonGrammarTerminals.Add(ToTerm(@"\"));

      // 5. Operators precedence
      RegisterOperators(1, "+", "-");
      RegisterOperators(2, "*", "/");
      RegisterOperators(3, Associativity.Right, "**");

      // 6. Miscellaneous: punctuation, braces, transient nodes
      MarkPunctuation("(", ")", ":");
      RegisterBracePair("(", ")");
      MarkTransient(Term, Expr, Stmt, ExtStmt, UnOp, BinOp, ExtStmt, ParExpr, Block);

      // 7. Error recovery rule
      ExtStmt.ErrorRule = SyntaxError + Eos;
      FunctionDef.ErrorRule = SyntaxError + Dedent; 

      // 8. Syntax error reporting
      AddToNoReportGroup("(");
      AddToNoReportGroup(Eos); 
      AddOperatorReportGroup("operator"); 

      // 9. Initialize console attributes
      ConsoleTitle = "Mini-Python Console";
      ConsoleGreeting =
@"Irony Sample Console for mini-Python.
 
   Supports a small sub-set of Python: assignments, arithmetic operators, 
   function declarations with 'def'. Supports big integer arithmetics.
   Supports Python indentation and line-joining rules, including '\' as 
   a line joining symbol. 

Press Ctrl-C to exit the program at any time.
";
      ConsolePrompt = ">>>"; 
      ConsolePromptMoreInput = "..."; 
      
      // 10. Language flags
      this.LanguageFlags = LanguageFlags.NewLineBeforeEOF | LanguageFlags.CreateAst | LanguageFlags.SupportsBigInt;

    }//constructor
    public MyCGrammarExtended() {
      #region Declare Terminals Here
      CommentTerminal blockComment = new CommentTerminal("block-comment", "/*", "*/");
      CommentTerminal lineComment = new CommentTerminal("line-comment", "//",
          "\r", "\n", "\u2085", "\u2028", "\u2029");
      NonGrammarTerminals.Add(blockComment);
      NonGrammarTerminals.Add(lineComment);

      NumberLiteral number = new NumberLiteral("number");
      IdentifierTerminal identifier = new IdentifierTerminal("identifier");
      #endregion

      #region Declare NonTerminals Here
      NonTerminal program = new NonTerminal("program");
      NonTerminal declarations = new NonTerminal("declaration");
      NonTerminal declaration = new NonTerminal("declaration");
      NonTerminal simpleDeclarations = new NonTerminal("simple-declarations");
      NonTerminal simpleDeclaration = new NonTerminal("simple-declaration");
      NonTerminal semiDeclaration = new NonTerminal("semi-declaration");
      NonTerminal parenParameters = new NonTerminal("paren-parameters");
      NonTerminal parameters = new NonTerminal("parameters");
      NonTerminal classOption = new NonTerminal("class-option");
      NonTerminal variableType = new NonTerminal("variable-type");
      NonTerminal block = new NonTerminal("block");
      NonTerminal blockContent = new NonTerminal("block-content");
      NonTerminal statements = new NonTerminal("statements");
      NonTerminal statement = new NonTerminal("statement");
      NonTerminal parenExpressionAlways = new NonTerminal("paren-expression-always");
      NonTerminal parenExpression = new NonTerminal("paren-expression");
      NonTerminal forHeader = new NonTerminal("for-header");
      NonTerminal forBlock = new NonTerminal("for-block");
      NonTerminal semiStatement = new NonTerminal("semi-statement");
      NonTerminal arguments = new NonTerminal("arguments");
      NonTerminal parenArguments = new NonTerminal("paren-arguments");
      NonTerminal assignExpression = new NonTerminal("assign-expression");
      NonTerminal expression = new NonTerminal("expression");
      NonTerminal booleanOperator = new NonTerminal("boolean-operator");
      NonTerminal relationalExpression = new NonTerminal("relational-expression");
      NonTerminal relationalOperator = new NonTerminal("relational-operator");
      NonTerminal bitExpression = new NonTerminal("bit-expression");
      NonTerminal bitOperator = new NonTerminal("bit-operator");
      NonTerminal addExpression = new NonTerminal("add-expression");
      NonTerminal addOperator = new NonTerminal("add-operator");
      NonTerminal multiplyExpression = new NonTerminal("multiply");
      NonTerminal multiplyOperator = new NonTerminal("multiply-operator");
      NonTerminal prefixExpression = new NonTerminal("prefix-expression");
      NonTerminal prefixOperator = new NonTerminal("prefix-operator");
      NonTerminal factor = new NonTerminal("factor");
      NonTerminal identifierExpression = new NonTerminal("identifier-expression");
      #endregion

      #region Place Rules Here
      this.Root = program;

      program.Rule = declarations;

      declarations.Rule = MakeStarRule(declarations, declaration);

      declaration.Rule
          = classOption + variableType + identifier + parameters + block
          | classOption + identifier + parenParameters + block
          | variableType + identifier + parenParameters + block
          | identifier + parenParameters + block
          | simpleDeclaration;

      simpleDeclarations.Rule = MakePlusRule(simpleDeclarations, simpleDeclaration);

      simpleDeclaration.Rule = semiDeclaration + ";";

      semiDeclaration.Rule
          = semiDeclaration + "," + identifier
          | classOption + variableType + identifier
          | variableType + identifier;

      parameters.Rule
          = parameters + "," + variableType + identifier
          | variableType + identifier;

      parenParameters.Rule
          = ToTerm("(") + ")"
          | "(" + parameters + ")";

      classOption.Rule
          = ToTerm("static")
          | "auto"
          | "extern";

      variableType.Rule
          = ToTerm("int")
          | "void";

      block.Rule
          = ToTerm("{") + "}"
          | "{" + blockContent + "}";

      blockContent.Rule
          = simpleDeclarations + statements
          | simpleDeclarations
          | statements;

      statements.Rule = MakePlusRule(statements, statement);

      statement.Rule
          = semiStatement + ";"
          | block
          | "while" + parenExpressionAlways + statement
          | "for" + forHeader + statement
          | "if" + parenExpressionAlways + statement
          | "if" + parenExpressionAlways + statement + PreferShiftHere() + "else" + statement;

      parenExpressionAlways.Rule = parenExpression;

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

      forHeader.Rule = "(" + forBlock + ")";

      forBlock.Rule = assignExpression + ";" + expression + ";" + assignExpression;

      semiStatement.Rule
          = assignExpression
          | "return" + expression
          | "break"
          | "continue";

      arguments.Rule
          = expression + "," + arguments
          | expression;

      parenArguments.Rule
          = ToTerm("(") + ")"
          | "(" + arguments + ")";

      assignExpression.Rule
          = identifier + "=" + expression
          | expression;

      expression.Rule
          = relationalExpression + booleanOperator + expression
          | relationalExpression;

      booleanOperator.Rule
          = ToTerm("&&")
          | "||";

      relationalExpression.Rule
          = bitExpression + relationalOperator + bitExpression
          | bitExpression;

      relationalOperator.Rule
          = ToTerm(">")
          | ">="
          | "<"
          | "<="
          | "=="
          | "!=";

      bitExpression.Rule
          = addExpression + bitOperator + bitExpression
          | addExpression;

      bitOperator.Rule
          = ToTerm("|")
          | "&"
          | "^";

      addExpression.Rule
          = multiplyExpression + addOperator + addExpression
          | prefixExpression;

      addOperator.Rule
          = ToTerm("+") | "-";

      multiplyExpression.Rule
          = prefixExpression + multiplyOperator + multiplyExpression
          | prefixExpression;

      multiplyOperator.Rule
          = ToTerm("*")
          | "/";

      prefixExpression.Rule
          = prefixOperator + factor
          | factor;

      prefixOperator.Rule = ToTerm("!");

      factor.Rule
          = identifierExpression + parenArguments
          | identifierExpression
          | number
          | parenExpression;

      identifierExpression.Rule
          = identifier
          | identifierExpression + "." + identifier;
      #endregion

      #region Define Keywords
      this.MarkReservedWords("break", "continue", "else", "extern", "for",
          "if", "int", "return", "static", "void", "while");
      #endregion
    }
Exemplo n.º 17
0
        public MtGrammar()
            : base(true)
        {
            // Terminals
            var stringLiteral = new StringLiteral("stringLiteral", "\"", StringOptions.AllowsLineBreak | StringOptions.AllowsAllEscapes);
            var nbrLiteral = new NumberLiteral("nbrLiteral");
            var identifier = new IdentifierTerminal("identifier", IdOptions.IsNotKeyword);

            var comment = new CommentTerminal("comment", "/*", "*/");

            // Punctuation terminals; these shouldn't appear on the tree
            var pipe = ToTerm("|", "pipe");
            var semicomma = ToTerm(";", "semicomma");
            var openparen = ToTerm("(", "openparen");
            var closeparen = ToTerm(")", "closeparen");
            var openbrace = ToTerm("{", "openbrace");
            var closebrace = ToTerm("}", "closebrace");
            var openbracket = ToTerm("[", "openbracket");
            var closebracket = ToTerm("]", "closebracket");
            var bind = ToTerm("<=", "bind");
            var argsBodySeparator = ToTerm("=>", "argsBodySeparator");
            var comma = ToTerm(",", "comma");
            var lambda = ToTerm("L", "lambda");
            var ift = ToTerm("if", "if");
            var dot = ToTerm(".", "dot");
            var flowRightToLeft = ToTerm("<-", "flowRightToLeft");
            var listenerOp = ToTerm("on", "listenerOp");

            MarkPunctuation(pipe, semicomma, openparen, closeparen,
                            openbrace, closebrace,
                            openbracket, closebracket, bind,
                            argsBodySeparator, comma, lambda,
                            ift, dot, flowRightToLeft, listenerOp);
            //--

            // Non Terminals
            AstNodeCreator MakeExpressionNode = delegate(AstContext context, ParseTreeNode treeNode)
            {
                if (treeNode == null)
                    throw new Exception("treeNode cant be null at MakeExpressionNode");

                if (treeNode.ChildNodes.Count != 1)
                    throw new Exception("Expression expects 1 child (received {0}.)".SafeFormat(treeNode.ChildNodes.Count));

                // Check child term name
                var possibleValid = treeNode.ChildNodes[0];
                if (possibleValid == null)
                    throw new Exception("Only child cant be null at MakeExpressionNode");

                var tag = possibleValid.Term.Name;
                if (string.IsNullOrWhiteSpace(tag))
                    throw new Exception("tag cant be null or empty at MakeExpressionNode");

                if (tag == "APPLICATION")
                {
                    treeNode.AstNode = _.NewAndInit<MtApplication>(context, possibleValid);
                }
                else if (tag == "ATOM")
                {
                    treeNode.AstNode = _.NewAndInit<MtAtom>(context, possibleValid);
                }
                else if (tag == "FORK")
                {
                    treeNode.AstNode = _.NewAndInit<MtFork>(context, possibleValid);
                }
                else if (tag == "BIND")
                {
                    treeNode.AstNode = _.NewAndInit<MtBind>(context, possibleValid);
                }
                else if (tag == "IF")
                {
                    treeNode.AstNode = _.NewAndInit<MtIf>(context, possibleValid);
                }
                else if (tag == "FUNCTION_LITERAL")
                {
                    treeNode.AstNode = _.NewAndInit<MtFunctionLiteral>(context, possibleValid);
                }
                else if (tag == "FLOW_RIGHT_TO_LEFT")
                {
                    treeNode.AstNode = _.NewAndInit<MtFlowRightToLeft>(context, possibleValid);
                }
                else if (tag == "ARRAY")
                {
                    treeNode.AstNode = _.NewAndInit<MtArray>(context, possibleValid);
                }
                else if (tag == "LISTENER_STATEMENT")
                {
                    treeNode.AstNode = _.NewAndInit<MtListenerStatement>(context, possibleValid);
                }
                else if (tag == "identifier")
                {
                    // Do nothing here ...
                    treeNode.AstNode = _.NewAndInit<Irony.Interpreter.Ast.IdentifierNode>(context, possibleValid);
                }
                else
                {
                    throw new Exception("Unexpected tag in Expression child: {0}".SafeFormat(tag));
                }
            };

            var TOP_CHAIN = new NonTerminal("TOP_CHAIN", delegate(AstContext context, ParseTreeNode treeNode)
            {
                if (treeNode.ChildNodes.Count != 1)
                    throw new Exception("Top chain expects 1 child (received {0}.)".SafeFormat(treeNode.ChildNodes.Count));

                // Check child term name
                var possibleValid = treeNode.ChildNodes[0];
                var tag = possibleValid.Term.Name;

                if (tag == "CHAIN")
                {
                    treeNode.AstNode = _.NewAndInit<MtChain>(context, possibleValid);
                }
                else if (tag == "EXPRESSION")
                {
                    // HACK
                    MakeExpressionNode(context, possibleValid);
                    treeNode.AstNode = possibleValid.AstNode;
                }
                else
                {
                    throw new Exception("Unexpected tag in TOP_CHAIN child: {0}".SafeFormat(tag));
                }
            });

            var ARRAY = new NonTerminal("ARRAY", typeof(MtArray));
            var IF = new NonTerminal("IF", typeof(MtIf));
            var CHAIN = new NonTerminal("CHAIN", typeof(MtChain));
            var ATOM = new NonTerminal("ATOM", typeof(MtAtom));
            var NCHAINS = new NonTerminal("NCHAINS", typeof(MtFork));
            var APPLICATION = new NonTerminal("APPLICATION", typeof(MtApplication));
            var BIND = new NonTerminal("BIND", typeof(MtBind));
            var FORK = new NonTerminal("FORK", typeof(MtFork));

            var ARG_LIST_FOR_DECL = new NonTerminal("ARG_LIST_FOR_DECL", typeof(MtArgListForDecl));
            var FUNCTION_LITERAL = new NonTerminal("FUNCTION_LITERAL", typeof(MtFunctionLiteral));

            var EXPRESSION_LIST = new NonTerminal("EXPRESSION_LIST", typeof(MtExpressionList));

            var DOTTED_EXPRESSION = new NonTerminal("DOTTED_EXPRESSION", typeof(MtDottedExpression));

            var FLOW_RIGHT_TO_LEFT = new NonTerminal("FLOW_RIGHT_TO_LEFT", typeof(MtFlowRightToLeft));

            var LISTENER_STATEMENT = new NonTerminal("LISTENER_STATEMENT", typeof(MtListenerStatement));

            var FUNCTION = new NonTerminal("FUNCTION", delegate(AstContext context, ParseTreeNode treeNode)
            {
                if (treeNode.ChildNodes.Count != 1)
                    throw new Exception("Function expects 1 child (received {0}.)".SafeFormat(treeNode.ChildNodes.Count));

                // Check child term name
                var possibleValid = treeNode.ChildNodes[0];
                var tag = possibleValid.Term.Name;

                if (tag == "APPLICATION")
                {
                    treeNode.AstNode = _.NewAndInit<MtApplication>(context, possibleValid);
                }
                else if (tag == "identifier")
                {
                    // This is ugly as f**k, but works
                    Type t = identifier.AstConfig.NodeType;
                    treeNode.AstNode = t.GetConstructors()[0].Invoke(new object[]{ });
                    (treeNode.AstNode as AstNode).Init(context, possibleValid);
                    // _.NewAndInit<t>(context, possibleValid);
                }
                else if (tag == "FUNCTION_LITERAL")
                {
                    treeNode.AstNode = _.NewAndInit<MtFunctionLiteral>(context, possibleValid);
                }
                else
                {
                    throw new Exception("Unexpected tag in FUNCTION child: {0}".SafeFormat(tag));
                }
            });

            var EXPRESSION = new NonTerminal("EXPRESSION", MakeExpressionNode);

            Root = NCHAINS;

            /*
             * RULES
             */

            // TODO: FUNCTION LITERALS / LAMBDAS
            // TODO: SWITCH

            NCHAINS.Rule = MakePlusRule(NCHAINS, TOP_CHAIN);

            TOP_CHAIN.Rule = CHAIN + semicomma |
                            EXPRESSION + semicomma;

            CHAIN.Rule = EXPRESSION + pipe + EXPRESSION |
                        EXPRESSION + pipe + CHAIN;

            EXPRESSION.Rule = ARRAY | FORK | IF | BIND |
                    FUNCTION_LITERAL | APPLICATION |
                    LISTENER_STATEMENT | FLOW_RIGHT_TO_LEFT |
                    ATOM | identifier;

            FORK.Rule = openbrace + NCHAINS + closebrace;

            LISTENER_STATEMENT.Rule = identifier + listenerOp + identifier + FUNCTION;

            ATOM.Rule =
                      nbrLiteral |
                      stringLiteral /*|
                      identifier*/;

            FLOW_RIGHT_TO_LEFT.Rule = identifier + flowRightToLeft + identifier;

            APPLICATION.Rule = FUNCTION + openparen + EXPRESSION_LIST + closeparen;

            EXPRESSION_LIST.Rule = MakeStarRule(EXPRESSION_LIST, comma, EXPRESSION);

            FUNCTION.Rule = identifier | FUNCTION_LITERAL | APPLICATION;

            BIND.Rule = identifier + bind + EXPRESSION;

            IF.Rule = ift + EXPRESSION + TOP_CHAIN + TOP_CHAIN;

            ARRAY.Rule = openbracket + EXPRESSION_LIST + closebracket;

            // For function literals
            ARG_LIST_FOR_DECL.Rule = MakeStarRule(ARG_LIST_FOR_DECL, comma, identifier);

            FUNCTION_LITERAL.Rule = lambda + openparen + ARG_LIST_FOR_DECL + closeparen + argsBodySeparator + TOP_CHAIN;
        }
Exemplo n.º 18
0
        public IdlGrammar()
        {
            #region Initial setup of the grammar

            // 1. define all the non-terminals
            var tDocument = new NonTerminal(NTNAME_TDOCUMENT);
            var tHeader = new NonTerminal(NTNAME_THEADER);
            var tInclude = new NonTerminal(NTNAME_TINCLUDE);
            var tNamespace = new NonTerminal(NTNAME_TNAMESPACE);
            var tNamespaceScope = new NonTerminal(NTNAME_TNAMESPACE_SCOPE);
            var tDefinition = new NonTerminal(NTNAME_TDEFINITION);
            var tEnum = new NonTerminal(NTNAME_TENUM);
            var tStruct = new NonTerminal(NTNAME_TSTRUCT);
            var tService = new NonTerminal(NTNAME_TSERVICE);
            var tField = new NonTerminal(NTNAME_TFIELD);
            var tFieldId = new NonTerminal(NTNAME_TFIELD_ID);
            var tFieldReq = new NonTerminal(NTNAME_TFIELD_REQ);
            var tFunction = new NonTerminal(NTNAME_TFUNCTION);
            var tFieldType = new NonTerminal(NTNAME_TFIELD_TYPE);
            var tBaseType = new NonTerminal(NTNAME_TBASE_TYPE);
            var tContainerType = new NonTerminal(NTNAME_TCONTAINER_TYPE);
            var tMapType = new NonTerminal(NTNAME_TMAP_TYPE);
            var tSetType = new NonTerminal(NTNAME_TSET_TYPE);
            var tListType = new NonTerminal(NTNAME_TLIST_TYPE);
            var tListSeparator = new NonTerminal("TListSeparator");


            // 2. define all the terminals
            var tSingleQuoteLiteral = new StringLiteral(TNAME_TSINGLE_QUOTE_LITERAL, "\'");
            var tDoubleQuoteLiteral = new StringLiteral(TNAME_TDOUBLE_QUOTE_LITERAL, "\"");
            // Identifier      ::=  ( Letter | '_' ) ( Letter | Digit | '.' | '_' )*
            var tIdentifier = new IdentifierTerminal(TNAME_TIDENTIFIER, "._", "_");
            var tIntNumber = new NumberLiteral("TIntNumber", NumberOptions.AllowSign | NumberOptions.IntOnly);

            CommentTerminal WELL_LINE_COMMENT = new CommentTerminal("WELL_LINE_COMMENT", "#", "\n", "\r\n");
            CommentTerminal SLASH_LINE_COMMENT = new CommentTerminal("SLASH_LINE_COMMENT", "//", "\n", "\r\n");
            CommentTerminal BLOCK_COMMENT = new CommentTerminal("BLOCK_COMMENT", "/*", "*/");
            NonGrammarTerminals.Add(WELL_LINE_COMMENT);
            NonGrammarTerminals.Add(SLASH_LINE_COMMENT);
            NonGrammarTerminals.Add(BLOCK_COMMENT);


            #endregion

            #region Define the grammar

            // 3. define BNF rules
            // Document ::= Header* Definition*
            var headers = new NonTerminal(NTNAME_HEADERS);
            var definitions = new NonTerminal(NTNAME_DEFINITIONS);
            headers.Rule = MakeStarRule(headers, tHeader);
            definitions.Rule = MakeStarRule(definitions, tDefinition);
            tDocument.Rule = headers + definitions;
            // Header ::= Include | Namespace
            tHeader.Rule = tInclude | tNamespace;
            // Include ::= 'include' Literal
            var literal = (tSingleQuoteLiteral | tDoubleQuoteLiteral);
            var includeValue = new NonTerminal(NTNAME_INCLUDE_VALUE);
            includeValue.Rule = (tSingleQuoteLiteral | tDoubleQuoteLiteral);
            tInclude.Rule = "include" + includeValue;
            // Namespace ::= 'namespace' NamespaceScope Identifier
            var namespaceValue = new NonTerminal(NTNAME_NAMESPACE_VALUE);
            namespaceValue.Rule = tIdentifier | literal;
            tNamespace.Rule = "namespace" + tNamespaceScope + namespaceValue;
            // NamespaceScope ::= 'java' | 'csharp' | 'objc'
            tNamespaceScope.Rule = ToTerm("*") | tIdentifier;
            // Definition ::= Enum | Struct | Service
            tDefinition.Rule = tEnum | tStruct | tService;
            var listSeparatorOrEmpty = new NonTerminal("ListSeparatorOrEmpty");
            listSeparatorOrEmpty.Rule = tListSeparator | Empty;
            // Enum ::= 'enum' Identifier '{' (Identifier ('=' IntConstant)? ListSeparator?)* '}'
            var enumValue = new NonTerminal(NTNAME_ENUM_VALUE);
            enumValue.Rule = ("=" + tIntNumber) | Empty;
            var enumField = new NonTerminal(NTNAME_ENUM_FIELD);
            enumField.Rule = tIdentifier + enumValue;
            var enumFields = new NonTerminal(NTNAME_ENUM_FIELDS);
            enumFields.Rule = MakeListRule(enumFields, tListSeparator, enumField, TermListOptions.StarList | TermListOptions.AllowTrailingDelimiter);
            tEnum.Rule = "enum" + tIdentifier + "{" + enumFields + "}";
            // Struct ::= 'struct' Identifier '{' Field* '}'
            var structFields = new NonTerminal(NTNAME_STRUCT_FIELDS);
            structFields.Rule = MakeStarRule(structFields, null, tField);
            tStruct.Rule = "struct" + tIdentifier + "{" + structFields + "}";
            // Service ::= 'service' Identifier '{' Function* '}'
            var functions = new NonTerminal(NTNAME_FUNCTIONS);
            functions.Rule = MakeStarRule(functions, null, tFunction);
            tService.Rule = "service" + tIdentifier + "{" + functions + "}";
            // Field ::= FieldID FieldReq? FieldType Identifier ('=' ConstValue)? ListSeparator?
            var fieldReq = new NonTerminal(NTNAME_FIELD_REQ);
            fieldReq.Rule = tFieldReq | Empty;
            tField.Rule = tFieldId + fieldReq + tFieldType + tIdentifier + listSeparatorOrEmpty;
            // FieldID ::= IntConstant ':'
            tFieldId.Rule = tIntNumber + ":";
            // FieldReq ::= 'required' | 'optional'
            tFieldReq.Rule = ToTerm("required") | "optional";
            // Function ::=  Identifier Identifier '(' Identifier Identifier ')' ListSeparator?
            tFunction.Rule = tIdentifier + tIdentifier + "(" + tIdentifier + tIdentifier + ")" + listSeparatorOrEmpty;
            // FieldType ::= Identifier | BaseType | ContainerType
            tFieldType.Rule = tIdentifier | tBaseType | tContainerType;
            // BaseType ::= 'bool' | 'byte' | 'i16' | 'i32' | 'i64' | 'double' | 'string' | 'binary'
            tBaseType.Rule = ToTerm("bool") | "byte" | "i16" | "i32" | "i64" | "double" | "string" | "binary";
            // ContainerType ::= MapType | SetType | ListType
            tContainerType.Rule = tMapType | tSetType | tListType;
            // MapType ::= 'map' '<' FieldType ',' FieldType '>'
            tMapType.Rule = ToTerm("map") + "<" + tFieldType + "," + tFieldType + ">";
            // SetType ::= 'set' '<' + FieldType '>'
            tSetType.Rule = ToTerm("set") + "<" + tFieldType + ">";
            // ListType ::= 'list' '<' FieldType '>'
            tListType.Rule = ToTerm("list") + "<" + tFieldType + ">";
            // ListSeparator ::= ',' | ';'
            tListSeparator.Rule = ToTerm(",") | ";";

            #endregion

            // Set grammar root
            this.Root = tDocument;

            // 4. Punctuation and transient terms
            MarkPunctuation("include", "namespace", "=", "enum", "struct", "{", "}", "(", ")",
                "service", "map", "set", "list", "<", ">", ",", "[", "]", ":");
            RegisterBracePair("(", ")");
            RegisterBracePair("{", "}");
            RegisterBracePair("[", "]");
            RegisterBracePair("<", ">");

            //automatically add NewLine before EOF so that our BNF rules work correctly when there's no final line break in source
            this.LanguageFlags = LanguageFlags.NewLineBeforeEOF;
        }
Exemplo n.º 19
0
 private void Comments()
 {
     var comment = new CommentTerminal("multiline_comment", "/*", "*/");
     var lineComment = new CommentTerminal("singleline_comment", "--", "\n", "\r\n");
     NonGrammarTerminals.Add(comment);
     NonGrammarTerminals.Add(lineComment);
 }
Exemplo n.º 20
0
        public SchematraGrammer()
            : base(false)
        {
            const string dotNotationWordPattern     = @"[\w\._]+";
            const string singleWordPattern          = @"[\w_]+";
            const string integerNumberPattern       = "[0-9]+";

            // ******** //
            // Comments //
            // ******** //

            var SingleLineComment   = new CommentTerminal("single-line-comment", "//", "\r", "\n", "\u2085", "\u2028", "\u2029");
            var DelimitedComment    = new CommentTerminal("multi-line-comment", "/*", "*/");
            NonGrammarTerminals.Add(SingleLineComment);
            NonGrammarTerminals.Add(DelimitedComment);

            // ************* //
            // Scalar values //
            // ************* //

            RegexBasedTerminal word         = new RegexBasedTerminal("word", singleWordPattern),
                               identifier   = new RegexBasedTerminal("identifier", dotNotationWordPattern);

            StringLiteral stringValue       = TerminalFactory.CreateCSharpString("string-value");
            NumberLiteral numberValue       = TerminalFactory.CreateCSharpNumber("number-value");

            NonTerminal value               = new NonTerminal("value");
            value.Rule                      = (numberValue | stringValue);

            // **************** //
            // Field grammer //
            // **************** //

            RegexBasedTerminal fieldIndex   = new RegexBasedTerminal(term_field_index, integerNumberPattern),
                               fieldName    = new RegexBasedTerminal(term_field_name, singleWordPattern),
                               fieldSchema  = new RegexBasedTerminal(term_field_schema, dotNotationWordPattern);

            NonTerminal field               = new NonTerminal(term_field),
                        fieldNullable       = new NonTerminal(term_field_nullable),
                        fieldInitValue      = new NonTerminal(term_field_init_value),
                        fieldQualifier      = new NonTerminal(term_field_qualifier);

            fieldNullable.Rule              = ToTerm("nullable") | Empty;

            field.Rule                      = fieldIndex + ":" + fieldQualifier + fieldNullable + fieldSchema +
                                               fieldName + fieldInitValue + ";";

            fieldInitValue.Rule             = (ToTerm("=") + value) | Empty;
            fieldQualifier.Rule             = ToTerm("optional") | "required";

            // ************** //
            // Schema grammer //
            // ************** //

            StringLiteral schemaDefTag          = TerminalFactory.CreateCSharpString(term_schema_def_tag);
            RegexBasedTerminal schemaDefExtends = new RegexBasedTerminal(term_schema_def_extends, dotNotationWordPattern);
            RegexBasedTerminal schemaDefName = new RegexBasedTerminal(term_schema_def_name, singleWordPattern);

            NonTerminal schemaDef               = new NonTerminal(term_schema_def),
                        schemaDefOption         = new NonTerminal(term_schema_def_option),
                        schemaDefTaggedOption   = new NonTerminal(term_schema_def_tagged_option),
                        schemaDefExtendsOption  = new NonTerminal(term_schema_def_extends_option),
                        schemaDefOptions        = new NonTerminal(term_schema_def_options),
                        schemaDefBody           = new NonTerminal(term_schema_def_body);

            schemaDefTaggedOption.Rule          = ToTerm("tagged") + schemaDefTag;
            schemaDefExtendsOption.Rule         = ToTerm("extends") + schemaDefExtends;

            schemaDefOption.Rule                = schemaDefTaggedOption | schemaDefExtendsOption;
            schemaDefOptions.Rule               = MakeStarRule(schemaDefOptions, schemaDefOption);
            schemaDef.Rule                      = ToTerm("record") + schemaDefName + schemaDefOptions + "{" + schemaDefBody + "}";
            schemaDefBody.Rule                  = MakeStarRule(schemaDefBody, field);

            // ************* //
            // Using grammer //
            // ************* //

            RegexBasedTerminal usingDefName     = new RegexBasedTerminal(term_using_def_name, dotNotationWordPattern);

            NonTerminal usingDefs               = new NonTerminal(term_using_defs),
                        usingDef                = new NonTerminal(term_using_def);

            usingDef.Rule                       = ToTerm("using") + usingDefName + ";";
            usingDefs.Rule                      = MakeStarRule(usingDefs, usingDef);

            // *************** //
            // Unit grammer //
            // *************** //

            RegexBasedTerminal namespaceDefName = new RegexBasedTerminal(term_namespace_def_name, dotNotationWordPattern);

            NonTerminal unit                = new NonTerminal(term_unit),
                        def                 = new NonTerminal(term_def),
                        defs                = new NonTerminal(term_defs),
                        namespaceDef        = new NonTerminal(term_namespace_def);

            unit.Rule                       = usingDefs + defs;
            defs.Rule                       = MakeStarRule(defs, def);
            def.Rule                        = schemaDef | namespaceDef;
            namespaceDef.Rule               = ToTerm("namespace") + namespaceDefName + "{" + defs + "}";

            this.Root = unit;

            MarkPunctuation("enum", "a", "=", "[", "]", "record", "{", "}", ",", ";", ":", "namespace", "tagged", "extends", "schema", "using");
        }
Exemplo n.º 21
0
        TerminalSet _skipTokensInPreview = new TerminalSet(); //used in token preview for conflict resolution

        #endregion Fields

        #region Constructors

        public CSharpGrammar()
        {
            this.GrammarComments = "NOTE: This grammar is just a demo, and it is a broken demo.\r\n" +
                             "Demonstrates token preview technique to help parser resolve conflicts.\r\n";
              #region Lexical structure
              StringLiteral StringLiteral = TerminalFactory.CreateCSharpString("StringLiteral");
              StringLiteral CharLiteral = TerminalFactory.CreateCSharpChar("CharLiteral");
              NumberLiteral Number = TerminalFactory.CreateCSharpNumber("Number");
              IdentifierTerminal identifier = TerminalFactory.CreateCSharpIdentifier("Identifier");

              CommentTerminal SingleLineComment = new CommentTerminal("SingleLineComment", "//", "\r", "\n", "\u2085", "\u2028", "\u2029");
              CommentTerminal DelimitedComment = new CommentTerminal("DelimitedComment", "/*", "*/");
              NonGrammarTerminals.Add(SingleLineComment);
              NonGrammarTerminals.Add(DelimitedComment);
              //Temporarily, treat preprocessor instructions like comments
              CommentTerminal ppInstruction = new CommentTerminal("ppInstruction", "#", "\n");
              NonGrammarTerminals.Add(ppInstruction);

              //Symbols
              KeyTerm colon = ToTerm(":", "colon");
              KeyTerm semi = ToTerm(";", "semi");
              NonTerminal semi_opt = new NonTerminal("semi?");
              semi_opt.Rule = Empty | semi;
              KeyTerm dot = ToTerm(".", "dot");
              KeyTerm comma = ToTerm(",", "comma");
              NonTerminal comma_opt = new NonTerminal("comma_opt", Empty | comma);
              NonTerminal commas_opt = new NonTerminal("commas_opt");
              commas_opt.Rule = MakeStarRule(commas_opt, null, comma);
              KeyTerm qmark = ToTerm("?", "qmark");
              NonTerminal qmark_opt = new NonTerminal("qmark_opt", Empty | qmark);
              KeyTerm Lbr = ToTerm("{");
              KeyTerm Rbr = ToTerm("}");
              KeyTerm Lpar = ToTerm("(");
              KeyTerm Rpar = ToTerm(")");
              KeyTerm tgoto = ToTerm("goto");
              KeyTerm yld = ToTerm("yield");

              KeyTerm Lparx = ToTerm("(*");
              #endregion

              #region NonTerminals
              //B.2.1. Basic concepts
              var qual_name_with_targs = new NonTerminal("qual_name_with_targs");
              var base_type_list = new NonTerminal("base_type_list");
              var generic_dimension_specifier = new NonTerminal("generic_dimension_specifier");
              var qual_name_segment = new NonTerminal("qual_name_segment");
              var qual_name_segments_opt = new NonTerminal("qual_name_segments_opt");
              var type_or_void = new NonTerminal("type_or_void", "type or void");
              var builtin_type = new NonTerminal("builtin_type", "built-in type");
              var type_ref_list = new NonTerminal("type_ref_list");
              var identifier_ext = new NonTerminal("identifier_ext");
              var identifier_or_builtin = new NonTerminal("identifier_or_builtin");

              //B.2.2. Types
              var type_ref = new NonTerminal("type_ref");
              var new_type_ref = new NonTerminal("new_type_ref");
              var type_argument_list = new NonTerminal("type_argument_list");
              var typearg_or_gendimspec_list = new NonTerminal("typearg_or_gendimspec_list");
              var type_argument_list_opt = new NonTerminal("type_argument_list_opt");
              var integral_type = new NonTerminal("integral_type");

              //B.2.4. Expressions
              var argument = new NonTerminal("argument");
              var argument_list = new NonTerminal("argument_list");
              var argument_list_opt = new NonTerminal("argument_list_opt");
              var expression = new NonTerminal("expression", "expression");
              var expression_list = new NonTerminal("expression_list");
              var expression_opt = new NonTerminal("expression_opt");
              var conditional_expression = new NonTerminal("conditional_expression");
              var lambda_expression = new NonTerminal("lambda_expression");
              var query_expression = new NonTerminal("query_expression");
              var unary_operator = new NonTerminal("unary_operator");
              var assignment_operator = new NonTerminal("assignment_operator");
              var primary_expression = new NonTerminal("primary_expression");
              var unary_expression = new NonTerminal("unary_expression");
              var pre_incr_decr_expression = new NonTerminal("pre_incr_decr_expression");
              var post_incr_decr_expression = new NonTerminal("post_incr_decr_expression");
              var primary_no_array_creation_expression = new NonTerminal("primary_no_array_creation_expression");
              var literal = new NonTerminal("literal");
              var parenthesized_expression = new NonTerminal("parenthesized_expression");
              var member_access = new NonTerminal("member_access");
              var member_access_segment = new NonTerminal("member_access_segment");
              var member_access_segments_opt = new NonTerminal("member_access_segments_opt");
              var array_indexer = new NonTerminal("array_indexer");
              var argument_list_par = new NonTerminal("argument_list_par");
              var argument_list_par_opt = new NonTerminal("argument_list_par_opt");
              var incr_or_decr = new NonTerminal("incr_or_decr");
              var incr_or_decr_opt = new NonTerminal("incr_or_decr_opt");
              var creation_args = new NonTerminal("creation_args");
              var object_creation_expression = new NonTerminal("object_creation_expression");
              // delegate creation is syntactically equiv to object creation
              //var delegate_creation_expression = new NonTerminal("delegate_creation_expression");
              var anonymous_object_creation_expression = new NonTerminal("anonymous_object_creation_expression");
              var typeof_expression = new NonTerminal("typeof_expression");
              var checked_expression = new NonTerminal("checked_expression");
              var unchecked_expression = new NonTerminal("unchecked_expression");
              var default_value_expression = new NonTerminal("default_value_expression");
              var anonymous_method_expression = new NonTerminal("anonymous_method_expression");

              var elem_initializer = new NonTerminal("elem_initializer");
              var elem_initializer_list = new NonTerminal("elem_initializer_list");
              var elem_initializer_list_ext = new NonTerminal("elem_initializer_list_ext");
              var initializer_value = new NonTerminal("initializer_value");

              var anonymous_object_initializer = new NonTerminal("anonymous_object_initializer");
              var member_declarator = new NonTerminal("member_declarator");
              var member_declarator_list = new NonTerminal("member_declarator_list");
              var unbound_type_name = new NonTerminal("unbound_type_name");
              var generic_dimension_specifier_opt = new NonTerminal("generic_dimension_specifier_opt");
              var anonymous_function_signature = new NonTerminal("anonymous_function_signature");
              var anonymous_function_signature_opt = new NonTerminal("anonymous_function_signature_opt");
              var anonymous_function_parameter = new NonTerminal("anonymous_function_parameter");
              var anonymous_function_parameter_decl = new NonTerminal("anonymous_function_parameter_decl");
              var anonymous_function_parameter_list_opt = new NonTerminal("anonymous_function_parameter_list_opt");
              var anonymous_function_parameter_modifier_opt = new NonTerminal("anonymous_function_parameter_modifier_opt");
              var anonymous_function_body = new NonTerminal("anonymous_function_body");
              var lambda_function_signature = new NonTerminal("lambda_function_signature");
              var bin_op_expression = new NonTerminal("bin_op_expression");
              var typecast_expression = new NonTerminal("typecast_expression");
              var bin_op = new NonTerminal("bin_op", "operator symbol");

              //B.2.5. Statements
              var statement = new NonTerminal("statement", "statement");
              var statement_list = new NonTerminal("statement_list");
              var statement_list_opt = new NonTerminal("statement_list_opt");
              var labeled_statement = new NonTerminal("labeled_statement");
              var declaration_statement = new NonTerminal("declaration_statement");
              var embedded_statement = new NonTerminal("embedded_statement");
              var selection_statement = new NonTerminal("selection_statement");
              var iteration_statement = new NonTerminal("iteration_statement");
              var jump_statement = new NonTerminal("jump_statement");
              var try_statement = new NonTerminal("try_statement");
              var checked_statement = new NonTerminal("checked_statement");
              var unchecked_statement = new NonTerminal("unchecked_statement");
              var lock_statement = new NonTerminal("lock_statement");
              var using_statement = new NonTerminal("using_statement");
              var yield_statement = new NonTerminal("yield_statement");
              var block = new NonTerminal("block");
              var statement_expression = new NonTerminal("statement_expression");
              var statement_expression_list = new NonTerminal("statement_expression_list");
              var local_variable_declaration = new NonTerminal("local_variable_declaration");
              var local_constant_declaration = new NonTerminal("local_constant_declaration");
              var local_variable_type = new NonTerminal("local_variable_type");
              var local_variable_declarator = new NonTerminal("local_variable_declarator");
              var local_variable_declarators = new NonTerminal("local_variable_declarators");
              var if_statement = new NonTerminal("if_statement");
              var switch_statement = new NonTerminal("switch_statement");
              var else_clause_opt = new NonTerminal("else_clause_opt");
              var switch_section = new NonTerminal("switch_section");
              var switch_sections_opt = new NonTerminal("switch_sections_opt");
              var switch_label = new NonTerminal("switch_label");
              var switch_labels = new NonTerminal("switch_labels");
              var while_statement = new NonTerminal("while_statement");
              var do_statement = new NonTerminal("do_statement");
              var for_statement = new NonTerminal("for_statement");
              var foreach_statement = new NonTerminal("foreach_statement");
              var for_initializer_opt = new NonTerminal("for_initializer_opt");
              var for_condition_opt = new NonTerminal("for_condition_opt");
              var for_iterator_opt = new NonTerminal("for_iterator_opt");
              var break_statement = new NonTerminal("break_statement");
              var continue_statement = new NonTerminal("continue_statement");
              var goto_statement = new NonTerminal("goto_statement");
              var return_statement = new NonTerminal("return_statement");
              var throw_statement = new NonTerminal("throw_statement");
              var try_clause = new NonTerminal("try_clause");
              var try_clauses = new NonTerminal("try_clauses");

              var catch_clause = new NonTerminal("catch_clause");
              var finally_clause = new NonTerminal("finally_clause");
              var catch_specifier_opt = new NonTerminal("catch_specifier_opt");
              var identifier_opt = new NonTerminal("identifier_opt");

              var resource_acquisition = new NonTerminal("resource_acquisition");

              //namespaces, compilation units
              var compilation_unit = new NonTerminal("compilation_unit");
              var extern_alias_directive = new NonTerminal("extern_alias_directive");
              var extern_alias_directives_opt = new NonTerminal("extern_alias_directives_opt");
              var using_directive = new NonTerminal("using_directive");
              var using_directives = new NonTerminal("using_directives");
              var using_directives_opt = new NonTerminal("using_directives_opt");
              var namespace_declaration = new NonTerminal("namespace_declaration");
              var namespace_declarations_opt = new NonTerminal("namespace_declarations_opt");
              var qualified_identifier = new NonTerminal("qualified_identifier");
              var namespace_body = new NonTerminal("namespace_body");
              var namespace_member_declaration = new NonTerminal("namespace_member_declaration");
              var namespace_member_declarations = new NonTerminal("namespace_member_declarations");
              var using_alias_directive = new NonTerminal("using_alias_directive");
              var using_ns_directive = new NonTerminal("using_ns_directive");
              var type_declaration = new NonTerminal("type_declaration");
              var class_declaration = new NonTerminal("class_declaration");
              var delegate_declaration = new NonTerminal("delegate_declaration");
              var qualified_alias_member = new NonTerminal("qualified_alias_member");
              var class_body = new NonTerminal("class_body");

              //B.2.7 Classes
              Terminal partial = ToTerm("partial");
              var type_parameter_list_opt = new NonTerminal("type_parameter_list_opt");
              var type_parameter = new NonTerminal("type_parameter");
              var type_parameters = new NonTerminal("type_parameters");
              var bases_opt = new NonTerminal("bases_opt");
              var type_parameter_constraints_clause = new NonTerminal("type_parameter_constraints_clause");
              var type_parameter_constraints_clauses_opt = new NonTerminal("type_parameter_constraints_clauses");
              var type_parameter_constraint = new NonTerminal("type_parameter_constraint");
              var type_parameter_constraints = new NonTerminal("type_parameter_constraints");
              var member_declaration = new NonTerminal("member_declaration");
              var member_declarations_opt = new NonTerminal("member_declarations_opt");
              var constant_declaration = new NonTerminal("constant_declaration");
              var field_declaration = new NonTerminal("field_declaration");
              var method_declaration = new NonTerminal("method_declaration");
              var property_declaration = new NonTerminal("property_declaration");
              var event_declaration = new NonTerminal("event_declaration");
              var indexer_declaration = new NonTerminal("indexer_declaration");
              var constructor_declaration = new NonTerminal("constructor_declaration");
              var destructor_declaration = new NonTerminal("destructor_declaration");
              var constant_declarator = new NonTerminal("constant_declarator");
              var constant_declarators = new NonTerminal("constant_declarators");
              var modifier = new NonTerminal("modifier");
              var modifiers_opt = new NonTerminal("modifiers_opt");
              var member_header = new NonTerminal("member_header");
              var accessor_name = new NonTerminal("accessor_name");
              var accessor_declaration = new NonTerminal("accessor_declaration");
              var accessor_declarations = new NonTerminal("accessor_declarations");
              var accessor_modifier_opt = new NonTerminal("accessor_modifier_opt");
              var event_body = new NonTerminal("event_body");
              var event_accessor_declarations = new NonTerminal("event_accessor_declarations");
              var add_accessor_declaration = new NonTerminal("add_accessor_declaration");
              var remove_accessor_declaration = new NonTerminal("remove_accessor_declaration");
              var indexer_name = new NonTerminal("indexer_name");
              var operator_declaration = new NonTerminal("operator_declaration");
              var conversion_operator_declaration = new NonTerminal("conversion_operator_declaration");
              var overloadable_operator = new NonTerminal("overloadable_operator");
              var operator_parameter = new NonTerminal("operator_parameter");
              var operator_parameters = new NonTerminal("operator_parameters");
              var conversion_operator_kind = new NonTerminal("conversion_operator_kind");
              var constructor_initializer_opt = new NonTerminal("constructor_initializer_opt");
              var constructor_base = new NonTerminal("constructor_base");
              var variable_declarator = new NonTerminal("variable_declarator");
              var variable_declarators = new NonTerminal("variable_declarators");
              var method_body = new NonTerminal("method_body");
              var formal_parameter_list = new NonTerminal("formal_parameter_list");
              var formal_parameter_list_par = new NonTerminal("formal_parameter_list_par");
              var fixed_parameter = new NonTerminal("fixed_parameter");
              var fixed_parameters = new NonTerminal("fixed_parameters");
              var parameter_modifier_opt = new NonTerminal("parameter_modifier_opt");
              var parameter_array = new NonTerminal("parameter_array");

              //B.2.8 struct
              var struct_declaration = new NonTerminal("struct_declaration");
              var struct_body = new NonTerminal("struct_body");

              //B.2.9. Arrays
              var rank_specifier = new NonTerminal("rank_specifier");
              var rank_specifiers = new NonTerminal("rank_specifiers");
              var rank_specifiers_opt = new NonTerminal("rank_specifiers_opt");
              var dim_specifier = new NonTerminal("dim_specifier");
              var dim_specifier_opt = new NonTerminal("dim_specifier_opt");
              var list_initializer = new NonTerminal("array_initializer");
              var list_initializer_opt = new NonTerminal("array_initializer_opt");

              //B.2.10 Interfaces
              var interface_declaration = new NonTerminal("interface_declaration");
              var interface_body = new NonTerminal("interface_body");
              var interface_member_declaration = new NonTerminal("interface_member_declaration");
              var interface_member_declarations = new NonTerminal("interface_member_declarations");
              var interface_method_declaration = new NonTerminal("interface_method_declaration");
              var interface_property_declaration = new NonTerminal("interface_property_declaration");
              var interface_event_declaration = new NonTerminal("interface_event_declaration");
              var interface_indexer_declaration = new NonTerminal("interface_indexer_declaration");
              var new_opt = new NonTerminal("new_opt");
              var interface_accessor = new NonTerminal("interface_get_accessor");
              var interface_accessors = new NonTerminal("interface_accessors");

              //B.2.11 Enums
              var enum_declaration = new NonTerminal("enum_declaration");
              var enum_base_opt = new NonTerminal("enum_base_opt");
              var enum_member_declaration = new NonTerminal("enum_member_declaration");
              var enum_member_declarations = new NonTerminal("enum_member_declarations");

              //B.2.13 Attributes
              var attribute_section = new NonTerminal("attribute_section");
              var attributes_opt = new NonTerminal("attributes_opt");
              var attribute_target_specifier_opt = new NonTerminal("attribute_target_specifier_opt");
              var attribute_target = new NonTerminal("attribute_target");
              var attribute = new NonTerminal("attribute");
              var attribute_list = new NonTerminal("attribute_list");
              var attribute_arguments_opt = new NonTerminal("attribute_arguments");
              var named_argument = new NonTerminal("named_argument");
              var attr_arg = new NonTerminal("attr_arg");
              var attribute_arguments_par_opt = new NonTerminal("attribute_arguments_par_opt");

              #endregion

              #region operators, punctuation and delimiters
              RegisterOperators(1, "||");
              RegisterOperators(2, "&&");
              RegisterOperators(3, "|");
              RegisterOperators(4, "^");
              RegisterOperators(5, "&");
              RegisterOperators(6, "==", "!=");
              RegisterOperators(7, "<", ">", "<=", ">=", "is", "as");
              RegisterOperators(8, "<<", ">>");
              RegisterOperators(9, "+", "-");
              RegisterOperators(10, "*", "/", "%");
              //RegisterOperators(11, ".");
              // RegisterOperators(12, "++", "--");
              #region comments
              //The following makes sense, if you think about "?" in context of operator precedence.
              // What we say here is that "?" has the lowest priority among arithm operators.
              // Therefore, the parser should prefer reduce over shift when input symbol is "?".
              // For ex., when seeing ? in expression "a + b?...", the parser will perform Reduce:
              //  (a + b)->expr
              // and not shift the "?" symbol.
              // Same goes for ?? symbol
              #endregion
              RegisterOperators(-3, "=", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<=", ">>=");
              RegisterOperators(-2, "?");
              RegisterOperators(-1, "??");

              this.Delimiters = "{}[](),:;+-*/%&|^!~<>=";
              this.MarkPunctuation(";", ",", "(", ")", "{", "}", "[", "]", ":");
              this.MarkTransient(namespace_member_declaration, member_declaration, type_declaration, statement, embedded_statement, expression,
            literal, bin_op, primary_expression, expression);

              this.AddTermsReportGroup("assignment", "=", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<=", ">>=");
              this.AddTermsReportGroup("typename", "bool", "decimal", "float", "double", "string", "object",
            "sbyte", "byte", "short", "ushort", "int", "uint", "long", "ulong", "char");
              this.AddTermsReportGroup("statement", "if", "switch", "do", "while", "for", "foreach", "continue", "goto", "return", "try", "yield",
                                            "break", "throw", "unchecked", "using");
              this.AddTermsReportGroup("type declaration", "public", "private", "protected", "static", "internal", "sealed", "abstract", "partial",
                                                   "class", "struct", "delegate", "interface", "enum");
              this.AddTermsReportGroup("member declaration", "virtual", "override", "readonly", "volatile", "extern");
              this.AddTermsReportGroup("constant", Number, StringLiteral, CharLiteral);
              this.AddTermsReportGroup("constant", "true", "false", "null");

              this.AddTermsReportGroup("unary operator", "+", "-", "!", "~");

              this.AddToNoReportGroup(comma, semi);
              this.AddToNoReportGroup("var", "const", "new", "++", "--", "this", "base", "checked", "lock", "typeof", "default",
                               "{", "}", "[");

              //
              #endregion

              #region "<" conflict resolution
              var gen_lt = new NonTerminal("gen_lt");
              gen_lt.Rule = CustomActionHere(this.ResolveLessThanConflict) + "<";
              #endregion
              /*
              #region Keywords
              string strKeywords =
            "abstract as base bool break byte case catch char checked " +
            "class	const	continue decimal default delegate  do double else enum event explicit extern false finally " +
            "fixed float for foreach goto if implicit in int interface internal is lock long namespace " +
            "new null object operator out override params private protected public " +
            "readonly ref return sbyte sealed short sizeof stackalloc static string " +
            "struct switch this throw true try typeof uint ulong unchecked unsafe ushort using virtual void " +
            "volatile while";
              AddKeywordList(strKeywords);
              #endregion
             */

              // RULES
              //B.2.1. Basic concepts
              //qual_name_with_targs is an alias for namespace-name, namespace-or-type-name, type-name,

              generic_dimension_specifier.Rule = gen_lt + commas_opt + ">";
              qual_name_segments_opt.Rule = MakeStarRule(qual_name_segments_opt, null, qual_name_segment);
              identifier_or_builtin.Rule = identifier | builtin_type;
              identifier_ext.Rule = identifier_or_builtin | "this" | "base";
              qual_name_segment.Rule = dot + identifier
                              | "::" + identifier
                              | type_argument_list;
              //generic_dimension_specifier.Rule = lt + commas_opt + ">";
              generic_dimension_specifier.Rule = gen_lt + commas_opt + ">";
              qual_name_with_targs.Rule = identifier_or_builtin + qual_name_segments_opt;

              type_argument_list.Rule = gen_lt + type_ref_list + ">";
              type_argument_list_opt.Rule = Empty | type_argument_list;
              typearg_or_gendimspec_list.Rule = type_argument_list | generic_dimension_specifier_opt;

              //B.2.2. Types
              type_or_void.Rule = qual_name_with_targs | "void";
              builtin_type.Rule = integral_type | "bool" | "decimal" | "float" | "double" | "string" | "object";

              type_ref.Rule = type_or_void + qmark_opt + rank_specifiers_opt + typearg_or_gendimspec_list;
              type_ref_list.Rule = MakePlusRule(type_ref_list, comma, type_ref);

              var comma_list_opt = new NonTerminal("comma_list_opt");
              comma_list_opt.Rule = MakeStarRule(comma_list_opt, comma);
              rank_specifier.Rule = "[" + comma_list_opt + "]";
              rank_specifiers.Rule = MakePlusRule(rank_specifiers, null, rank_specifier);
              rank_specifiers_opt.Rule = rank_specifiers.Q();
              integral_type.Rule = ToTerm("sbyte") | "byte" | "short" | "ushort" | "int" | "uint" | "long" | "ulong" | "char";

              //B.2.4. Variables
              //Quite strange in specs -
              //  variable-reference:
              //     expression
              // Is that case it would be possible to do the following:
              //                 GetMyStuff(out (a+b));
              //  but MS c# rejects it

              //B.2.4. Expressions
              argument.Rule = expression | "ref" + identifier | "out" + identifier;
              argument_list.Rule = MakePlusRule(argument_list, comma, argument);
              argument_list_opt.Rule = Empty | argument_list;
              expression.Rule = conditional_expression
                    | bin_op_expression
                    | typecast_expression
                    | primary_expression;
              expression_opt.Rule = Empty | expression;
              expression_list.Rule = MakePlusRule(expression_list, comma, expression);
              unary_operator.Rule = ToTerm("+") | "-" | "!" | "~" | "*";
              assignment_operator.Rule = ToTerm("=") | "+=" | "-=" | "*=" | "/=" | "%=" | "&=" | "|=" | "^=" | "<<=" | ">>=";
              conditional_expression.Rule = expression + PreferShiftHere() + qmark + expression + colon + expression;// + ReduceThis();
              bin_op_expression.Rule = expression + bin_op + expression;

              typecast_expression.Rule = parenthesized_expression + primary_expression;
              primary_expression.Rule =
            literal
            | unary_expression
            | parenthesized_expression
            | member_access
            | pre_incr_decr_expression
            | post_incr_decr_expression
            | object_creation_expression
            | anonymous_object_creation_expression
            | typeof_expression
            | checked_expression
            | unchecked_expression
            | default_value_expression
            | anonymous_method_expression;
              unary_expression.Rule = unary_operator + primary_expression;
              dim_specifier.Rule = "[" + expression_list + "]";
              dim_specifier_opt.Rule = dim_specifier.Q();
              literal.Rule = Number | StringLiteral | CharLiteral | "true" | "false" | "null";
              parenthesized_expression.Rule = Lpar + expression + Rpar;
              pre_incr_decr_expression.Rule = incr_or_decr + member_access;
              post_incr_decr_expression.Rule = member_access + incr_or_decr;

              //joined invocation_expr and member_access; for member access left the most general variant
              member_access.Rule = identifier_ext + member_access_segments_opt;
              member_access_segments_opt.Rule = MakeStarRule(member_access_segments_opt, null, member_access_segment);
              member_access_segment.Rule = dot + identifier
                                 | array_indexer
                                 | argument_list_par
                                 | type_argument_list;
              array_indexer.Rule = "[" + expression_list + "]";

              argument_list_par.Rule = Lpar + argument_list_opt + Rpar;

              argument_list_par_opt.Rule = Empty | argument_list_par;

              list_initializer.Rule = Lbr + elem_initializer_list_ext + Rbr;
              list_initializer_opt.Rule = list_initializer.Q();

              elem_initializer.Rule = initializer_value | identifier + "=" + initializer_value;
              elem_initializer_list.Rule = MakePlusRule(elem_initializer_list, comma, elem_initializer);
              elem_initializer_list_ext.Rule = Empty | elem_initializer_list + comma_opt;
              initializer_value.Rule = expression | list_initializer;

              //delegate, anon-object, object
              object_creation_expression.Rule = "new" + qual_name_with_targs + qmark_opt + creation_args + list_initializer_opt;
              creation_args.Rule = dim_specifier | rank_specifier | argument_list_par;

              anonymous_object_creation_expression.Rule = "new" + anonymous_object_initializer;
              anonymous_object_initializer.Rule = Lbr + Rbr | Lbr + member_declarator_list + comma_opt + Rbr;
              member_declarator.Rule = expression | identifier + "=" + expression;
              member_declarator_list.Rule = MakePlusRule(member_declarator_list, comma, member_declarator);
              //typeof
              typeof_expression.Rule = "typeof" + Lpar + type_ref + Rpar;
              generic_dimension_specifier_opt.Rule = Empty | gen_lt + commas_opt + ">";
              //checked, unchecked
              checked_expression.Rule = "checked" + parenthesized_expression;
              unchecked_expression.Rule = "unchecked" + parenthesized_expression;
              //default-value
              default_value_expression.Rule = "default" + Lpar + type_ref + Rpar;
              //note: we treat ?? as bin-operation, so null-coalesce-expr used in spec as first (condition) component is replaced with expression
              // we resolve all this expr hierarchies of binary expressions using precedence

              //anonymous method and lambda - we join explicit and implicit param definitions, making 'type' element optional
              // TODO: add after-parse check for this
              anonymous_method_expression.Rule = "delegate" + anonymous_function_signature_opt + block;
              lambda_expression.Rule = lambda_function_signature + "=>" + anonymous_function_body;
              lambda_function_signature.Rule = anonymous_function_signature | identifier;
              anonymous_function_signature.Rule = Lpar + anonymous_function_parameter_list_opt + Rpar;
              anonymous_function_signature_opt.Rule = anonymous_function_signature.Q();
              anonymous_function_parameter_modifier_opt.Rule = Empty | "ref" | "out";
              anonymous_function_parameter.Rule = anonymous_function_parameter_modifier_opt + anonymous_function_parameter_decl;
              anonymous_function_parameter_decl.Rule = identifier | type_ref + identifier;
              anonymous_function_parameter_list_opt.Rule = MakeStarRule(anonymous_function_parameter_list_opt, comma, anonymous_function_parameter_decl);
              anonymous_function_body.Rule = expression | block;

              //we don't use grammar expressions to specify operator precedence, so we combine all these grammar elements together
              // and define just bin_op_expression. Where to put it?
              // In spec:     non_assignment_expression.Rule = conditional_expression | lambda_expression | query_expression;
              //I think it's a mistake; there must be additional entry here for arithm expressions, so we put them here.
              // We also have to add "is" and "as" expressions here, as we don't build entire hierarchy of elements for expressing
              // precedence (where they appear in original spec); so we put them here
              bin_op.Rule = ToTerm("<")
                  | "||" | "&&" | "|" | "^" | "&" | "==" | "!=" | ">" | "<=" | ">=" | "<<" | ">>" | "+" | "-" | "*" | "/" | "%"
                  | "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "&=" | "|=" | "^=" | "<<=" | ">>="
                  | "is" | "as" | "??";

              //type_check_expression.Rule = expression + "is" + type_ref | expression + "as" + type_ref;

              //Queries
              query_expression.Rule = "from";

              //B.2.5. Statements
              statement.Rule = labeled_statement | declaration_statement | embedded_statement;
              statement.ErrorRule = SyntaxError + semi; //skip all until semicolon
              statement_list.Rule = MakePlusRule(statement_list, null, statement);
              statement_list_opt.Rule = Empty | statement_list;
              //labeled_statement
              labeled_statement.Rule = identifier + colon + embedded_statement;
              //declaration_statement
              declaration_statement.Rule = local_variable_declaration + semi | local_constant_declaration + semi;
              local_variable_declaration.Rule = local_variable_type + local_variable_declarators; //!!!
              local_variable_type.Rule = member_access | "var"; // | builtin_type; //to fix the conflict, changing to member-access here
              local_variable_declarator.Rule = identifier | identifier + "=" + initializer_value;
              local_variable_declarators.Rule = MakePlusRule(local_variable_declarators, comma, local_variable_declarator);
              local_constant_declaration.Rule = "const" + type_ref + constant_declarators;
              //embedded_statement
              embedded_statement.Rule = block | semi /*empty_statement*/ | statement_expression + semi | selection_statement
                               | iteration_statement | jump_statement | try_statement | checked_statement | unchecked_statement
                               | lock_statement | using_statement | yield_statement;
              block.Rule = Lbr + statement_list_opt + Rbr;
              //selection (if and switch)
              selection_statement.Rule = if_statement | switch_statement;
              if_statement.Rule = ToTerm("if") + Lpar + expression + Rpar + embedded_statement + else_clause_opt;
              else_clause_opt.Rule = Empty | PreferShiftHere() + "else" + embedded_statement;
              switch_statement.Rule = "switch" + parenthesized_expression + Lbr + switch_sections_opt + Rbr;
              switch_section.Rule = switch_labels + statement_list;
              switch_sections_opt.Rule = MakeStarRule(switch_sections_opt, null, switch_section);
              switch_label.Rule = "case" + expression + colon | "default" + colon;
              switch_labels.Rule = MakePlusRule(switch_labels, null, switch_label);
              //iteration statements
              iteration_statement.Rule = while_statement | do_statement | for_statement | foreach_statement;
              while_statement.Rule = "while" + parenthesized_expression + embedded_statement;
              do_statement.Rule = "do" + embedded_statement + "while" + parenthesized_expression + semi;
              for_statement.Rule = "for" + Lpar + for_initializer_opt + semi + for_condition_opt + semi + for_iterator_opt + Rpar + embedded_statement;
              for_initializer_opt.Rule = Empty | local_variable_declaration | statement_expression_list;
              for_condition_opt.Rule = Empty | expression;
              for_iterator_opt.Rule = Empty | statement_expression_list;
              foreach_statement.Rule = "foreach" + Lpar + local_variable_type + identifier + "in" + expression + Rpar + embedded_statement;
              //jump-statement
              jump_statement.Rule = break_statement | continue_statement | goto_statement | return_statement | throw_statement;
              break_statement.Rule = "break" + semi;
              continue_statement.Rule = "continue" + semi;
              goto_statement.Rule = tgoto + identifier + semi | tgoto + "case" + expression + semi | tgoto + "default" + semi;
              return_statement.Rule = "return" + expression_opt + semi;
              throw_statement.Rule = "throw" + expression_opt + semi;
              //try-statement
              //changed to avoid conflicts; need to check correct ordering of catch/finally clause in after-parse validation
              try_statement.Rule = "try" + block + try_clauses;
              try_clause.Rule = catch_clause | finally_clause;
              try_clauses.Rule = MakePlusRule(try_clauses, null, try_clause);
              catch_clause.Rule = "catch" + catch_specifier_opt + block;
              finally_clause.Rule = "finally" + block;
              catch_specifier_opt.Rule = Empty | Lpar + qual_name_with_targs + identifier_opt + Rpar;
              identifier_opt.Rule = Empty | identifier;
              //checked, unchecked, locked, using
              checked_statement.Rule = "checked" + block;
              unchecked_statement.Rule = "unchecked" + block;
              lock_statement.Rule = "lock" + parenthesized_expression + embedded_statement;
              using_statement.Rule = "using" + Lpar + resource_acquisition + Rpar + embedded_statement;
              resource_acquisition.Rule = local_variable_declaration | expression;
              //yield statement
              yield_statement.Rule = yld + "return" + expression + semi | yld + "break" + semi;

              //expression statement
              // expression_statement.Rule = statement_expression + semi;
              statement_expression.Rule = object_creation_expression
                                | member_access | member_access + assignment_operator + expression
                                | pre_incr_decr_expression | post_incr_decr_expression
                                ;
              statement_expression_list.Rule = MakePlusRule(statement_expression_list, comma, statement_expression);
              incr_or_decr_opt.Rule = Empty | ToTerm("++") | "--";
              incr_or_decr.Rule = ToTerm("++") | "--";

              //B.2.6. Namespaces
              this.Root = compilation_unit;
              compilation_unit.Rule = extern_alias_directives_opt
                            + using_directives_opt
                            + attributes_opt + namespace_declarations_opt;
              extern_alias_directive.Rule = PreferShiftHere() + ToTerm("extern") + "alias" + identifier + semi;
              extern_alias_directives_opt.Rule = MakeStarRule(extern_alias_directives_opt, null, extern_alias_directive);
              namespace_declaration.Rule = "namespace" + qualified_identifier + namespace_body + semi_opt;
              namespace_declarations_opt.Rule = MakeStarRule(namespace_declarations_opt, null, namespace_declaration);
              qualified_identifier.Rule = MakePlusRule(qualified_identifier, dot, identifier);

              namespace_body.Rule = "{" + extern_alias_directives_opt + using_directives_opt + namespace_member_declarations + "}";

              using_directive.Rule = using_alias_directive | using_ns_directive;
              using_directives.Rule = MakePlusRule(using_directives, null, using_directive);
              using_directives_opt.Rule = Empty | using_directives;

              using_alias_directive.Rule = "using" + identifier + "=" + qual_name_with_targs + semi;
              using_ns_directive.Rule = "using" + qual_name_with_targs + semi;
              namespace_member_declaration.Rule = namespace_declaration | type_declaration;
              namespace_member_declarations.Rule = MakePlusRule(namespace_member_declarations, null, namespace_member_declaration);

              type_declaration.Rule = class_declaration | struct_declaration | interface_declaration | enum_declaration | delegate_declaration;

              //B.2.7. Classes
              class_declaration.Rule = member_header + "class" + identifier + type_parameter_list_opt +
            bases_opt + type_parameter_constraints_clauses_opt + class_body;
              class_body.Rule = Lbr + member_declarations_opt + Rbr;
              bases_opt.Rule = Empty | colon + base_type_list;
              base_type_list.Rule = MakePlusRule(base_type_list, comma, qual_name_with_targs);

              //Type parameters
              type_parameter.Rule = attributes_opt + identifier;
              type_parameters.Rule = MakePlusRule(type_parameters, comma, type_parameter);
              type_parameter_list_opt.Rule = Empty | gen_lt + type_parameters + ">";
              type_parameter_constraints_clause.Rule = "where" + type_parameter + colon + type_parameter_constraints;
              type_parameter_constraints.Rule = MakePlusRule(type_parameter_constraints, comma, type_parameter_constraint);
              type_parameter_constraints_clauses_opt.Rule = MakeStarRule(type_parameter_constraints_clauses_opt, null, type_parameter_constraints_clause);
              //Note for post-processing - make sure the order is correct: new() is always last, etc. See p.503 of the spec
              type_parameter_constraint.Rule = qual_name_with_targs | "class" | "struct" | ToTerm("new") + Lpar + Rpar;

              //Class members
              //Note: we split operator-declaration into two separate operator elements: bin/unary and conversion operators
              //  to avoid possible ambiguities and conflicts
              member_declaration.Rule = constant_declaration | field_declaration | method_declaration
             | property_declaration | event_declaration | indexer_declaration
             | operator_declaration | conversion_operator_declaration
             | constructor_declaration | destructor_declaration | type_declaration;
              member_declaration.ErrorRule = SyntaxError + ";" | SyntaxError + "}" ;
              member_declarations_opt.Rule = MakeStarRule(member_declarations_opt, null, member_declaration);

              //Modifiers - see note #1 in Notes.txt file
              modifier.Rule = ToTerm("new") | "public" | "protected" | "internal" | "private" | "static" | "virtual" | "sealed" |
            "override" | "abstract" | "readonly" | "volatile" | "partial" | "extern"; //!!!
              modifiers_opt.Rule = MakeStarRule(modifiers_opt, null, modifier);
              //Joined member header - see note #2
              member_header.Rule = attributes_opt + modifiers_opt;
              constant_declaration.Rule = member_header + "const" + type_ref + constant_declarators + semi;
              constant_declarator.Rule = identifier + "=" + expression;
              constant_declarators.Rule = MakePlusRule(constant_declarators, comma, constant_declarator);
              field_declaration.Rule = member_header + type_ref + variable_declarators + semi;
              variable_declarator.Rule = identifier | identifier + "=" + elem_initializer;
              variable_declarators.Rule = MakePlusRule(variable_declarators, comma, variable_declarator);
              //See note #3 about merging type_parameter_list into type_arguments of the preceding qual_name.
              method_declaration.Rule = member_header + type_ref + qual_name_with_targs  // + type_parameter_list.Q()
            + formal_parameter_list_par + type_parameter_constraints_clauses_opt + method_body;
              formal_parameter_list.Rule = fixed_parameters | fixed_parameters + comma + parameter_array | parameter_array;
              formal_parameter_list_par.Rule = Lpar + Rpar | Lpar + formal_parameter_list + Rpar;

              fixed_parameter.Rule = attributes_opt + parameter_modifier_opt + type_ref + identifier;
              fixed_parameters.Rule = MakePlusRule(fixed_parameters, comma, fixed_parameter);
              parameter_modifier_opt.Rule = Empty | "ref" | "out" | "this";
              parameter_array.Rule = attributes_opt + "params" + type_ref + /*"[" + "]" + */ identifier;
              method_body.Rule = block | semi;
              // See note #4 about member-name
              //TODO: add after-parse validation that no more than one accessor of each type is there.
              property_declaration.Rule = member_header + type_ref + qual_name_with_targs/*member-name*/ + Lbr + accessor_declarations + Rbr;
              accessor_declaration.Rule = attributes_opt + accessor_modifier_opt + accessor_name + block;
              accessor_declarations.Rule = MakePlusRule(accessor_declarations, null, accessor_declaration);
              accessor_name.Rule = ToTerm("get") | "set";
              accessor_modifier_opt.Rule = Empty | "protected" | "internal" | "private" |
                           ToTerm("protected") + "internal" | ToTerm("internal") + "protected";

              event_declaration.Rule = member_header + "event" + type_ref + event_body;
              event_body.Rule = variable_declarators + semi | qual_name_with_targs + Lbr + event_accessor_declarations + Rbr;
              event_accessor_declarations.Rule = add_accessor_declaration + remove_accessor_declaration |
                                         remove_accessor_declaration + add_accessor_declaration;
              add_accessor_declaration.Rule = attributes_opt + "add" + block;
              remove_accessor_declaration.Rule = attributes_opt + "remove" + block;

              //indexer
              indexer_declaration.Rule = member_header + type_ref + indexer_name + "[" + formal_parameter_list + "]" +
                                     Lbr + accessor_declarations + Rbr;
              indexer_name.Rule = "this" | qual_name_with_targs + dot + "this";

              //operator
              // note: difference with specs - we separate unary/binary operators from conversion operator,
              //   and join binary and unary operator definitions, see note #5
              operator_declaration.Rule = member_header + type_ref + "operator" + overloadable_operator + Lpar + operator_parameters + Rpar + block;
              overloadable_operator.Rule = ToTerm("+") | "-" | "!" | "~" | "++" | "--" | "true" | "false" //unary operators
                                 | "*" | "/" | "%" | "&" | "|" | "^" | "<<" | ">>" | "==" | "!=" | ">" | "<" | ">=" | "<=";
              operator_parameters.Rule = operator_parameter | operator_parameter + comma + operator_parameter;
              operator_parameter.Rule = type_ref + identifier;
              conversion_operator_declaration.Rule = member_header + conversion_operator_kind +
               "operator" + type_ref + Lpar + operator_parameter + Rpar + block;
              conversion_operator_kind.Rule = ToTerm("implicit") | "explicit";

              //constructor - also covers static constructor; the only difference is the word static
              constructor_declaration.Rule = member_header + identifier + formal_parameter_list_par +
            constructor_initializer_opt + block;
              constructor_initializer_opt.Rule = Empty | colon + constructor_base + argument_list_par;
              constructor_base.Rule = ToTerm("this") | "base";

              destructor_declaration.Rule = member_header + // changed from Symbol("extern").Q()
                                     "~" + identifier + Lpar + Rpar + block;

              //B.2.8
              struct_declaration.Rule = member_header + "struct" + identifier + type_parameter_list_opt + bases_opt
            + type_parameter_constraints_clauses_opt + struct_body;
              struct_body.Rule = Lbr + member_declarations_opt + Rbr;

              //B.2.9. Arrays

              //B.2.10 Interface
              interface_declaration.Rule = member_header + "interface" + identifier + type_parameter_list_opt + bases_opt
            + type_parameter_constraints_clauses_opt + interface_body;
              interface_body.Rule = Lbr + interface_member_declarations + Rbr;
              interface_member_declaration.Rule = interface_method_declaration | interface_property_declaration
                                        | interface_event_declaration | interface_indexer_declaration;
              interface_member_declarations.Rule = MakePlusRule(interface_member_declarations, null, interface_member_declaration);
              interface_method_declaration.Rule = attributes_opt + new_opt + type_ref + identifier + type_parameter_list_opt +
             formal_parameter_list_par + type_parameter_constraints_clauses_opt + semi;
              //NOte: changing type to type_ref to fix the conflict
              //Note: add after-parse validation that no more than one  accessor of each type is there.
              interface_property_declaration.Rule = attributes_opt + new_opt + type_ref + identifier + Lbr + interface_accessors + Rbr;
              interface_accessor.Rule = attributes_opt + accessor_name + semi;
              interface_accessors.Rule = MakePlusRule(interface_accessors, null, interface_accessor);
              interface_event_declaration.Rule = attributes_opt + new_opt + "event" + type_ref + identifier;
              interface_indexer_declaration.Rule = attributes_opt + new_opt + type_ref + "this" +
                                            "[" + formal_parameter_list + "]" + Lbr + interface_accessors + Rbr;
              new_opt.Rule = Empty | "new";

              //B.2.11 Enums
              enum_declaration.Rule = member_header + "enum" + identifier + enum_base_opt + Lbr + enum_member_declarations + Rbr + semi_opt;
              enum_base_opt.Rule = Empty | colon + integral_type;
              enum_member_declaration.Rule = attributes_opt + identifier | attributes_opt + identifier + "=" + expression;
              enum_member_declarations.Rule = MakeListRule(enum_member_declarations, comma, enum_member_declaration, TermListOptions.PlusList | TermListOptions.AllowTrailingDelimiter);

              //B.2.12 Delegates
              delegate_declaration.Rule = member_header + "delegate" + type_ref + identifier +
            type_parameter_list_opt + formal_parameter_list_par + type_parameter_constraints_clauses_opt + semi;

              //B.2.13. Attributes

              attributes_opt.Rule = MakeStarRule(attributes_opt, null, attribute_section);
              attribute_section.Rule = "[" + attribute_target_specifier_opt + attribute_list + comma_opt + "]";
              attribute_list.Rule = MakePlusRule(attribute_list, comma, attribute);
              attribute.Rule = qual_name_with_targs + attribute_arguments_par_opt;

              attribute_target_specifier_opt.Rule = Empty | attribute_target + colon;
              attribute_target.Rule = ToTerm("field") | "event" | "method" | "param" | "property" | "return" | "type";
              attribute_arguments_par_opt.Rule = Empty | Lpar + attribute_arguments_opt + Rpar;
              attribute_arguments_opt.Rule = MakeStarRule(attribute_arguments_opt, comma, attr_arg);
              attr_arg.Rule = identifier + "=" + expression | expression;

              //Prepare term set for conflict resolution
              _skipTokensInPreview.UnionWith(new Terminal[] { dot, identifier, comma, ToTerm("::"), comma, ToTerm("["), ToTerm("]") });
        }
Exemplo n.º 22
0
        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
        }
Exemplo n.º 23
0
        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;
        }
        void InitializeComments()
        {
            ////        comment:
            ////            single_line_comment
            ////            requires_comment
            ////            delimited_comment

            ////        single_line_comment:
            ////            #   input_characters_opt
            ////        input_characters:
            ////            input_character
            ////            input_characters   input_character
            ////        input_character:
            ////            Any Unicode character except a new_line_character
            CommentTerminal comment = new CommentTerminal("comment", "#", "\r", "\n", "\r\n");
            NonGrammarTerminals.Add(comment);
        }
Exemplo n.º 25
0
        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 joinKindOpt = new NonTerminal("joinKindOpt");
              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 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);

              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 = "(" + 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;

              //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 | "*";
              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;
              joinChainOpt.Rule = Empty | joinKindOpt + JOIN + idlist + ON + Id + "=" + Id;
              joinKindOpt.Rule = Empty | "INNER" | "LEFT" | "RIGHT";
              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 = Id | string_literal | number | funCall | tuple | parSelectStmt;// | 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;
              inStmt.Rule = expression + "IN" + "(" + exprList + ")";

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

              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.
              base.MarkTransient(stmt, term, asOpt, aliasOpt, stmtLine, expression);
        }
Exemplo n.º 26
0
        void InitializeComments()
        {
            ////        comment:
            ////            single_line_comment
            ////            requires_comment
            ////            delimited_comment

            ////        single_line_comment:
            ////            #   input_characters_opt
            ////        input_characters:
            ////            input_character
            ////            input_characters   input_character
            ////        input_character:
            ////            Any Unicode character except a new_line_character
            CommentTerminal comment = new CommentTerminal("comment", "#", "\r", "\n", "\r\n");
            NonGrammarTerminals.Add(comment);

            ////        delimited_comment:
            ////            <#   delimited_comment_text_opt   hashes   >
            ////        delimited_comment_text:
            ////            delimited_comment_section
            ////            delimited_comment_text   delimited_comment_section
            ////        delimited_comment_section:
            ////            >
            ////            hashes_opt   not_greater_than_or_hash
            ////        hashes:
            ////            #
            ////            hashes   #
            ////        not_greater_than_or_hash:
            ////            Any Unicode character except > or #

            CommentTerminal delimited_comment = new CommentTerminal("delimited_comment", "<#", "#>");
            NonGrammarTerminals.Add(delimited_comment);
        }
Exemplo n.º 27
0
		public RefalGrammar() : base(true) // case sensitive
		{
			GrammarComments = "Refal-5 language interpreter based on Irony toolkit.";

			// Terminals
			var Number = new NumberLiteral("Number");
			Number.DefaultIntTypes = new TypeCode[] { TypeCode.Int32, TypeCode.Int64, NumberLiteral.TypeCodeBigInt };
			Number.AddPrefix("0x", NumberOptions.Hex);
			Number.AddSuffix("u", TypeCode.UInt32);
			Number.AddSuffix("l", TypeCode.Int64);
			Number.AddSuffix("ul", TypeCode.UInt64);
			Number.Options |= NumberOptions.IntOnly;

			var CharLiteral = new StringLiteral("Char", "'", StringOptions.AllowsAllEscapes);
			var StringLiteral = new StringLiteral("String", "\"", StringOptions.AllowsAllEscapes);
			var Identifier = new IdentifierTerminal("Identifier", "_-", "");

			var LineComment = new CommentTerminal("LineComment", "*", "\n", "\r");
			LineComment.ValidateToken += LineComment_ValidateToken;

			var BlockComment = new CommentTerminal("BlockComment", "/*", "*/");
			NonGrammarTerminals.Add(LineComment);
			NonGrammarTerminals.Add(BlockComment);

			// Non-terminals
			var Program = new NonTerminal("Program", typeof(Program));
			var Definition = new NonTerminal("Definition");
			var Function = new NonTerminal("Function", typeof(DefinedFunction));
			var External = new NonTerminal("External", typeof(AuxiliaryNode));
			var IdentifierList = new NonTerminal("Identifier+", typeof(AuxiliaryNode));
			var Block = new NonTerminal("Block", typeof(Block));
			var Sentence = new NonTerminal("Sentence", typeof(Sentence));
			var RSentence = new NonTerminal("RSentence", typeof(AuxiliaryNode));
			var SentenceList = new NonTerminal("Sentence+", typeof(AuxiliaryNode));
			var Pattern = new NonTerminal("Pattern", typeof(Pattern));
			var PatternItem = new NonTerminal("PatternItem");
			var PatternInParentheses = new NonTerminal("(Pattern)", typeof(ExpressionInBraces));
			var Expression = new NonTerminal("Expression", typeof(Expression));
			var ExpressionItem = new NonTerminal("ExpressionItem");
			var ExpressionInParentheses = new NonTerminal("(Expression)", typeof(ExpressionInBraces));
			var Var = new NonTerminal("Variable", Variable.CreateVariableNode);
			var VarPrefix = new NonTerminal("VariablePrefix");
			var VarIndex = new NonTerminal("VariableIndex");
			var Symbol = new NonTerminal("Symbol", LiteralValueNodeHelper.InitNode);
			var Call = new NonTerminal("Call", typeof(FunctionCall));
			var FunctionName = new NonTerminal("FunctionName", typeof(AuxiliaryNode));
			var WhereOrWithClause = new NonTerminal("WhereOrWithClause", typeof(Conditions));
			var CommaOrAmpersand = new NonTerminal("CommaOrAmpersand");
			var RWhereOrWithClause = new NonTerminal("RWhereOrWithClause", typeof(AuxiliaryNode));
			var RExpressionOrWhereOrWithClause = new NonTerminal("RExpressionOrWhereOrWithClause");

			var SemicolonOpt = new NonTerminal("[;]", Empty | ";");
			var EntryOpt = new NonTerminal("[ENTRY]", Empty | "$ENTRY");
			var Extern = new NonTerminal("Extern", ToTerm("$EXTRN") | "$EXTERN" | "$EXTERNAL");

			// Rules
			Root = Program;

			Program.Rule = MakePlusRule(Program, Definition);
			Definition.Rule = Function | External;
			External.Rule = Extern + IdentifierList + ";";
			IdentifierList.Rule = MakePlusRule(IdentifierList, ToTerm(","), Identifier);

			Function.Rule = EntryOpt + Identifier + Block + SemicolonOpt;
			Block.Rule = "{" + SentenceList + SemicolonOpt + "}";
			SentenceList.Rule = MakePlusRule(SentenceList, ToTerm(";"), Sentence);

			Sentence.Rule = Pattern + RSentence;
			RSentence.Rule = "=" + Expression | WhereOrWithClause;
			Pattern.Rule = MakeStarRule(Pattern, PatternItem);
			PatternItem.Rule = Var | Symbol | PatternInParentheses;
			PatternInParentheses.Rule = "(" + Pattern + ")";
			Expression.Rule = MakeStarRule(Expression, ExpressionItem);
			ExpressionItem.Rule = Call | Var | Symbol | ExpressionInParentheses;
			ExpressionInParentheses.Rule = "(" + Expression + ")";

			Var.Rule = VarPrefix + "." + VarIndex;
			VarPrefix.Rule = ToTerm("e") | "s" | "t";
			VarIndex.Rule = Number | Identifier;
			Symbol.Rule = StringLiteral | CharLiteral | Number | "True" | "False" | Identifier;
			Call.Rule = "<" + FunctionName + Expression + ">";
			FunctionName.Rule = Identifier | "+" | "-" | "*" | "/";

			WhereOrWithClause.Rule = CommaOrAmpersand + Expression + ":" + RWhereOrWithClause;
			CommaOrAmpersand.Rule = ToTerm(",") | "&";
			RWhereOrWithClause.Rule = Block // with-clause
				| Pattern + RExpressionOrWhereOrWithClause; // where-clause
			RExpressionOrWhereOrWithClause.Rule = ToTerm("=") + Expression | WhereOrWithClause;

			// Punctuation, braces, transient terms, options
			MarkPunctuation("(", ")");
			MarkPunctuation("{", "}");
			MarkPunctuation("<", ">");
			MarkPunctuation("=", ",", "&", ";");

			RegisterBracePair("(", ")");
			RegisterBracePair("<", ">");
			RegisterBracePair("{", "}");

			MarkTransient(Definition, PatternItem, ExpressionItem, SemicolonOpt, EntryOpt, Extern, CommaOrAmpersand, VarPrefix, VarIndex, RExpressionOrWhereOrWithClause);
			LanguageFlags = LanguageFlags.CreateAst | LanguageFlags.SupportsBigInt | LanguageFlags.TailRecursive;
		}
Exemplo n.º 28
0
Arquivo: STL.cs Projeto: 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;
        }
Exemplo n.º 29
0
    public SLAngGrammer()
      : base() {
      StringLiteral stringLiteral = TerminalFactory.CreateCSharpString("StringLiteral");
      StringLiteral charLiteral = TerminalFactory.CreateCSharpChar("CharLiteral");
      NumberLiteral number = TerminalFactory.CreateCSharpNumber("Number");
      IdentifierTerminal identifier = TerminalFactory.CreateCSharpIdentifier("Identifier");
      CommentTerminal delimitedComment = new CommentTerminal("DelimitedComment", "/[", "]/");
      CommentTerminal SingleLineComment = new CommentTerminal("SingleLineComment", "--", "\r", "\n", "\u2085", "\u2028", "\u2029");
      NonGrammarTerminals.Add(SingleLineComment);
      NonGrammarTerminals.Add(delimitedComment);

      #region Terminals
      KeyTerm colon = ToTerm(":");
      KeyTerm dot = ToTerm(".");
      KeyTerm comma = ToTerm(",");
      KeyTerm propertyIs = ToTerm("->");
      KeyTerm lbr = ToTerm("{");
      KeyTerm rbr = ToTerm("}");
      KeyTerm lpar = ToTerm("(");
      KeyTerm rpar = ToTerm(")");
      KeyTerm scopeIn = ToTerm("::");
      KeyTerm suchThat = ToTerm("|");
      KeyTerm _package = ToTerm("package");
      KeyTerm context = ToTerm("context");
      KeyTerm body = ToTerm("body");
      KeyTerm def = ToTerm("def");
      KeyTerm derive = ToTerm("derive");
      KeyTerm In = ToTerm("in");
      KeyTerm inv = ToTerm("inv");
      KeyTerm let = ToTerm("let");
      KeyTerm post = ToTerm("post");
      KeyTerm pre = ToTerm("pre");
      KeyTerm Static = ToTerm("static");
      KeyTerm self = ToTerm("self");
      KeyTerm result = ToTerm("result");
      KeyTerm equalsTo = ToTerm("=");
      KeyTerm _null = ToTerm("null");
      KeyTerm invalid = ToTerm("invalid");
      KeyTerm not = ToTerm("not");
      KeyTerm and = ToTerm("and");
      KeyTerm or = ToTerm("or");
      KeyTerm xor = ToTerm("xor");
      #endregion

      #region NonTerminal
      var specification = new NonTerminal("specification");
      var specificationBody = new NonTerminal("specificationBody");
      var package = new NonTerminal("package");
      var packages = new NonTerminal("packages");
      var oclPackage = new NonTerminal("oclPackage");
      var emofOclPackage = new NonTerminal("emofOclPackage");
      var packageBody = new NonTerminal("packageBody");
      var packageBodyItem = new NonTerminal("packageBodyItem");
      var contextExp = new NonTerminal("contextExp");
      var classType = new NonTerminal("classType");
      var enumeration = new NonTerminal("enumeration");
      var primitive = new NonTerminal("primitive");
      var primitiveType = new NonTerminal("primitiveType");
      var primitiveTypes = new NonTerminal("primitiveTypes");
      var delimitedIdentifier = new NonTerminal("delimitedIdentifier");
      var classSignature = new NonTerminal("classSignature");
      var classBody = new NonTerminal("classBody");
      var classBodyItem = new NonTerminal("classBodyItem");
      var invExp = new NonTerminal("invExp");
      var functionDefination = new NonTerminal("functionDefination");
      var attributeDiclaration = new NonTerminal("attributeDiclaration");
      var emofAttributeDiclaration = new NonTerminal("emofAttributeDiclaration");
      var oclAttributeDiclaration = new NonTerminal("oclAttributeDiclaration");
      var type = new NonTerminal("type");
      var expression = new NonTerminal("expression");
      var customType = new NonTerminal("customType");
      var collectionTpye = new NonTerminal("collectionTpye");
      var fullType = new NonTerminal("fullType");
      var globalType = new NonTerminal("globalType");
      var setType = new NonTerminal("setType");
      var orderedSetType = new NonTerminal("orderedSetType");
      var sequenceType = new NonTerminal("sequenceType");
      var bagType = new NonTerminal("bagType");
      var functionSignature = new NonTerminal("functionSignature");
      var functionSignatureBody = new NonTerminal("functionSignatureBody");
      var functionBody = new NonTerminal("functionBody");
      var oclFunctionSignature = new NonTerminal("oclFunctionSignature");
      var emofFunctionSignature = new NonTerminal("emofFunctionSignature");
      var argumentList = new NonTerminal("argumentList");
      var variableDiclaration = new NonTerminal("variableDiclaration");
      var emofFunctionBody = new NonTerminal("emofFunctionBody");
      var oclFunctionBody = new NonTerminal("oclFunctionBody");
      var singleValueCollectionMember = new NonTerminal("singleValueCollectionMember");
      var booleanValueCollection = new NonTerminal("booleanValueCollection");
      var letExp = new NonTerminal("letExp");
      var ifThenElseExp = new NonTerminal("ifThenElseExp");
      var collectionValueExp = new NonTerminal("collectionValueExp");
      var sum = new NonTerminal("sum");
      var size = new NonTerminal("size");
      var first = new NonTerminal("first");
      var last = new NonTerminal("last");
      var at = new NonTerminal("at");
      var indexOf = new NonTerminal("indexOf");
      var countOperation = new NonTerminal("countOperation");
      var maxOperation = new NonTerminal("maxOperation");
      var minOperation = new NonTerminal("minOperation");
      var valueExp = new NonTerminal("valueExp");
      var includesOperation = new NonTerminal("includesOperation");
      var includesAllOperation = new NonTerminal("includesAllOperation");
      var excludesOperation = new NonTerminal("excludesOperation");
      var excludesAllOperation = new NonTerminal("excludesAllOperation");
      var isEmptyOperation = new NonTerminal("isEmptyOperation");
      var notEmptyOperation = new NonTerminal("notEmptyOperation");
      var specialIteratorBodyExp = new NonTerminal("specialIteratorBodyExp");
      var existsExp = new NonTerminal("existsExp");
      var forAllExp = new NonTerminal("forAllExp");
      var isUniqueExp = new NonTerminal("isUniqueExp");
      var anyExp = new NonTerminal("anyExp");
      var oneExp = new NonTerminal("oneExp");
      var selectExp = new NonTerminal("selectExp");
      var includingOperation = new NonTerminal("includingOperation");
      var excludingOperation = new NonTerminal("excludingOperation");
      var collect = new NonTerminal("collect");
      var subOrderedSet = new NonTerminal("subOrderedSet");
      var symmetricDifference = new NonTerminal("symmetricDifference");
      var prepend = new NonTerminal("prepend");
      var append = new NonTerminal("append");
      var insertAt = new NonTerminal("insertAt");
      var intersection = new NonTerminal("intersection");
      var union = new NonTerminal("union");
      var asBag = new NonTerminal("asBag");
      var asSequence = new NonTerminal("asSequence");
      var asOrderdSet = new NonTerminal("asOrderdSet");
      var asSet = new NonTerminal("asSet");
      var flatten = new NonTerminal("flatten");
      var subSequence = new NonTerminal("subSequence");
      var andExp = new NonTerminal("andExp");
      var orExp = new NonTerminal("orExp");
      var notExp = new NonTerminal("notExp");
      var xorExp = new NonTerminal("xorExp");
      var impliesExp = new NonTerminal("impliesExp");
      var comparisonOperator = new NonTerminal("comparisonOperator");
      var arithmaticOperator = new NonTerminal("arithmaticOperator");
      var oclInvExp = new NonTerminal("oclInvExp");
      var emofInvExp = new NonTerminal("emofInvExp");
      var operationContextExp = new NonTerminal("operationContextExp");
      var attributeContextExp = new NonTerminal("attributeContextExp");
      var classContextExp = new NonTerminal("classContextExp");
      var classContextSignature = new NonTerminal("classContextSignature");
      var attributeContextbody = new NonTerminal("attributeContextbody");
      var attributeContextbodyItem = new NonTerminal("attributeContextbodyItem");
      var deriveExp = new NonTerminal("deriveExp");
      var initExp = new NonTerminal("initExp");
      var operationContextBodyExps = new NonTerminal("operationContextBodyExps");
      var operationContextSignature = new NonTerminal("operationContextSignature");
      var operationContextBodyItem = new NonTerminal("operationContextBodyItem");
      var preCondition = new NonTerminal("preCondition");
      var postCondition = new NonTerminal("postCondition");
      var bodyExp = new NonTerminal("bodyExp");
      var iterateExp = new NonTerminal("iterateExp");
      var productExp = new NonTerminal("productExp");
      var tupleExp = new NonTerminal("tupleExp");
      var rejectExp = new NonTerminal("rejectExp");
      var collection = new NonTerminal("collection");
      var tuplElementList = new NonTerminal("tuplElementList");
      var tupleElement = new NonTerminal("tupleElement");
      var binaryOperator = new NonTerminal("binaryOperator");
      var parameterList = new NonTerminal("parameterList");
      var structuralExp = new NonTerminal("structuralExp");
      var setLiteral = new NonTerminal("setLiteral");
      var bagLiteral = new NonTerminal("orderedSetLiteral");
      var orderedSetLiteral = new NonTerminal("");
      var sequenceLiteral = new NonTerminal("sequenceLiteral");
      var tupleLiteral = new NonTerminal("tupleLiteral");
      var literalList = new NonTerminal("literalList");
      var iteratorList = new NonTerminal("iteratorList");
      var iteratorInitializationList = new NonTerminal("iteratorInitializationList");
      var iteratorInitialization = new NonTerminal("iteratorInitialization");
      var collectionValue = new NonTerminal("collectionValue");
      var ArrayType = new NonTerminal("ArrayType");
      var binaryBooleanOperator = new NonTerminal("binaryBooleanOperator");
      var oclIsTypeOf = new NonTerminal("oclIsTypeOf");
      var ValueExp = new NonTerminal("ValueExp");
      var unValueExp = new NonTerminal("unValueExp");
      var instanceMemberAccess = new NonTerminal("instanceMemberAccess");
      var instanceMathodAccess = new NonTerminal("instanceMathodAccess");
      #endregion

      #region Rules

      #region specification
      specification.Rule = "specification" + identifier + lbr + specificationBody + rbr;
      specificationBody.Rule = MakePlusRule(packages, package);
      #endregion

      #region package
      package.Rule = oclPackage | emofOclPackage;
      oclPackage.Rule = _package + identifier + packageBody + "endpackage";
      emofOclPackage.Rule = _package + identifier + lbr + packageBody + rbr;
      packageBody.Rule = MakeStarRule(packageBody, null, packageBodyItem);
      packageBodyItem.Rule = primitive | enumeration | classType | contextExp | package;
      #endregion

      #region primitive
      primitive.Rule = "primitive" + primitiveTypes + identifier + "IDENTICAL";
      primitiveTypes.Rule = ToTerm("Real") | ToTerm("Integer") | ToTerm("String") | ToTerm("Boolean");
      #endregion

      #region enumeration
      enumeration.Rule = "enumeration" + identifier + lbr + delimitedIdentifier + rbr;
      delimitedIdentifier.Rule = MakePlusRule(delimitedIdentifier, comma, identifier);
      #endregion

      #region class
      classType.Rule = classSignature + lbr + classBody + rbr;
      classSignature.Rule = ToTerm("class") + identifier
                             | ToTerm("abstract") + ToTerm("class") + identifier
                             | ToTerm("abstract") + ToTerm("class") + identifier + ToTerm("extends") + identifier
                             | ToTerm("class") + identifier + ToTerm("extends") + type;
      classBody.Rule = MakeStarRule(classBody, classBodyItem);
      classBodyItem.Rule = attributeDiclaration | functionDefination | invExp;
      #endregion

      #region attribute
      attributeDiclaration.Rule = oclAttributeDiclaration | emofAttributeDiclaration;
      oclAttributeDiclaration.Rule = def + colon + identifier + type + ReduceHere()
                                     | def + colon + identifier + type + PreferShiftHere() + equalsTo + expression + ReduceHere()
                                     | def + colon + "attr" + identifier + type + PreferShiftHere() + equalsTo + expression + ReduceHere()
                                     | def + colon + "attr" + identifier + type + ReduceHere();
      emofAttributeDiclaration.Rule = identifier + colon + type + ReduceHere()
                                      | ToTerm("component") + identifier + colon + type + ToTerm("opposite") + identifier + ReduceHere()
                                      | ToTerm("component") + identifier + colon + type + ToTerm("unique") + ToTerm("opposite") + identifier + ReduceHere()
                                      | identifier + colon + type + equalsTo + expression + ReduceHere()
                                      | identifier + colon + type + ToTerm("opposite") + identifier + ReduceHere()
                                      | identifier + colon + type + ToTerm("unique") + ToTerm("opposite") + identifier + ReduceHere()
                                      | identifier + colon + type + ToTerm("unique") + ReduceHere();
      #endregion

      #region type
      type.Rule = primitiveTypes | customType;
      customType.Rule = fullType | globalType | ArrayType | collectionTpye | tupleExp;
      fullType.Rule = identifier + scopeIn + fullType | identifier + ReduceHere();
      globalType.Rule = PreferShiftHere() + scopeIn + fullType
                       | PreferShiftHere() + scopeIn + ArrayType;
      ArrayType.Rule = fullType + "[" + "*" + "]"
                       | fullType + "[" + identifier + "]"
                       | fullType + "[" + number + "]"
                       | fullType + "[" + number + comma + number + "]"
                       | fullType + "[" + number + comma + "*" + "]";
      collectionTpye.Rule = setType | orderedSetType | sequenceType | bagType | collection;
      setType.Rule = "Set(" + customType + ")";
      orderedSetType.Rule = "OrderedSet(" + customType + ")";
      sequenceType.Rule = "Sequence(" + customType + ")";
      bagType.Rule = "Bag(" + customType + ")";
      collection.Rule = "Collection(" + customType + ")";
      tupleExp.Rule = "Tuple" + lbr + argumentList + rbr;
      #endregion

      #region function
      functionDefination.Rule = functionSignature + functionBody;
      functionSignature.Rule = oclFunctionSignature | emofFunctionSignature;
      oclFunctionSignature.Rule = def + colon + functionSignatureBody;
      functionSignatureBody.Rule = identifier + lpar + argumentList + rpar + colon + type
                                   | identifier + lpar + argumentList + rpar + colon + type + ToTerm("ordered") + ToTerm("unique")
                                   | identifier + lpar + argumentList + rpar + colon;
      argumentList.Rule = MakeStarRule(argumentList, comma, variableDiclaration);
      variableDiclaration.Rule = identifier + PreferShiftHere() + colon + type;
      emofFunctionSignature.Rule = functionSignatureBody;
      functionBody.Rule = oclFunctionBody | emofFunctionBody;
      oclFunctionBody.Rule = equalsTo + expression;
      emofFunctionBody.Rule = equalsTo + lbr + expression + rbr;
      #endregion

      #region expression
      expression.Rule = valueExp | structuralExp;
      #endregion

      #region valueExp
      valueExp.Rule = // ValueExp + ReduceHere() |
                    unValueExp + ReduceHere()
                    | valueExp + PreferShiftHere() + binaryOperator + valueExp
                    | ToTerm("not") + valueExp
                    | lpar + valueExp + rpar;
      #endregion

      #region unValueExp

      unValueExp.Rule = booleanValueCollection
                             | ToTerm("false") | ToTerm("true")
                             | collectionValue
                             | tupleLiteral
                             | singleValueCollectionMember
                             | collectionValueExp
                             | iterateExp
                             | stringLiteral
                             | charLiteral
                             | number
                             | self
                             | oclIsTypeOf
                             | unValueExp + lpar + parameterList + rpar
                             | instanceMemberAccess
                             | instanceMathodAccess
                             | ToTerm("-") + number;
      #endregion

      #region ValueExp
      ValueExp.Rule = fullType + dot + instanceMemberAccess
                          | globalType + dot + instanceMemberAccess
                          | ValueExp + dot + identifier + lpar + parameterList + rpar;
      #endregion

      #region instanceMemberAccess
      instanceMemberAccess.Rule = MakePlusRule(instanceMemberAccess, dot, identifier);
      instanceMathodAccess.Rule = unValueExp + dot + identifier + lpar + parameterList + rpar;
      #endregion

      #region parameterList
      parameterList.Rule = MakeStarRule(parameterList, comma, expression);
      #endregion

      #region booleanExp
      booleanValueCollection.Rule = includesOperation | includesAllOperation | excludesOperation | excludesAllOperation
                        | isEmptyOperation | notEmptyOperation | existsExp | forAllExp | isUniqueExp | anyExp | oneExp;
      #endregion

      #region oclBuildInMethods
      oclIsTypeOf.Rule = valueExp + dot + ToTerm("oclIsTypeOf") + lpar + type + rpar;
      #endregion

      #region binaryOperator

      binaryOperator.Rule = comparisonOperator | arithmaticOperator | binaryBooleanOperator;
      arithmaticOperator.Rule = ToTerm("/") | ToTerm("div") | ToTerm("*") | ToTerm("+") | ToTerm("-");
      comparisonOperator.Rule = ToTerm(">") | ToTerm("<") | ToTerm(">=") | ToTerm("<=") | ToTerm("<>") | equalsTo;
      binaryBooleanOperator.Rule = ToTerm("and") | ToTerm("or") | ToTerm("xor") | ToTerm("implies");

      #endregion

      #region booleanValueCollection
      includesOperation.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("includes") + lpar + valueExp + rpar;
      includesAllOperation.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("includesAll") + lpar + identifier + rpar;
      excludesOperation.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("excludes") + lpar + identifier + rpar;
      excludesAllOperation.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("excludesAll") + lpar + identifier + rpar;
      isEmptyOperation.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("isEmpty") + lpar + rpar;
      notEmptyOperation.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("notEmpty") + lpar + rpar;
      existsExp.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("exists") + lpar + specialIteratorBodyExp + rpar;
      forAllExp.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("forAll") + lpar + specialIteratorBodyExp + rpar;
      isUniqueExp.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("isUnique") + lpar + specialIteratorBodyExp + rpar;
      anyExp.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("any") + lpar + specialIteratorBodyExp + rpar;
      oneExp.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("one") + lpar + specialIteratorBodyExp + rpar;
      specialIteratorBodyExp.Rule = delimitedIdentifier + colon + type + suchThat + valueExp
                                  | argumentList + suchThat + valueExp
                                  | valueExp;
      #endregion

      #region collectionValue
      collectionValue.Rule = setLiteral | bagLiteral | orderedSetLiteral | sequenceLiteral;
      setLiteral.Rule = "Set" + lbr + literalList + rbr
                         | "Set" + lpar + type + rpar + lbr + literalList + rbr;
      bagLiteral.Rule = "Bag" + lbr + literalList + rbr
                        | "Bag" + lpar + type + rpar + lbr + literalList + rbr;
      orderedSetLiteral.Rule = "OrderedSet" + lbr + literalList + rbr
                               | "OrderedSet" + lpar + type + rpar + lbr + literalList + rbr;
      sequenceLiteral.Rule = "Sequence" + lbr + literalList + rbr
                             | "Sequence" + lpar + type + rpar + lbr + literalList + rbr;
      literalList.Rule = MakeStarRule(literalList, comma, valueExp);
      tupleLiteral.Rule = "Tuple" + lbr + tuplElementList + rbr;
      tuplElementList.Rule = MakePlusRule(tuplElementList, comma, tupleElement);
      tupleElement.Rule = variableDiclaration + equalsTo + valueExp | identifier + equalsTo + valueExp;
      collectionValueExp.Rule = includingOperation | excludingOperation | selectExp | rejectExp
                               | union | intersection | insertAt | append | prepend | symmetricDifference | subOrderedSet | collect | productExp
                               | subSequence | flatten | asSet | asOrderdSet | asSequence | asBag;
      includingOperation.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("including") + lpar + identifier + rpar;
      excludingOperation.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("excluding") + lpar + identifier + rpar;
      selectExp.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("select") + lpar + specialIteratorBodyExp + rpar;
      rejectExp.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("reject") + lpar + specialIteratorBodyExp + rpar;
      union.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("union") + lpar + valueExp + rpar;
      intersection.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("intersection") + lpar + identifier + rpar;
      insertAt.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("insertAt") + lpar + number + comma + identifier + rpar;
      append.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("append") + lpar + identifier + rpar;
      prepend.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("prepend") + lpar + identifier + rpar;
      symmetricDifference.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("symmetricDifference") + lpar + identifier + rpar;
      subOrderedSet.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("subOrderedSet") + lpar + number + comma + number + rpar;
      collect.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("collect") + lpar + specialIteratorBodyExp + rpar
                   | valueExp + PreferShiftHere() + propertyIs + ToTerm("collect") + lpar + identifier + rpar
                   | valueExp + dot + identifier + lpar + argumentList + rpar
                   | valueExp + PreferShiftHere() + propertyIs + identifier + lpar + argumentList + rpar;
      productExp.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("product") + lpar + identifier + rpar;
      subSequence.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("subSequence") + lpar + number + comma + number + rpar;
      flatten.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("flatten") + lpar + rpar;
      asSet.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("asSet") + lpar + rpar;
      asOrderdSet.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("asOrderdSet") + lpar + rpar;
      asSequence.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("asSequence") + lpar + rpar;
      asBag.Rule = valueExp + PreferShiftHere() + propertyIs + ToTerm("asBag") + lpar + rpar;

      #endregion

      #region singleValueCollectionMember
      singleValueCollectionMember.Rule = maxOperation | minOperation | countOperation | at | indexOf | first | last | sum | size;
      maxOperation.Rule = valueExp + PreferShiftHere() + propertyIs + "max" + lpar + rpar;
      minOperation.Rule = valueExp + PreferShiftHere() + propertyIs + "min" + lpar + rpar;
      countOperation.Rule = valueExp + PreferShiftHere() + propertyIs + "count" + lpar + identifier + rpar;
      at.Rule = valueExp + PreferShiftHere() + propertyIs + "at" + lpar + identifier + rpar;
      indexOf.Rule = valueExp + PreferShiftHere() + propertyIs + "indexOf" + lpar + identifier + rpar;
      first.Rule = valueExp + PreferShiftHere() + propertyIs + "first" + lpar + rpar;
      last.Rule = valueExp + PreferShiftHere() + propertyIs + "last" + lpar + rpar;
      sum.Rule = valueExp + PreferShiftHere() + propertyIs + "sum" + lpar + rpar;
      size.Rule = valueExp + PreferShiftHere() + propertyIs + "size" + lpar + rpar;
      #endregion

      #region iterateExp
      iterateExp.Rule = valueExp + PreferShiftHere() + propertyIs + "iterate" + lpar + iteratorList + ";"
                        + iteratorInitializationList + suchThat + expression + rpar;
      iteratorList.Rule = MakePlusRule(iteratorList, comma, variableDiclaration);
      iteratorInitializationList.Rule = MakePlusRule(iteratorInitializationList, comma, iteratorInitialization);
      iteratorInitialization.Rule = variableDiclaration + equalsTo + valueExp;
      #endregion

      #region structuralExp
      structuralExp.Rule = ifThenElseExp | letExp;
      #endregion

      #region ifThenElseExp
      ifThenElseExp.Rule = "if" + valueExp + "then" + expression + "endif"
                          | "if" + valueExp + "then" + expression + "else" + expression + "endif";
      #endregion

      #region letExp
      letExp.Rule = let + variableDiclaration + equalsTo + valueExp + In + expression
                   | let + identifier + equalsTo + valueExp + In + expression;
      #endregion

      #region invExp
      invExp.Rule = oclInvExp | emofInvExp;
      oclInvExp.Rule = inv + identifier + colon + expression
                       | inv + colon + expression;
      emofInvExp.Rule = "invariant" + lbr + expression + rbr;
      #endregion

      #region contextExp
      contextExp.Rule = classContextExp | attributeContextExp | operationContextExp;
      #endregion

      #region classContextExp
      classContextExp.Rule = classContextSignature + classBody;
      classContextSignature.Rule = context + type
                                   | context + identifier + colon + type;
      classBody.Rule = MakePlusRule(classBody, null, classBodyItem);
      classBodyItem.Rule = invExp | attributeDiclaration | functionDefination;
      #endregion

      #region attributeContextExp
      attributeContextExp.Rule = context + type + colon + type + attributeContextbody;
      attributeContextbody.Rule = MakePlusRule(attributeContextbody, null, attributeContextbodyItem);
      attributeContextbodyItem.Rule = initExp | deriveExp;
      #endregion

      #region initExp
      initExp.Rule = ToTerm("init") + colon + equalsTo + valueExp;
      #endregion

      #region deriveExp
      deriveExp.Rule = ToTerm("derive") + colon + expression;
      #endregion

      #region operationContextExp
      operationContextExp.Rule = operationContextSignature + invExp + operationContextBodyExps;
      operationContextSignature.Rule = context + customType + PreferShiftHere() + scopeIn + functionSignature;
      operationContextBodyExps.Rule = MakePlusRule(operationContextBodyExps, null, operationContextBodyItem);
      operationContextBodyItem.Rule = preCondition | bodyExp | postCondition;
      #endregion

      #region preCondition
      preCondition.Rule = pre + identifier + colon + valueExp
                         | pre + colon + valueExp;
      #endregion

      #region bodyExp
      bodyExp.Rule = body + colon + expression;
      #endregion

      #region postCondition
      postCondition.Rule = post + colon + valueExp
                           | post + identifier + colon + valueExp;
      #endregion

      #endregion

      #region Operator,punctuation
      MarkPunctuation(",", "(", ")", "{", "}", "[", "]", ":");
      MarkMemberSelect(".", "->"); //dot, propertyIs);
      RegisterOperators(1, lpar, rpar);
      RegisterOperators(2, "let", "in");
      RegisterOperators(3, letExp, In);
      RegisterOperators(4, dot, scopeIn);
      RegisterOperators(5, not);
      RegisterOperators(6, "*", "/");
      RegisterOperators(7, letExp, In);
      RegisterOperators(8, dot, scopeIn);
      RegisterOperators(9, "+", "-");
      RegisterOperators(10, "<", ">", "<=", ">=");
      RegisterOperators(11, "=", "<>");
      RegisterOperators(12, and);
      RegisterOperators(12, "div", "implies");
      RegisterOperators(13, or);
      RegisterOperators(14, xor);
      RegisterOperators(15, "=", "<>");
      #endregion
      this.Root = specification;
    }
Exemplo n.º 30
0
        /// <summary>
        ///
        /// </summary>
        public MrtGrammar()
            : base(true)
        {
            NonGrammarTerminals.Add (NewLine);

            #region Numbers Strings Identifiers
            var comment = new CommentTerminal ("comment", "#", "\n", "\r");
            var number = new NumberLiteral ("number", NumberOptions.AllowSign | NumberOptions.AllowStartEndDot);
            var str = new StringLiteral ("path", "\"");
            #endregion

            #region Transformations
            var lookAt = new NonTerminal ("look-at", typeof (Nodes.LookAtNode));
            var scale = new NonTerminal ("scale", typeof(Nodes.ScaleNode));
            var translate = new NonTerminal ("translate", typeof(Nodes.TranslateNode));
            var rotate = new NonTerminal ("rotate", typeof(Nodes.RotateNode));
            var reverseOrientation = new NonTerminal ("reverse-orientation", typeof(Nodes.ReverseOrientationNode));
            var coordSysTransform = new NonTerminal ("coord-sys-transform", typeof(Nodes.CoordSysTransformNode));
            var concatTransform = new NonTerminal ("concat-transform", typeof(Nodes.ConcatTransformNode));
            var transformations = new NonTerminal ("translate", typeof(StatementListNode));
            #endregion

            var include = new NonTerminal ("include", typeof(Nodes.IncludeNode));

            var attributeBegin = new NonTerminal ("attribute-begin", typeof(Nodes.AttributeBeginNode));
            var attributeEnd = new NonTerminal ("attribute-end", typeof(Nodes.AttributeEndNode));

            var worldBegin = new NonTerminal ("world-begin", typeof (Nodes.WorldBeginNode));
            var worldEnd = new NonTerminal ("world-end", typeof(Nodes.WorldEndNode));

            var transformBegin = new NonTerminal ("transform-begin", typeof(Nodes.TransformBeginNode));
            var transformEnd = new NonTerminal ("transform-end", typeof(Nodes.TransformEndNode));

            var paramList = new NonTerminal ("param-list");
            var paramListContents = new NonTerminal ("param-list-contents", typeof(Nodes.ParamListContentNode));
            var paramListEntry = new NonTerminal ("param-list-entry", typeof(Nodes.ParamListEntryNode));

            var array = new NonTerminal ("array", typeof(Nodes.ArrayNode));
            var stringArray = new NonTerminal ("string-array", typeof(Nodes.StringArrayNode));
            var numArray = new NonTerminal ("num-array", typeof(Nodes.NumberArrayNode));

            var camera = new NonTerminal ("camera", typeof(Nodes.CameraNode));
            var film = new NonTerminal ("film", typeof(Nodes.FilmNode));
            var sampler = new NonTerminal ("sampler", typeof(Nodes.SamplerNode));
            var surfaceIntegrator = new NonTerminal ("surface-integrator", typeof(Nodes.SurfaceIntegratorNode));
            var volumeIntegrator = new NonTerminal ("volume-integrator", typeof(Nodes.VolumeIntegratorNode));
            var texture = new NonTerminal ("texture", typeof(Nodes.TextureNode));
            var shape = new NonTerminal ("shape", typeof(Nodes.ShapeNode));
            var pixelFilter = new NonTerminal ("pixel-filter", typeof(Nodes.PixelFilterNode));
            var material = new NonTerminal ("material", typeof(Nodes.MaterialNode));
            var namedMaterial = new NonTerminal ("named-material", typeof(Nodes.NamedMaterialNode));
            var lightSource = new NonTerminal ("light", typeof(Nodes.LightNode));
            var areaLightSource = new NonTerminal ("area-light", typeof(Nodes.AreaLightSourceNode));
            var plugin = new NonTerminal ("plugin", typeof(StatementListNode));

            var statements = new NonTerminal ("statements", typeof(StatementListNode));
            var scene = new NonTerminal ("scene", typeof(StatementListNode));

            NonGrammarTerminals.Add (comment);

            #region Rules
            lookAt.Rule = "LookAt" + number + number + number + number + number + number + number + number + number;
            scale.Rule = "Scale" + number + number + number;
            translate.Rule = "Translate" + number + number + number;
            rotate.Rule = "Rotate" + number + number + number + number;
            reverseOrientation.Rule = "ReverseOrientation";
            coordSysTransform.Rule = "CoordSysTransform" + str;
            concatTransform.Rule = "ConcatTransform" + number + number + number + number + number + number + number + number + number + number + number + number + number + number + number + number;
            transformations.Rule = scale | translate | rotate | lookAt | coordSysTransform | concatTransform;
            include.Rule = "Include" + str;

            attributeBegin.Rule = "AttributeBegin";
            attributeEnd.Rule = "AttributeEnd";
            worldBegin.Rule = "WorldBegin";
            worldEnd.Rule = "WorldEnd";

            paramList.Rule = paramListContents;
            paramListContents.Rule = MakeStarRule (paramListContents, paramListEntry);
            paramListEntry.Rule = str + array;

            stringArray.Rule = MakeStarRule (stringArray, str);
            numArray.Rule = MakeStarRule (numArray, number);
            array.Rule = "[" + (stringArray | numArray) + "]";

            transformBegin.Rule = "TransformBegin";
            transformEnd.Rule = "TransformEnd";

            camera.Rule = "Camera" + str + paramListContents;
            film.Rule = "Film" + str + paramListContents;
            sampler.Rule = "Sampler" + str + paramListContents;
            surfaceIntegrator.Rule = "SurfaceIntegrator" + str + paramListContents;
            volumeIntegrator.Rule = "VolumeIntegrator" + str + paramListContents;
            shape.Rule = "Shape" + str + paramListContents;
            pixelFilter.Rule = "PixelFilter" + str + paramListContents;
            texture.Rule = "Texture" + str + str + str + paramListContents;
            material.Rule = "Material" + str + paramListContents;
            namedMaterial.Rule = "NamedMaterial" + str + str + paramListContents;
            lightSource.Rule = "LightSource" + str + paramListContents;
            areaLightSource.Rule = "AreaLightSource" + str + paramListContents;
            plugin.Rule = camera | film | sampler | surfaceIntegrator | volumeIntegrator | shape | pixelFilter | texture | material | namedMaterial | lightSource | areaLightSource;

            statements.Rule = transformations | include | attributeBegin | attributeEnd | paramListContents | plugin | statements | worldBegin | worldEnd | comment;
            scene.Rule = MakePlusRule (scene, statements);
            #endregion

            #region Config
            this.Root = scene;
            this.LanguageFlags = LanguageFlags.CreateAst;
            #endregion
        }