Giter VIP home page Giter VIP logo

funclog's Introduction

Funclog Documentation

Contributors: Elliot Fayman, Ryan Kao, Liliana Rivas
Advisor: Kyle Dewey
Date: May 17th, 2024

Table of Contents

  1. Overview
  2. Language Justification
  3. Design
  4. Basic Examples
  5. Modules
  6. Usage Guide

Overview

Funclog is a nondeterministic programming language with functional programming features, designed to support higher-order functions and basic nondeterministic programming.

Language Justification

Funclog stands out by offering higher-order functions in a nondeterministic context, a feature rarely found in commercial logic programming languages.

Design

The Funclog compiler generates Prolog code using Scala, leveraging its functional programming capabilities. The compiler is modular, consisting of the Lexer, Parser, Type Checker, and Code Generator, ensuring clarity and maintainability.

Basic Examples

Here are some key features of Funclog:

Nondeterminism

(def foo () int (choice (return 1) (return 2)))

Creates nondeterministic behavior within software.

Assertions

(def bar (int x) int (block (assert (< x 5)) (return x)))

Applies assertions within software.

Higher-Order Functions

(def bash ((=> ( ) int) func) int (return (call func ())))

Allows passing and calling functions.

Example Conversion

Funclog:

(def f (int X) int (choice 
 (block 
   (var (=> (int) int) Z (=>  (int Inner) (return Inner)))            
   (var (=> ((=> (int) int)) int) Y (=> ((=> (int) int) Func) (return (call Func (5))))) 
   (return (call Y (Z)))
 ) 
 (return X))
)

Prolog:

lambda_func4(XInner, Rtn4) :- 
  Rtn4 is XInner.

lambda_func12(Rtn12) :- 
  lambda_func4(5, R0), 
  Rtn12 is R0.

func_f(XX, RtnV21) :- 
  (true, 
   true, 
   lambda_func12(Rtn12), 
   RtnV21 is Rtn12, 
   ; 
   RtnV21 is XX).

Module Overview

The Funclog compiler consists of the Lexer, Parser, Type Checker, and Code Generator. The compilation process involves:

  1. Tokenizing the source file using the Lexer.
  2. Generating an abstract syntax tree (AST) with the Parser.
  3. Checking the AST for type correctness with the Type Checker.
  4. Emitting semantically equivalent Prolog code with the Code Generator.

Lexer

Processes strings into tokens. Tokens include Basic Type Tokens, Identifier Tokens, Operator/Grammar Tokens, and Reserved Word Tokens.

Parser

Creates an abstract syntax tree (AST) from tokens, using Scala parser combinator library for enhanced simplicity and readability.

Type Checker

Enforces static typing rules, catching type-related errors early and improving program stability.

Code Generator

Transforms a well-typed AST into executable Prolog code, employing defunctionalization techniques for higher-order functions.

Language Interface Guide

Compilation Guide

Dependencies: Git, Scala, Scala Build Tool (SBT). Clone the repository and compile the compiler:

git clone 'https://github.com/elliotfayman/funclog'
sbt compile

Basic Usage Guide

Create a .funclog program and compile it into Prolog:

sbt "run path/to/yourfile.funclog"

Use the compiled output in a Prolog engine.

funclog's People

Contributors

elliotfayman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.