This file contains hidden or 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
// ParserTest.cs | |
[TestFixture] | |
public class ParserTest | |
{ | |
//... | |
[Test] | |
public void TestParser() | |
{ | |
var tests = new [] | |
{ |
This file contains hidden or 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
public class Parser | |
{ | |
//... | |
public Expression Parse() | |
{ | |
return this.ParseExpression(Precedence.LOWEST); | |
} | |
private Expression ParseExpression(Precedence precedence) | |
{ | |
if(this.PrefixFns.ContainsKey(this._currentToken.Type)) |
This file contains hidden or 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
//Pecedence.cs | |
public enum Precedence | |
{ | |
LOWEST = 0, | |
SUM = 1, | |
PRODUCT = 2, | |
PREFIX = 3, | |
POWER = 4, | |
GROUP = 5, | |
} |
This file contains hidden or 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
public abstract class Expression | |
{ | |
public abstract string TokenLiteral(); | |
} | |
//IntegerExpression.cs | |
public class IntegerExpression : Expression | |
{ | |
public Token Token { get; set; } | |
public long Value { get; set; } | |
//... |
This file contains hidden or 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
// Lexer.cs | |
public class Lexer | |
{ | |
//... | |
public Token NextToken() | |
{ | |
//... | |
char character = this.input[this.position]; | |
switch (character) | |
{ |
This file contains hidden or 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
[Test] | |
public void TestLexerNextToken() | |
{ | |
string input = @"1 + 2 * (12 - 6) / 3 + 2 ^ 3 | |
+ ((4+3) * 4) | |
/ 4 | |
"; | |
var tests = new[] | |
{ |
This file contains hidden or 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
//Token.cs | |
public class Token | |
{ | |
public TokenType Type { get; set; } | |
public string Literal { get; set; } | |
} |
This file contains hidden or 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
//Token.cs | |
public enum TokenType | |
{ | |
INT, | |
PLUS, | |
MINUS, | |
MULTIPLY, | |
DIVIDE, | |
POWER, | |
LPAREN, |
This file contains hidden or 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
// program.cs | |
static void Main(string[] args) | |
{ | |
const string WELCOME = "Welcome to Calculator. Feel free to type any expression you want."; | |
const string PROMPT = ">> "; | |
Console.Out.Write(WELCOME + Environment.NewLine); | |
while(true) | |
{ | |
Console.Out.Write(PROMPT); | |
try |
This file contains hidden or 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
@gen.coroutine | |
def receive(self, exchange, routing_key, queue_name, handler, no_ack=False, prefetch_count=0): | |
""" | |
receive message. creating a brand new channel to consume message. Before consuming, it have to declaring | |
exchange and queue. And bind queue to particular exchange with routing key. if received properties is not | |
none, it publishes result back to `reply_to` queue. | |
:param exchange: exchange name | |
:param routing_key: routing key (e.g. dog.*, *.big) | |
:param queue_name: queue name | |
:param handler: message handler, |