PL/0 - Grammar

Grammar

The following is the syntax rules of the model language defined in EBNF:

program = block "." . block = { "procedure" ident ";" block ";" } statement . statement = [ ident ":=" expression | "call" ident | "begin" statement {";" statement } "end" | "if" condition "then" statement | "while" condition "do" statement ]. condition = "odd" expression | expression ("="|"#"|"<"|"<="|">"|">=") expression . expression = term { ("+"|"-") term}. term = factor {("*"|"/") factor}. factor = ident | number | "(" expression ")".

It is rather easy for students to write a recursive descent parser for such a simple syntax. Therefore, the PL/0 compiler is still widely used in courses on compiler construction throughout the world. Due to the lack of features in the original specification, students usually spend most of their time with extending the language and their compiler. They usually start with introducing REPEAT .. UNTIL and continue with more advanced features like parameter passing to procedures or data structures like arrays, strings or floating point numbers.

Read more about this topic:  PL/0

Famous quotes containing the word grammar:

    Grammar is a tricky, inconsistent thing. Being the backbone of speech and writing, it should, we think, be eminently logical, make perfect sense, like the human skeleton. But, of course, the skeleton is arbitrary, too. Why twelve pairs of ribs rather than eleven or thirteen? Why thirty-two teeth? It has something to do with evolution and functionalism—but only sometimes, not always. So there are aspects of grammar that make good, logical sense, and others that do not.
    John Simon (b. 1925)

    Hence, a generative grammar must be a system of rules that can iterate to generate an indefinitely large number of structures. This system of rules can be analyzed into the three major components of a generative grammar: the syntactic, phonological, and semantic components.
    Noam Chomsky (b. 1928)

    I went to a very militantly Republican grammar school and, under its influence, began to revolt against the Establishment, on the simple rule of thumb, highly satisfying to a ten-year-old, that Irish equals good, English equals bad.
    Bernadette Devlin (b. 1947)