SF Prm Cmb для строк

This commit is contained in:
Mikhalkovich Stanislav 2024-12-14 15:25:16 +03:00
parent 6ef11f249c
commit a53dcd9ed2
14 changed files with 6515 additions and 3609 deletions

View file

@ -15,7 +15,7 @@ internal static class RevisionClass
public const string Major = "3";
public const string Minor = "10";
public const string Build = "2";
public const string Revision = "3589";
public const string Revision = "3593";
public const string MainVersion = Major + "." + Minor;
public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision;

View file

@ -1,4 +1,4 @@
%MINOR%=10
%REVISION%=3589
%REVISION%=3593
%COREVERSION%=2
%MAJOR%=3

View file

@ -0,0 +1,14 @@
begin
var a := [1,2,3]; // по умолчанию - массив
Println(a,TypeName(a));
var s := [2..4]; // если есть диапазон, то множество
Println(s,TypeName(s));
var s1: set of byte := [3,4,5]; // множество инициализируется значениями в []
Println(s1,TypeName(s1));
// Если один из операндов - множество, то результат - множество
Println(s + [1,2,3], s * [1,2,3], [1,2,3] - s, s - [1,2,3]);
// Это - операции с массивами
Println(a + [7,8,9], a * 3);
// Операция in для массива и для множества. Внешний вид одинаков
Println(5 in [3,5,7], 5 in [3..5,7]);
end.

View file

@ -1,9 +1,9 @@
//
// This CSharp output file generated by Gardens Point LEX
// Version: 1.1.3.301
// Machine: DESKTOP-G8V08V4
// DateTime: 19.07.2024 12:42:46
// UserName: ?????????
// Machine: LAPTOP-TE3HP881
// DateTime: 14.12.2024 15:20:04
// UserName: miks
// GPLEX input file <ABCPascal.lex>
// GPLEX frame file <embedded resource>
//
@ -2193,7 +2193,7 @@ if (parserTools.buildTreeForFormatter)
parserTools.ParseDirective(yytext, CurrentLexLocation, out var directiveName, out var directiveParams);
var orgDirectiveName = directiveName;
if (directiveName == "") // сл<EFBFBD>?<3F>?ай п<>?с<>?ой ди<D0B4>?ек<D0B5>?ив<D0B8>?
if (directiveName == "") // Ñ<EFBFBD>лÑ?Ñ?ай пÑ?Ñ<>Ñ?ой диÑ?екÑ?ивÑ?
break;
directiveName = directiveName.ToUpper();
@ -2290,7 +2290,7 @@ BEGIN(INITIAL);
parserTools.ParseDirective(yytext, CurrentLexLocation, out directiveName, out directiveParams);
orgDirectiveName = directiveName;
if (directiveName == "") // сл<EFBFBD>?<3F>?ай п<>?с<>?ой ди<D0B4>?ек<D0B5>?ив<D0B8>?
if (directiveName == "") // Ñ<EFBFBD>лÑ?Ñ?ай пÑ?Ñ<>Ñ?ой диÑ?екÑ?ивÑ?
break;
directiveName = directiveName.ToUpper();

View file

@ -140,7 +140,7 @@
%type <stn> program_header
%type <stn> parameter_decl
%type <stn> parameter_decl_list property_parameter_list
%type <ex> const_set
%type <ex> const_set pascal_set_const
%type <ex> question_expr question_constexpr new_question_expr
%type <ex> record_const const_field_list_1 const_field_list
%type <stn> const_field
@ -987,9 +987,9 @@ const_factor
// $$ = new roof_dereference($2 as addressed_value, @$);
// }
;
const_set
: tkSquareOpen elem_list tkSquareClose
pascal_set_const
: tkSquareOpen elem_list tkSquareClose
{
// Если elem_list пуст или содержит диапазон, то это множество, иначе массив. С PascalABC.NET 3.10
/*var is_set = false;
@ -1002,6 +1002,13 @@ const_set
$$ = new pascal_set_constant($2 as expression_list, @$);
//else $$ = new array_const_new($2 as expression_list, @$);
}
;
const_set
: pascal_set_const
{
$$ = $1;
}
| tkVertParen elem_list tkVertParen
{
$$ = new array_const_new($2 as expression_list, @$);
@ -2915,6 +2922,11 @@ proc_call
{
$$ = new procedure_call($1 as addressed_value, $1 is ident, @$);
}
/*| pascal_set_const tkPoint identifier_keyword_operatorname
{
var abcd = new dot_node($1 as addressed_value, $3 as addressed_value, @$);
$$ = new procedure_call(abcd as addressed_value, abcd is ident, @$);
} */
;
goto_stmt
@ -4164,6 +4176,8 @@ factor_without_unary_op
| var_reference
{ $$ = $1; }
;
factor
: tkNil
@ -4175,19 +4189,18 @@ factor
{ $$ = $1; }
| default_expr
{ $$ = $1; }
| tkSquareOpen elem_list tkSquareClose
| pascal_set_const
{
// Если elem_list пуст или содержит диапазон, то это множество, иначе массив. С PascalABC.NET 3.10
/*var is_set = false;
var el = $2 as expression_list;
if (el == null || el.Count == 0)
is_set = true;
else if (el.expressions.Count(x => x is diapason_expr_new) > 0)
is_set = true;
if (is_set)*/
$$ = new pascal_set_constant($2 as expression_list, @$);
//else $$ = new array_const_new($2 as expression_list, @$);
$$ = $1;
}
| factor tkPoint identifier_keyword_operatorname
{
$$ = new dot_node($1 as addressed_value, $3 as addressed_value, @$);
}
| factor tkRoundOpen optional_expr_list_func_param tkRoundClose
{
$$ = new method_call($1 as addressed_value,$3 as expression_list, @$);
}
| tkNot factor
{
$$ = new un_expr($2, $1.type, @$);
@ -4375,6 +4388,7 @@ variable
}
| variable_or_literal_or_number tkSquareOpen expr_list tkSquareClose
{
//$$ = NewIndexerOrSlice($1 as addressed_value,$3 as expression_list,@$);
var el = $3 as expression_list; // SSM 10/03/16
if (el.Count==1 && el.expressions[0] is format_expr)
{

File diff suppressed because it is too large Load diff

View file

@ -14,7 +14,6 @@
<name value="const_elem" />
<name value="record_const" />
<name value="const_term" />
<name value="const_set" />
<name value="relop_expr" />
<name value="as_is_expr" />
<name value="term" />
@ -43,10 +42,7 @@
<name value="const_elem_list" />
<name value="const_elem_list1" />
<name value="head_compiler_directives" />
<name value="template_param_list" />
<name value="one_or_some_attribute" />
<name value="enumeration_id_list" />
<name value="simple_type_list" />
<name value="class_attributes" />
<name value="class_attributes1" />
<name value="base_classes_names_list" />
@ -74,9 +70,7 @@
<name value="program_param" />
<name value="used_unit_name" />
<name value="abc_decl_sect" />
<name value="template_param" />
<name value="one_attribute" />
<name value="simple_type_or_" />
<name value="class_attribute" />
<name value="base_class_name" />
<name value="where_part" />
@ -103,7 +97,6 @@
<name value="assign_operator" />
</tag>
<tag value="Константные выражения">
<name value="const_set" />
<name value="const_factor" />
<name value="const_term" />
<name value="unsigned_number" />
@ -137,12 +130,10 @@
<name value="literal_list" />
</tag>
<tag value="Описания">
<name value="simple_type_decl" />
<name value="only_const_decl" />
<name value="const_decl" />
<name value="type_decl" />
<name value="const_field" />
<name value="proc_type_decl" />
<name value="method_or_property_decl" />
<name value="simple_field_or_const_definition" />
<name value="field_definition" />
@ -174,9 +165,6 @@
<name value="unit_name" />
<name value="label_name" />
<name value="const_field_name" />
<name value="type_decl_identifier" />
<name value="template_identifier_with_equal" />
<name value="simple_type_identifier" />
<name value="proc_name" />
<name value="func_name" />
<name value="func_class_name_ident" />
@ -220,22 +208,8 @@
<name value="func_header" />
</tag>
<tag value="Типы">
<name value="type_decl_type" />
<name value="type_ref" />
<name value="template_type" />
<name value="pointer_type" />
<name value="structured_type" />
<name value="unsized_array_type" />
<name value="set_type" />
<name value="file_type" />
<name value="string_type" />
<name value="procedural_type" />
<name value="object_type" />
<name value="record_type" />
<name value="proc_type_decl" />
<name value="sequence_type" />
<name value="enumeration_id" />
<name value="template_param" />
</tag>
<tag value="Ключевые слова">
<name value="meth_modificator" />
@ -250,19 +224,15 @@
</tag>
<tag value="new_expr" />
<tag value="TemplateTypeName">
<name value="type_decl_identifier" />
<name value="template_identifier_with_equal" />
<name value="func_name_ident" />
</tag>
<tag value="FuncName">
<name value="func_name" />
<name value="simple_type_identifier" />
</tag>
<tag value="Проблема с атрибутами">
<name value="type_decl_sect" />
<name value="type_decl" />
<name value="attribute_declarations" />
<name value="simple_type_decl" />
</tag>
<tag value="Лямбда-выражения">
<name value="full_lambda_fp_list" />

View file

@ -1,16 +1,19 @@
lex=ABCPascal.lex
yacc=ABCPascal.y
lexGen=D:\PABC_Git\Parsers\PascalABCParserNewSaushkin\GPLex_GPPG\Gplex.exe
yaccGen=D:\PABC_Git\Parsers\PascalABCParserNewSaushkin\GPLex_GPPG\gppg.exe
lexGen=D:\PABC_GIT\pascalabcnet\Parsers\PascalABCParserNewSaushkin\GPLex_GPPG\Gplex.exe
yaccGen=D:\PABC_GIT\pascalabcnet\Parsers\PascalABCParserNewSaushkin\GPLex_GPPG\gppg.exe
lexGenOpt=/unicode
yaccGenOpt=/gplex
useCustomScript
script=
"D:\PABC_Git\Parsers\PascalABCParserNewSaushkin\GPLex_GPPG\gplex.exe" /unicode "D:\PABC_Git\Parsers\PascalABCParserNewSaushkin\ABCPascal.lex"
"D:\PABC_GIT\pascalabcnet\Parsers\PascalABCParserNewSaushkin\GPLex_GPPG\gplex.exe" /unicode "D:\PABC_Git\Parsers\PascalABCParserNewSaushkin\ABCPascal.lex"
"D:\PABC_GIT\pascalabcnet\Parsers\PascalABCParserNewSaushkin\GPLex_GPPG\gppg.exe" /no-lines /gplex "D:\PABC_Git\Parsers\PascalABCParserNewSaushkin\ABCPascal.y"
"D:\PABC_GIT\pascalabcnet\Parsers\PascalABCParserNewSaushkin\convert4.exe"
"D:\PABC_Git\Parsers\PascalABCParserNewSaushkin\GPLex_GPPG\gppg.exe" /no-lines /gplex "D:\PABC_Git\Parsers\PascalABCParserNewSaushkin\ABCPascal.y"
"D:\PABC_Git\Parsers\PascalABCParserNewSaushkin\convert4.exe"

View file

@ -1,6 +1,7 @@
// Copyright (c) Ivan Bondarev, Stanislav Mikhalkovich (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using QUT.Gppg;
@ -566,6 +567,52 @@ namespace Languages.Pascal.Frontend.Core
return sl;
}/**/
public expression NewIndexerOrSlice(addressed_value av, expression_list el, LexLocation loc)
{
if (el.Count == 1 && el.expressions[0] is format_expr)
{
var fe = el.expressions[0] as format_expr;
if (!parserTools.buildTreeForFormatter)
{
if (fe.expr == null)
fe.expr = new int32_const(int.MaxValue,el.source_context);
if (fe.format1 == null)
fe.format1 = new int32_const(int.MaxValue, el.source_context);
}
return new slice_expr(av, fe.expr, fe.format1, fe.format2, el.source_context);
}
// многомерные срезы
else if (el.expressions.Any(e => e is format_expr))
{
// Срезы многомерных массивов разрешены только для массивов размерности < 5
if (el.expressions.Count > 4)
parserTools.AddErrorFromResource("SLICES_OF MULTIDIMENSIONAL_ARRAYS_ALLOW_ONLY_FOR_RANK_LT_5",loc);
var ll = new List<Tuple<expression, expression, expression>>();
foreach (var ex in el.expressions)
{
if (ex is format_expr fe)
{
if (fe.expr == null)
fe.expr = new int32_const(int.MaxValue, fe.source_context);
if (fe.format1 == null)
fe.format1 = new int32_const(int.MaxValue, fe.source_context);
if (fe.format2 == null)
fe.format2 = new int32_const(1, fe.source_context);
ll.Add(Tuple.Create(fe.expr, fe.format1, fe.format2));
}
else
{
// скалярное значение вместо среза
ll.Add(Tuple.Create(ex, (expression)new int32_const(0, ex.source_context), (expression)new int32_const(int.MaxValue, ex.source_context)));
}
}
var sle = new slice_expr(av, null, null, null,loc);
sle.slices = ll;
return sle;
}
else return new indexer(av, el, loc);
}
public procedure_definition CreateAndAddToClassReadFunc(expression ex, ident id, SourceContext sc)
{
var fd = SyntaxTreeBuilder.BuildShortFuncDefinition(new formal_parameters(), null, new method_name(id.name, sc), new no_type(), ex, sc);

View file

@ -1,5 +1,5 @@
cls
GPLex_GPPG\gplex.exe /unicode ABCPascal.lex
GPLex_GPPG\gppg.exe /no-lines /gplex ABCPascal.y
GPLex_GPPG\gppg.exe /report /no-lines /gplex ABCPascal.y
convert4.exe
pause

View file

@ -1 +1 @@
3.10.1.3589
3.10.2.3593

View file

@ -1 +1 @@
!define VERSION '3.10.2.3589'
!define VERSION '3.10.2.3593'

View file

@ -14832,30 +14832,31 @@ begin
Result := (Self[0], Self[1], Self[2], Self[3], Self[4], Self[5], v);
end;
/// Выводит кортеж
/// Выводит кортеж на экран, после чего выводит пробел
procedure Print<T1, T2>(Self: (T1, T2)); extensionmethod := Print(Self);
/// Выводит кортеж
/// Выводит кортеж на экран, после чего выводит пробел
procedure Print<T1, T2, T3>(Self: (T1, T2, T3)); extensionmethod := Print(Self);
/// Выводит кортеж
/// Выводит кортеж на экран, после чего выводит пробел
procedure Print<T1, T2, T3, T4>(Self: (T1, T2, T3, T4)); extensionmethod := Print(Self);
/// Выводит кортеж
/// Выводит кортеж на экран, после чего выводит пробел
procedure Print<T1, T2, T3, T4, T5>(Self: (T1, T2, T3, T4, T5)); extensionmethod := Print(Self);
/// Выводит кортеж
/// Выводит кортеж на экран, после чего выводит пробел
procedure Print<T1, T2, T3, T4, T5, T6>(Self: (T1, T2, T3, T4, T5, T6)); extensionmethod := Print(Self);
/// Выводит кортеж
/// Выводит кортеж на экран, после чего выводит пробел
procedure Print<T1, T2, T3, T4, T5, T6, T7>(Self: (T1, T2, T3, T4, T5, T6, T7)); extensionmethod := Print(Self);
/// Выводит кортеж и переходит на новую строку
/// Выводит кортеж на экран и переходит на новую строку
procedure Println<T1, T2>(Self: (T1, T2)); extensionmethod := Println(Self);
/// Выводит кортеж и переходит на новую строку
/// Выводит кортеж на экран и переходит на новую строку
procedure Println<T1, T2, T3>(Self: (T1, T2, T3)); extensionmethod := Println(Self);
/// Выводит кортеж и переходит на новую строку
/// Выводит кортеж на экран и переходит на новую строку
procedure Println<T1, T2, T3, T4>(Self: (T1, T2, T3, T4)); extensionmethod := Println(Self);
/// Выводит кортеж и переходит на новую строку
/// Выводит кортеж на экран и переходит на новую строку
procedure Println<T1, T2, T3, T4, T5>(Self: (T1, T2, T3, T4, T5)); extensionmethod := Println(Self);
/// Выводит кортеж и переходит на новую строку
/// Выводит кортеж на экран и переходит на новую строку
procedure Println<T1, T2, T3, T4, T5, T6>(Self: (T1, T2, T3, T4, T5, T6)); extensionmethod := Println(Self);
/// Выводит кортеж и переходит на новую строку
/// Выводит кортеж на экран и переходит на новую строку
procedure Println<T1, T2, T3, T4, T5, T6, T7>(Self: (T1, T2, T3, T4, T5, T6, T7)); extensionmethod := Println(Self);
/// Преобразует кортеж элементов одного типа в массив
function ToArray<T>(Self: (T,T)): array of T; extensionmethod := |Self[0],Self[1]|;
/// Преобразует кортеж элементов одного типа в массив

View file

@ -127,10 +127,6 @@ begin
max := x
end;
/// Возвращает все перестановки
function Prm<T>(Self: array of T): sequence of array of T; extensionmethod
:= Self.Permutations;
/// Возвращает все сочетания по m элементов
function Cmb<T>(Self: array of T; m: integer): sequence of array of T; extensionmethod
:= Self.Combinations(m);
@ -281,42 +277,67 @@ procedure Tr<T>(a: array of T; transform: T->T) := a.Transform(transform);
function H<T>(Self: array of T): integer; extensionmethod := Self.High;
/// Возвращает все перестановки множества элементов, заданного массивом
function Prm<T>(Self: array of T): sequence of array of T; extensionmethod := Self.Permutations;
function Prm<T>(Self: array of T): sequence of array of T; extensionmethod
:= Self.Permutations;
/// Возвращает все перестановки множества элементов, заданного массивом
function Prm<T>(Self: sequence of T): sequence of array of T; extensionmethod := Self.Permutations;
function Prm<T>(Self: sequence of T): sequence of array of T; extensionmethod
:= Self.Permutations;
/// Возвращает все частичные перестановки из n элементов по m
function Prm<T>(Self: array of T; m: integer): sequence of array of T; extensionmethod := Self.Permutations(m);
function Prm<T>(Self: array of T; m: integer): sequence of array of T; extensionmethod
:= Self.Permutations(m);
/// Возвращает все частичные перестановки из n элементов по m
function Prm<T>(Self: sequence of T; m: integer): sequence of array of T; extensionmethod := Self.Permutations(m);
function Prm<T>(Self: sequence of T; m: integer): sequence of array of T; extensionmethod
:= Self.Permutations(m);
/// Возвращает все перестановки букв в строке в виде последовательности строк
function Prm(Self: string): sequence of string; extensionmethod
:= Self.Permutations;
/// Возвращает все частичные перестановки букв строки по m символов в виде последовательности строк
function Prm(Self: string; m: integer): sequence of string; extensionmethod
:= Self.Permutations(m);
/// Возвращает n-тую декартову степень множества элементов, заданного массивом
function Cart<T>(Self: array of T; n: integer): sequence of array of T; extensionmethod := Self.Cartesian(n);
function Cart<T>(Self: array of T; n: integer): sequence of array of T; extensionmethod
:= Self.Cartesian(n);
/// Возвращает n-тую декартову степень множества элементов, заданного массивом
function Cart<T>(Self: sequence of T; n: integer): sequence of array of T; extensionmethod := Self.Cartesian(n);
function Cart<T>(Self: sequence of T; n: integer): sequence of array of T; extensionmethod
:= Self.Cartesian(n);
/// Возвращает n-тую декартову степень множества символов, заданного строкой
function Cart(Self: string; n: integer): sequence of string; extensionmethod := Self.CartesianPower(n);
function Cart(Self: string; n: integer): sequence of string; extensionmethod
:= Self.CartesianPower(n);
/// Возвращает декартово произведение последовательностей в виде последовательности пар
function Cart<T, T1>(Self: sequence of T; b: sequence of T1): sequence of (T, T1); extensionmethod := Self.Cartesian(b);
function Cart<T, T1>(Self: sequence of T; b: sequence of T1): sequence of (T, T1); extensionmethod
:= Self.Cartesian(b);
/// Возвращает декартово произведение последовательностей, проектируя каждую пару на значение
function Cart<T, T1, T2>(Self: sequence of T; b: sequence of T1; func: (T,T1)->T2): sequence of T2; extensionmethod := Self.Cartesian(b,func);
function Cart<T, T1, T2>(Self: sequence of T; b: sequence of T1; func: (T,T1)->T2): sequence of T2; extensionmethod
:= Self.Cartesian(b,func);
/// Возвращает все сочетания по m элементов
function Cmb<T>(Self: array of T; m: integer): sequence of array of T; extensionmethod
:= Self.Combinations(m);
/// Возвращает все сочетания по m элементов
function Cmb<T>(Self: sequence of T; m: integer): sequence of array of T; extensionmethod
:= Self.Combinations(m);
/// Возвращает все сочетания по m элементов
function Cmb(Self: string; m: integer): sequence of string; extensionmethod
:= Self.Combinations(m);
/// Возвращает исходную последовательность или одноэлементную последовательность если исходная последовательность пуста
function DefIfE<T>(Self: sequence of T; def: T): sequence of T; extensionmethod := Self.DefaultIfEmpty(def);
/// Возвращает все сочетания по m элементов
function Cmb<T>(Self: array of T; m: integer): sequence of array of T; extensionmethod := Self.Combinations(m);
/// Возвращает все сочетания по m элементов
function Cmb<T>(Self: sequence of T; m: integer): sequence of array of T; extensionmethod := Self.Combinations(m);
/// Выводит кортеж
/// Выводит кортеж на экран, после чего выводит пробел
function Pr<T1,T2>(Self: (T1,T2)): (T1,T2); extensionmethod;
begin
Result := Self;