Solved

Inconsistent accessibility: return type ' ' is less accessible than method ' '

Posted on 2012-04-03
5
2,330 Views
Last Modified: 2012-04-08
Hi all,
I'm getting this error message when compiling my codes.
Can anyone help me to solve this prob, i know is something to deal with the public method trying to access the existing private method.

Inconsistent accessibility: return type 'Clite_Parser.Token' is less accessible than method 'Clite_Parser.Type.get_Token_Type()'

Here's the code:

i have an interface of Type.cs called IType.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Clite_Parser;

namespace CLite_Parser.Interface
{
    public interface IType
    {
        Token get_Token_Type(); <-- Inconsistent accessibility
    }
}

Open in new window


Type.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CLite_Parser.Interface;

namespace Clite_Parser
{
    public class Type : IType
    {
        readonly static String INTEGER = "int";
        readonly static String BOOLEAN = "bool";
        readonly static String FLOAT = "float";
        readonly static String CHAR = "char";
        String id;

        public Type(String t)
        {
            id = t;
        }

        public bool isInt()
        {
            return id.Equals(INTEGER);
        }

        public bool isBool()
        {
            return id.Equals(BOOLEAN);
        }

        public bool isFloat()
        {
            return id.Equals(FLOAT);
        }

        public bool isChar()
        {
            return id.Equals(CHAR);
        }

        public Token get_Token_Type()  <--  Inconsistent accessibility
        {
            return id; <-- id - Cannot implicitly convert type 'string' to 'Clite_Parser.Token'
        }
    }

}

Open in new window


Token.cs that related with the above errors
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Clite_Parser
{
    class Token
    {
        public enum TokenType
        {
            Bool, Char, Else, False, Float,
            If, Int, Main, True, While,
            Eof, LeftBrace, RightBrace, LeftBracket, RightBracket,
            LeftParen, RightParen, Semicolon, Comma, Assign,
            Equals, Less, LessEqual, Greater, GreaterEqual,
            Not, NotEqual, Plus, Minus, Multiply,
            Divide, And, Or, Identifier, IntLiteral,
            FloatLiteral, CharLiteral
        }

        private static readonly int KEYWORDS = 10;

        private static readonly String[] reserved = new String[KEYWORDS];
        private static Token[] token = new Token[KEYWORDS];

        public static readonly Token eofTok = new Token(TokenType.Eof, "<<EOF>>");
        public static readonly Token boolTok = new Token(TokenType.Bool, "bool");
        public static readonly Token charTok = new Token(TokenType.Char, "char");
        public static readonly Token elseTok = new Token(TokenType.Else, "else");
        public static readonly Token falseTok = new Token(TokenType.False, "false");
        public static readonly Token floatTok = new Token(TokenType.Float, "float");
        public static readonly Token ifTok = new Token(TokenType.If, "if");
        public static readonly Token intTok = new Token(TokenType.Int, "int");
        public static readonly Token mainTok = new Token(TokenType.Main, "main");
        public static readonly Token trueTok = new Token(TokenType.True, "true");
        public static readonly Token whileTok = new Token(TokenType.While, "while");
        public static readonly Token leftBraceTok = new Token(TokenType.LeftBrace, "{");
        public static readonly Token rightBraceTok = new Token(TokenType.RightBrace, "}");
        public static readonly Token leftBracketTok = new Token(TokenType.LeftBracket, "[");
        public static readonly Token rightBracketTok = new Token(TokenType.RightBracket, "]");
        public static readonly Token leftParenTok = new Token(TokenType.LeftParen, "(");
        public static readonly Token rightParenTok = new Token(TokenType.RightParen, ")");
        public static readonly Token semicolonTok = new Token(TokenType.Semicolon, ";");
        public static readonly Token commaTok = new Token(TokenType.Comma, ",");
        public static readonly Token assignTok = new Token(TokenType.Assign, "=");
        public static readonly Token eqeqTok = new Token(TokenType.Equals, "==");
        public static readonly Token ltTok = new Token(TokenType.Less, "<");
        public static readonly Token lteqTok = new Token(TokenType.LessEqual, "<=");
        public static readonly Token gtTok = new Token(TokenType.Greater, ">");
        public static readonly Token gteqTok = new Token(TokenType.GreaterEqual, ">=");
        public static readonly Token notTok = new Token(TokenType.Not, "!");
        public static readonly Token noteqTok = new Token(TokenType.NotEqual, "!=");
        public static readonly Token plusTok = new Token(TokenType.Plus, "+");
        public static readonly Token minusTok = new Token(TokenType.Minus, "-");
        public static readonly Token multiplyTok = new Token(TokenType.Multiply, "*");
        public static readonly Token divideTok = new Token(TokenType.Divide, "/");
        public static readonly Token andTok = new Token(TokenType.And, "&&");
        public static readonly Token orTok = new Token(TokenType.Or, "||");

        private TokenType type;
        private String value = "";


        private Token(TokenType t, String v)
        {
            type = t;
            value = v;
            if (t.CompareTo(TokenType.Eof) < 0)
            {
                int ti = (int)t;
                reserved[ti] = v;
                token[ti] = this;
            }
        }

        public TokenType getType() { return type; }

        public String getValue() { return value; }

        public static Token keyword(String name)
        {
            char ch = name[0];
            if (ch >= 'A' && ch <= 'Z') return mkIdentTok(name);
            for (int i = 0; i < KEYWORDS; i++)
                if (name.CompareTo(reserved[i]) == 0) return token[i];
            return mkIdentTok(name);
        } // keyword

        public static Token mkIdentTok(String name)
        {
            return new Token(TokenType.Identifier, name);
        }

        public static Token mkIntLiteral(String name)
        {
            return new Token(TokenType.IntLiteral, name);
        }

        public static Token mkFloatLiteral(String name)
        {
            return new Token(TokenType.FloatLiteral, name);
        }

        public static Token mkCharLiteral(String name)
        {
            return new Token(TokenType.CharLiteral, name);
        }

        public String toString()
        {
            if (type.CompareTo(TokenType.Identifier) < 0) return value;
            return type + "\t" + value;
        } // toString
    }
}

Open in new window

0
Comment
Question by:crazy4s
5 Comments
 
LVL 4

Assisted Solution

by:jatkin
jatkin earned 166 total points
Comment Utility
I think you're missing the public declaration on the class:

namespace Clite_Parser
{
    public class Token
....
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 167 total points
Comment Utility
public Token get_Token_Type()

That says the function RETURNS a Token, but the code you have has it returning a string, not a Token.  Either return a Token object or change the return type to a string.
0
 

Author Comment

by:crazy4s
Comment Utility
hmm token.cs was given by the lecturer, so is there any possible that making any changes only to Type.cs without changing anything in Token.cs and IType.cs?
0
 

Author Comment

by:crazy4s
Comment Utility
i have this code which convert the type to string and send it to type.cs at line 10:
so to make it into token object, can i just not convert it to string?
private IType type()
        {
            IType t = null;
            switch (current_token.getType())
            {
                case Token.TokenType.Int:
                case Token.TokenType.Char:
                case Token.TokenType.Float:
                case Token.TokenType.Bool:
                    t = Factory.create_Type(current_token.toString());
                    current_token = mylexer.next();
                    return t;
                default:
                    Console.WriteLine("Syntax error: line " + mylexer.getCurrentLine() + " expecting: int, char, bool, or float" + "; saw: " + current_token.getType() + "value is " + current_token.toString());
                    current_token = mylexer.next();
                    error_flag = true;
                    break;
            }

            return t;
        }

Open in new window

0
 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 167 total points
Comment Utility
As jatkin noted, you haven't put an access modifier on the Token class. When you leave the modifier off, the default (for classes) is internal (1). Because you have given both the Type class and IType interface an access modifier of public, the cannot figure out which access is supposed to be used for everything--the three types are in conflict. You must make the Token class public to match the access modifiers of the other two types (I assume you want to keep public because it is used by some other code.

1.

http://msdn.microsoft.com/en-us/library/ms173121.aspx
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now