Permutations Combinations Cartesian для последовательностей
This commit is contained in:
Mikhalkovich Stanislav 2021-01-07 14:12:06 +03:00
parent 499767fe5b
commit 6553f62573
15 changed files with 116 additions and 41 deletions

View file

@ -1682,7 +1682,11 @@ namespace CodeFormatters
if (_program_module.program_name != null)
visit_node(_program_module.program_name);
if (_program_module.used_units != null && _program_module.used_units.source_context != null)
visit_node(_program_module.used_units);
{
if (_program_module.program_block != null && _program_module.program_block.program_code.left_logical_bracket.text.StartsWith("##"))
;
else visit_node(_program_module.used_units);
}
if (_program_module.program_block != null)
visit_node(_program_module.program_block);
//sb.Append(".");

View file

@ -15,7 +15,7 @@ internal static class RevisionClass
public const string Major = "3";
public const string Minor = "7";
public const string Build = "1";
public const string Revision = "2784";
public const string Revision = "2785";
public const string MainVersion = Major + "." + Minor;
public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision;

View file

@ -1,4 +1,4 @@
%COREVERSION%=1
%REVISION%=2784
%MINOR%=7
%REVISION%=2785
%COREVERSION%=1
%MAJOR%=3

View file

@ -2,7 +2,8 @@
<head>
<object type="application/x-oleobject" classid="clsid:1e2a7bd0-dab9-11d0-b93a-00c04fc99f9e">
<param name="Keyword" value="">
<param name="Keyword" value="Attribute">
<param name="Keyword" value="Àòðèáóò">
</object>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title></title>
@ -11,11 +12,46 @@
<body>
<H1>Àòðèáóòû</H1>
<p>Òåêñò íàõîäèòñÿ â ðàçðàáîòêå</p>
<p> ÿçûêå èìååòñÿ îãðàíè÷åííîå ÷èñëî ñòàíäàðòíûõ àòðèáóòîâ, çàäàâàåìûõ
êëþ÷åâûìè ñëîâàìè - íàïðèìåð: àòðèáóòû óðîâíÿ äîñòóïà public, private è
protected, àòðèáóòû static, virtual è override äëÿ ìåòîäîâ. </p>
<p>Ïîëüçîâàòåëüñêèå àòðèáóòû (äàëåå ïðîñòî àòðèáóòû) - ñïåöèàëüíûå ÿçûêîâûå
êîíñòðóêöèè, ïîçâîëÿþùèå ïîìå÷àòü êëàññû, ìåòîäû, ïîäïðîãðàììû, ïàðàìåòðû
íåêîòîðûì èìåíåì (âîçìîæíî ñ ïàðàìåòðàìè).</p>
<p>Íàïðèìåð, äëÿ ìåõàíèçìà ñåðèàëèçàöèè êëàññ ïîìå÷àåòñÿ àòðèáóòîì
[Serializable], à ïîëÿ, êîòîðûå íå ñëåäóåò ñåðèàëèçîâûâàòü, àòðèáóòîì
[NonSerialized]. Ïðè Unit-òåñòèðîâàíèè òåñòîâûé ìåòîä ïîìå÷àåòñÿ àòðèáóòîì
[Test] èëè àòðèáóòîì [TestCase]. Ðàñïîçíàþòñÿ àòðèáóòû ìåòîäîì îòðàæåíèÿ
(ðåôëåêñèè).</p>
<p>Àòðèáóò - ýòî îáû÷íûé êëàññ, óíàñëåäîâàííûé îò System.Atribute. Íàïðèìåð: </p>
<blockquote>
<p><code><b>t</b></code></p>
<p><code><b>type </b>AuthorAttribute = <strong>class</strong>(System.Attribute)<br>&nbsp;
<strong>auto</strong> property Name: string;<br>&nbsp; <strong>constructor</strong> (n: string);<br>&nbsp;
<strong>begin</strong><br>&nbsp;&nbsp;&nbsp; name := n;<br>&nbsp; <strong>end</strong>;&nbsp; <strong><br>end</strong>;</code></p>
</blockquote>
<p>Å</p>
<p>Ñëåäóåò îáðàòèòü âíèìàíèå, ÷òî êëàññ àòðèáóòà ïðèíÿòî îêàí÷èâàòü íà <code>
Attribute</code>.</p>
<p>Ïðè ïîìåòêå ñóùíîñòè àòðèáóòîì èìÿ àòðèáóòà çàêëþ÷àåòñÿ â êâàäðàòíûå ñêîáêè. Êîíñòðóêòîð àòðèáóòà ïðåäîñòàâëÿåò
òàêæå âîçìîæíîñòü èñïîëüçîâàòü àòðèáóòû ñ
ïàðàìåòðàìè. Íàïðèìåð, ìîæíî ïîìåòèòü êëàññ
àòðèáóòîì <code>AuthorAttribute</code>. </p>
<blockquote>
<p><code>[Author('Alex')]<b><br>type </b>My = <strong>class</strong><br>&nbsp; // ...<strong><br>
end</strong>;</code></p>
</blockquote>
<p>Ñëåäóåò îáðàòèòü âíèìàíèå, ÷òî îêîí÷àíèå <code>Attribute</code> ìîæíî íå
óêàçûâàòü.</p>
<p>Ðàñïîçíàòü, ïîìå÷åí ëè äàííûé êëàññ àòðèáóòîì, ìîæíî, èñïîëüçóÿ
îòðàæåíèå: </p>
<blockquote>
<p><code><strong>begin</strong> <br>&nbsp; <strong>var</strong> t := typeof(My);
<br>&nbsp; <strong>var</strong> attrs := t.GetCustomAttributes(false); <br>&nbsp;
<strong>foreach</strong> <strong>var</strong> attr <strong>in</strong> attrs
<strong>do</strong> <br>&nbsp;&nbsp;&nbsp; <strong>if</strong> attr <strong>is</strong> AuthorAttribute (<strong>var</strong> auth)
<strong>then</strong> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Print(auth.Name);
<br><strong>end</strong>.</code></p>
</blockquote>
<p>Ñëåä</p>
</body>
</html>

View file

@ -2,7 +2,7 @@
// This CSharp output file generated by Gardens Point LEX
// Version: 1.1.3.301
// Machine: DESKTOP-G8V08V4
// DateTime: 25.12.2020 21:59:53
// DateTime: 07.01.2021 12:07:22
// UserName: ?????????
// GPLEX input file <ABCPascal.lex>
// GPLEX frame file <embedded resource>

View file

@ -188,20 +188,24 @@ parse_goal
{ root = $1; }
| parts
{ root = $1; }
| tkShortProgram stmt_list
| tkShortProgram uses_clause stmt_list
{
var stl = $2 as statement_list;
var stl = $3 as statement_list;
stl.left_logical_bracket = $1;
stl.right_logical_bracket = new token_info("");
root = $$ = NewProgramModule(null, null, null, new block(null, stl, @$), new token_info(""), @$);
var ul = $2 as uses_list;
root = $$ = NewProgramModule(null, null, ul, new block(null, stl, @$), new token_info(""), @$);
}
| tkShortSFProgram stmt_list
| tkShortSFProgram uses_clause stmt_list
{
var stl = $2 as statement_list;
var stl = $3 as statement_list;
stl.left_logical_bracket = $1;
var un = new unit_or_namespace(new ident_list("SF"),null);
var ul = $2 as uses_list;
if (ul == null)
//var un1 = new unit_or_namespace(new ident_list("School"),null);
var ul = new uses_list(un,null);
ul = new uses_list(un,null);
else ul.Insert(0,un);
//ul.Add(un1);
root = $$ = NewProgramModule(null, null, ul, new block(null, stl, @$), new token_info(""), @$);
}

View file

@ -2,9 +2,9 @@
// GPPG version 1.3.6
// Machine: DESKTOP-G8V08V4
// DateTime: 25.12.2020 21:59:54
// DateTime: 07.01.2021 12:07:22
// UserName: ?????????
// Input file <ABCPascal.y>
// Input file <D:\PABC_Git\Parsers\PascalABCParserNewSaushkin\ABCPascal.y>
// options: no-lines gplex
@ -59,7 +59,7 @@ public abstract class ScanBase : AbstractScanner<PascalABCSavParser.Union,LexLoc
public partial class GPPGParser: ShiftReduceParser<PascalABCSavParser.Union, LexLocation>
{
// Verbatim content from ABCPascal.y
// Verbatim content from D:\PABC_Git\Parsers\PascalABCParserNewSaushkin\ABCPascal.y
// <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD> GPPGParser, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> gppg
public syntax_tree_node root; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
@ -71,13 +71,13 @@ public partial class GPPGParser: ShiftReduceParser<PascalABCSavParser.Union, Lex
public ParserLambdaHelper lambdaHelper = new ParserLambdaHelper();
public GPPGParser(AbstractScanner<PascalABCSavParser.Union, LexLocation> scanner) : base(scanner) { }
// End verbatim content from ABCPascal.y
// End verbatim content from D:\PABC_Git\Parsers\PascalABCParserNewSaushkin\ABCPascal.y
#pragma warning disable 649
private static Dictionary<int, string> aliasses;
#pragma warning restore 649
private static Rule[] rules = new Rule[987];
private static State[] states = new State[1633];
private static State[] states = new State[1635];
private static string[] nonTerms = new string[] {
"parse_goal", "unit_key_word", "class_or_static", "assignment", "optional_array_initializer",
"attribute_declarations", "ot_visibility_specifier", "one_attribute", "attribute_variable",
@ -168,7 +168,7 @@ public partial class GPPGParser: ShiftReduceParser<PascalABCSavParser.Union, Lex
"tuple_pattern_item_list", "const_pattern_expr_list", "$accept", };
static GPPGParser() {
states[0] = new State(new int[]{58,1536,11,843,85,1611,87,1616,86,1623,73,1629,75,1631,3,-27,49,-27,88,-27,56,-27,26,-27,64,-27,47,-27,50,-27,59,-27,41,-27,34,-27,25,-27,23,-27,27,-27,28,-27,102,-207,103,-207,106,-207},new int[]{-1,1,-226,3,-227,4,-297,1548,-6,1549,-242,862,-167,1610});
states[0] = new State(new int[]{58,1536,11,843,85,1611,87,1616,86,1623,73,1629,75,1632,3,-27,49,-27,88,-27,56,-27,26,-27,64,-27,47,-27,50,-27,59,-27,41,-27,34,-27,25,-27,23,-27,27,-27,28,-27,102,-207,103,-207,106,-207},new int[]{-1,1,-226,3,-227,4,-297,1548,-6,1549,-242,862,-167,1610});
states[1] = new State(new int[]{2,2});
states[2] = new State(-1);
states[3] = new State(-2);
@ -1797,17 +1797,19 @@ public partial class GPPGParser: ShiftReduceParser<PascalABCSavParser.Union, Lex
states[1626] = new State(new int[]{107,411,108,412,109,413,110,414,111,415,135,-750,133,-750,115,-750,114,-750,128,-750,129,-750,130,-750,131,-750,127,-750,113,-750,112,-750,125,-750,126,-750,123,-750,6,-750,5,-750,117,-750,122,-750,120,-750,118,-750,121,-750,119,-750,134,-750,16,-750,2,-750,13,-750,116,-742},new int[]{-186,137});
states[1627] = new State(-12);
states[1628] = new State(-13);
states[1629] = new State(new int[]{138,380,140,23,83,25,84,26,78,28,76,255,42,387,39,597,8,598,18,275,19,280,141,161,143,162,142,164,151,651,154,167,153,168,152,169,74,482,54,624,88,129,37,630,22,637,94,653,51,658,32,663,52,673,99,679,44,686,33,689,50,697,57,745,72,750,70,737,35,759,10,-486,2,-486},new int[]{-244,1630,-253,649,-252,134,-4,135,-104,136,-123,369,-103,565,-138,650,-142,24,-143,27,-183,424,-249,458,-287,459,-15,607,-156,158,-158,159,-157,163,-16,165,-17,460,-55,608,-107,488,-204,622,-124,623,-247,628,-144,629,-33,636,-239,652,-309,657,-115,662,-310,672,-151,677,-294,678,-240,685,-114,688,-305,696,-56,741,-166,742,-165,743,-160,744,-117,749,-118,756,-116,757,-339,758,-134,1058});
states[1630] = new State(new int[]{10,132,2,-5});
states[1631] = new State(new int[]{138,380,140,23,83,25,84,26,78,28,76,255,42,387,39,597,8,598,18,275,19,280,141,161,143,162,142,164,151,651,154,167,153,168,152,169,74,482,54,624,88,129,37,630,22,637,94,653,51,658,32,663,52,673,99,679,44,686,33,689,50,697,57,745,72,750,70,737,35,759,10,-486,2,-486},new int[]{-244,1632,-253,649,-252,134,-4,135,-104,136,-123,369,-103,565,-138,650,-142,24,-143,27,-183,424,-249,458,-287,459,-15,607,-156,158,-158,159,-157,163,-16,165,-17,460,-55,608,-107,488,-204,622,-124,623,-247,628,-144,629,-33,636,-239,652,-309,657,-115,662,-310,672,-151,677,-294,678,-240,685,-114,688,-305,696,-56,741,-166,742,-165,743,-160,744,-117,749,-118,756,-116,757,-339,758,-134,1058});
states[1632] = new State(new int[]{10,132,2,-6});
states[1629] = new State(-38,new int[]{-295,1630});
states[1630] = new State(new int[]{49,14,138,380,140,23,83,25,84,26,78,28,76,255,42,387,39,597,8,598,18,275,19,280,141,161,143,162,142,164,151,651,154,167,153,168,152,169,74,482,54,624,88,129,37,630,22,637,94,653,51,658,32,663,52,673,99,679,44,686,33,689,50,697,57,745,72,750,70,737,35,759,10,-486,2,-486},new int[]{-244,1631,-253,649,-252,134,-4,135,-104,136,-123,369,-103,565,-138,650,-142,24,-143,27,-183,424,-249,458,-287,459,-15,607,-156,158,-158,159,-157,163,-16,165,-17,460,-55,608,-107,488,-204,622,-124,623,-247,628,-144,629,-33,636,-239,652,-309,657,-115,662,-310,672,-151,677,-294,678,-240,685,-114,688,-305,696,-56,741,-166,742,-165,743,-160,744,-117,749,-118,756,-116,757,-339,758,-134,1058});
states[1631] = new State(new int[]{10,132,2,-5});
states[1632] = new State(-38,new int[]{-295,1633});
states[1633] = new State(new int[]{49,14,138,380,140,23,83,25,84,26,78,28,76,255,42,387,39,597,8,598,18,275,19,280,141,161,143,162,142,164,151,651,154,167,153,168,152,169,74,482,54,624,88,129,37,630,22,637,94,653,51,658,32,663,52,673,99,679,44,686,33,689,50,697,57,745,72,750,70,737,35,759,10,-486,2,-486},new int[]{-244,1634,-253,649,-252,134,-4,135,-104,136,-123,369,-103,565,-138,650,-142,24,-143,27,-183,424,-249,458,-287,459,-15,607,-156,158,-158,159,-157,163,-16,165,-17,460,-55,608,-107,488,-204,622,-124,623,-247,628,-144,629,-33,636,-239,652,-309,657,-115,662,-310,672,-151,677,-294,678,-240,685,-114,688,-305,696,-56,741,-166,742,-165,743,-160,744,-117,749,-118,756,-116,757,-339,758,-134,1058});
states[1634] = new State(new int[]{10,132,2,-6});
rules[1] = new Rule(-349, new int[]{-1,2});
rules[2] = new Rule(-1, new int[]{-226});
rules[3] = new Rule(-1, new int[]{-297});
rules[4] = new Rule(-1, new int[]{-167});
rules[5] = new Rule(-1, new int[]{73,-244});
rules[6] = new Rule(-1, new int[]{75,-244});
rules[5] = new Rule(-1, new int[]{73,-295,-244});
rules[6] = new Rule(-1, new int[]{75,-295,-244});
rules[7] = new Rule(-167, new int[]{85,-82});
rules[8] = new Rule(-167, new int[]{85,47,-135});
rules[9] = new Rule(-167, new int[]{87,-311});
@ -2811,21 +2813,25 @@ public partial class GPPGParser: ShiftReduceParser<PascalABCSavParser.Union, Lex
case 4: // parse_goal -> parts
{ root = ValueStack[ValueStack.Depth-1].stn; }
break;
case 5: // parse_goal -> tkShortProgram, stmt_list
case 5: // parse_goal -> tkShortProgram, uses_clause, stmt_list
{
var stl = ValueStack[ValueStack.Depth-1].stn as statement_list;
stl.left_logical_bracket = ValueStack[ValueStack.Depth-2].ti;
stl.left_logical_bracket = ValueStack[ValueStack.Depth-3].ti;
stl.right_logical_bracket = new token_info("");
root = CurrentSemanticValue.stn = NewProgramModule(null, null, null, new block(null, stl, CurrentLocationSpan), new token_info(""), CurrentLocationSpan);
var ul = ValueStack[ValueStack.Depth-2].stn as uses_list;
root = CurrentSemanticValue.stn = NewProgramModule(null, null, ul, new block(null, stl, CurrentLocationSpan), new token_info(""), CurrentLocationSpan);
}
break;
case 6: // parse_goal -> tkShortSFProgram, stmt_list
case 6: // parse_goal -> tkShortSFProgram, uses_clause, stmt_list
{
var stl = ValueStack[ValueStack.Depth-1].stn as statement_list;
stl.left_logical_bracket = ValueStack[ValueStack.Depth-2].ti;
stl.left_logical_bracket = ValueStack[ValueStack.Depth-3].ti;
var un = new unit_or_namespace(new ident_list("SF"),null);
var ul = ValueStack[ValueStack.Depth-2].stn as uses_list;
if (ul == null)
//var un1 = new unit_or_namespace(new ident_list("School"),null);
var ul = new uses_list(un,null);
ul = new uses_list(un,null);
else ul.Insert(0,un);
//ul.Add(un1);
root = CurrentSemanticValue.stn = NewProgramModule(null, null, ul, new block(null, stl, CurrentLocationSpan), new token_info(""), CurrentLocationSpan);
}

View file

@ -300,5 +300,6 @@ script=

View file

@ -1 +1 @@
3.7.1.2784
3.7.1.2785

View file

@ -1 +1 @@
!define VERSION '3.7.1.2784'
!define VERSION '3.7.1.2785'

View file

@ -190,9 +190,11 @@ namespace PascalABCCompiler.SyntaxTree
var ts = m as procedure_definition;
if (!HasConstructor)
{
if (ts != null && ts.proc_header is constructor)
if (ts != null && ts.proc_header is constructor
&& (ts.proc_header.parameters?.params_list.SelectMany(tp => tp.idents.idents).Count() ?? 0) == names.Count
)
{
HasConstructor = true;
HasConstructor = true; // на самом деле это означает, что есть конструктор с точно таким же количеством параметров
}
}

View file

@ -379,7 +379,7 @@ type
procedure AddToObject3DList;
procedure DeleteFromObject3DList;
protected
procedure CreateBase0(m: Visual3D; x, y, z: real);
begin
model := m;
@ -395,7 +395,7 @@ type
hvp.Children.Add(model);
AddToObject3DList;
end;
private
procedure SetX(xx: real) := Invoke(()->begin transltransform.OffsetX += xx - Self.X; end);
function GetX: real := InvokeReal(()->transfgroup.Value.OffsetX);
procedure SetY(yy: real) := Invoke(()->begin transltransform.OffsetY += yy - Self.Y; end);

View file

@ -379,7 +379,7 @@ type
procedure AddToObject3DList;
procedure DeleteFromObject3DList;
protected
procedure CreateBase0(m: Visual3D; x, y, z: real);
begin
model := m;
@ -395,7 +395,7 @@ type
hvp.Children.Add(model);
AddToObject3DList;
end;
private
procedure SetX(xx: real) := Invoke(()->begin transltransform.OffsetX += xx - Self.X; end);
function GetX: real := InvokeReal(()->transfgroup.Value.OffsetX);
procedure SetY(yy: real) := Invoke(()->begin transltransform.OffsetY += yy - Self.Y; end);

View file

@ -11815,6 +11815,12 @@ begin
until not NextCombHelper(ind,m,n);
end;
/// Возвращает все сочетания по m элементов
function Combinations<T>(Self: sequence of T; m: integer): sequence of array of T; extensionmethod;
begin
Result := Self.ToArray.Combinations(m);
end;
// Возвращает все сочетания по 2 элемента в виде кортежей
{function Combinations2<T>(Self: array of T): sequence of (T,T); extensionmethod;
begin
@ -11858,12 +11864,23 @@ begin
until not NextPermutation(ind);
end;
/// Возвращает все перестановки множества элементов, заданного последовательностью
function Permutations<T>(Self: sequence of T): sequence of array of T; extensionmethod;
begin
Result := Self.ToArray.Permutations
end;
/// Возвращает все частичные перестановки из n элементов по m
function Permutations<T>(Self: array of T; m: integer): sequence of array of T; extensionmethod;
begin
Result := Self.Combinations(m).SelectMany(c->c.Permutations);
end;
/// Возвращает все частичные перестановки из n элементов по m
function Permutations<T>(Self: sequence of T; m: integer): sequence of array of T; extensionmethod;
begin
Result := Self.ToArray.Permutations(m);
end;
/// Возвращает n-тую декартову степень множества элементов, заданного массивом
function Cartesian<T>(Self: array of T; n: integer): sequence of array of T; extensionmethod;
@ -11895,6 +11912,11 @@ begin
end;
end;
/// Возвращает n-тую декартову степень множества элементов, заданного массивом
function Cartesian<T>(Self: sequence of T; n: integer): sequence of array of T; extensionmethod;
begin
Result := Self.ToArray.Cartesian(n);
end;
// Внутренние функции для одномерных массивов

Binary file not shown.