Skip to content

lascar-pacagi/Prolog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tree Walk Interpreter of a Subset of Prolog

To execute:

dune exec prolog examples/list.pl

It's better to use rlwrap to get persistent history and completion:

rlwrap dune exec prolog examples/list.pl

To get more answers type ; and enter. If you don't want another answer type enter.

Our subset of Prolog is described by the following grammar :

Program   ::= ( Clause )+ 'eof'

Query     ::= Predicate ( ',' Predicate )* '.' 'eof'

Clause    ::= UserPredicate ( ':-' Predicate ( ',' Predicate )* )? '.'

Predicate ::= UserPredicate | BuiltinPredicate

UserPredicate    ::= Name '(' Term ( ',' Term )* ')'

BuiltinPredicate ::= ( '<=' | '>=' | '=' | '==' | '=:=' | '\=' | '\==' | '=\=' | 'is' ) '(' Term ',' Term ')'
                   | ( 'var' | 'not_var' | 'integer' | 'not_integer' ) '(' Term ')'


Term ::= Int | Variable | ( '+' | '-' | '*' | '/' ) '(' Term ',' Term ')'
       | Name ( '(' ( Term ( ',' Term )* )? ')' )?
       | List

List ::= '[' ( Term ( ',' Term )* ( '|' ( List | Variable ) )? )? ']'

Int  ::= [0-9]+

Name ::= [a-z][a-zA-Z0-9_]*

Variable ::= [A-Z_][a-zA-Z0-9_]*

Comment  ::= '/*' ( [^*] | '*'+ [^*/] )* '*'* '*/' | '%' [^\n]* '\n'

Prolog Interpreter

About

Tree walk interpreter of a subset of Prolog

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published