Beispiel #1
0
 public ScheminPrimitive(string name, Token token)
 {
     this.SourceToken = token;
     this.Definition = PrimitiveFactory.Get(name);
     if (this.Definition.Rewriter)
         this.Rewriter = true;
     this.Name = name;
 }
Beispiel #2
0
 private IScheminType ConvertAtom(ScheminAtom atom, Token token)
 {
     switch (atom.Name)
     {
         // these are special forms that can't be bound to symbols, they're always primitives
         case "lambda":
             return new ScheminPrimitive("lambda", token);
         case "define":
             return new ScheminPrimitive("define", token);
         case "define-rewriter":
             return new ScheminPrimitive("define-rewriter", token);
         case "quote":
             return new ScheminPrimitive("quote", token);
         case "unquote":
             return new ScheminPrimitive("unquote", token);
         case "unquote-splicing":
             return new ScheminPrimitive("unquote-splicing", token);
         case "quasiquote":
             return new ScheminPrimitive("quasiquote", token);
         case "begin":
             return new ScheminPrimitive("begin", token);
         case "if":
             return new ScheminPrimitive("if", token);
         case "or":
             return new ScheminPrimitive("or", token);
         case "and":
             return new ScheminPrimitive("and", token);
         case "cond":
             return new ScheminPrimitive("cond", token);
         case "let":
             return new ScheminPrimitive("let", token);
         case "letrec":
             return new ScheminPrimitive("letrec", token);
         case "let*":
             return new ScheminPrimitive("let*", token);
         case "set!":
             return new ScheminPrimitive("set!", token);
         case "call/cc":
             return new ScheminPrimitive("call/cc", token);
         default:
             return atom;
     }
 }
Beispiel #3
0
 private IScheminType ConvertToken(Token token)
 {
     switch (token.Type)
     {
         case TokenType.Symbol:
             return AtomFactory.GetAtom(token.Value);
         case TokenType.IntegerLiteral:
             return new ScheminInteger(BigInteger.Parse(token.Value));
         case TokenType.DecimalLiteral:
             return new ScheminDecimal(decimal.Parse(token.Value));
         case TokenType.StringLiteral:
             return new ScheminString(token.Value);
         case TokenType.BoolLiteral:
             return ScheminBool.GetValue(token.Value == "#t" ? true : false);
         case TokenType.CharLiteral:
             return new ScheminChar(token.Value.Replace("#\\", ""));
         default:
             throw new Exception(string.Format("Unable to convert token of type: {0}", token.Type));
     }
 }
Beispiel #4
0
        private Token RemapQuote(Token quote)
        {
            Dictionary<string, Token> remapped = new Dictionary<string, Token>();
            remapped.Add("'", new Token(TokenType.Symbol, "quote"));
            remapped.Add("`", new Token(TokenType.Symbol, "quasiquote"));
            remapped.Add(",", new Token(TokenType.Symbol, "unquote"));
            remapped.Add(",@", new Token(TokenType.Symbol, "unquote-splicing"));

            return remapped[quote.Value];
        }
Beispiel #5
0
        private bool IsQuoteToken(Token token)
        {
            string[] quotes = { "'", "`", ",", ",@" };
            if (quotes.Contains(token.Value))
            {
                return true;
            }

            return false;
        }
Beispiel #6
0
 private bool IsQuotable(Token token)
 {
     TokenType[] quotables = { TokenType.DecimalLiteral, TokenType.IntegerLiteral, TokenType.OpenParen,
         TokenType.StringLiteral, TokenType.Symbol, TokenType.VectorLiteral };
     if (quotables.Contains(token.Type))
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Beispiel #7
0
 private KeyValuePair<Token, int> MakeTokenPair(TokenType type, String tokenName, char[] input, int beginPosition, int endPosition)
 {
     Token currentToken = new Token(type, tokenName);
     currentToken.LineNumber = GetLineNumber(input, beginPosition);
     currentToken.ColNumber = GetColNumber(input, beginPosition);
     return new KeyValuePair<Token, int>(currentToken, endPosition);
 }