Ejemplo n.º 1
0
        public override void Check()
        {
            exp.Check();

            if (exp.type != 'b')
            {
                throw new ArgumentException($"  Semantic error at line {line}: If argument has to be of type bool.");
            }
        }
Ejemplo n.º 2
0
        public override void Check()
        {
            Compiler.loopDepth++;
            exp.Check();

            if (exp.type != 'b')
            {
                throw new ArgumentException($"  Semantic error at line {line}: While argument has to be of type bool.");
            }
        }
Ejemplo n.º 3
0
        public override void Check()
        {
            left.Check();
            right.Check();

            if (left.type != 'i' || right.type != 'i')
            {
                throw new ArgumentException($"  Semantic error at line {line}: For bit operations both arguments have to be of type int.");
            }

            type = 'i';
        }
Ejemplo n.º 4
0
        public override void Check()
        {
            left.Check();
            right.Check();

            if (left.type == 'b' || right.type == 'b')
            {
                throw new ArgumentException($"  Semantic error at line {line}: Bool is not a proper type for additive and multiplivative operations.");
            }

            type = left.type == 'i' && right.type == 'i' ? 'i' : 'd';
        }
Ejemplo n.º 5
0
        public override void Check()
        {
            left.Check();
            right.Check();

            if ((left.type == 'b') ^ (right.type == 'b'))
            {
                throw new ArgumentException($"  Semantic error at line {line}: For relational operations both arguments or none of them have to be of type bool.");
            }

            if (left.type == 'b' && (kind != Tokens.Equal && kind != Tokens.NotEqual))
            {
                throw new ArgumentException($"  Semantic error at line {line}: The only accepted comparisons between two bools are == and !=.");
            }

            type = 'b';
        }
Ejemplo n.º 6
0
        public override void Check()
        {
            exp.Check();

            if (kind == Tokens.Minus)
            {
                if (exp.type == 'b')
                {
                    throw new ArgumentException($"  Semantic error at line {line}: Unary minus does not accept arguments of type bool.");
                }

                type = exp.type;
            }
            else if (kind == Tokens.BitNeg)
            {
                if (exp.type != 'i')
                {
                    throw new ArgumentException($"  Semantic error at line {line}: Bitwise negation accepts only arguments of type int.");
                }

                type = exp.type;
            }
            else if (kind == Tokens.Neg)
            {
                if (exp.type != 'b')
                {
                    throw new ArgumentException($"  Semantic error at line {line}: Logical negation accepts only arguments of type bool.");
                }

                type = exp.type;
            }
            else if (kind == Tokens.IntCast)
            {
                type = 'i';
            }
            else if (kind == Tokens.DoubleCast)
            {
                type = 'd';
            }
        }
Ejemplo n.º 7
0
        public override void Check()
        {
            if (!Compiler.symbols.Any(x => x.ident == ident))
            {
                throw new ArgumentException($"  Semantic error at line {line}: {ident} undeclared.");
            }

            var originalSymbol = Compiler.symbols.First(x => x.ident == ident);

            type          = originalSymbol.type;
            generatedName = originalSymbol.generatedName;

            exp.Check();

            if (type != exp.type)
            {
                if (type != 'd' || exp.type != 'i')
                {
                    throw new ArgumentException($"  Semantic error at line {line}: Cannot assign expression type to ident type.");
                }
            }
        }
Ejemplo n.º 8
0
 public override void Check()
 {
     exp.Check();
 }