%% file: g0.pl %% A grammar must specify variables, terminals, and rules. %% Here is the context-free grammar for a simple grammar %% of arithmetic expressions using only addition with %% the only terminals being 0 and 1. %% s -> v + s | v %% v -> 0 | 1 %% Variables are stated as facts. These facts simply state the names of the variables. %% In this example, the facts state that s and v are variables. %% These are all in lower case because Prolog thinks of anything beginning %% in uppercase as one of its own unbound variables. variable(s). variable(v). %% And here are the two terminals in this grammar... terminal(0). terminal(1). terminal(+). %% Rules are stated as ordered pairs, where the first element is the left-hand-side %% of a rule and the second argument is the LIST of elements appearing on the right-hand-side %% of that rule. rule(s, [v, +, s]). rule(s, [v]). rule(v, [0]). rule(v, [1]).