public ImportTextFileForm()
        {
            InitializeComponent();

            program = new OricProgram();
            program.New();

            basicTokens = new BasicTokens(BasicTokens.ROMVersion.V1_1);
        }
    static private string MakeToken(BasicTokens t, string buf)
    {
        Tokenized nt = new Tokenized(t, buf);

        if (tokenList.Count != 0)
        {
            LastToken = tokenList[tokenList.Count - 1].type;
        }
        tokenList.Add(nt);
        return("");
    }
        public Tokenized get(BasicTokens expected)
        {
            if (_index >= _tokens.Length)
            {
                return(_default);
            }
            Tokenized tok = _tokens[_index];

            if (tok.type != expected)
            {
                throw new System.Exception("Unexpected token " + tok.value + " at line " + tok.line);
            }
            _index++;
            return(tok);
        }
Exemple #4
0
        public frmImportAtmosBasicFile()
        {
            InitializeComponent();

            basicTokens = new BasicTokens(BasicTokens.ROMVersion.V1_1);
        }
    static private string HandleDefault(char c, string buffer)
    {
        if (c == '\t')
        {
            BasicTokens type = tokenList[tokenList.Count - 1].type;
            if (type == BasicTokens.NEW_LINE || type == BasicTokens.INDENT)
            {
                buffer = MakeToken(BasicTokens.INDENT, buffer);
            }
        }
        else if (IsSpecialChar(c))
        {
            if (buffer.Length > 0)
            {
                int attempt;
                if (buffer == "true" || buffer == "false")
                {
                    buffer = MakeToken(BasicTokens.BOOLEAN, buffer);
                }
                else if (int.TryParse(buffer, out attempt))
                {
                    buffer = MakeToken(BasicTokens.INTEGER, buffer);
                }
                else
                {
                    buffer = MakeToken(BasicTokens.VARIABLE, buffer);
                }
            }


            if (c == '#')
            {
                state.value = State.COMMENT;
            }
            else if (c == '"' || c == '“')
            {
                state.push(State.STRING);
            }
            else if (c == '[')
            {
                state.push(State.COMMAND);
            }
            else if (c == ')')
            {
                MakeToken(BasicTokens.OPEN_PAREN, "");
            }
            else if (c == '(')
            {
                MakeToken(BasicTokens.CLOSE_PAREN, "");
            }
            else if (c == ']' || c == '”')
            {
                throw new System.Exception("Invalid " + c + " at line " + lineNumber.ToString());
            }
            else if (c != ' ' && c != '\n' && c != '\r')
            {
                buffer = c.ToString();
                state.push(State.SPECIAL);
            }
        }
        else
        {
            buffer = buffer + c;
        }

        return(buffer);
    }
 public Tokenized(BasicTokens t, string val)
 {
     type  = t;
     value = val;
     line  = lineNumber;
 }