1 / 2
Jun 2009

Hi guys, I'm new to this site, but I'm finding it very useful already.
I am using C#, and I am starting to get some odd errors like the one below:

syntax error, got token `SEMICOLON', expecting AS IS OPEN_BRACKET OPEN_PARENS CLOSE_PARENS DOT PLUS MINUS ASSIGN OP_LT OP_GT BITWISE_AND BITWISE_OR STAR PERCENT DIV CARRET INTERR OP_INC OP_DEC OP_SHIFT_LEFT OP_SHIFT_RIGHT OP_LE OP_GE OP_EQ OP_NE OP_AND OP_OR OP_MULT_ASSIGN OP_DIV_ASSIGN OP_MOD_ASSIGN OP_ADD_ASSIGN OP_SUB_ASSIGN OP_SHIFT_LEFT_ASSIGN OP_SHIFT_RIGHT_ASSIGN OP_AND_ASSIGN OP_XOR_ASSIGN OP_OR_ASSIGN OP_PTR IDENTIFIER
/sources/tested.cs(31) error CS1002: Expecting `;'
Compilation failed: 1 error(s), 0 warnings

The source code is below, I'm attempting to solve ONP.

using System;
using System.Text;
using System.Collections;
namespace InfixToPostfix
{
	class MainClass
	{
		static String InfixToPostfix(String postfixString)
		{
			StringBuilder sb = new StringBuilder();
			Stack operatorStack = new Stack();
			Char[] operators = {'+','/','^','*','(',')'};
			foreach (char c in postfixString)
			{
				Boolean operatorBool = false;
				foreach (Char op in operators)
				{
					if (op == c)
					{
						operatorBool = true;
						break;	
					}
				}
				if (operatorBool)				
				{
					operatorStack.Push(c);
				}
				else (sb.Append(c));
				if (c == ')')
				{
					while ((char)operatorStack.Peek() != '(')
					{
						if ((char)operatorStack.Peek() != '(' && (char) operatorStack.Peek() != ')')
						sb.Append(operatorStack.Pop());
						else operatorStack.Pop();
					}
					operatorStack.Pop();
				}
			}
			return sb.ToString();
		}
		public static void Main(string[] args)
		{
			//InfixToPostfix("(a+(b*c))");
			int numberOfTestCases = Int32.Parse(System.Console.ReadLine());
			String[] testCases = new String[numberOfTestCases];
			for (int i = 0; i < numberOfTestCases; i++) testCases[i] = System.Console.ReadLine();
			for (int i = 0; i < numberOfTestCases; i++) System.Console.WriteLine(InfixToPostfix(testCases[i]));
		}
	}
}

I am testing it on Mono myself, but on a recent version, and no compiler errors are detected.

BTW, is there any hope of getting the C# compiler upgraded? As it is, I'd like to use some more advanced features of C# like generics, but I'm unable to, due to this artificial limitation of having to compile with a very old version.

  • created

    Jun '09
  • last reply

    Jul '10
  • 1

    reply

  • 401

    views

  • 2

    users

1 year later

Actually gmcs 2.0.1 is available.

In the future requests, please the report detailed compiler version you like to use.