Search code examples
javagenericsconstructlanguage-construct

Which aspects of the JAVA conditional operator construct are described formally, and which are described informally


This question on my courswork that I could not understand. Q. The JAVA Language Specification (3rd Edn.) is available for browsing or downloading at java.sun.com/docs/books/jls/. Locate the section of it that describes the so-called conditional operator ‘? :’. Which aspects of the JAVA conditional operator construct are described formally, and which are described informally. please help me understand what dose it mean by "aspects of the JAVA conditional operator construct are described formally"


Solution

  • By formal specification, I would guess your instructor is referring to BNF, which is about the only formal description you will find in the JLS. The goal of formal specifications is too express computer languages in a form which can be mathematically analyzed.

    I do not want to do your homework for you, but here is an example of a formal language expression in BNF:

    grammar ::= [{ assignment }] eoi
    assignment ::= name ('::=' | '=') expression
    expression = term [{ '|' term }]
    term = factor [{ white factor }]
    factor = IO | name | '[' expression ']' | '&{' expression '&}'
    IO = '\'' string '\'' | '"' string '"' | '`' string '`'
    

    This little gem is a BNF which ironically, defines the grammar of a BNF. You will notice that each element in a line is described by the lines below it. BNF is just one type of formal notation, but is very commonly used to mathematically express programming languages because it is easily broken down by parsers.

    The non-formal parts of the JLS will be those portions that are not expressed in BNF. They may take the form of simple sentences or bulleted lists that describe a function in plain English. You will find quite a lot of these in your homework assignment. Good luck!