Example #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;
        }
Example #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();
            }
        }
Example #3
0
 public Number(Token token, double value) : base(token)
 {
     this.value = value;
 }
Example #4
0
 public WrongTokenFound(Token token, string rawValue) : base(CreateMessage(token, rawValue))
 {
 }
 public DivisionExpression(Token token, Expression leftHandStatement, Expression rightHandStatement) : base(token, leftHandStatement, rightHandStatement)
 {
 }
Example #6
0
 public Bool(Token token, bool value) : base(token)
 {
     this.value = value;
 }
Example #7
0
 public Identifier(Token token, string content) : base(token)
 {
     name = content;
 }
Example #8
0
 public Condition(Token token, Expression leftHandStatement, Expression rightHandStatement) : base(token, leftHandStatement, rightHandStatement)
 {
 }
Example #9
0
 public Expression(Token token) : base(token)
 {
 }
Example #10
0
 public Literal(Token token) => Value = new VariableInfo(ConvertTokenType(token), null)
Example #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);
Example #12
0
 public TypeNotFound(Token token) : base(CreateMessage(token))
 {
 }
Example #13
0
 private static bool IsOperator(Token token, Operator @operator) =>
 token.TypeId == Token.Type.Operator && (Operator)token.Value == @operator;
Example #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;
Example #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);
 public MultiplyExpression(Token token, Expression leftHandStatement, Expression rightHandStatement) : base(token, leftHandStatement, rightHandStatement)
 {
 }
Example #17
0
 public Call(Token token) : base(token)
 {
 }
Example #18
0
 public Text(Token token, string value) : base(token)
 {
     this.value = value;
 }
Example #19
0
 public BinaryExpression(Token token, Expression leftHandStatement, Expression rightHandStatement) : base(token)
 {
     this.leftHandStatement = leftHandStatement;
     this.rightHandStatement = rightHandStatement;
 }
Example #20
0
 public Assignment(Token token) : base(token)
 {
 }
Example #21
0
 public Statement(Token token) : base(token)
 {
 }
Example #22
0
 public Primitive(Token token) : base(token)
 {
 }
Example #23
0
 public Identifier(Token token) : base(token)
 {
     name = token.content;
 }
Example #24
0
 public Symbol(Token token)
 {
     this.token = token;
 }
Example #25
0
 public ProgramBlock(Token token, List<Statement> statements)
 {
     Symbol symbol = new Symbol(token);
     this.statements = statements;
 }
Example #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;
        }
Example #27
0
 public Block(Token token, List<Statement> statements) : base(token)
 {
     this.statements = statements;
 }
 public SubtractExpression(Token token, Expression leftHandStatement, Expression rightHandStatement) : base(token, leftHandStatement, rightHandStatement)
 {
 }