Exemplo n.º 1
0
Arquivo: IoLexer.cs Projeto: 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);
        }
Exemplo n.º 2
0
Arquivo: IoLexer.cs Projeto: ypyf/io
        public IoToken pop()
        {
            IoToken first = top();

            resultIndex++;
            return(first);
        }
Exemplo n.º 3
0
Arquivo: IoLexer.cs Projeto: 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);
        }
Exemplo n.º 4
0
Arquivo: IoMessage.cs Projeto: 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);
        }
Exemplo n.º 5
0
Arquivo: IoLexer.cs Projeto: ypyf/io
        public void print()
        {
            IoToken first = tokenStream[0];

            if (first != null)
            {
                first.print();
            }
            Console.WriteLine();
        }
Exemplo n.º 6
0
Arquivo: IoLexer.cs Projeto: 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();
        }
Exemplo n.º 7
0
Arquivo: IoLexer.cs Projeto: 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());
        }
Exemplo n.º 8
0
Arquivo: IoLexer.cs Projeto: 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);
        }
Exemplo n.º 9
0
Arquivo: IoMessage.cs Projeto: 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;
        }
Exemplo n.º 10
0
Arquivo: IoLexer.cs Projeto: 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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;
        }
Exemplo n.º 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;
        }
Exemplo n.º 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;
        }
Exemplo n.º 15
0
 public void readMessageError(string name)
 {
     popPosBack();
     errorToken = currentToken();
     errorToken.error = name;
 }
Exemplo n.º 16
0
Arquivo: IoLexer.cs Projeto: ypyf/io
 public void readMessageError(string name)
 {
     popPosBack();
     errorToken       = currentToken();
     errorToken.error = name;
 }
Exemplo n.º 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;
        }