diff --git a/cfg/CfgDocument.cs b/cfg/CfgDocument.cs index 26f1e9e..a57b023 100644 --- a/cfg/CfgDocument.cs +++ b/cfg/CfgDocument.cs @@ -57,17 +57,17 @@ public string StartSymbol { { if (!IsSymbol(value)) throw new KeyNotFoundException("The specified symbol does not exist"); - foreach(var sattrs in AttributeSets) + foreach (var sattrs in AttributeSets) { - var i =sattrs.Value.IndexOf("start"); - if(-1 EnumNonTerminals() { var seen = new HashSet(); var ic = Rules.Count; - for(var i=0;i FillNonTerminals(IList result=null) + public IList FillNonTerminals(IList result = null) { if (null == result) result = new List(); @@ -126,7 +126,7 @@ public IEnumerable EnumSymbols() for (var i = 0; i < ic; ++i) { var right = Rules[i].Right; - for(int jc=right.Count,j=0;j FillSymbols(IList result = null) result.Add(s); } } - foreach(var attrs in AttributeSets) - if(seen.Add(attrs.Key)) + foreach (var attrs in AttributeSets) + if (seen.Add(attrs.Key)) if (!result.Contains(attrs.Key)) result.Add(attrs.Key); - + if (!result.Contains("#EOS")) result.Add("#EOS"); if (!result.Contains("#ERROR")) @@ -405,7 +405,7 @@ public IDictionary> FillFirsts(IDictionary>(); var predictNT = _FillPredictNT(); - + // finally, for each non-terminal N we still have in the firsts, resolve FIRSTS(N) foreach (var kvp in predictNT) { @@ -416,14 +416,14 @@ public IDictionary> FillFirsts(IDictionary()); foreach (var r in res) col.Add((item.Rule, r)); - + } result.Add(kvp.Key, col); } return result; } - void _ResolvePredict(string symbol,ICollection result,IDictionary> predictNT,HashSet seen) + void _ResolvePredict(string symbol, ICollection result, IDictionary> predictNT, HashSet seen) { if (seen.Add(symbol)) { @@ -451,7 +451,7 @@ public IDictionary> FillFollows(IDictionary>(); - var followsNT = new Dictionary>(); + var followsNT = new Dictionary>(); // we'll need the predict table //Console.Error.WriteLine("Computing predict..."); @@ -524,7 +524,7 @@ public IDictionary> FillFollows(IDictionary(); @@ -534,7 +534,7 @@ public IDictionary> FillFollows(IDictionary result, IDictionary> followsNT, HashSet seen) { @@ -619,13 +619,13 @@ public IList FillClosure(string symbol, IList result = null) } return result; } - public object GetAttribute(string symbol,string name, object @default = null) + public object GetAttribute(string symbol, string name, object @default = null) { CfgAttributeList l; - if(AttributeSets.TryGetValue(symbol,out l)) + if (AttributeSets.TryGetValue(symbol, out l)) { var i = l.IndexOf(name); - if(-1'); @@ -762,14 +763,15 @@ internal static CfgDocument Parse(ParseContext pc) CfgNode.SkipCommentsAndWhitespace(pc); } result.Rules.Add(rule); - } else if ('=' == pc.Current) + } + else if ('=' == pc.Current) { pc.TrySkipUntil('\n', true); } if ('\n' == pc.Current) pc.Advance(); CfgNode.SkipCommentsAndWhitespace(pc); - + } return result; } @@ -790,7 +792,7 @@ public bool Equals(CfgDocument rhs) foreach (var attr in attrs.Value) { var i = d.IndexOf(attr.Name); - if (0>i || !Equals(d[i].Value, attr.Value)) + if (0 > i || !Equals(d[i].Value, attr.Value)) return false; } } @@ -813,11 +815,11 @@ public override int GetHashCode() var result = 0; foreach (var attrs in AttributeSets) { - if(null!=attrs.Key) + if (null != attrs.Key) result ^= attrs.Key.GetHashCode(); foreach (var attr in attrs.Value) { - if(null!=attr.Name) + if (null != attr.Name) result ^= attr.Name.GetHashCode(); if (null != attr.Value) result ^= attr.Value.GetHashCode(); @@ -843,4 +845,4 @@ public override int GetHashCode() } #endregion } -} +} \ No newline at end of file diff --git a/pckw/XbnfToPckTransform.cs b/pckw/XbnfToPckTransform.cs index fb1a80a..f4ff0df 100644 --- a/pckw/XbnfToPckTransform.cs +++ b/pckw/XbnfToPckTransform.cs @@ -5,16 +5,16 @@ namespace Pck { - [Transform("xbnfToPck",".xbnf",".pck","Translates an xbnf grammar to a pck spec.")] + [Transform("xbnfToPck", ".xbnf", ".pck", "Translates an xbnf grammar to a pck spec.")] static class XbnfToPckTransform { public static void Transform(TextReader input, TextWriter output) => Transform(XbnfDocument.ReadFrom(input), output); - public static void Transform(XbnfDocument document,TextWriter writer) + public static void Transform(XbnfDocument document, TextWriter writer) { var syms = new HashSet(); // gather the attributes and production names - for(int ic=document.Productions.Count,i=0;i")); foreach (var s in rule.Value) @@ -102,28 +102,28 @@ public static void Transform(XbnfDocument document,TextWriter writer) } writer.WriteLine(); // write our terminals - for(int ic = tmap.Count,i=0;i> _GetDysjunctions( XbnfDocument d, ICollection syms, - IDictionary tmap, - IDictionary attrs, - IList>> rules, + IDictionary tmap, + IDictionary attrs, + IList>> rules, XbnfProduction p, XbnfExpression e ) { var le = e as XbnfLiteralExpression; - if(null!=le) + if (null != le) { var res = new List>(); var l = new List(); @@ -203,7 +203,7 @@ XbnfExpression e return res; } var rfe = e as XbnfRefExpression; - if(null!=rfe) + if (null != rfe) { var res = new List>(); var l = new List(); @@ -212,19 +212,19 @@ XbnfExpression e return res; } var ce = e as XbnfConcatExpression; - if(null!=ce) - return _GetDysConcat(d, syms, tmap,attrs,rules, p, ce); - + if (null != ce) + return _GetDysConcat(d, syms, tmap, attrs, rules, p, ce); + var oe = e as XbnfOrExpression; - if(null!=oe) - return _GetDysOr(d, syms, tmap, attrs,rules,p, oe); + if (null != oe) + return _GetDysOr(d, syms, tmap, attrs, rules, p, oe); var ope = e as XbnfOptionalExpression; - if(null!=ope) + if (null != ope) { return _GetDysOptional(d, syms, tmap, attrs, rules, p, ope); } var re = e as XbnfRepeatExpression; - if(null!=re) + if (null != re) return _GetDysRepeat(d, syms, tmap, attrs, rules, p, re); throw new NotSupportedException("The specified expression type is not supported."); } @@ -269,6 +269,7 @@ static IList> _GetDysRepeat(XbnfDocument d, ICollection sy ++i; } syms.Add(ss); + listId = ss; var attr = new XbnfAttribute("collapsed", true); var attrlist = new XbnfAttributeList(); attrlist.Add(attr); @@ -300,13 +301,13 @@ static IList> _GetDysRepeat(XbnfDocument d, ICollection sy } } - static IList> _GetDysOr(XbnfDocument d, ICollection syms, IDictionary tmap, IDictionary attrs,IList>> rules, XbnfProduction p, XbnfOrExpression oe) + static IList> _GetDysOr(XbnfDocument d, ICollection syms, IDictionary tmap, IDictionary attrs, IList>> rules, XbnfProduction p, XbnfOrExpression oe) { var l = new List>(); if (null == oe.Left) l.Add(new List()); else - foreach (var ll in _GetDysjunctions(d, syms, tmap, attrs,rules,p,oe.Left)) + foreach (var ll in _GetDysjunctions(d, syms, tmap, attrs, rules, p, oe.Left)) if (!l.Contains(ll, OrderedCollectionEqualityComparer.Default)) l.Add(ll); if (null == oe.Right) @@ -316,7 +317,7 @@ static IList> _GetDysOr(XbnfDocument d, ICollection syms, l.Add(ll); } else - foreach (var ll in _GetDysjunctions(d, syms, tmap, attrs,rules,p, oe.Right)) + foreach (var ll in _GetDysjunctions(d, syms, tmap, attrs, rules, p, oe.Right)) if (!l.Contains(ll, OrderedCollectionEqualityComparer.Default)) l.Add(ll); return l; @@ -328,19 +329,19 @@ static IList> _GetDysConcat(XbnfDocument d, ICollection sy if (null == ce.Right) { if (null == ce.Left) return l; - foreach (var ll in _GetDysjunctions(d, syms, tmap, attrs,rules,p, ce.Left)) + foreach (var ll in _GetDysjunctions(d, syms, tmap, attrs, rules, p, ce.Left)) l.Add(new List(ll)); return l; } else if (null == ce.Left) { - foreach (var ll in _GetDysjunctions(d, syms, tmap, attrs,rules,p, ce.Right)) + foreach (var ll in _GetDysjunctions(d, syms, tmap, attrs, rules, p, ce.Right)) l.Add(new List(ll)); return l; } - foreach (var ll in _GetDysjunctions(d, syms, tmap, attrs,rules,p, ce.Left)) + foreach (var ll in _GetDysjunctions(d, syms, tmap, attrs, rules, p, ce.Left)) { - foreach (var ll2 in _GetDysjunctions(d, syms, tmap, attrs,rules,p, ce.Right)) + foreach (var ll2 in _GetDysjunctions(d, syms, tmap, attrs, rules, p, ce.Right)) { var ll3 = new List(); ll3.AddRange(ll); @@ -352,9 +353,9 @@ static IList> _GetDysConcat(XbnfDocument d, ICollection sy return l; } - static XbnfProduction _GetProductionForExpression(XbnfDocument d,XbnfExpression e) + static XbnfProduction _GetProductionForExpression(XbnfDocument d, XbnfExpression e) { - for(int ic = d.Productions.Count,i=0;i te } } -} +} \ No newline at end of file