public static ParserComb.NamedNode ScopeAndType(IEnumerable <PTok> toksIN, CH_closedScope scopeIN, MG.PI StartProd, Func <NamedNode, TranslationUnit> TRInstantiate) { TranslationUnit TR; var NN = Scope(toksIN, scopeIN, StartProd, TRInstantiate, out TR); return(NN); }
public static void JsonifyCompilat(Compilat compilat, string filename_postfix = "") { var CHs = new HashSet <TypedCH>(); using (var SW = new StreamWriter(new FileStream("compilat" + filename_postfix + ".json", FileMode.Create))) { // diagram in Nutshell 614 ... wtf? foreach (var opcode in compilat.OPs) { SW.WriteLine(conv(opcode)); foreach (var edge in OP2CH_edge(opcode)) { CHs.Add(edge.CH); SW.WriteLine(conv(opcode, edge)); } } foreach (var ch in CHs) { SW.WriteLine(conv(ch)); } CH_closedScope scope = compilat.deltaScope.close(); foreach (var _ref in scope.refs()) { SW.WriteLine(conv(_ref.name, _ref.CH)); } } }
public static CH_closedScope DummyScope() { CH_closedScope sc = new CH_closedScope(); sc = sc. decl("VDummyType", TestcasesLHSsingletonTypedCH). decl("Vint", DummyIntHeaderSing); return(sc); }
public static void Test2() { CH_closedScope sc = DummyInstances.DummyScope(); string expr_l = "..str", expr_r = " -> foo "; string expr = expr_l + expr_r; Tok[] strippedToks = TranslateEntry.LexxAndStripWS(expr); var NN = TranslateEntry.Scope(strippedToks, DummyInstances.GE_TestStartRX, DummyInstances.DummyTransLHS); }
public static ParserComb.NamedNode ScopeAndType(string src, CH_closedScope scopeIN, MG.PI StartProd, Func <ParserComb.NamedNode, TranslationUnit> TRInstantiate) { ParserComb.NamedNode NN = LexxAndParse_incomplete_tolerant(src, StartProd); // TR constructors do not provide a uniform interface because there is no need for it TranslationUnit TR = TRInstantiate(NN); var deltaScope = new preCH_deltaScope(scopeIN); var combinedScope = TR.scope(deltaScope); return(NN); }
public static Column DummyEval(string expr) // condense all the junk in plumbing { CH_closedScope dummy_out_scope = null; // todo: this goes to a variant of parse that silently drops unconsumed tokens in those cases where there is no full parse of the entire token sequence return(Evaluate.Eval(expr, startProdGE, new TranslateLHS { preCH_LHS = null, // not needed for start prod scope = new CH_closedScope() }, new MemMapper(), out dummy_out_scope)); }
public static ParserComb.NamedNode Scope( IEnumerable <PTok> toksIN, CH_closedScope scopeIN, MG.PI StartProd, Func <NamedNode, TranslationUnit> TRInstantiate, out TranslationUnit TRU) { var matches = MG.RUN_with_rest(StartProd, toksIN).ToArray(); if (matches.Length.NLSend("matchlen") == 0 || matches[0].rest.Any()) { throw new Exception(); // no match , or the most greedy match could not consume whole input } // MAJOR-TODO !! ambigous grammars with epsilon consuming productions can yield // an INFINITE number of alternatives , if there is a .ToArray() somewhere -> CRASH !! NamedNode NN = matches[0].N; TranslationUnit TR = TRInstantiate(NN); var deltaScope = new preCH_deltaScope(scopeIN); var combinedScope = TR.scope(deltaScope); TRU = TR; return(NN); }
public static void Test1() { //LexxAndRun( ".*foo -> x <- y -> z " ); Console.WriteLine(LexxAndParse(".*foo", MG.MemA)); Console.WriteLine(LexxAndParse(".*foo -> x ", MG.MemAVT)); Console.WriteLine(LexxAndParse(".*foo -> x ", MGRX.MemAVT_RX)); Console.WriteLine(LexxAndParse("..str", MGRX.MemAVT_RX)); Console.WriteLine(LexxAndParse("..str -> foo", MGRX.MemAVT_RX)); Console.WriteLine(LexxAndParse("..str -> foo", TestMG1.TestStartRX)); Console.WriteLine("----------- whoooo ------- "); Console.WriteLine(LexxAndParse(" <- $XX ", MG.SingleAssign)); Console.WriteLine(LexxAndParse(" <- $XX -> a -> b ", MG.AssignVT)); Console.WriteLine(LexxAndParse(" .*foo -> decl1 <- $ARG -> decl2 ", TestMG1.TestStart)); // ----------------------------------------------------------------- var MM = new MemMapper(); var dollar_arg_CH = new TypedSingleCH <int>(); // Method I: hack column entries into MM directly ColumnSingle <int> dollar_arg_Column = (ColumnSingle <int>)dollar_arg_CH.SpawnColumn(); // todo: maybe provide SpawnColumnT that "kinda-overloads" on the return type MM.D[dollar_arg_CH] = dollar_arg_Column; dollar_arg_Column.AddVal(3, null); dollar_arg_Column.AddVal(4, null); // Method II: abuse MemMapper for column creation ColumnSingle <TestcasesLHSType> LHS_column; LHS_column = MM.get(DummyInstances.TestcasesLHSsingletonTypedCH); // TypedSingle<DummyType> LHS_column.AddVal(new TestcasesLHSType(), null); LHS_column.AddVal(new TestcasesLHSType(), null); LHS_column.AddVal(new TestcasesLHSType(), null); CH_closedScope scope = new CH_closedScope(); scope = scope.decl("ARG", dollar_arg_CH); CH_closedScope out_scope; var TR_LHS = new TranslateLHS { preCH_LHS = new adapter_preCH(DummyInstances.TestcasesLHSsingletonTypedCH), scope = scope }; Console.WriteLine("in -> " + LHS_column); Column res = Evaluate.Eval_incomplete_tolerant(" ..intMem1 -> decl1 <- $ARG -> decl2 ", DummyInstances.GE_TestStart, TR_LHS, MM, out out_scope); foreach (var s in ColumnChainPrttS( res, CH => MM.D[CH] ).Reverse()) { Console.WriteLine(s); } }
public static Column Eval(string strExpr, GrammarEntry GE, TranslateLHS trans_LHS, MemMapper MM, out CH_closedScope scope_out) { var compilat = TranslateEntry.TranslateFully(strExpr, GE, trans_LHS); scope_out = compilat.deltaScope.close(); #if todo_fixme // external refs in the scopes still need implementation ( done . todo plug this shit in ) foreach (var sc_ref in compilat.ownDecls) { scope_out = (ClosedScope)scope_out.decl(sc_ref); } #endif compilat.run(MM); // atm the MM keeps references on tmp columns around forever - some pruning mechanism is needed VBoxTU last_VBT = compilat.VBoxTrs.Last(); return(MM.getGen(last_VBT.CH_out)); }