-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from maryvilledev/cs_90
Add C, Clojure, Java (not java8), and Lua #90
- Loading branch information
Showing
44 changed files
with
1,453 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
[submodule "grammars-v4"] | ||
path = grammars-v4 | ||
url = https://github.com/maryvilledev/grammars-v4.git | ||
[submodule "antlr4"] | ||
path = antlr4 | ||
url = https://github.com/maryvilledev/antlr4.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
(defn run [nvecs nitems nthreads niters] | ||
(let [vec-refs (->> (range (* nvecs nitems)) (partition nitems) (map (comp ref vec)) vec) | ||
swap #(let [v1 (rand-int nvecs) | ||
v2 (rand-int nvecs) | ||
i1 (rand-int nitems) | ||
i2 (rand-int nitems)] | ||
(dosync | ||
(let [tmp (nth @(vec-refs v1) i1)] | ||
(alter (vec-refs v1) assoc i1 (nth @(vec-refs v2) i2)) | ||
(alter (vec-refs v2) assoc i2 tmp)))) | ||
report #(let [derefed (map deref vec-refs)] | ||
(prn derefed) | ||
(println "Distinct:" (->> derefed (apply concat) distinct count)))] | ||
(report) | ||
(dorun (apply pcalls (repeat nthreads #(dotimes [_ niters] (swap))))) | ||
(report))) | ||
|
||
(run 100 10 10 100000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Just a concatenation of some of the snippets from https://en.wikipedia.org/wiki/C_syntax | ||
|
||
enum colors { RED, GREEN, BLUE = 5, YELLOW } paint_color; | ||
|
||
struct thing { | ||
int num; | ||
}; /* thing struct type is now completed */ | ||
|
||
typedef struct Bert Bert; | ||
typedef struct Wilma Wilma; | ||
|
||
struct Bert { | ||
Wilma *wilma; | ||
}; | ||
|
||
struct Wilma { | ||
Bert *bert; | ||
}; | ||
|
||
union u { | ||
int x; | ||
float y; | ||
char *z; | ||
} n; | ||
|
||
struct f { | ||
unsigned int flag : 1; /* a bit flag: can either be on (1) or off (0) */ | ||
signed int num : 4; /* a signed 4-bit field; range -7...7 or -8...7 */ | ||
signed int : 3; /* 3 bits of padding to round out to 8 bits */ | ||
} g; | ||
|
||
void func() { | ||
int *p; | ||
int a, b; | ||
int (*ptr_to_array)[100] = &array; | ||
|
||
a = 10; | ||
p = &a; | ||
b = *p; | ||
a = malloc(n * sizeof(int)); | ||
a[3] = 10; | ||
|
||
for (int i = 0; i < limit; ++i) { | ||
printf("helloworld.c: %d: Hello world\n", i); | ||
} | ||
} | ||
|
||
int (*operation)(int x, int y); | ||
|
||
int add(int x, int y) | ||
{ | ||
return x + y; | ||
} | ||
|
||
int subtract(int x, int y) | ||
{ | ||
return x - y; | ||
} | ||
|
||
int main(int argc, char* args[]) | ||
{ | ||
int foo = 1, bar = 1; | ||
|
||
operation = add; | ||
printf("%d + %d = %d\n", foo, bar, operation(foo, bar)); | ||
operation = subtract; | ||
printf("%d - %d = %d\n", foo, bar, operation(foo, bar)); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,3 @@ | |
print('sum =', total) | ||
except ValueError: | ||
print('Please supply integer arguments') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Just a concatenation of some of the snippets from https://en.wikipedia.org/wiki/Java_(programming_language) | ||
|
||
// This is an example of a single line comment using two slashes | ||
|
||
/* This is an example of a multiple line comment using the slash and asterisk. | ||
This type of comment can be used to hold a lot of information or deactivate | ||
code, but it is very important to remember to close the comment. */ | ||
|
||
package fibsandlies; | ||
import java.util.HashMap; | ||
|
||
/** | ||
* This is an example of a Javadoc comment; Javadoc can compile documentation | ||
* from this text. Javadoc comments must immediately precede the class, method, or field being documented. | ||
*/ | ||
public class FibCalculator extends Fibonacci implements Calculator { | ||
private static Map<Integer, Integer> memoized = new HashMap<Integer, Integer>(); | ||
|
||
/* | ||
* The main method written as follows is used by the JVM as a starting point for the program. | ||
*/ | ||
public static void main(String[] args) { | ||
memoized.put(1, 1); | ||
memoized.put(2, 1); | ||
System.out.println(fibonacci(12)); //Get the 12th Fibonacci number and print to console | ||
} | ||
|
||
/** | ||
* An example of a method written in Java, wrapped in a class. | ||
* Given a non-negative number FIBINDEX, returns | ||
* the Nth Fibonacci number, where N equals FIBINDEX. | ||
* @param fibIndex The index of the Fibonacci number | ||
* @return The Fibonacci number | ||
*/ | ||
public static int fibonacci(int fibIndex) { | ||
if (memoized.containsKey(fibIndex)) { | ||
return memoized.get(fibIndex); | ||
} else { | ||
int answer = fibonacci(fibIndex - 1) + fibonacci(fibIndex - 2); | ||
memoized.put(fibIndex, answer); | ||
return answer; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
-- Just a concatenation of some of the snippets from https://en.wikipedia.org/wiki/Lua_(programming_language) | ||
|
||
function factorial(n) | ||
local x = 1 | ||
for i = 2, n do | ||
x = x * i | ||
end | ||
return x | ||
end | ||
|
||
function addto(x) | ||
-- Return a new function that adds x to the argument | ||
return function(y) | ||
--[=[ When we refer to the variable x, which is outside of the current | ||
scope and whose lifetime would be shorter than that of this anonymous | ||
function, Lua creates a closure.]=] | ||
return x + y | ||
end | ||
end | ||
fourplus = addto(4) | ||
print(fourplus(3)) -- Prints 7 | ||
|
||
--This can also be achieved by calling the function in the following way: | ||
print(addto(4)(3)) | ||
--[[ This is because we are calling the returned function from `addto(4)' with the argument `3' directly. | ||
This also helps to reduce data cost and up performance if being called iteratively. | ||
]] | ||
|
||
a_table = {x = 10} -- Creates a new table, with one entry mapping "x" to the number 10. | ||
print(a_table["x"]) -- Prints the value associated with the string key, in this case 10. | ||
b_table = a_table | ||
b_table["x"] = 20 -- The value in the table has been changed to 20. | ||
print(b_table["x"]) -- Prints 20. | ||
print(a_table["x"]) -- Also prints 20, because a_table and b_table both refer to the same table. | ||
|
||
Point = {} | ||
|
||
Point.new = function(x, y) | ||
return {x = x, y = y} -- return {["x"] = x, ["y"] = y} | ||
end | ||
|
||
Point.set_x = function(point, x) | ||
point.x = x -- point["x"] = x; | ||
end | ||
|
||
fibs = { 1, 1 } -- Initial values for fibs[1] and fibs[2]. | ||
setmetatable(fibs, { | ||
__index = function(values, n) --[[ __index is a function predefined by Lua, | ||
it is called if key "n" does not exist. ]] | ||
values[n] = values[n - 1] + values[n - 2] -- Calculate and memoize fibs[n]. | ||
return values[n] | ||
end | ||
}) | ||
|
||
local Vector = {} | ||
Vector.__index = Vector | ||
|
||
function Vector:new(x, y, z) -- The constructor | ||
return setmetatable({x = x, y = y, z = z}, Vector) | ||
end | ||
|
||
function Vector:magnitude() -- Another method | ||
-- Reference the implicit object using self | ||
return math.sqrt(self.x^2 + self.y^2 + self.z^2) | ||
end | ||
|
||
local vec = Vector:new(0, 1, 0) -- Create a vector | ||
print(vec:magnitude()) -- Call a method (output: 1) | ||
print(vec.x) -- Access a member variable (output: 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule antlr4
deleted from
2ebae9
Submodule grammars-v4
updated
3 files
+2 −2 | clojure/Clojure.g4 | |
+1,786 −0 | java8/Java8.TypeScriptTarget.g4 | |
+1,570 −0 | python3/Python3.TypeScriptTarget.g4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Configuration that can only be read by the compiler. | ||
|
||
module.exports = { | ||
'grammar_files': { | ||
'Java': 'grammars-v4/c/C.g4', | ||
'TypeScript': 'grammars-v4/c/C.g4', | ||
}, | ||
'tree_matcher_specs': require('./c.tree_matcher_specs.js'), | ||
}; |
Oops, something went wrong.