4
I Use This!
Very Low Activity

News

Analyzed 1 day ago. based on code collected 1 day ago.
Posted over 9 years ago by kambiante
Hi, I have created the next easy grammar: RegexBasedTerminal anyText = new RegexBasedTerminal("anyText", "[^;]*;"); NonTerminal commands = new NonTerminal("commands"), command = new NonTerminal("command"), ... [More] insertStatement = new NonTerminal("insertStatement"), updateStatement = new NonTerminal("updateStatement"), deleteStatement = new NonTerminal("deleteStatement"), createStatement = new NonTerminal("createStatement"), dropStatement = new NonTerminal("dropStatement"), selectStatement = new NonTerminal("selectStatement"), commitStatement = new NonTerminal("commitStatement"); commands.Rule = command | command + commands; command.Rule = insertStatement | updateStatement | deleteStatement | createStatement | dropStatement | selectStatement | commitStatement; insertStatement.Rule = ToTerm("INSERT", typeof(BinaryOperationNode)) + anyText; updateStatement.Rule = ToTerm("UPDATE") + anyText; deleteStatement.Rule = ToTerm("DELETE") + anyText; createStatement.Rule = ToTerm("CREATE") + anyText; dropStatement.Rule = ToTerm("DROP") + anyText; selectStatement.Rule = ToTerm("SELECT") + anyText; commitStatement.Rule = ToTerm("COMMIT") + anyText; this.Root = commands; After, that, I am getting the result with: DsnGram dsnGram = new DsnGram(); LanguageData languageData = new LanguageData(dsnGram); Parser parserCommands = new Parser(languageData); ParseTree parseTree = parserCommands.Parse(File.ReadAllText(sysinLseqFn)); ParseTreeNode dsnCommands = parseTree.Root; Where sysinLseqFn contains: DROP TABLE TESTJ; CREATE TABLE TESTJ (F1 CHAR(3) not null); INSERT INTO TESTJ VALUES('AAA'); SELECT * FROM TESTJ; The problem is that in the TreeNode, the first statement is "CREATE .." instead of "DROP ..." because the TreeNode is sorted: [DEBUG] commands [DEBUG] command [DEBUG] createStatement [DEBUG] CREATE (Keyword) [DEBUG] TABLE TESTJ (F1 CHAR(3) not null); (anyText) [DEBUG] commands [DEBUG] command [DEBUG] dropStatement [DEBUG] DROP (Keyword) [DEBUG] TABLE TESTJ; (anyText) [DEBUG] commands [DEBUG] command [DEBUG] dropStatement [DEBUG] DROP (Keyword) [DEBUG] TABLE TESTJ; (anyText) [DEBUG] commands [DEBUG] command [DEBUG] insertStatement [DEBUG] INSERT (Keyword) [DEBUG] INTO TESTJ VALUES('AAA'); (anyText) [DEBUG] commands [DEBUG] command [DEBUG] selectStatement [DEBUG] SELECT (Keyword) [DEBUG] * FROM TESTJ; (anyText) How could I get the TreeNode unsorted? Thanks in advance! [Less]
Posted over 9 years ago by akku27
Hi, I would like to extract conditions from the expression which can be easily represented as restriction object, what would be best way of doing that. Eg if age > 50, then disallow, is my expression. I would like to create restriction object ... [More] with property MaxAge =50 Basically have Restriction object and result object as output from Expression tree, there by giving me flexibility to play with C# object and not worry abt string Thanks, Akhil [Less]
Posted over 9 years ago by akku27
Hi, I would like to extract conditions from the expression which can be easily represented as restriction object, what would be best way of doing that. Eg if age > 50, then disallow, is my expression. I would like to create restriction object ... [More] with property MaxAge =50 Basically have Restriction object and result object as output from Expression tree, there by giving me flexibility to play with C# object and not worry abt string Thanks, Akhil [Less]
Posted almost 10 years ago by rivantsov
Man, with so many conflicts you should not even start parsing test files. Fix all conflicts first! Read about shift-reduce and reduce-reduce conflicts in LALR parser, there's much info there, just google. Try to understand what causes the conflict from reading the state printout and its transitions
Posted almost 10 years ago by eduardcastany
Attached only modification as in the above example where all the code sent, not seen as there is a character limit.var T_NOT=ToTerm("NOT"); //Addedvar NT_BETWEEN=new NonTerminal("NT_BETWEEN");//Addedexpression.Rule = term | unExpr | binExpr | ... [More] betweenExpr; betweenExpr.Rule=expression+NT_BETWEEN+term+"AND"+term;//added by ECFNT_BETWEEN.Rule=ToTerm("BETWEEN")|T_NOT+"BETWEEN"; //added by ECFRegisterOperators(8,"=",">","<",">=","<=","<>","!=","!<","!>","LIKE","IN","BETWEEN");//Added [Less]
Posted almost 10 years ago by eduardcastany
Thank you for this parser, is beautiful!!I just checked the SQL grammar and I modified the non-terminal Between to contemplate the sentence between.I attached all the code with the modificationusing System;using System.Collections.Generic;using ... [More] System.Linq;using System.Text;using Irony.Parsing;namespace Irony.Samples.SQL { // Loosely based on SQL89 grammar from Gold parser. Supports some extra TSQL constructs. [Language("SQL", "89", "SQL 89 grammar")] public class FormsGrammar : Grammar { public FormsGrammar() : 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"); var T_NOT=ToTerm("NOT"); //Added By ECF //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"); var NT_BETWEEN=new NonTerminal("NT_NotOpcional"); //Added by ECF //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 | "WHER [Less]
Posted almost 10 years ago by Afr0
Hi! I'm trying to create a parser for a custom UI language. I thought I was done with it, as it has successfully parsed other scripts, but all of a sudden I found a script that caused GrammarExplorer to say "expected alignments". I searched for that ... [More] syntax error on these boards, and I couldn't find it. Is this possibly a bug with Irony? Here's my grammar. Here's the script I'm trying to parse. Here's my parser conflicts. Grammar Explorer is complaining about line 204, character 17. Please tell me what I can do to correct this, thanks! [Less]
Posted almost 10 years ago by oturkan
thank you worked
Posted almost 10 years ago by rivantsov
Just define a new term (ToTerm("?")) and add it to term.Rule
Posted almost 10 years ago by oturkan
Hi I have sql clause like "Id = ? And Person.FirstName = ?" how can i add ? to grammer