[Nemerle] yield глючит
От: WolfHound  
Дата: 27.09.06 16:07
Оценка: +1
Вот такой код вышибает коспилятор в Internal compiler error
using System.IO;
using System.Collections.Generic;
using System.Console;

[Record]
variant Token
{
    public pos : int;
    public len : int;
    
    | Identifier { name : string; }
    
    | Operator { name : string }

    | Semicolon     // ;
    | Colon         // :
    | Comma
    | BeginBrace    // {
    | EndBrace      // }
    | BeginRound    // (
    | EndRound      // )

    | End
}

class Lexer
{
    public GetTokens(text : string) : IEnumerable[Token]
    {
        mutable pos = 0;
        def substr(start, e)
        {
            text.Substring(start, start - e)
        }
        def end()
        {
            pos >= text.Length
        }
        def isSpace(c)
        {
            c == ' ' || c == '\t' || c == '\n'
        }
        def skipSpaces()
        {
            while (!end() && isSpace(text[pos]))
                ++pos;
        }
        yield Token.End(pos, 0);
    }
}

module Test
{
    Main() : void
    {
        def lexer = Lexer();
        using (def file = File.OpenText("test.pcd"))
        {
            foreach(token in lexer.GetTokens(file.ReadToEnd()))
            {
            | Identifier(name) =>
                WriteLine(name);
            | End => break;
            }
        }
    }
}

Компилю Bootstrap'ом ревизия 6642
... << RSDN@Home 1.1.4 stable SR1 rev. 568>>

30.01.07 18:13: Перенесено модератором из 'Декларативное программирование' — IT
Пусть это будет просто:
просто, как только можно,
но не проще.
(C) А. Эйнштейн
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.