public override bool Check(TableEntry left, TableEntry right, string[] tokens) { // tries to match the value of tokens x through y (inclusive) of the LHS with the length of the RHS int start = left.Key[0] + X; int end = left.Key[0] + Y; string[] sublist = Utilities.GetSubArray(tokens, start, end, true); int length = Utilities.GetValue(sublist, 0, sublist.Length); if (length != right.Key[1]) return false; else return true; }
public static Field[] GetFields(TableEntry root) { List<Field> fields = new List<Field>(); foreach (TableEntry child in root.Children) { if (root.Base == "Field") { Field newField = new Field(){Type=root.Children[0].Base,Start=root.Key[0],Length=root.Key[1]}; fields.Add(newField); } fields.AddRange(GetFields(child)); } return fields.ToArray(); }
private void AddEntry(TableEntry entry) { string entryBase = entry.Rule.LHS.Text; if(!_table.ContainsKey(entry.Key)) _table.Add(entry.Key, new Dictionary<string,TableEntry>()); // if table already has an entry with the same base, keep the more probable of the two if (_table[entry.Key].ContainsKey(entryBase)) { TableEntry oldEntry = _table[entry.Key][entryBase]; if (oldEntry.Probability < entry.Probability) { _table[entry.Key][entry.Base] = entry; #if DEBUG Console.WriteLine("OVERWRITING " + oldEntry + " WITH " + entry + " AT " + string.Format("({0},{1})", entry.Key[0], entry.Key[1])); #endif } #if DEBUG Console.WriteLine("FAILED TO OVERWRITE " + oldEntry + " WITH " + entry + " AT " + string.Format("({0},{1})", entry.Key[0], entry.Key[1])); #endif } else { _table[entry.Key].Add(entryBase, entry); #if DEBUG Console.WriteLine("ADDING " + entry + " AT " + string.Format("({0},{1})", entry.Key[0], entry.Key[1])); #endif } // handle alias rules (rules of the form A --> B) for (int i = 0; i < _grammar.RhsIndex[entry.Base].Count; i++) { ProductionRule rule = _grammar.RhsIndex[entry.Base][i]; if (rule.RHS.Length == 1) AddEntry(new TableEntry(entry.Key, rule, new TableEntry[] { entry })); } }
public static Field[] GetFields(TableEntry root) { List <Field> fields = new List <Field>(); foreach (TableEntry child in root.Children) { if (root.Base == "Field") { Field newField = new Field() { Type = root.Children[0].Base, Start = root.Key[0], Length = root.Key[1] }; fields.Add(newField); } fields.AddRange(GetFields(child)); } return(fields.ToArray()); }
public abstract bool Check(TableEntry left, TableEntry right, string[] tokens);
public override bool Check(TableEntry left, TableEntry right, string[] tokens) { // format: [('range_restrict', [(n, (min, max))])] // matches only if the nth field on the rhs of the rule is within the specified value range string[] sublist = Utilities.GetSubArray(tokens, left.Key[0], left.Key[0] + left.Key[1], true); int value = Utilities.GetValue(sublist, Index, Index + 1); if (value < Convert.ToInt32(Min) || value > Convert.ToInt32(Max)) return false; return true; }
public override bool Check(TableEntry left, TableEntry right, string[] tokens) { // matches if length of 2nd element of RHS matches value of 1st element of RHS plus adjustment times multiplier int length = Utilities.GetValue(tokens, left.Key[0], left.Key[0] + left.Key[1]); if (length != (right.Key[1] + Adjustment) * Multiplier) return false; else return true; }