crazy4s
asked on
error: list<> does not contain a definition for ' '
Hi all,
I'm getting this error for my following program, can anyone explain the below error and how can i solve it?
thanks in advance.
error CS1061: 'System.Collections.Generi c.List<Abs tractSynta x.Declarat ion>' does not contain a definition for 'toStringIndented' and no extension method 'toStringIndented' accepting a first argument of type 'System.Collections.Generi c.List<Abs tractSynta x.Declarat ion>' could be found (are you missing a using directive or an assembly reference?)
in my abstractsyntax.cs:
in my parser.cs:
I'm getting this error for my following program, can anyone explain the below error and how can i solve it?
thanks in advance.
error CS1061: 'System.Collections.Generi
in my abstractsyntax.cs:
public class CProgram
{
List<Declaration> decpart = new List<Declaration>();
List<Statement> body = new List<Statement>();
public CProgram(List<Declaration> d, List<Statement> b)
{
decpart = d;
body = b;
}
public String toString()
{
return toStringIndented("");
}
public String toStringIndented(String indent)
{
return indent + "Program(\n"
+ decpart.toStringIndented(indent + " ") + ",\n" <-- error
+ body.toStringIndented(indent + " ") + "\n" <-- error
+ indent + ")";
}
}
public class Declaration
{
public List<Declaration> decl = null;
public Declaration()
{
}
public Declaration(List<Declaration> Declarations)
{
this.decl = Declarations;
}
public String toString()
{
return toStringIndented("");
}
public String toStringIndented(String indent)
{
StringBuilder sb = new StringBuilder();
sb.Append(indent);
sb.Append("Declarations(\n");
int i = 0;
foreach (Declaration s in decl)
{
sb.Append(this.toStringIndented(indent + " "));
i++;
if (i == decl.Count)
sb.Append("\n");
else
sb.Append(",\n");
}
sb.Append(indent);
sb.Append(")");
return sb.ToString();
}
}
in my parser.cs:
public void program()
{
match(Token.TokenType.Int);
match(Token.TokenType.Main);
match(Token.TokenType.LeftParen);
match(Token.TokenType.RightParen);
match(Token.TokenType.LeftBrace);
List<Declaration> decls = declarations();
List<Statement> stmts = statements();
match(Token.TokenType.RightBrace);
if (error_flag == false)
Console.WriteLine("No Syntax Error. Comgratulation!");
CProgram p = new CProgram(decls,stmts);
}
private List<Declaration> declarations()
{
List<Declaration> ds = new List<Declaration>();
List<Declaration> dsl = new List<Declaration>();
while (current_token.getType() == Token.TokenType.Int ||
current_token.getType() == Token.TokenType.Float ||
current_token.getType() == Token.TokenType.Char ||
current_token.getType() == Token.TokenType.Bool)
{
dsl = declaration();
ds.AddRange(dsl);
}
return ds;
}
private List<Declaration> declaration()
{
List<Declaration> result = new List<Declaration>();
Type t = type();
Variable v = new Variable(match(Token.TokenType.Identifier));
if (current_token.getType() == Token.TokenType.LeftBracket)
{
match(Token.TokenType.LeftBracket);
int i = Convert.ToInt32(match(Token.TokenType.IntLiteral));
match(Token.TokenType.RightBracket);
ArrayDecl ad = new ArrayDecl(v, t, i);
result.Add(ad);
}
else
{
VariableDecl vd = new VariableDecl(v, t);
result.Add(vd);
}
while (current_token.getType() == Token.TokenType.Comma)
{
match(Token.TokenType.Comma);
Variable v1 = new Variable(match(Token.TokenType.Identifier));
if (current_token.getType() == Token.TokenType.LeftBracket)
{
match(Token.TokenType.LeftBracket);
int i = Convert.ToInt32(match(Token.TokenType.IntLiteral));
match(Token.TokenType.RightBracket);
ArrayDecl ad = new ArrayDecl(v1, t, i);
result.Add(ad);
}
else
{
VariableDecl vd2 = new VariableDecl(v1, t);
result.Add(vd2);
}
}
match(Token.TokenType.Semicolon);
return result;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.