Skip to content

Instantly share code, notes, and snippets.

@erikbgithub
Created September 28, 2010 13:48
Show Gist options
  • Save erikbgithub/601016 to your computer and use it in GitHub Desktop.
Save erikbgithub/601016 to your computer and use it in GitHub Desktop.
setValue(AB) :-> A'='B /*store the relation A=>B somewhere, for example a dict() or a Hashmap*/
getValue(A) :-> B /*load and return it from the storage*/
Operation(aBC) :-> B+C, a='+'
:-> B-C, a='-'
:-> B*C, a='*'
:-> B/C, a='/'
Newline(a) :-> a; a in [\n|\r|\n\r]
Letter(a) :-> a; a in [a-zA-Z]
DigitNoZero(a) :-> a; a in [1-9]
Digit(a) :-> a; a = 0
:-> DigitNoZero(a); alle a
LetterOrDigit(a) :-> Letter(a), all
:-> Digit(a), all
Number(zA) :-> (Digit(a) foreach a in A); z in (null, +)
:-> -(Digit(a) foreach a in A); z = '-'
Name(fL) :-> Letter(f)(LetterOrDigit(l) foreach l in L), all
Call(NP) :-> Program(getValue(N)(Expression(p) for p in P)), all
Factor(aBC) :-> Expression(B), a='(' and C=')'
:-> Number(B), a,c = null
:-> Call(BC)
Summand(AbC) :-> Factor(A), b=null
:-> (Operation(bFactor('1')Factor(D)) forall D in C), A=null, b in [*/], D is a Factor, C is List of
:-> (Operation(bFactor(A)Factor(D)) forall D in C), b in [*/], D is a Factor, C is List of Factors
Expression(AbC) :-> Summand(A) , b=null
:-> (Operation(b Summand('1')Summand(D)) forall D in C), A=null, b in [+-], D is a Factor, C is List of
:-> (Operation(bSummand(A)Summand(D)) forall D in C), b in [+-] C is a Summand, B is List of Summands
Identifier(NP) :-> Name(N)(Name(C) forall C in P), C is a ParamName, P is List of ParamNames
Assignment(AbC) :-> (setValue(Identifier(A)Expression(C)) and AbC, b='='
Line(aBc) :-> Expression(B), a in [(,null] and c in [),null]
Program(AB) :-> Line(A)(NewLine(c)Line(D) for cD in B)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment