コード例 #1
0
ファイル: infix.cs プロジェクト: MilkTool/kiezellisp
        public Vector Scanner(string infix)
        {
            var v     = new Vector();
            var index = 0;

            while (index < infix.Length)
            {
                int  pos = index;
                char ch  = infix[index];

                if (Char.IsWhiteSpace(ch))
                {
                    // Skip white space
                    ++index;
                }
                else if (Char.IsDigit(ch))
                {
                    // Numbers can have decimal point.
                    // No commas allowed since this would break function parameter list syntax.
                    while (index < infix.Length)
                    {
                        ch = infix[index];

                        // Same as below. If there are letters, this will give runtime error.
                        if (!(Char.IsLetterOrDigit(ch) || ch == '.' || ch == '_'))
                        {
                            break;
                        }

                        ++index;
                    }
                    var number = infix.Substring(pos, index - pos);
                    v.Add(number.ParseNumber());
                }
                else if (Char.IsLetter(ch) || ch == '_' || ch == ':')
                {
                    // ident

                    while (index < infix.Length)
                    {
                        ch = infix[index];

                        if (!(Char.IsLetterOrDigit(ch) || ch == '_' || ch == ':'))
                        {
                            break;
                        }

                        ++index;
                    }

                    var ident = infix.Substring(pos, index - pos);
                    v.Add(Runtime.FindSymbol(ident));
                }
                else if (index + 1 < infix.Length)
                {
                    var oper = infix.Substring(index, 2);
                    if (FindOper(oper, Opers) == null)
                    {
                        oper = infix.Substring(index, 1);
                        if (FindOper(oper, Opers) == null)
                        {
                            throw new LispException("Invalid operator {0} in infix expression: {1}", oper, infix);
                        }
                    }
                    index += oper.Length;
                    v.Add(oper);
                }
                else
                {
                    var oper = infix.Substring(index, 1);
                    if (FindOper(oper, Opers) == null)
                    {
                        throw new LispException("Invalid operator {0} in infix expression: {1}", oper, infix);
                    }
                    index += oper.Length;
                    v.Add(oper);
                }
            }

            return(v);
        }
コード例 #2
0
ファイル: term-lib.cs プロジェクト: jantolenaar/kiezellisp
 internal static void Init(Runtime.CommandLineOptions options, TerminalMainProgram mainProgram)
 {
     Width = options.Width;
     Height = options.Height;
     DefaultForeColor = new ColorType(options.ForeColor);
     DefaultBackColor = new ColorType(options.BackColor);
     History = new TerminalHistory();
     TerminalWindow = new TerminalMainForm(options.FontName, options.FontSize, Width, Height, mainProgram);
     WindowList = new List<Window>();
     StdScr = ReplWindow.CreateReplWindow(Width, Height, options.BufferHeight);
     Register(StdScr);
     RefreshAll();
     TerminalWindow.Show();
     TerminalWindow.Activate();
     Application.Run(TerminalWindow);
     //Runtime.Quit();
 }
コード例 #3
0
ファイル: infix.cs プロジェクト: MilkTool/kiezellisp
        private Symbol GetLispOperator(object oper)
        {
            switch ((string)oper)
            {
            case "==":
            {
                return(Symbols.Equality);
            }

            case "||":
            {
                return(Symbols.Or);
            }

            case "&&":
            {
                return(Symbols.And);
            }

            case "!":
            {
                return(Symbols.Not);
            }

            case "|":
            {
                return(Symbols.BitOr);
            }

            case "&":
            {
                return(Symbols.BitAnd);
            }

            case "~":
            {
                return(Symbols.BitNot);
            }

            case "^":
            {
                return(Symbols.BitXor);
            }

            case "**":
            {
                return(Symbols.Pow);
            }

            case "<<":
            {
                return(Symbols.BitShiftLeft);
            }

            case ">>":
            {
                return(Symbols.BitShiftRight);
            }

            default:
            {
                return(Runtime.FindSymbol((string)oper));
            }
            }
        }