Added support for floating point types

This commit is contained in:
Emmanuel Briot 2022-10-21 15:15:57 +02:00
parent 8f3c5919a7
commit cac7dd6bec
2 changed files with 176 additions and 8 deletions

View File

@ -37,7 +37,8 @@ Derived type
================================================================================ ================================================================================
package P is package P is
type B is new Integer; type B is new Integer
with Size => 8;
end P; end P;
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -54,6 +55,138 @@ end P;
(derived_type_definition (derived_type_definition
(subtype_indication (subtype_indication
(name (name
(identifier))))))) (identifier)))))
(aspect_specification
(aspect_mark_list
(aspect_association
(aspect_mark
(identifier))
(aspect_definition
(expression
(relation
(simple_expression
(term
(factor
(primary
(numeric_literal)))))))))))))
(name
(identifier)))))
================================================================================
Modular types
================================================================================
package P is
type C is mod 256;
end P;
--------------------------------------------------------------------------------
(compilation
(compilation_unit
(package_specification
(name
(identifier))
(type_declaration
(full_type_declaration
(identifier)
(type_definition
(integer_type_definition
(modular_type_definition
(expression
(relation
(simple_expression
(term
(factor
(primary
(numeric_literal))))))))))))
(name
(identifier)))))
================================================================================
Fixed points
================================================================================
package P is
type B is new Float range 0.0 .. 1.0;
type D is delta 0.1 digits 8;
type E is delta 0.1 range 0.0 .. 1.0;
end P;
--------------------------------------------------------------------------------
(compilation
(compilation_unit
(package_specification
(name
(identifier))
(type_declaration
(full_type_declaration
(identifier)
(type_definition
(derived_type_definition
(subtype_indication
(name
(identifier))
(constraint
(scalar_constraint
(range_constraint
(range_g
(simple_expression
(term
(factor
(primary
(numeric_literal)))))
(simple_expression
(term
(factor
(primary
(numeric_literal))))))))))))))
(type_declaration
(full_type_declaration
(identifier)
(type_definition
(real_type_definition
(fixed_point_definition
(decimal_fixed_point_definition
(expression
(relation
(simple_expression
(term
(factor
(primary
(numeric_literal)))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(numeric_literal)))))))))))))
(type_declaration
(full_type_declaration
(identifier)
(type_definition
(real_type_definition
(fixed_point_definition
(ordinary_fixed_point_definition
(expression
(relation
(simple_expression
(term
(factor
(primary
(numeric_literal)))))))
(real_range_specification
(simple_expression
(term
(factor
(primary
(numeric_literal)))))
(simple_expression
(term
(factor
(primary
(numeric_literal))))))))))))
(name (name
(identifier))))) (identifier)))))

View File

@ -568,7 +568,7 @@ module.exports = grammar({
// optional($.known_discriminant_part), // optional($.known_discriminant_part),
reservedWord('is'), reservedWord('is'),
$.type_definition, $.type_definition,
// optional($.aspect_specification), optional($.aspect_specification),
';', ';',
), ),
// $.task_type_declaration, // $.task_type_declaration,
@ -577,7 +577,7 @@ module.exports = grammar({
type_definition: $ => choice( type_definition: $ => choice(
// $.enumeration_type_definition, // $.enumeration_type_definition,
$.integer_type_definition, $.integer_type_definition,
// $.real_type_definition, $.real_type_definition,
// $.array_type_definition, // $.array_type_definition,
// $.record_type_definition, // $.record_type_definition,
// $.access_type_definition, // $.access_type_definition,
@ -586,7 +586,42 @@ module.exports = grammar({
), ),
integer_type_definition: $ => choice( integer_type_definition: $ => choice(
$.signed_integer_type_definition, $.signed_integer_type_definition,
// $.modular_type_definition, $.modular_type_definition,
),
modular_type_definition: $ => seq(
reservedWord('mod'),
$.expression,
),
real_type_definition: $ => choice(
$.floating_point_definition,
$.fixed_point_definition,
),
floating_point_definition: $ => seq(
reservedWord('digits'),
$.expression,
optional($.real_range_specification),
),
real_range_specification: $ => seq(
reservedWord('range'),
$.simple_expression,
'..',
$.simple_expression,
),
fixed_point_definition: $ => choice(
$.ordinary_fixed_point_definition,
$.decimal_fixed_point_definition,
),
decimal_fixed_point_definition: $ => seq(
reservedWord('delta'),
$.expression,
reservedWord('digits'),
$.expression,
optional($.real_range_specification),
),
ordinary_fixed_point_definition: $ => seq(
reservedWord('delta'),
$.expression,
$.real_range_specification,
), ),
signed_integer_type_definition: $ => seq( signed_integer_type_definition: $ => seq(
reservedWord('range'), reservedWord('range'),
@ -594,7 +629,7 @@ module.exports = grammar({
'..', '..',
$.simple_expression, $.simple_expression,
), ),
derived_type_definition: $ => seq( derived_type_definition: $ => prec.left(seq(
optional(reservedWord('abstract')), optional(reservedWord('abstract')),
optional(reservedWord('limited')), optional(reservedWord('limited')),
reservedWord('new'), reservedWord('new'),
@ -606,7 +641,7 @@ module.exports = grammar({
// )), // )),
$.record_extension_part, $.record_extension_part,
)), )),
), )),
record_extension_part: $ => seq( record_extension_part: $ => seq(
reservedWord('with'), reservedWord('with'),
$.record_definition, $.record_definition,