Версия с неверно форматирующимся

##
{asg}
uses School;

procedure p := Print(1);

p;

Код с ### пока без процедур и функций
This commit is contained in:
Mikhalkovich Stanislav 2021-02-27 23:44:07 +03:00
parent 05f158875d
commit c77b124cce
20 changed files with 3869 additions and 3706 deletions

View file

@ -1679,13 +1679,14 @@ namespace CodeFormatters
public override void visit(program_module _program_module)
{
// Где-то хранить и добавить ##
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)
{
if (_program_module.program_block != null && _program_module.program_block.program_code.left_logical_bracket.text.StartsWith("##"))
/*if (_program_module.program_block != null && _program_module.program_block.program_code.left_logical_bracket.text.StartsWith("##"))
;
else visit_node(_program_module.used_units);
else*/ visit_node(_program_module.used_units);
}
if (_program_module.program_block != null)
visit_node(_program_module.program_block);

View file

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

View file

@ -1,4 +1,4 @@
%COREVERSION%=2
%REVISION%=2830
%REVISION%=2838
%MINOR%=7
%MAJOR%=3

Binary file not shown.

View file

@ -2,7 +2,7 @@
// This CSharp output file generated by Gardens Point LEX
// Version: 1.1.3.301
// Machine: DESKTOP-G8V08V4
// DateTime: 24.02.2021 14:31:41
// DateTime: 27.02.2021 21:02:16
// UserName: ?????????
// GPLEX input file <ABCPascal.lex>
// GPLEX frame file <embedded resource>

View file

@ -70,6 +70,7 @@
%type <stn> case_stmt
%type <stn> case_list
%type <stn> program_decl_sect_list int_decl_sect_list1 inclass_decl_sect_list1 interface_decl_sect_list decl_sect_list decl_sect_list1 inclass_decl_sect_list
%type <stn> decl_sect_list_proc_func_only
%type <stn> field_or_const_definition abc_decl_sect decl_sect int_decl_sect type_decl simple_type_decl simple_field_or_const_definition res_str_decl_sect
%type <stn> method_decl_withattr method_or_property_decl property_definition fp_sect
%type <ex> default_expr tuple
@ -159,7 +160,7 @@
%type <stn> template_param_list template_empty_param_list template_type_params template_type_empty_params
%type <td> template_type
%type <stn> try_stmt
%type <stn> uses_clause used_units_list
%type <stn> uses_clause used_units_list uses_clause_one uses_clause_one_or_empty
%type <stn> unit_file
%type <stn> used_unit_name
%type <stn> unit_header
@ -188,15 +189,17 @@ parse_goal
{ root = $1; }
| parts
{ root = $1; }
| tkShortProgram uses_clause stmt_list
| tkShortProgram uses_clause_one_or_empty decl_sect_list_proc_func_only stmt_list
{
var stl = $3 as statement_list;
var stl = $4 as statement_list;
stl.left_logical_bracket = $1;
stl.right_logical_bracket = new token_info("");
var ul = $2 as uses_list;
root = $$ = NewProgramModule(null, null, ul, new block(null, stl, @$), new token_info(""), @$);
SourceContext sc3 = @3;
SourceContext sc4 = @4;
root = $$ = NewProgramModule(null, null, ul, new block($3 as declarations, stl, @4), new token_info(""), @$);
}
| tkShortSFProgram uses_clause stmt_list
| tkShortSFProgram uses_clause_one stmt_list
{
var stl = $3 as statement_list;
stl.left_logical_bracket = $1;
@ -330,21 +333,43 @@ ident_or_keyword_pointseparator_list
}
;
uses_clause_one
: tkUses used_units_list tkSemiColon
{
$$ = $2;
$$.source_context = @$;
}
;
uses_clause_one_or_empty
:
{
$$ = null;
}
| uses_clause_one
{
if (parsertools.build_tree_for_formatter)
$$ = new uses_closure($1 as uses_list,@$);
$$ = $1;
}
;
uses_clause
:
{
$$ = null;
}
| uses_clause tkUses used_units_list tkSemiColon
| uses_clause uses_clause_one
{
if (parsertools.build_tree_for_formatter)
{
if ($1 == null)
{
$$ = new uses_closure($3 as uses_list,@$);
$$ = new uses_closure($2 as uses_list,@$);
}
else {
($1 as uses_closure).AddUsesList($3 as uses_list,@$);
($1 as uses_closure).AddUsesList($2 as uses_list,@$);
$$ = $1;
}
}
@ -352,12 +377,12 @@ uses_clause
{
if ($1 == null)
{
$$ = $3;
$$ = $2;
$$.source_context = @$;
}
else
{
($1 as uses_list).AddUsesList($3 as uses_list,@$);
($1 as uses_list).AddUsesList($2 as uses_list,@$);
$$ = $1;
$$.source_context = @$;
}
@ -497,6 +522,28 @@ decl_sect_list
}
;
decl_sect_list_proc_func_only
:
{
$$ = new declarations();
if (GlobalDecls==null)
GlobalDecls = $$ as declarations;
}
| decl_sect_list_proc_func_only proc_func_decl_noclass
{
var dcl = $1 as declarations;
if (dcl.Count == 0)
$$ = dcl.Add($2 as declaration, @2);
else
{
var sc = dcl.source_context;
sc = sc.Merge($2.source_context);
$$ = dcl.Add($2 as declaration, @2);
$$.source_context = sc;
}
}
;
decl_sect_list1
:
{

File diff suppressed because it is too large Load diff

View file

@ -232,7 +232,6 @@
<name value="const_decl_sect" />
<name value="res_str_decl_sect" />
<name value="type_decl_sect" />
<name value="uses_clause" />
<name value="interface_part" />
<name value="implementation_part" />
<name value="abc_interface_part" />

View file

@ -313,6 +313,8 @@ script=

View file

@ -1 +1 @@
3.7.2.2830
3.7.2.2838

View file

@ -1 +1 @@
!define VERSION '3.7.2.2830'
!define VERSION '3.7.2.2838'

View file

@ -32,10 +32,12 @@ namespace SyntaxVisitors.SugarVisitors
eel.Add(sl1);
IndexVisitor.New.ProcessNode(sl1); // индексный визитор сам не вызывается поскольку в многомерных срезах хранится List кортежей троек expression, который сам не обходится
var sl2 = slice.Item2;
eel.Add(slice.Item2);
eel.Add(sl2);
IndexVisitor.New.ProcessNode(sl2);
var sl3 = slice.Item3; // и step тоже надо обходить!!!
eel.Add(sl3);
IndexVisitor.New.ProcessNode(sl3);
eel.Add(slice.Item3);
var mc = new method_call(tup, eel, sc); // sc - не очень хорошо - ошибка будет в общем месте
el.Add(mc);
// по идее все параметры готовы. Надо только проверить, что они целые

View file

@ -10026,7 +10026,7 @@ begin
Result := Self.Reverse.Skip(count).Reverse;
end;
/// Декартово произведение последовательностей
/// Возвращает декартово произведение последовательностей в виде последовательности пар
function Cartesian<T, T1>(Self: sequence of T; b: sequence of T1): sequence of (T, T1); extensionmethod;
begin
if b = nil then
@ -10037,7 +10037,7 @@ begin
yield (x, y)
end;
/// Декартово произведение последовательностей
/// Возвращает декартово произведение последовательностей, проектируя каждую пару на значение
function Cartesian<T, T1, T2>(Self: sequence of T; b: sequence of T1; func: (T,T1)->T2): sequence of T2; extensionmethod;
begin
if b = nil then

View file

@ -24,6 +24,7 @@ type
ProcI = int -> ();
ProcR = real -> ();
ProcS = string -> ();
HS<T> = HashSet<T>;
procedure Pr(params a: array of object) := Print(a);
procedure Pr(o: object) := Print(o);
@ -216,6 +217,10 @@ function Agr<T,TAcc>(Self: sequence of T; seed: TAcc; func: (TAcc,T)->TAcc): TAc
/// Фильтрует последовательность по условию cond
function Wh<T>(Self: sequence of T; cond: T->boolean): sequence of T; extensionmethod := Self.Where(cond);
/// Группирует элементы последовательности в соответствии с заданной функцией проекции на ключ группы
function GrBy<T,TKey>(Self: sequence of T; selector: T->TKey): sequence of System.Linq.IGrouping<TKey,T>; extensionmethod := Self.GroupBy(selector);
/// Преобразует последовательность в массив
function ToA<T>(Self: sequence of T): array of T; extensionmethod := Self.ToArray;
@ -227,10 +232,6 @@ function ToHS<T>(Self: sequence of T): HashSet<T>; extensionmethod := Self.ToHas
/// Преобразует последовательность в SortedSet
function ToSS<T>(Self: sequence of T): SortedSet<T>; extensionmethod := Self.ToSortedSet;
/// Преобразует последовательность в HashSet
function HS<T>(s: sequence of T): HashSet<T> := s.ToHashSet;
/// Преобразует последовательность в SortedSet
function SS<T>(s: sequence of T): SortedSet<T> := s.ToSortedSet;
/// Инвертирует последовательность
procedure Rev<T>(a: array of T) := Reverse(a);
@ -280,6 +281,15 @@ function Cart<T>(Self: array of T; n: integer): sequence of array of T; extensio
/// Возвращает n-тую декартову степень множества элементов, заданного массивом
function Cart<T>(Self: sequence of T; n: integer): sequence of array of T; extensionmethod := Self.Cartesian(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, T2>(Self: sequence of T; b: sequence of T1; func: (T,T1)->T2): sequence of T2; extensionmethod := Self.Cartesian(b,func);
/// Возвращает исходную последовательность или одноэлементную последовательность если исходная последовательность пуста
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);

View file

@ -26,5 +26,5 @@ begin
AssertEq(m[1,:],|5,6,7,8|);
AssertEq(m[^1,:],|9,10,11,12|);
AssertEq(m[:,^1],|4,8,12|);
Print(m[:,^1]);
//Print(m[:,^1]);
end.

View file

@ -74,14 +74,37 @@ namespace PascalABCCompiler.TreeConverter
}
}
void CheckInteger(expression ex)
{
if (ex == null)
return;
var semex = convert_strong(ex);
var b = convertion_data_and_alghoritms.can_convert_type(semex, SystemLibrary.SystemLibrary.integer_type);
if (!b)
AddError(get_location(ex), "INTEGER_VALUE_EXPECTED");
}
void CheckIntegerOrIndex(expression ex)
{
var semex = convert_strong(ex);
var b = convertion_data_and_alghoritms.can_convert_type(semex, SystemLibrary.SystemLibrary.integer_type);
var toIsIndex = (semex is common_constructor_call toCall) &&
toCall.common_type.comprehensive_namespace.namespace_full_name.Equals("PABCSystem") &&
toCall.common_type.PrintableName.Equals("SystemIndex");
var toIsIndex1 = (semex is compiled_constructor_call toCall1) &&
toCall1.compiled_type.compiled_type.FullName.Equals("PABCSystem.SystemIndex");
if (!b && !toIsIndex && !toIsIndex1)
{
AddError(get_location(ex), "INTEGER_VALUE_EXPECTED" + semex);
}
}
void semantic_check_method_call_as_slice_expr(SyntaxTree.method_call mc)
// нельзя проверять сахарный узел, т.к.могут быть вложенные сахарные expression!!
{
var v = (mc.dereferencing_value as dot_node).left;
var from = mc.parameters.expressions[1] as expression;
var to = mc.parameters.expressions[2] as expression;
expression step = mc.parameters.expressions.Count > 3 ? mc.parameters.expressions[3] : null;
var semvar = convert_strong(v);
if (semvar is typed_expression)
semvar = convert_typed_expression_to_function_call(semvar as typed_expression);
@ -108,38 +131,49 @@ namespace PascalABCCompiler.TreeConverter
if (IsSlicedType == 0)
AddError(get_location(v), "BAD_SLICE_OBJECT");
var semfrom = convert_strong(from);
var b = convertion_data_and_alghoritms.can_convert_type(semfrom, SystemLibrary.SystemLibrary.integer_type);
var fromIsIndex = (semfrom is common_constructor_call fromCall) &&
fromCall.common_type.comprehensive_namespace.namespace_full_name.Equals("PABCSystem") &&
fromCall.common_type.PrintableName.Equals("SystemIndex");
if (!b && !fromIsIndex)
AddError(get_location(from), "INTEGER_VALUE_EXPECTED");
// semantic tree - type special kind
// staticSystemLib посмотреть.
// SystemIndex - переименовать.
var semto = convert_strong(to);
b = convertion_data_and_alghoritms.can_convert_type(semto, SystemLibrary.SystemLibrary.integer_type);
var toIsIndex = (semto is common_constructor_call toCall) &&
toCall.common_type.comprehensive_namespace.namespace_full_name.Equals("PABCSystem") &&
toCall.common_type.PrintableName.Equals("SystemIndex");
if (!b && !toIsIndex)
AddError(get_location(to), "INTEGER_VALUE_EXPECTED");
if (step != null)
{
var semstep = convert_strong(step);
b = convertion_data_and_alghoritms.can_convert_type(semstep, SystemLibrary.SystemLibrary.integer_type);
if (!b)
AddError(get_location(step), "INTEGER_VALUE_EXPECTED");
}
var from = mc.parameters.expressions[1];
var to = mc.parameters.expressions[2];
expression step = mc.parameters.expressions.Count > 3 ? mc.parameters.expressions[3] : null;
CheckIntegerOrIndex(from);
CheckIntegerOrIndex(to);
CheckInteger(step);
}
void semantic_check_method_call_as_slice_expr_multi(SyntaxTree.method_call mc)
{
var v = (mc.dereferencing_value as dot_node).left;
var semvar = convert_strong(v);
if (semvar is typed_expression)
semvar = convert_typed_expression_to_function_call(semvar as typed_expression);
if (semvar.type.type_special_kind != SemanticTree.type_special_kind.array_kind)
AddError(semvar.location, "SLICES_MULTI_DIMENSIONAL_ARRAY_EXPECTED");
// Теперь с размерностями разберёмся
int rank = 0;
if (semvar.type is compiled_type_node)
rank = (semvar.type as compiled_type_node).rank;
else if (semvar.type is common_type_node)
rank = (semvar.type as common_type_node).rank;
if (rank != mc.parameters.Count)
AddError(semvar.location, "NUMBER_OF_SLICES_IN_MULTIDIMENSIONAL_ARRAY_SHOULD_BE_EQUAL_TO_ARRAY_RANK");
foreach (var param in mc.parameters.expressions)
{
var p = param as method_call; // Tuple.Create
if (p == null)
AddError(semvar.location, "_Compiler_error_param_must_be_Tuple");
var from = p.parameters.expressions[0];
var to = p.parameters.expressions[1];
var step = p.parameters.expressions[2];
CheckIntegerOrIndex(from);
CheckIntegerOrIndex(to);
CheckInteger(step);
}
}
/*void semantic_check_tuple(SyntaxTree.tuple_node tup)

View file

@ -10026,7 +10026,7 @@ begin
Result := Self.Reverse.Skip(count).Reverse;
end;
/// Декартово произведение последовательностей
/// Возвращает декартово произведение последовательностей в виде последовательности пар
function Cartesian<T, T1>(Self: sequence of T; b: sequence of T1): sequence of (T, T1); extensionmethod;
begin
if b = nil then
@ -10037,7 +10037,7 @@ begin
yield (x, y)
end;
/// Декартово произведение последовательностей
/// Возвращает декартово произведение последовательностей, проектируя каждую пару на значение
function Cartesian<T, T1, T2>(Self: sequence of T; b: sequence of T1; func: (T,T1)->T2): sequence of T2; extensionmethod;
begin
if b = nil then

View file

@ -24,6 +24,7 @@ type
ProcI = int -> ();
ProcR = real -> ();
ProcS = string -> ();
HS<T> = HashSet<T>;
procedure Pr(params a: array of object) := Print(a);
procedure Pr(o: object) := Print(o);
@ -216,6 +217,10 @@ function Agr<T,TAcc>(Self: sequence of T; seed: TAcc; func: (TAcc,T)->TAcc): TAc
/// Фильтрует последовательность по условию cond
function Wh<T>(Self: sequence of T; cond: T->boolean): sequence of T; extensionmethod := Self.Where(cond);
/// Группирует элементы последовательности в соответствии с заданной функцией проекции на ключ группы
function GrBy<T,TKey>(Self: sequence of T; selector: T->TKey): sequence of System.Linq.IGrouping<TKey,T>; extensionmethod := Self.GroupBy(selector);
/// Преобразует последовательность в массив
function ToA<T>(Self: sequence of T): array of T; extensionmethod := Self.ToArray;
@ -227,10 +232,6 @@ function ToHS<T>(Self: sequence of T): HashSet<T>; extensionmethod := Self.ToHas
/// Преобразует последовательность в SortedSet
function ToSS<T>(Self: sequence of T): SortedSet<T>; extensionmethod := Self.ToSortedSet;
/// Преобразует последовательность в HashSet
function HS<T>(s: sequence of T): HashSet<T> := s.ToHashSet;
/// Преобразует последовательность в SortedSet
function SS<T>(s: sequence of T): SortedSet<T> := s.ToSortedSet;
/// Инвертирует последовательность
procedure Rev<T>(a: array of T) := Reverse(a);
@ -280,6 +281,15 @@ function Cart<T>(Self: array of T; n: integer): sequence of array of T; extensio
/// Возвращает n-тую декартову степень множества элементов, заданного массивом
function Cart<T>(Self: sequence of T; n: integer): sequence of array of T; extensionmethod := Self.Cartesian(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, T2>(Self: sequence of T; b: sequence of T1; func: (T,T1)->T2): sequence of T2; extensionmethod := Self.Cartesian(b,func);
/// Возвращает исходную последовательность или одноэлементную последовательность если исходная последовательность пуста
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);

View file

@ -46,4 +46,6 @@ STATIC_CLASS_CANNOT_HAVE_PREDEFINITION=Static class cannot be predefined
OPERATIONS_CANNOT_BE_CALLED_USING_THIS_SYNTAX=Operations cannot be called using this syntax
MEMBER_{0}_OF_TYPE_{1}_CANNOT_BE_FOUND_IN_THE_CONTEEXT_OF_FUNCTION_WITH_YIELD=Name {0} cannot be found in type {1} in the context of function with yield statement
UNCOMPARABLE_TYPES_IN_ARRAY_CONST=Uncomparable types in array initializers
IMPOSSIBLE_TO_CONVERT_ARRAY_CONST_TO_{0}=It is impossible to convert array initializer to type {0}
IMPOSSIBLE_TO_CONVERT_ARRAY_CONST_TO_{0}=It is impossible to convert array initializer to type {0}
SLICES_MULTI_DIMENSIONAL_ARRAY_EXPECTED=Multidimensional slices are allowed for multidimensional arrays only
NUMBER_OF_SLICES_IN_MULTIDIMENSIONAL_ARRAY_SHOULD_BE_EQUAL_TO_ARRAY_RANK=Number of slices in multidimensional array should be equal to the array rank

View file

@ -46,4 +46,6 @@ STATIC_CLASS_CANNOT_HAVE_PREDEFINITION=Статический класс не м
OPERATIONS_CANNOT_BE_CALLED_USING_THIS_SYNTAX=Операции нельзя вызывать, используя данный синтаксис
MEMBER_{0}_OF_TYPE_{1}_CANNOT_BE_FOUND_IN_THE_CONTEEXT_OF_FUNCTION_WITH_YIELD=Имя {0} не удаётся найти в типе {1} в контексте функции с оператором yield
UNCOMPARABLE_TYPES_IN_ARRAY_CONST=Несовместимые типы при задании массива
IMPOSSIBLE_TO_CONVERT_ARRAY_CONST_TO_{0}=Невозможно преобразовать инициализатор массива к типу {0}
IMPOSSIBLE_TO_CONVERT_ARRAY_CONST_TO_{0}=Невозможно преобразовать инициализатор массива к типу {0}
SLICES_MULTI_DIMENSIONAL_ARRAY_EXPECTED=Многмерные срезы доступны только для многомерных массивов
NUMBER_OF_SLICES_IN_MULTIDIMENSIONAL_ARRAY_SHOULD_BE_EQUAL_TO_ARRAY_RANK=Количество срезов или индексов многомерного массива должно совпадать с количеством размерностей этого массива