示例#1
0
文件: IoLexer.cs 项目: ypyf/io
        public int lex()
        {
            pushPos();
            messageChain();

            if (!onNULL())
            {
                if (errorToken == null)
                {
                    if (tokenStream.Count != 0)
                    {
                        errorToken = currentToken();
                    }
                    else
                    {
                        int restLength = s.Length - currentPos;
                        int limit      = restLength < MaxErrorToken ? restLength : MaxErrorToken;
                        errorToken = addTokenStringType(s.Substring(currentPos, limit), IoTokenType.NO_TOKEN);
                    }

                    errorToken.error = "Syntax error near this location";
                }
                return(-1);
            }
            return(0);
        }
示例#2
0
文件: IoLexer.cs 项目: ypyf/io
        public IoToken pop()
        {
            IoToken first = top();

            resultIndex++;
            return(first);
        }
示例#3
0
文件: IoLexer.cs 项目: ypyf/io
        // terminators

        public int readTerminator()
        {
            int terminated = 0;

            pushPos();
            readSeparator();

            while (readTerminatorChar() != 0)
            {
                terminated = 1;
                readSeparator();
            }

            if (terminated != 0)
            {
                IoToken top = currentToken();

                // avoid double terminators
                if (top != null && top.type == IoTokenType.TERMINATOR_TOKEN)
                {
                    return(1);
                }

                addTokenStringType(";", IoTokenType.TERMINATOR_TOKEN);
                popPos();
                return(1);
            }

            popPosBack();
            return(0);
        }
示例#4
0
文件: IoMessage.cs 项目: ypyf/io
        void parseName(IoState state, IoLexer lexer)
        {
            IoToken token = lexer.pop();

            messageName = IoSeq.createSymbolInMachine(state, token.name);
            ifPossibleCacheToken(token);
            //rawSetLineNumber(token.lineNumber);
            //rawSetCharNumber(token.charNumber);
        }
示例#5
0
文件: IoLexer.cs 项目: ypyf/io
        public void print()
        {
            IoToken first = tokenStream[0];

            if (first != null)
            {
                first.print();
            }
            Console.WriteLine();
        }
示例#6
0
文件: IoLexer.cs 项目: ypyf/io
        public void printTokens()
        {
            int i;

            for (i = 0; i < tokenStream.Count; i++)
            {
                IoToken t = tokenStream[i];
                Console.Write("'{0}' {1}", t.name, t.typeName());
                if (i < tokenStream.Count - 1)
                {
                    Console.Write(", ");
                }
            }
            Console.WriteLine();
        }
示例#7
0
文件: IoLexer.cs 项目: ypyf/io
        public void popPosBack()
        {
            int i        = Convert.ToInt32(tokenStack.Pop());
            int topIndex = Convert.ToInt32(tokenStack.Peek());

            if (i > -1)
            {
                if (i != topIndex)
                {
                    IoToken parent = currentToken();
                    if (parent != null)
                    {
                        parent.nextToken = null;
                    }
                }
            }
            currentPos = Convert.ToInt32(posStack.Pop());
        }
示例#8
0
文件: IoLexer.cs 项目: ypyf/io
        public int readMonoQuote()
        {
            pushPos();

            if (nextChar() == '"')
            {
                while (true)
                {
                    char c = nextChar();

                    if (c == '"')
                    {
                        break;
                    }

                    if (c == '\\')
                    {
                        nextChar();
                        continue;
                    }

                    if (c == 0)
                    {
                        errorToken = currentToken();

                        if (errorToken != null)
                        {
                            errorToken.error = "unterminated quote";
                        }

                        popPosBack();
                        return(0);
                    }
                }

                grabTokenType(IoTokenType.MONOQUOTE_TOKEN);
                popPos();
                return(1);
            }

            popPosBack();
            return(0);
        }
示例#9
0
文件: IoMessage.cs 项目: ypyf/io
        void ifPossibleCacheToken(IoToken token)
        {
            IoSeq    method = this.messageName;
            IoObject r      = null;

            switch (token.type)
            {
            case IoTokenType.TRIQUOTE_TOKEN:
                break;

            case IoTokenType.MONOQUOTE_TOKEN:
                r = IoSeq.createSymbolInMachine(
                    method.state,
                    IoSeq.rawAsUnescapedSymbol(
                        IoSeq.rawAsUnquotedSymbol(
                            IoSeq.createObject(method.state, method.value)
                            )
                        ).value
                    );
                break;

            case IoTokenType.NUMBER_TOKEN:
                r = IoNumber.newWithDouble(this.state, Convert.ToDouble(method.value, CultureInfo.InvariantCulture));
                break;

            default:
                if (method.value.Equals("nil"))
                {
                    r = state.ioNil;
                }
                else if (method.value.Equals("true"))
                {
                    r = state.ioTrue;
                }
                else if (method.value.Equals("false"))
                {
                    r = state.ioFalse;
                }
                break;
            }
            this.cachedResult = r;
        }
示例#10
0
文件: IoLexer.cs 项目: ypyf/io
        public IoToken addTokenStringType(string s1, IoTokenType type)
        {
            IoToken top = currentToken();
            IoToken t   = new IoToken();

            t.lineNumber = currentLineNumber();
            t.charNumber = currentPos;

            if (t.charNumber < 0)
            {
                System.Console.WriteLine("bad t->charNumber = %i\n", t.charNumber);
            }

            t.name = s1;
            t.type = type;

            if (top != null)
            {
                top.nextToken = t;
            }

            tokenStream.Add(t);
            return(t);
        }
示例#11
0
        public int lex()
        {
            pushPos();
            messageChain();

            if (!onNULL())
            {
                if (errorToken == null)
                {
                    if (tokenStream.Count != 0)
                    {
                        errorToken = currentToken();
                    }
                    else
                    {
                        errorToken = addTokenStringType(s.Substring(currentPos, 30), IoTokenType.NO_TOKEN);
                    }

                    errorToken.error = "Syntax error near this location";
                }
                return(-1);
            }
            return(0);
        }
示例#12
0
        public IoToken addTokenStringType(string s1, IoTokenType type)
        {
            IoToken top = currentToken();
            IoToken t = new IoToken();

            t.lineNumber = currentLineNumber();
            t.charNumber = currentPos;

            if (t.charNumber < 0)
            {
                System.Console.WriteLine("bad t->charNumber = %i\n", t.charNumber);
            }

            t.name = s1;
            t.type = type;

            if (top != null)
            {
                top.nextToken = t;
            }

            tokenStream.Add(t);
            return t;
        }
示例#13
0
        public int lex()
        {
            pushPos();
            messageChain();

            if (!onNULL())
            {

                if (errorToken == null)
                {
                    if (tokenStream.Count != 0)
                    {
                        errorToken = currentToken();
                    }
                    else
                    {
                        errorToken = addTokenStringType(s.Substring(currentPos, 30), IoTokenType.NO_TOKEN);
                    }

                    errorToken.error = "Syntax error near this location";
                }
                return -1;
            }
            return 0;
        }
示例#14
0
        public int readMonoQuote()
        {
            pushPos();

            if (nextChar() == '"')
            {
                while (true)
                {
                    char c = nextChar();

                    if (c == '"')
                    {
                        break;
                    }

                    if (c == '\\')
                    {
                        nextChar();
                        continue;
                    }

                    if (c == 0)
                    {
                        errorToken = currentToken();

                        if (errorToken != null)
                        {
                            errorToken.error = "unterminated quote";
                        }

                        popPosBack();
                        return 0;
                    }
                }

                grabTokenType(IoTokenType.MONOQUOTE_TOKEN);
                popPos();
                return 1;
            }

            popPosBack();
            return 0;
        }
示例#15
0
 public void readMessageError(string name)
 {
     popPosBack();
     errorToken = currentToken();
     errorToken.error = name;
 }
示例#16
0
文件: IoLexer.cs 项目: ypyf/io
 public void readMessageError(string name)
 {
     popPosBack();
     errorToken       = currentToken();
     errorToken.error = name;
 }
示例#17
0
        void ifPossibleCacheToken(IoToken token)
        {
            IoSeq method = this.messageName;
            IoObject r = null;
            switch (token.type)
            {
                case IoTokenType.TRIQUOTE_TOKEN:
                    break;
                case IoTokenType.MONOQUOTE_TOKEN:
                    r = IoSeq.createSymbolInMachine(
                            method.state,
                            IoSeq.rawAsUnescapedSymbol(
                                IoSeq.rawAsUnquotedSymbol(
                                    IoSeq.createObject(method.state, method.value)
                                )
                            ).value
                        );
                    break;
                case IoTokenType.NUMBER_TOKEN:
                    r = IoNumber.newWithDouble(this.state, Convert.ToDouble(method.value, CultureInfo.InvariantCulture));
                    break;
                default:
                    if (method.value.Equals("nil"))
                    {
                        r = state.ioNil;
                    }
                    else if (method.value.Equals("true"))
                    {
                        r = state.ioTrue;
                    }
                    else if (method.value.Equals("false"))
                    {
                        r = state.ioFalse;
                    }
                    break;

            }
            this.cachedResult = r;
        }