Esempio n. 1
0
        public Scanner(string filename, TextReader source, int tabsize)
        {
            // set up keyword map to TokenKind
            dictPop();

            _source = source;
            _cursor = new Position(filename, 1, 0);  // filename could be "(console)" if doing interactive interpretation
            _tabsize = tabsize;

            ReadChar();    // fetch initial lookahead character
            _nextToken = ScanToken();  // fetch initial lookahead token
        }
Esempio n. 2
0
 public ParserError(Position position, string message)
     : base(position, message)
 {
 }
Esempio n. 3
0
File: Token.cs Progetto: bencz/Beryl
 public Token(Position position)
 {
     _position = new Position(position);  // create a DEEP copy of the position to avoid problems ahead.
 }
Esempio n. 4
0
File: Token.cs Progetto: bencz/Beryl
 public Token()
 {
     _position = new Position();
 }
Esempio n. 5
0
 private OperatorKind TokenKindToOperator(Position position, TokenKind kind)
 {
     switch (kind)
     {
         case TokenKind.Asterisk: return OperatorKind.Multiplication;
         case TokenKind.Backslash: return OperatorKind.Difference;
         case TokenKind.Equal: return OperatorKind.Equality;
         case TokenKind.GreaterThan: return OperatorKind.GreaterThan;
         case TokenKind.LessThan: return OperatorKind.LessThan;
         case TokenKind.Minus: return OperatorKind.Subtraction;
         case TokenKind.Plus: return OperatorKind.Addition;
         default: throw new ParserError(position, "Invalid operator encountered: " + kind.ToString());
     }
 }
Esempio n. 6
0
 private string TokenKindToOperatorName(Position position, TokenKind kind)
 {
     switch (kind)
     {
         case TokenKind.Asterisk   : return "*";
         case TokenKind.Backslash  : return "\\";
         case TokenKind.Equal      : return "=";
         case TokenKind.GreaterThan: return ">";
         case TokenKind.LessThan   : return "<";
         case TokenKind.Minus      : return "-";
         case TokenKind.Plus       : return "+";
         default: throw new ParserError(position, "Invalid operator encountered: " + kind.ToString());
     }
 }
Esempio n. 7
0
        private Declaration[] CreateStandardEnvironment(bool insert = false)
        {
            List<Declaration> result = new List<Declaration>();

            // signal that the following symbols are part of the standard library
            Position position = new Position("(library)", 0, 0);
            Declaration declaration;
            Expression expression;

            // enter the predefined constant 'maxint' into the symbol table
            expression = new IntegerExpression(position, int.MaxValue);
            declaration = new ConstantDeclaration(position, "maxint", new IntegerType(position), expression);
            result.Add(declaration);

            // enter the predefined constants 'false' and 'true' into the symbol table
            expression = new BooleanExpression(position, false);
            declaration = new ConstantDeclaration(position, "false", new BooleanType(position), expression);
            result.Add(declaration);

            expression = new BooleanExpression(position, true);
            declaration = new ConstantDeclaration(position, "true", new BooleanType(position), expression);
            result.Add(declaration);

            // enter the predefined operators into the symbol table
            // ... the \ operator
            declaration = new FunctionDeclaration(
                position,
                "\\",
                new BooleanType(position),
                new ParameterDeclaration[] { new ParameterDeclaration(position, "value", new BooleanType(position)) },
                null        // note: the code generator must handle these predefined functions so no body is defined
            );
            result.Add(declaration);

            // ... all Triangle operators of the form Boolean x Boolean -> Boolean
            string[] boolean_and_boolean_to_boolean_operators = { "/\\", "\\/", "=", "\\=" };
            foreach (string @operator in boolean_and_boolean_to_boolean_operators)
            {
                declaration = new FunctionDeclaration(
                    position,
                    @operator,
                    new BooleanType(position),
                    new ParameterDeclaration[]
                    {
                        new ParameterDeclaration(position, "first", new BooleanType(position)),
                        new ParameterDeclaration(position, "other", new BooleanType(position))
                    },
                    null    // note: the code generator must handle these predefined functions so no body is defined
                );
                result.Add(declaration);
            }

            // ... all Triangle operators of the form Integer x Integer -> Integer
            string[] integer_and_integer_to_integer_operators = { "+", "-", "*", "/", "//" };
            foreach (string @operator in integer_and_integer_to_integer_operators)
            {
                declaration = new FunctionDeclaration(
                    position,
                    @operator,
                    new IntegerType(position),
                    new ParameterDeclaration[]
                    {
                        new ParameterDeclaration(position, "first", new IntegerType(position)),
                        new ParameterDeclaration(position, "other", new IntegerType(position))
                    },
                    null    // note: the code generator must handle these predefined functions so no body is defined
                );
                result.Add(declaration);
            }

            // ... all Triangle operators of the form Integer x Integer -> Boolean
            string[] integer_and_integer_to_boolean_operators = { "<", "<=", ">", ">=", "=", "\\=" };
            foreach (string @operator in integer_and_integer_to_boolean_operators)
            {
                declaration = new FunctionDeclaration(
                    position,
                    @operator,
                    new BooleanType(position),
                    new ParameterDeclaration[]
                    {
                        new ParameterDeclaration(position, "first", new IntegerType(position)),
                        new ParameterDeclaration(position, "other", new IntegerType(position))
                    },
                    null    // note: the code generator must handle these predefined functions so no body is defined
                );
                result.Add(declaration);
            }

            // enter the predefined functions (getint and putint) into the symbol table
            declaration = new FunctionDeclaration(
                position,
                "getint",
                new IntegerType(position),
            #if false
                new ParameterDeclaration[] { new ParameterDeclaration(position, "value", new IntegerType(position))},
            #else
                new ParameterDeclaration[0],
            #endif
                null        // note: the code generator must handle these predefined functions so no body is defined
            );
            result.Add(declaration);

            declaration = new FunctionDeclaration(
                position,
                "putint",
                new IntegerType(position),
                new ParameterDeclaration[] { new ParameterDeclaration(position, "value", new IntegerType(position))},
                null        // note: the code generator must handle these predefined functions so no body is defined
            );
            result.Add(declaration);

            return result.ToArray();
        }
Esempio n. 8
0
 public ScannerError(Position position, string message)
     : base(position, message)
 {
 }
Esempio n. 9
0
 public BerylError(Position position, string message)
     : base(message)
 {
     _position = new Position(position);    // make DEEP copy to avoid nasty side effects
 }
Esempio n. 10
0
 public BerylError(string message)
     : base(message)
 {
     _position = null;
 }
Esempio n. 11
0
 public Position(Position position)
 {
     _file = position.File;
     _line = position.Line;
     _char = position.Char;
 }
Esempio n. 12
0
 public CheckerError(Position position, string message)
     : base(position, message)
 {
 }