A grammar for a small Prolog language is given below; it follows the grammar for Horn clause form closely. Variable names begin with a capital letter. It simplifies matters to make a program consist of zero or more rules followed by a single query; in other systems queries can be interspersed with the rules. Note also that most Prologs use `:-' instead of `<=' and use `,' instead of `and' to separate atoms.
<Program> ::= [ <rules> ] <query> <rule> ::= <atom> . | <atom> <= <literals> . <rules> ::= <rule> [ <rules> ] <query> ::= ? <literals> . <literal> ::= <atom> | not <atom> <literals> ::= <literal> [ and <literals> ] <atom> ::= <ident> | <ident> ( <terms> ) <term> ::= <ident> | <numeral> | -- constants <ident> ( <terms> ) | -- functions <IDENT> -- variables <terms> ::= <term> [, <terms> ] --- Prolog-S Syntax. ---