Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++/CLI C# conversion
Hi Smile | :)
I'm try to convert a simple code of C# to C++/CLI, but when I try to build the converted code, i got this erros:
 
Quote:
1>------ Build started: Project: Compiler2, Configuration: Debug Win32 ------
1> Source.cpp
1>Source.cpp(21): error C2143: syntax error : missing ';' before '^'
1>Source.cpp(21): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>Source.cpp(28): error C2143: syntax error : missing ';' before '^'
1>Source.cpp(28): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>Source.cpp(36): error C2143: syntax error : missing ';' before '^'
1>Source.cpp(36): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>Source.cpp(44): error C2143: syntax error : missing ';' before '^'
1>Source.cpp(44): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>Source.cpp(45): error C2143: syntax error : missing ';' before '^'
1>Source.cpp(45): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>Source.cpp(101): error C2146: syntax error : missing ';' before identifier 'Op'
1>Source.cpp(101): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

 

and, my code is that:
// AST.cs

using namespace System;
 
/* <stmt> := var <ident> = <expr>
    | <ident> = <expr>
    | for <ident> = <expr> to <expr> do <stmt> end
    | read_int <ident>
    | print <expr>
    | <stmt> ; <stmt>
  */
public ref class Stmt abstract
{
};
 
// var <ident> = <expr>
public ref class DeclareVar : Stmt
{
public:
    String^ Ident;
    Expr^ expr;
};
 
// print <expr>
public ref class Print : Stmt
{
public:
    Expr^ Expr;
};
 
// <ident> = <expr>
public ref class Assign : Stmt
{
public:
    String^ Ident;
    Expr^ Expr;
};
 
// for <ident> = <expr> to <expr> do <stmt> end
public ref class ForLoop : Stmt
{
public:
    String^ Ident;
    Expr^ From;
    Expr^ To;
    Stmt^ Body;
};
 
// read_int <ident>
public ref class ReadInt : Stmt
{
public:
    String^ Ident;
};
 
// <stmt> ; <stmt>
public ref class Sequence : Stmt
{
public:
    Stmt^ First;
    Stmt^ Second;
};
 
/* <expr> := <string>
 *  | <int>
 *  | <arith_expr>
 *  | <ident>
 */
public ref class Expr abstract
{
};
 
// <string> := " <string_elem>* "
public ref class StringLiteral : Expr
{
public:
    String^ Value;
};
 
// <int> := <digit>+
public ref class IntLiteral : Expr
{
public:
    int Value;
};
 
// <ident> := <char> <ident_rest>*
// <ident_rest> := <char> | <digit>
public ref class Variable : Expr
{
public:
    String^ Ident;
};
 
// <bin_expr> := <expr> <bin_op> <expr>
public ref class BinExpr : Expr
{
public:
    Expr^ Left;
    Expr^ Right;
    BinOp Op;
};
 
// <bin_op> := + | - | * | /
public enum class BinOp
{
    Add,
    Sub,
    Mul,
    Div
};
 

Ok, how I can fix this error ?? ( because, for me, the code is right... )
Posted 15-Mar-13 3:14am
Comments
ThePhantomUpvoter at 15-Mar-13 9:11am
   
Try changing your target platform to C++/CLI might help.
CHill60 at 15-Mar-13 9:21am
   
What's "Expr" - missing a namespace?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 230
1 PIEBALDconsult 150
2 DamithSL 125
3 Andreas Gieriet 90
4 Jochen Arndt 90
0 OriginalGriff 5,790
1 DamithSL 4,601
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,195


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 15 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100