|
my code isn't inelegant. but yeah it's not for the faint of heart
(real world excerpt - not production ready)
public static Lalr1ParseTable ToLalr1ParseTable(this CfgDocument cfg)
{
var start = cfg.GetAugmentedStartId(cfg.StartSymbol);
var pda = _ToLrfa(cfg);
var trnsCfg = _ToLRTransitionGrammar(cfg,pda);
var closure = new List<FA<string, ICollection<LRItem>>>();
var lalrclosure = new Lalr1ParseTable();
var itemSets = new List<ICollection<LRItem>>();
pda.FillClosure(closure);
var i = 0;
foreach (var p in closure)
{
itemSets.Add(p.AcceptSymbol);
lalrclosure.Add(new Dictionary<string, (int RuleOrStateId, string Left, string[] Right)>());
++i;
}
i = 0;
foreach (var p in closure)
{
foreach (var trn in p.Transitions)
{
var idx = closure.IndexOf(trn.Value);
lalrclosure[i].Add(
trn.Key,
(idx, null, null)
);
}
foreach (var item in p.AcceptSymbol)
{
if (Equals(item.Rule.Left, start) && item.RightIndex == item.Rule.Right.Count)
{
lalrclosure[i].Add(
"#EOS",
(-1, null, null));
break;
}
}
++i;
}
var map = new Dictionary<CfgRule, ICollection<string>>(_TransitionMergeRuleComparer.Default);
var follows = trnsCfg.FillFollows();
var rtbl = new List<IDictionary<object, CfgRule>>();
foreach (var rule in trnsCfg.Rules)
{
ICollection<string> f;
if (!map.TryGetValue(rule, out f))
map.Add(rule, follows[rule.Left]);
else
foreach (var o in follows[rule.Left])
if (!f.Contains(o))
f.Add(o);
}
foreach (var me in map)
{
var rule = me.Key;
var lr = _LrtSymbol.Parse(rule.Right[rule.Right.Count - 1]);
var left = _LrtSymbol.Parse(rule.Left).Id;
var right = new List<string>();
foreach (var s in rule.Right)
right.Add(_LrtSymbol.Parse(s).Id);
var newRule = new CfgRule(left, right);
if (!Equals(left, start))
foreach (var f in me.Value)
{
var rr = new string[newRule.Right.Count];
for (var ri = 0; ri < rr.Length; ri++)
rr[ri] = newRule.Right[ri];
var iid = _LrtSymbol.Parse(f).Id;
(int RuleOrStateId, string Left, string[] Right) tuple;
var rid = cfg.Rules.IndexOf(newRule);
if (0 > rid)
System.Diagnostics.Debugger.Break();
if (lalrclosure[lr.To].TryGetValue(iid, out tuple))
{
if (rid != tuple.RuleOrStateId)
System.Diagnostics.Debugger.Break();
}
else
{
lalrclosure[lr.To].Add(_LrtSymbol.Parse(f).Id,
(rid, newRule.Left, rr));
}
}
}
return lalrclosure;
}
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
modified 6-Aug-19 9:18am.
|
|
|
|
|
Well-organized code can be developed only by a committee.
However, it doesn't work and it's never finished, but just look how pretty it all is!
modified 6-Aug-19 14:43pm.
|
|
|
|
|
Sadly, your remark deserves far more upvotes than I have to give.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Sorry, but I'm a great believer in the "Clean Desk" policy.
My desk is always so covered in papers, files, boxes, and other random stuff that dirt can't get anywhere near it.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
Okay, but I classify a lot of things as filth.
Like this *waves small stack of papers* 6 page pile of rubbish I spent 3 days implementing before I realized it was someone's homework assignment and not a whitepaper (they really should warn people)
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
honey the monster, codewitch wrote: 6 page pile of rubbish I spent 3 days implementing before I realized it was someone's homework assignment and not a whitepaper (they really should warn people) Welcome to CP.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
actually this came out of some university in Israel. That's why i made the mistake. Three students getting at best a D from me, because they got a 1/3 of what they did wrong, and I found out the hard way, by trying to code it.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
|
Yeah, I got taken for a ride. I suck.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
It was so much like me, except for my remaining human parts
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
Are you sure you weren't already replaced?
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
I've just put my empty beer can in the robot who will replace the PM.
|
|
|
|
|
CPallini wrote: I've just put my empty beer can in the robot who will replace the PM
The sad thing is that I didn't have to ask "PM of which country?"
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
'Project Manager' was intended. However, 'Prime Minister' fits nicely as well.
|
|
|
|
|
So does president.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
|
|
|
|
|
… and whose least circuits you are unworthy to design.
(With apologies to Douglas Adams)
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
|
Electric sheep?
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
|
|
|
|
|
|
You were just temporarily disconnected from the Matrix.
We expect no further disruptions and we apologize for any inconveniences.
|
|
|
|
|
As popular demand was crying out for "our own NuGet server", I thought TeamCity 2019 would be the obvious choice for this as it has a built-in NuGet server capability.
After more than a day I managed to get it working for our own built artifacts, but then was puzzled by how to host other .nupkg files on it.
No mention on the TeamCity website how to do this, only after much digging on the internet I found this:
Quote: But I guess it's clear that Team City at the moment doesn't offers full NuGet server capabilities which can be used to establish company's local repository Add existing nuget package to the feed – TeamCity Support | JetBrains[^]
Grrrrr
|
|
|
|
|
|
So I have to make this SOAP (1.1) service so some third party application can connect with our system and request data.
Fine, just tell me what the SOAP service should look like.
So I get a WSDL, which is invalid because two types with the same name have the same namespace (x3).
So I get a new WSDL and right after that a third because the other wasn't correct, which, after testing with the third party application (which I don't have myself), turns out to be incorrect because the namespaces don't match.
And I go back to the old WSDL, which still has the same type names.
I've just implemented the fifth WSDL with XSD's and I have no idea if this is going to work or not.
The version of the WSDL is embedded in the namespace, but apparently it's not possible to just give me that version of the WSDL.
I'm getting different versions in the namespaces, but I just changed the version to match that of the third party application and hope it'll work when I can test this stuff again.
The best part is that this is apparently a standard that's maintained by a work group and I'm the third person to implement this standard (about 10 years after the last implementation)
|
|
|
|
|
Ha! XML! It was all the rage back in 1999!
|
|
|
|
|
The standard message I had to implement pretty much predates the internet (and I guess XML as well)
Here's a two line example.
DN1400150015090337000150024010001500250200015002305000150906010001509070900015001901000150021060001500460100015210101000152102010001500280100015002904100150032010001500360310015003802000150104010001500350310015003403100150304060
VN1400152019053100000001230491000011000938127???0000110009381272938127020011890580A E6181581 Now imagine having 100s of lines
(There may be some personal data in there, but I think it's safe to share )
The SOAP service is just so we can exchange these kinds of messages.
You can imagine XML is actually the lesser of evils
|
|
|
|