Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/smack0007/snowflake
Scripting language which compiles to C# and then to IL code using Roslyn.
https://github.com/smack0007/snowflake
Last synced: 20 days ago
JSON representation
Scripting language which compiles to C# and then to IL code using Roslyn.
- Host: GitHub
- URL: https://github.com/smack0007/snowflake
- Owner: smack0007
- Created: 2012-04-19T19:51:39.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2018-06-21T05:58:24.000Z (over 6 years ago)
- Last Synced: 2024-11-07T11:48:00.640Z (2 months ago)
- Language: C#
- Homepage:
- Size: 839 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
[![The MIT License](https://img.shields.io/badge/license-MIT-orange.svg?style=flat-square)](http://opensource.org/licenses/MIT)
![Build Status](https://smack0007.visualstudio.com/_apis/public/build/definitions/3c2bd649-f280-4370-b4aa-e4a0a0b13fb8/6/badge)# Snowflake
Snowflake is a scripting language implemented in C#. The following is an example Snowflake script:
```
func buildMultiplier(x) {
return func(y) {
return x * y;
};
}var x5 = buildMultiplier(5);
for (var i = 0; i < 10; i += 1) {
print("5 * " + i + " = " + x5(i));
}var values = [ 1, 2, 3, 4, 5 ];
print(values.Count);
```## Interop
Snowflake scripts by default do not have access to any .NET BCL classes or methods besides those types which are baked into the language. Access can
be given to scripts if necessary by setting global variables inside the ScriptEngine:```csharp
engine.SetGlobalFunction("print", (x) => Console.WriteLine(x));
```In order to allow objects to be available in your script, you'll need to register the objects with the ScriptEngine:
```csharp
engine.RegisterType("MyApp.Person", typeof(Person));
```Once the ScriptEngine has access to the type, your scripts can create objects like so:
```
var person = new MyApp.Person();
person.FirstName = "Bob";
person.LastName = "Freeman";
person.Age = 42;
```Static objects can also be accessed this way:
```csharp
engine.RegisterType("System.Console", typeof(Console));
```In your script:
```
System.Console.WriteLine("Hello World!");
```## Language Structure
The following is the structure of the language following the EBNF language as closely as possible:
```
Script = * EOF ;StatementBlock = "{" * "}" ;
Statement = ";" |
";" |
|
|
|
|
|
|
";" ;ConstDeclaration = "const" "=" ;
VariableDeclaration = "var" ( "=" )? ;
FunctionDeclaration = "func" "(" ")" ;
FunctionParameters = ? ( "," )* ;
If = "if" "(" ")" { "else" } ;
While = "while" "(" ")" ;
For = "for" "(" ( | ) ";" ";" ")" ;
ForEach = "foreach" "(" "in" ")" ;
Return = "return" ";" ;
Expression = ;
AssignmentExpression = | ;
ConditionalOrExpression = ( "||" )* ;
ConditionalAndExpression = ( "&&" )* ;
EqualityExpression = ( ( "==" | "!=" ) )* ;
RelationalExpression = ( ( "<" | "<=" | ">" | ">=" ) )* ;
AdditiveExpression = ( ( "+" | "-" ) )* ;
MultiplicativeExpression = ( ( "*" | "/" ) )* ;
UnaryExpression = ( ( "-" | "!" ) )* | ;
PrimaryExpression = "(" ")" |
|
|
|
|
|
|
|
|
|
;Assignment = ;
AssignmentTarget = | ;
AssignmentOperation = "=" | "+=" | "-=" | "*=" | "/=" ;
AnonymousFunction = "func" "(" ")" ;
FunctionCall = "(" ( ("," )* )? ")" ;
ConstructorCall = "new" "(" ( ("," )* )? ")" ;
TypeName = ( "." )* ( "<" ( "," )* ">" )? ;
List = "[" ? ( "," )* "]" ;
Array = "[|" ? ( "," )* "|]" ;
Dictionary = "{" ? ( "," )* "}" ;
DictionaryPair = ( | ) ":" ;
MemberAccess = "." ( "(" ( ( "," )* )? ")" )? ;
PostfixOperation = ( "++" | "--" ) ;
ElementAccess = "[" "]" ;
Identifier = [A-Za-z_][A-Za-z0-9_]* ;
Value = | | | | | ;
Null = "null" ;
Boolean = "true" | "false" ;
String = "\"" * "\"" ;
Integer = [1-9]* ;
Float = [1-9]*[.][1-9]* ;
```