2 Programming Languages
For Java, the specification document spells out both the lexical structure (vocabulary) and the syntax (grammar) with a mixture of structured English and formal enumerations. Take a look at the specifications to see how much care and work goes into an exemplary language specification.
class Fahrenheit { |
private double temperature = 0.0; |
public Celsius toCelsius() { |
return 5 * (this.temperature - 32) / 9; |
} |
} |
(define Fahrenheit (class object% [init-field (temperature #i0.0)] (define/public (toCelsius) (/ (* 5 (- temperature 32)) 9))))
x = x + 1; |
Since programming language researchers wish to ignore such syntactic differences and focus on models that predict behavior (semantics), they distill syntax to its essence: abstract syntax. Roughly speaking, the elements of an abstract syntax are trees that explain why an element belongs to the language. That is, the tree structure encapsulates the argument why a grammar such as Java’s “blesses” a sentence such as the class definition about.
a tool for writing down abstract syntax trees;
a tool for writing down functions on abstract syntax trees to check basic properties.