Skip to content

Instantly share code, notes, and snippets.

View dineshappavoo's full-sized avatar

Dinesh Appavoo dineshappavoo

  • The University of Texas
  • United States
View GitHub Profile
package main
import (
"fmt"
"log"
"strconv"
)
// CODE MAY NOT COMPILE WITHOUT REDIS API IMPLEMENTATION
@dineshappavoo
dineshappavoo / denotational-semantic
Last active August 29, 2015 14:11
Denotational semantic for the parse tree
newstore([]).
access(_,[],0).
access(I,[(I,V)|_],V).
access(I,[_|T],V) :- access(I,T,V).
update(I,NV,[],[(I,NV)]).
update(I,NV,[(I,_)|T],[(I,NV)|T]).
update(I,NV,[P|T],[P|T1]) :- update(I,NV,T,T1).
@dineshappavoo
dineshappavoo / parse-tree
Last active August 29, 2015 14:11
parse tree generater
program(pprog(K)) --> k(K),[.].
k(pblock(D,C)) --> [begin],d(D),[;],c(C),[end].
d(D) --> d_d(D).
d(pdeclaration(D1,D2)) --> d_d(D1),[;],d(D2).
d_d(pconstant(I,N)) --> [const],i(I),[=],n(N).
d_d(pvar(I)) --> [var],i(I).
c(C) --> c_c(C).
@dineshappavoo
dineshappavoo / grammar
Last active August 29, 2015 14:11
dcg-grammar
P ::= K.
K ::= begin D; C end
D ::= const I = N D' | var I D'
D' ::= ε | ; D D'
C ::= I := E C' | if B then C else C endif C' | while B do C endwhile C' | K C'
C' ::= ε | ; C C'
B ::= true | false | E = E | not B
E ::= I := E E' |I E' | N E'
E' ::= ε | + E E' | - E E' | * E E' | / E E'
I ::= x | y | z | u | v
@dineshappavoo
dineshappavoo / StringAnagram
Last active August 29, 2015 14:00
Find whether two strings are anagrams
public boolean isAnagram(String str1, String str2)
{
//To get the no of occurrences of each character and store it in their ASCII location
int[] strCountArr1=getASCIICountArr(str1);
int[] strCountArr2=getASCIICountArr(str2);
//To Test whether the two arrays have the same count of characters. Array size 256 since ASCII 256 unique values
for(int i=0;i<256;i++)
{
if(strCountArr1[i]!=strCountArr2[i])
return false;