Click here to Skip to main content
14,937,212 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
 
GeneralRe: I write code like I approach everything Pin
honey the codewitch7-Aug-19 3:30
mvahoney the codewitch7-Aug-19 3:30 
GeneralRe: I write code like I approach everything Pin
Sander Rossel7-Aug-19 4:10
professionalSander Rossel7-Aug-19 4:10 
GeneralRe: I write code like I approach everything Pin
honey the codewitch7-Aug-19 4:11
mvahoney the codewitch7-Aug-19 4:11 
GeneralRe: I write code like I approach everything Pin
Sander Rossel7-Aug-19 4:23
professionalSander Rossel7-Aug-19 4:23 
GeneralRe: I write code like I approach everything Pin
honey the codewitch7-Aug-19 4:25
mvahoney the codewitch7-Aug-19 4:25 
GeneralRe: I write code like I approach everything Pin
honey the codewitch7-Aug-19 4:27
mvahoney the codewitch7-Aug-19 4:27 
GeneralRe: I write code like I approach everything Pin
W Balboos, GHB6-Aug-19 2:56
mveW Balboos, GHB6-Aug-19 2:56 
GeneralRe: I write code like I approach everything Pin
honey the codewitch6-Aug-19 3:07
mvahoney the codewitch6-Aug-19 3:07 
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;
	}
	// work on our reductions now
	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)
			{
				// build the rule data
				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(); // couldn't find our rule

				// this gets rid of duplicate entries which seem to crop up in the table
				// TODO: I think this is a shift reduce conflict if it debugger-breaks
				if (lalrclosure[lr.To].TryGetValue(iid, out tuple))
				{
					if (rid != tuple.RuleOrStateId)
						System.Diagnostics.Debugger.Break(); // possible shift-reduce conflice?
				}
				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.

GeneralRe: I write code like I approach everything Pin
PIEBALDconsult6-Aug-19 5:20
professionalPIEBALDconsult6-Aug-19 5:20 
GeneralRe: I write code like I approach everything Pin
honey the codewitch6-Aug-19 5:21
mvahoney the codewitch6-Aug-19 5:21 
GeneralRe: I write code like I approach everything Pin
Mark_Wallace6-Aug-19 10:10
MemberMark_Wallace6-Aug-19 10:10 
GeneralRe: I write code like I approach everything Pin
honey the codewitch6-Aug-19 10:48
mvahoney the codewitch6-Aug-19 10:48 
GeneralRe: I write code like I approach everything Pin
Mark_Wallace6-Aug-19 11:03
MemberMark_Wallace6-Aug-19 11:03 
GeneralRe: I write code like I approach everything Pin
honey the codewitch6-Aug-19 11:05
mvahoney the codewitch6-Aug-19 11:05 
GeneralRe: I write code like I approach everything Pin
Mark_Wallace6-Aug-19 11:54
MemberMark_Wallace6-Aug-19 11:54 
GeneralRe: I write code like I approach everything Pin
honey the codewitch6-Aug-19 11:56
mvahoney the codewitch6-Aug-19 11:56 
GeneralI dreamed of the robot who will replace me Pin
BillWoodruff6-Aug-19 1:21
mveBillWoodruff6-Aug-19 1:21 
GeneralRe: I dreamed of the robot who will replace me Pin
honey the codewitch6-Aug-19 1:22
mvahoney the codewitch6-Aug-19 1:22 
GeneralRe: I dreamed of the robot who will replace me Pin
CPallini6-Aug-19 1:28
mveCPallini6-Aug-19 1:28 
GeneralRe: I dreamed of the robot who will replace me Pin
Daniel Pfeffer6-Aug-19 1:42
professionalDaniel Pfeffer6-Aug-19 1:42 
GeneralRe: I dreamed of the robot who will replace me Pin
CPallini6-Aug-19 1:47
mveCPallini6-Aug-19 1:47 
GeneralRe: I dreamed of the robot who will replace me Pin
Rick York6-Aug-19 5:30
mveRick York6-Aug-19 5:30 
JokeRe: I dreamed of the robot who will replace me Pin
Daniel Pfeffer6-Aug-19 1:40
professionalDaniel Pfeffer6-Aug-19 1:40 
GeneralRe: I dreamed of the robot who will replace me Pin
RickZeeland6-Aug-19 1:45
mveRickZeeland6-Aug-19 1:45 
GeneralRe: I dreamed of the robot who will replace me Pin
Rick York6-Aug-19 5:30
mveRick York6-Aug-19 5:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.