Opiskelijoiden käsittelyyn nostamia teemoja ennakkolukemistosta

  • Kielen semantiikka voi hylätä ohjelmia (väitöskirja)

  • Sematiikan pohjalta voi olla myös määrittelemätön (väitöskirja)

  • Semantiikan ja syntaksin erotus? (The anatomy of a programming language)

  • Mistä tekstissä puhuttiin? (The anatomy of a programming language)

  • Laskin tehtävä? (The anatomy of a programming language)

Let's add exponentiation to the calculator language

Lexical syntax changed:

<lexeme> ::= <variable name> | <numeric constant> | let | in | = | + | - | * | / | ( | ) | ^
<variable name> ::= <first character> <rest of the variable name>
<first character> ::= <letter> | _
<rest of the variable name> ::= <empty> | <name character> <rest of the variable name>
<name character> ::= <letter> | <digit> | _
<numeric constant> ::= <integer constant> | <float constant>
<integer constant> ::= <digits>
<digits> ::= <digit> | <digit> <digits>
<float constant> ::= <digits> . | . <digits> | <digits> . <digits>

Basic phrase-structure grammar changed:

<expression> ::= <expression> + <expression>
               | <expression> - <expression>
               | <expression> * <expression>
               | <expression> / <expression>
               | <expression> ^ <expression>
               | + <expression>
               | - <expression>
               | <numeric constant>
               | <variable name>
               | let <variable name> = <expression> in <expression>
               | ( <expression> )

Unambiguous grammar changed:

<expression> ::= <term>
               | let <variable name> = <expression> in <expression>

<term> ::= <factor>
         | <term> + <factor>
         | <term> - <factor>
         
<factor> ::= <unary expression>
           | <factor> * <unary expression>
           | <factor> / <unary expression>

<unary expression> ::= <exp expression>
                     | + <exp expression>
                     | - <exp expression>

<exp expression> ::= <primary expression>
                   | <primary expression> ^ <exp expression>

<primary expression> ::= <numeric constant>
                       | <variable name>
                       | ( <expression> )

Abstract syntax changed (by AJK after meeting):

\[\begin{array}{rcl} E,F &\in& \mathbf{Exp}\\ E,F &::=& E + F \\ &\mid& E - F \\ &\mid& E \mathbin* F \\ &\mid& E \mathbin/ F \\ &\mid& E \mathbin{\texttt{^}} E \\ &\mid& -E\\ &\mid& c \\ &\mid& x \\ &\mid& \mathbf{let}~x=E~\mathbf{in}~F \\ c,d &\in& \mathbf{Const}\\ x ,y,z&\in& \mathbf{Var} \end{array}\]

data E = E :+: E
       | E :-: E
       | E :*: E
       | E :/: E
       | E :^: E
       | Neg E
       | Let String E E
       | Const Double
       | Var String
       deriving Show

Changes to the calculator source code can be found in the branch Meeting3_exponentiation

These are the current permissions for this document; please modify if needed. You can always modify these permissions from the manage page.