Skip to content

catrope/vb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ln -s /net/users/csg/csg1028/bin/sablecc sablecc

Example program:

-- example program given in the course just works:
LET d         = 7;
LET fac(n)    = IF n=0 THEN 1 ELSE n*fac(n-1);
fac(d)?
LET abs(r)    = IF r<0.0 THEN 0.0-r ELSE r;
LET eps       = 1.0/1000000.0;
LET sqrt(r,x) = IF abs(x*x-r)<eps THEN x ELSE sqrt(r,(x+r/x)/2.0);
sqrt(2.0,2.0)?

LET example(n) = IF (IF n < 5 THEN true ELSE false) THEN n ELSE -n;
-- nested expression, monadic minus
example(0)?
example(1.1)?
example(5.5)?
example(3.0e-2)? -- scientific notation
example(false)? -- booleans
example(true)?
example(' ')? -- characters
example(cos(42))? -- built-in functions
pow(2,8)?
LET pow(a,b) = a+a+a; -- overriding built-in functions
pow(2,8)?
pow(2,1/0)? -- lazy evaluation (a is evaluated only once!)
5+5.5? -- double/int coercion
5+5.5 > 10? -- comparison not only in IF statements
false+1? -- false and true are really just constants for 0 and 1
.

This gives the output:

5040
1.4142135623746899
0
1.1
-5.5
0.03
false
true
-32
-0.39998531498835127
256.0
6
6
10.5
true
1

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages