Code Monkey home page Code Monkey logo

sfp-lang's People

Contributors

herry13 avatar

Watchers

 avatar

sfp-lang's Issues

Virtual variable

Example:

main {
  a {
    virtual x = 1;
    b x;
  }
  a.x = 2;
}

The compilation output (YAML) of above specification should be:

a:
  b: 2

Abstract Syntax Tree <=> JSON

Convert AST to JSON, and vice versa. This will allow programs written in other languages to give input to the compiler.

Implement postprocessor step

  • create file plan
  • implement a function that removes dummy actions (of global constraints)
  • implement a function to convert a total-order to a partial-order plan
  • implement functions that generates JSON/YAML of a total or partial order plan

Operator

Operator ::= ( OperatorStmt )

OperatorStmt ::= UnaryOp BasicValue
| BasicValue ( BinaryOp BasicValue )?
| BasicValue ( NaryOp BasicValue )*

UnaryOp ::= !

BinaryOp ::= - | / | == | != | >= | > | <= | <

NaryOp ::= + | * | ++ | <> | && | ||

Examples:

main {
   a = true;
   b = (! a);
   c = 45;
   d = (100 - c);
   e = (100 - (c + 5));
   f = ("hello " ++ 42 ++ " people in the world");
   g = (c + d + 100);
}

Simplify type system

The following ideas can simplify the type-system:

  • References of all primitive types bool, int, float, and string are always pass by value.

    main {
       a = 1;
       b = a;
    }

    The compilation result should be:

    { "a" : 1, "b" : 1 }
  • References of all non-primitive types object and user-defined schemas are always pass by reference.

    main {
       a { }
       b = a;
    }

    The compilation result should be:

    { "a" : { }, "b" : "$a" }

Nothing <--> Undefined

Switch terminology between Nothing and Undefined. This implies that TUndefined should be renamed to TNothing.

Override action descriptions

Sometime, you may want to override or add an extra statement to a particular conditions or effects of an action without rewriting the whole action description. For example

import "state";
schema Package {
  state : State = TBD;
  def install {
    conditions {
      this.state = State.uninstalled;
    }
    effects {
      this.state = State.installed;
    }
  }
}
schema Service extends Package {
  override install.effects {  // replace the effects with current statement
    this.state = State.stopped;
  }
}

Syntax Change for Data & Link Reference

Current-syntax for data & link references:

main {
   a = 1;
   b = a; // data-reference
   c a; // link-reference
}

New-syntax for data & link references:

  • First proposal

    main {
       a = 1;
       b = $a; // data-reference
       c = a; // link-reference
    }
    
  • Second proposal

    main {
       a = 1;
       b = *a; // data-reference
       c = a; // link-reference
    }
    
  • Third proposal

    main {
       a = 1;
       b = a; // data-reference
       c := a; // link-reference
    }
    

Final constraints

Besides any value semantics, the specification of the desired state may have final constraints.

String concatenation operator

Example

main {
  a = "hello";
  b = "world!";
  greeting = a + " " + b;
}

The compilation output (YAML) would be:

a: "hello"
b: "world!"
greeting: "hello world!"

Enum Type

Example:

enum State { uninstalled, installed, running }

main {
  service {
    state : State = uninstalled;
  }
}

Refactor - use integers as symbol of identifiers

Currently, all identifiers are kept as a string. Unfortunately, comparing two strings are not efficient -- O(n) where n is the average length string. Thus, it might be better to use integers to represent identifiers because an integer symbol only has 32bits to be compared with others, no matter how long the string of identifier is.

This can be implemented in parser.mly when generating the AST: encode every string of symbol to integer, and then save the map (string->integer) to decode the integer back to string.

Failed test file test/herry6.sf

The SF compiler didn't terminate when parsing test/herry6.sf. The SFP compiler might have the same behaviour since it is developed based on SF compiler.

Distinguish include and import file

include "spec.sfp"; will include file spec.sfp at the current working directory.

import "spec"; will include file spec/spec.sfp at the current working directory.

Support SF syntax

SFP syntax is not similar with SF syntax. Thus, it may be worth to extend SF parser to generate SFP abstract syntax tree from SF syntax.

Some new notations must be introduced to support the notion of global constraints and actions.

Distinguish between include and import

include "spec.sfp"; will include file spec.sfp at the current working directory.

import "spec"; will include file spec/spec.sfp at the current working directory.

When using import, the compiler should also check environment variable SFP_LIB to find the target file. Assume import "spec";, then the priority orders are:

  1. spec/spec.sfp at the current working directory
  2. if the first element path of SFP_LIB equals to /lib1, then /lib1/spec/spec.sfp
  3. if the second element path of SFP_LIB equals to /lib2, then /lib2/spec/spec.sfp
  4. ... and so on until the last element path of SFP_LIB.

The format of SFP_LIB is: path1:path2:...:pathN.

Enable custom library path for import file

When using import, the compiler should also check environment variable SFP_LIB to find the target file. Assume import "spec";, then the priority orders are:

  1. spec/spec.sfp at the current working directory
  2. if the first element path of SFP_LIB equals to /lib1, then /lib1/spec/spec.sfp
  3. if the second element path of SFP_LIB equals to /lib2, then /lib2/spec/spec.sfp
  4. ... and so on until the last element path of SFP_LIB.

The format of SFP_LIB is: path1:path2:...:pathN.

Type time

New type time is required, for example: to declaratively define whether a service have to be restarted or not start_time > now.

Values:

  • #now
  • #today
  • 31/01/2014 04:00
  • 04:00 (equals to 31/01/2014 04:00 if today's day is 31/01/2014)
  • 31/01/2014 (equals to 31/01/2014 00:00)

Option -g is not working

Option -g (evaluate global constraints) is not working properly.

  • message The global constraints are satisfied. should be printed to STDOUT, or
  • message The global constraints are not satisfied. should be printed to STDERR.

TBD value

Support TBD (to be defined) value. When translating to FDR, This can represent any value semantics of SFP where the variable can be assigned with any value, which is a member of the variable's domain, at the final state.

SFP-based planner

FDR has become a standard representation of planning problems. But it has some shortcomings:

  • all constraints (action preconditions and goal) must be simple conjunction formulas -- complex formula must be converted to DNF
  • literal (atom and its negation) is not allowed in the preconditions -- positive atom only

The above restrictions simplify the problems, ease us to develop the heuristics techniques such as FF, CG, CEA, or Landmarks. However, there might be a benefit, such as more compact representation to speed-up search, on allowing a little more complex formulas:

  • supporting literal in the precondition and goal formulas, e.g. a = 1 and a != 1
  • supporting implication in the preconditions, e.g. (a = 1) -> (b = 2)
  • CNF in the preconditions, e.g. (a = 1) or (a = 2) or (a = 3)

The first two relaxation might be easier to be implemented. However, some modifications on heuristics are required e.g. calculating relaxed planning-graph in FF.

On the other side, the last idea of relaxation is similar with SAT-planning.

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.