Conditional Expressions and/or Operator

Proposal Editing Information

Language Change Specification Link

TopLCS2016_036: Implementation 1.

LCS2016_036a: New implementation based on "when"/selected signal assignment.

Requirement Summary

See prior work at FT10A. Rejected due to ambuguity introduced by the comma (","). Could use "else" instead of "," to create a general syntax.

Main issue missing is conditional expressions in a declaration, otherwise, a conditional assignment is possible. Does the feature also need to work in additional contexts, such as a port map or parameter association.

Can be language syntax, or a subprogram with anonymous IO.

Related Issues:

Current Problems / Issues

Implementation 1: Language Syntax

Can be implemented with language syntax using the same syntax as conditional assignment:

constant T : time := 1 ns if gA_VAL = '1' else 10 ns ;

No parser-generator conflicts were detected when expanding the grammar of an existing compiler with the above syntax. The expansion consists of the following additional rule:

<expression> ::= '?' '?' <primary>
               | <logical_expression> 'if' <expression> 'else' <logical_expression>
               | <logical_expression>

The change expands the definition of <expression> so that anywhere that an expression is valid, a conditional expression can also appear.

-- JimLewis - 2014-11-26

On comp.lang.vhdl, Allan Herriman noted that a BNF production for "conditional expressions" is already defined. Although it allows leaving out the else which implies "unaffected".

conditional_expressions ::=
    expression when condition
    { else expression when condition }
    [ else expression ]

Implementation 2: Language Syntax

If for some reason, 1 is rejected, add conditional expressions to initialization of constants, signals, and variables. So add the support there:

In Constant declarations, change constant declaration to:

constant_declaration ::=
    constant identifier_list : subtype_indication [ := expression | conditional_expressions ] ; Signal declarations, change signal declaration to:

signal_declaration ::=
    signal identifier_list : subtype_indication [ signal_kind ] [ := expression | conditional_expressions ] ; 

In Variable declarations, change variable declaration to:

variable_declaration ::=
[ shared ] variable identifier_list : subtype_indication [ := expression | conditional_expressions ] ; 

Implementation 3: Subprograms with anonymous inputs

Can be implemented as a function that uses anonymous inputs:

constant T : time := Cond(gA_VAL = '1', 1 ns , 20 ns) ;
function Cond (
    Sel : boolean ;
    A : anonymous ;
    B : A'Subtype 
) return A'subtype ; 

function Cond (
    Sel : bit ;
    A : anonymous ;
    B : A'Subtype 
) return A'subtype ; 

function Cond (
    Sel : std_ulogic ;
    A : anonymous ;
    B : A'Subtype 
) return A'subtype ; 



For the record, conditional expressions were added in Ada 2012:

General Comments

-- ErnstChristen - 2015-01-21

This capability is often required in initial value expressions. The workaround with a function call is clumsy.


Add your signature here to indicate your support for the proposal

In opposition

Add your signature here to indicate your opposition to the proposal *

Topic revision: r17 - 2020-02-17 - 15:34:28 - JimLewis
Copyright © 2008-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback