Esempio n. 1
0
        public bool next(List<Token> tokens)
        {

            if (lineRemaining == FileReader._EOF)
                return false;

            if (lineRemaining == "")
            {
                nextLine();
                return true;
            }

            foreach (TokenDefenition def in defenitions)
            {
                
                int matched = def.matcher.match(lineRemaining);

                if (matched <= 0) continue;
                int column = position + 1;
                position += matched;

                // comment lines made
                if (def.tokenType == TokenType.SINGLELINE)
                    matched = lineRemaining.Length;

                // stripping strings from ""
                string content = lineRemaining.Substring(0, matched);
                if (def.tokenType == TokenType.TEXT)
                    content = content.Substring(1, content.Length - 2);


                token = new Token(def.tokenType, position, lineNumber, column, indentationLevel, content);
                lineRemaining = lineRemaining.Substring(matched);

                if (lineRemaining.Length == 0)
                {
                    nextLine();
                }
                return true;
            }
            Console.WriteLine("WARNING - Unidentifier token '" + lineRemaining + "' on line: " + lineNumber);
            tokens.Add(new Token(TokenType.NONE, token.index, token.line, token.column,token.level, lineRemaining));
            nextLine();
            return true;
        }
Esempio n. 2
0
        public static Compiler.Type ConvertTokenType(Token token)
        {
            switch (token.TypeId)
            {
            case Token.Type.Keyword:
                switch ((TokenizerKeyword)token.Value)
                {
                case TokenizerKeyword.Null: return(new Compiler.Type(NullTypeInfo));

                case TokenizerKeyword.Void: return(new Compiler.Type(VoidTypeInfo));

                case TokenizerKeyword.True: return(new Compiler.Type(BoolTypeInfo));

                case TokenizerKeyword.False: return(new Compiler.Type(BoolTypeInfo));

                case TokenizerKeyword.Int: return(new Compiler.Type(IntTypeInfo));

                case TokenizerKeyword.Float: return(new Compiler.Type(FloatTypeInfo));

                case TokenizerKeyword.Char: return(new Compiler.Type(CharTypeInfo));

                case TokenizerKeyword.String: return(new Compiler.Type(StringTypeInfo));

                default: throw new InvalidOperationException();
                }

            case Token.Type.Int: return(new Compiler.Type(IntTypeInfo));

            case Token.Type.Char: return(new Compiler.Type(CharTypeInfo));

            case Token.Type.Float: return(new Compiler.Type(FloatTypeInfo));

            case Token.Type.String: return(new Compiler.Type(StringTypeInfo));

            default: throw new InvalidOperationException();
            }
        }
Esempio n. 3
0
 public Number(Token token, double value) : base(token)
 {
     this.value = value;
 }
Esempio n. 4
0
 public WrongTokenFound(Token token, string rawValue) : base(CreateMessage(token, rawValue))
 {
 }
Esempio n. 5
0
 public DivisionExpression(Token token, Expression leftHandStatement, Expression rightHandStatement) : base(token, leftHandStatement, rightHandStatement)
 {
 }
Esempio n. 6
0
 public Bool(Token token, bool value) : base(token)
 {
     this.value = value;
 }
Esempio n. 7
0
 public Identifier(Token token, string content) : base(token)
 {
     name = content;
 }
Esempio n. 8
0
 public Condition(Token token, Expression leftHandStatement, Expression rightHandStatement) : base(token, leftHandStatement, rightHandStatement)
 {
 }
Esempio n. 9
0
 public Expression(Token token) : base(token)
 {
 }
Esempio n. 10
0
 public Literal(Token token) => Value = new VariableInfo(ConvertTokenType(token), null)
Esempio n. 11
0
 private static string CreateMessage(Token token) =>
 string.Format("(r:{0}, c:{1}) syntax error: type '{2}' not found",
               token.RowIndex, token.ColIndex, (string)token.Value);
Esempio n. 12
0
 public TypeNotFound(Token token) : base(CreateMessage(token))
 {
 }
Esempio n. 13
0
 private static bool IsOperator(Token token, Operator @operator) =>
 token.TypeId == Token.Type.Operator && (Operator)token.Value == @operator;
Esempio n. 14
0
 private static bool IsTypeName(Token token) =>
 token.TypeId == Token.Type.Identifier && Compiler.Types.ContainsKey((string)token.Value) ||
 token.TypeId == Token.Type.Keyword && ((Keyword)token.Value & Keyword.Type) != 0;
Esempio n. 15
0
 private static string CreateMessage(Token token, string rawValue) =>
 string.Format("(r:{0}, c:{1}) syntax error: '{2}' expected, but {3} found",
               token.RowIndex, token.ColIndex, rawValue, token.RawValue);
Esempio n. 16
0
 public MultiplyExpression(Token token, Expression leftHandStatement, Expression rightHandStatement) : base(token, leftHandStatement, rightHandStatement)
 {
 }
Esempio n. 17
0
 public Call(Token token) : base(token)
 {
 }
Esempio n. 18
0
 public Text(Token token, string value) : base(token)
 {
     this.value = value;
 }
Esempio n. 19
0
 public BinaryExpression(Token token, Expression leftHandStatement, Expression rightHandStatement) : base(token)
 {
     this.leftHandStatement = leftHandStatement;
     this.rightHandStatement = rightHandStatement;
 }
Esempio n. 20
0
 public Assignment(Token token) : base(token)
 {
 }
Esempio n. 21
0
 public Statement(Token token) : base(token)
 {
 }
Esempio n. 22
0
 public Primitive(Token token) : base(token)
 {
 }
Esempio n. 23
0
 public Identifier(Token token) : base(token)
 {
     name = token.content;
 }
Esempio n. 24
0
 public Symbol(Token token)
 {
     this.token = token;
 }
Esempio n. 25
0
 public ProgramBlock(Token token, List<Statement> statements)
 {
     Symbol symbol = new Symbol(token);
     this.statements = statements;
 }
Esempio n. 26
0
        static Expression produceExpression(Token token, Expression leftHandStatement, Expression rightHandStatement)
        {
            TokenType type = token.tokenType;
            switch (type)
            {
                case TokenType.ADD:
                    return new AdditionExpression(token, leftHandStatement, rightHandStatement);
                case TokenType.SUBTRACT:
                    return new SubtractExpression(token, leftHandStatement, rightHandStatement);
                case TokenType.MULTIPLY:
                    return new MultiplyExpression(token, leftHandStatement, rightHandStatement);
                case TokenType.DIVISION:
                    return new DivisionExpression(token, leftHandStatement, rightHandStatement);
                case TokenType.MODULO:
                    return new ModuloExpression(token, leftHandStatement, rightHandStatement);
                case TokenType.SMALLER:
                    return new SmallerCondition(token, leftHandStatement, rightHandStatement);
                case TokenType.SMALLEREQUAL:
                    return new SmallerEqualCondition(token, leftHandStatement, rightHandStatement);
                case TokenType.LARGER:
                    return new GreaterCondition(token, leftHandStatement, rightHandStatement);
                case TokenType.LARGEREQUAL:
                    return new GreaterEqualCondition(token, leftHandStatement, rightHandStatement);
                case TokenType.EQUAL:
                    return new EqualCondition(token, leftHandStatement, rightHandStatement);
                case TokenType.NOTEQUAL:
                    return new NotEqualCondition(token, leftHandStatement, rightHandStatement);
                case TokenType.AND:
                    return new AndCondition(token, leftHandStatement, rightHandStatement);
                case TokenType.OR:
                    return new OrCondition(token, leftHandStatement, rightHandStatement);
            }

            return null;
        }
Esempio n. 27
0
 public Block(Token token, List<Statement> statements) : base(token)
 {
     this.statements = statements;
 }
Esempio n. 28
0
 public SubtractExpression(Token token, Expression leftHandStatement, Expression rightHandStatement) : base(token, leftHandStatement, rightHandStatement)
 {
 }