Example #1
0
        public void Visit(IdentifierExprParam identExprParam)
        {
            Item ident = Environment.GetItem(identExprParam.Value);

            switch (ident)
            {
            case StrItem _:
                Environment.PushToTheStack(identExprParam.Unary == false ? (ident as StrItem).Value
                        : throw new ExecutorException("Cannot apply unary operator on str"));
                break;

            case NumItem _:
                Environment.PushToTheStack(identExprParam.Unary == true ? (ident as NumItem).Value * (-1)
                        : (ident as NumItem).Value);
                break;

            case TurtleItem _:
                Environment.PushToTheStack(identExprParam.Unary == false ? ident
                        : throw new ExecutorException("Cannot apply unary operator on Turtle"));
                break;

            default:
                throw new ExecutorException($"Expecting identifier of one of types: str, num or Turtle, got {ident}");
            }
        }
 public void Visit(IdentifierExprParam identExprParam)
 {
     Console.Write(identExprParam.Unary ? $"-{identExprParam.Value}" : identExprParam.Value);
 }