Toggle navigation
?
users online
Logout
Open hangout
Open chat for current file
:- set_prolog_flag(double_quotes,chars). :- use_module(library(dcg/basics)). % Enable tabled execution to eliminate left recursion :- table expression//1, term//1. % Describes expressions expression(A+B) --> expression(A), "+", term(B). expression(A-B) --> expression(A), "-", term(B). expression(E) --> term(E). % Describes expressions that have multiplication, % division, or a higher precedence operator at their % root. term(A*B) --> term(A), "*", factor(B). term(A/B) --> term(A), "/", factor(B). term(E) --> factor(E). % Describes expressions that have exponentiation, or % a higher precedence operator at their root. factor(A^B) --> unary(A), "^", factor(B). factor(E) --> unary(E). % Describes the remaining cases: unary operators, % function calls, use of parenthesis, numbers, and % variables. unary(-E) --> "-", expression(E). unary(E) --> "(", expression(E), ")". unary(log(E)) --> "log(", expression(E), ")". unary(exp(E)) --> "exp(", expression(E), ")". unary(sin(E)) --> "sin(", expression(E), ")". unary(cos(E)) --> "cos(", expression(E), ")". unary(tan(E)) --> "tan(", expression(E), ")". unary(number(N)) --> number(N). unary(variable(V)) --> letters(V). % Helper DCG rules letters([L]) --> letter(L). letters([L|Ls]) --> letter(L), letters(Ls). letter(L) --> [L], { char_type(L, alpha) }.