Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow variable to start with a letter #3

Open
ryanheart opened this issue Mar 27, 2014 · 4 comments
Open

Allow variable to start with a letter #3

ryanheart opened this issue Mar 27, 2014 · 4 comments

Comments

@ryanheart
Copy link
Collaborator

Detect variables by first character based on a regex that can be overridden. Default could be [a-zA-Z$].

This provides better usage for end users and closely resembles algebra

@ircmaxell
Copy link
Owner

The simple support mechanism would be to implement a regex. The problem comes in that the tokenizer right now will greedily consume digits. So you could literally never have a variable that contained a digit (as it would be tokenized separately). This may be ok, as we could support alpha variables (without the leading $)...

The clean solution would be to rewrite the current system into a proper lexer rather than a dirty tokenizer. But that may be beyond the scope of the tool...

@ryanheart
Copy link
Collaborator Author

I think for now I'd be happy with the inclusion of only alpha characters. Maybe just throw an exception if a variable is added that does not conform.

@ryanheart
Copy link
Collaborator Author

I've been thinking about this and I think the fact digits would not be allowed in the equation is a good thing.

For instance if you have 2y4x this would actually be 2 * y * 4 * x at the moment the code would pick up 2,x,4,x and I think this is right and no operator should be used as multiplication.

@ruskid
Copy link

ruskid commented Jan 6, 2017

Its 2016 and thank you for the parser.
Unfortunately using numbers in variables was a must for me. ($q1 + $q2) * $q3

The regex I am using in tokenize function is:

((\$[a-zA-Z]+\d+)|(\d+\.?\d+|\+|-|\(|\)|\*|/)|\s+)

But this regex makes leading $ required, as commented above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants