Ejemplo n.º 1
0
 public ScannedToken(SheepTokenType type, BetterString text, int line)
 {
     Type     = type;
     Position = text.Position;
     Line     = line;
     Text     = text;
 }
Ejemplo n.º 2
0
        private float getFloatFromLiteralToken(SheepTokenType type, BetterString text)
        {
            if (type == SheepTokenType.LiteralFloat)
            {
                float data;
                if (text.TryParseFloat(out data))
                {
                    return(data);
                }
            }
            else if (type == SheepTokenType.LiteralInteger)
            {
                int data;
                if (text.TryParseInt(out data))
                {
                    return((float)data);
                }
            }

            throw new SheepCompilerException();
        }
Ejemplo n.º 3
0
        private int lookupStringConstant(BetterString str, bool addIfNotFound)
        {
            string s = str.ToString();

            int index;

            if (_stringConstants.TryGetValue(s, out index))
            {
                return(index);
            }

            if (addIfNotFound)
            {
                index = _stringConstants.Count;
                _stringConstants.Add(s, index);
                return(index);
            }
            else
            {
                return(-1);
            }
        }
Ejemplo n.º 4
0
        private void parseClosedStatement(ScannedToken token, SheepCodeTreeNode2 node)
        {
            if (token.Type == SheepTokenType.Semicolon)
            {
                // empty statement, do nothing
            }
            else if (token.Type == SheepTokenType.LocalIdentifier)
            {
                BetterString id = token.Text;
                token = _scanner.GetNextToken();
                if (token.Type == SheepTokenType.Equal)
                {
                    SheepCodeTreeNode2 assignment = _tree.AddAsChild(node);
                    assignment.Type = SheepTreeNodeType.Assignment;
                    assignment.Name = id;

                    SheepCodeTreeNode2 expr = parseExpression();
                    _tree.AddAsChild(assignment, expr);
                }
                else
                {
                    throw new SheepCompilerException();
                }
            }
            else if (token.Type == SheepTokenType.Return)
            {
                // return statement
                if (_scanner.GetNextToken().Type != SheepTokenType.Semicolon)
                {
                    throw new SheepCompilerException();
                }
            }

            // the only thing left to try is an expression
            parseExpression();
        }