Calculator Program Xcode Error Expected expression before '#' token - c++

I'm doing the Stanford xcode class CS193P assignment #2 and I'm getting some errors. The tasks is to write a calculator program with variables. I am using Xcode 3.2.6 www.stanford.edu/class/.../Assignment%202_1.pdf
I'm getting the error Expected expression before '#' token when I am declaring vp
#define VARIABLE_PREFIX #“%”
- (void)setVariableAsOperand:(NSString *)variableName
{
NSString *vp = VARIABLE_PREFIX; (error is on this line)
NSString *variable = [vp stringByAppendingString:variableName];
[self addObjectToExpression:variable];
}
Does anyone know how to fix this problem? Message me if you have any questions. Thanks for your help!

Quotes in C++ have to be of the right kind, i.e. " (U+0022, QUOTATION MARK). Some applications (read: not proper text editors) will convert typed quotes into ‘fancy’ ones, e.g. “ (U+201C, LEFT DOUBLE QUOTATION MARK) and ” (U+201D, RIGHT DOUBLE QUOTATION MARK).
Watch out for copying code via a word processor, e-mail composer, etc. And if you need to examine a character your text editor of choice might be able to do it (I know Emacs can), or you can use tools like this one.

Related

How to fix truncated syntax highlighting in Xcode for Macron Characters

In my project, I'm attempting to use identifiers with Macrons in them (which is perfectly valid, and everything still compiles).
The problem is that Xcode truncates syntax highlighting after the first occurrence of a character with a macron.
The standard answers for text highlighting issues have been:
Turn it off and on again.
Delete Derived Data, and turn it off and on again.
I've tried both with no success.
This example photo uses typedef to demonstrate the issue. For reference, ira and tōpū both roughly equate to float and int.
As you can see, the highlighting stops after the first t of tōpū, but ira is fully highlighted.
I would like to know how to get Xcode to recognise the macron characters and continue highlighting the entire identifier. Thanks!

How to find and replace box character in text file?

I have a large text file that I'm going to be working with programmatically but have run into problems with a special character strewn throughout the file. The file is way too large to scan it looking for specific characters. Most of the other unwanted special characters I've been able to get rid of using some regex pattern. But there is a box character, similar to "□". When I tried to copy the character from the actual text file and past it here I get "�", so the example of the box is from Windows character map which includes the code 'U+25A1', which I'm not sure how to interpret or if it's something I could use for a regex search.
Would anyone know how I could search for the box symbol similar to "□" in a UTF-8 encoded file?
EDIT:
Here is an example from the text file:
"� Prune palms when flower spathes show, or delay pruning until after the palm has finished flowering, to prevent infestation of palm flower caterpillars. Leave the top five rows."
The only problem is that, as mentioned in the original post, the square gets converted into a diamond question mark.
It's unclear where and how you are searching, although you could use the hex equivalent:
\x{25A1}
Example:
https://regex101.com/r/b84oBs/1
The black diamond with a question mark is not a character, per se. It is what a browser spits out at you when you give it unrecognizable bytes.
Find out where that data is coming from.
Determine its encoding. (Usually UTF-8, but might be something else.)
Be sure the browser is configured to display that encoding. This is likely to suffice <meta charset=UTF-8> in the header of the page.
I found a workaround using Notepad++ and this website. It's still not clear what encoding system the square is originally from, but when I post it into the query field in the website above or into the Notepad++ Conversion Table (Plugins > Converter > Conversion Table) it gives the hex-character code for the "Replacement Character" which is the diamond with the question mark.
Using this code in a regex expression, \x{FFFD}, within Notepad++ search gave me all the squares, although recognizing them as the Replacement Character.

Go validator.v2 gives error "unknown tag" for regexp

I have been trying to understand why some regular expressions give me an error "Unknown tag" while using the validator.v2 package in golang. It works for some regular expressions but does not work with some which have "{}" inside them, and when I use the validator.Validate() it gives me an error at runtime "unknown tag".
Here's the code:
type Company struct {
Name string `validate:"regexp=^[a-zA-Z .]{1,100}$"`
}
which gives me the following error at runtime:
Name: unknown tag
however this regex works perfectly fine
type Company struct {
Name string `validate:"regexp=^[a-zA-Z .]*$"`
}
I am using the braces because of length restrictions that I want to put on the string. There could be other ways to do it, but I feel the regex is the way to go and is easier to have it along with other rules right there in the expression.
The problem appears to be the , char in your first regex. You can see in the validator source code that the tag is split on ,. By UTSLing, I see no support for escaped commas in the tags; this is probably an oversight on the part of the project author. I suggest filing a bug/feature request.
The problem pointed out by #Flimzy is correct, but it's not a bug.
Probably it was fixed since then, so at the moment validator supports escape sequence \\ for such case, and you can do it like this:
type Company struct {
Name string `validate:"regexp=^[a-zA-Z .]{1\\,100}$"`
}

WebStorm - disable error for ES2016 double colon (bind operator)

Using the double colon to bind things is great, but WebStorm 11 makes it almost unusable since it throws an error on the first colon (expression expected) and then at the end of the expression (expecting newline or semicolon). This marks my file as having an error and whenever i do a quick code format (Alt+Cmd+L) it junks everything up. Any ideas on how to manage this?
Reproduction code:
const authenticate = promisify(::socket.authenticate);

RGoogleAnalytics replacing unexpectedly escaped characters with gsub

I'm using RGoogleAnalytics, I'm just at the learning stage at the moment.
I'm following the code in the tutorial here https://code.google.com/p/r-google-analytics/
But when I try to run
ga.goals <- conf$GetGoals()
ga.goals
I get an error message telling me there is an unexpected escaped character '\.' at pos 7
I get a similar message for the next two lines of code (GetSegments)
This question deals with a similar problems in the Facebook Graphs API
How to replace "unexpected escaped character" in R
I've tried using a similar bit of code
confGoalsSub <- gsub('\\.', ' ', conf$GetGoals())
to remove the escaped characters, but I get another error :
cannot coerce type 'closure' to vector of type 'character'
Out of desperation I have tried confGoalsSub <- gsub('\\.', ' ', conf) which returns a character vector that is just garbage (it's just the code for conf with the decimal points stripped out).
Can anyone suggest a better expression than gsub that will return a useful object?
EDIT: As per the suggestion below I've now added the brackets at the end of the function call but I still get the same error message about unexpected escape characters. I get the same error when I try to call other, similar function such as $GetSegments().
I saw on one video at the weekend that this package was broken for a long time, although the speaker did not provide details as to why. Perhaps I should give up and try one of the other Google Analytics packages in R.
Seems odd, given that this one is supposed to be Google supported.
I think this error arises when the RJSON library isn't able to parse the Google Analytics Data Feed properly and convert it into a nested list. The updated version of [RGoogleAnalytics] (http://cran.r-project.org/web/packages/RGoogleAnalytics/index.html) fixes this problem. Currently, you won't be able to retrieve Goals and Segments from your Google Analytics account using the library but beyond that it supports the full range of dimensions and metrics.