last day (23 days later) » 

13:15
5
A: Hello There Calculator

Bart KiersYou've given multiplication a higher precedence than division. Usually, these have the same precedence. I.e., the expression 1 / 2 * 3 is usually evaluated as (1 / 2) * 3 (from left to right), which is 1.5. But in your case, it will be evaluated as 1 / (2 * 3), which is 0.16666666666. Also, your...

Great advice except for the whole matching one or more expressions thing. Without that + the grammar won't generate. It complains about being left recursive. Thanks for the advice! Nice review.
Hmm, but when writing expression+ EOF, you're matching stuff like 1+1 2-2 3*3 as 3 expressions.
Well, that's a very good point. I'll have to add those cases to my tests and see what I can do to fix it. (along with the order of multiplication/division and addition/subtraction).
Oh wow. Actually, since I'm stripping white space, that would get read in as 1+12-23*3...
No, the whitespace trimming would only kick in at the parser-level. I.e. your parser would receive 9 tokens: 1, +, 1, 2, -, 2, 3, *, 3, not 7 tokens 1, +, 12, -, 23, *, 3.
Ahh. Okay. Thanks Bart. I misunderstood.
Hey Bart, throwing away the whitespace does indeed mean that that it gets interpreted as 1+12-23*3. I just verified it in my IDE.
13:15
It really does not. Perhaps if you print your token stream, it looks like that, but it really, really doesn't. Let me whip up a demo.
I'm not going to argue with you, when I run this through my Visitor, it Adds 1 + 12 before subtracting 23*3. I'm running the code here. Have you?
You either found a bug in ANTLR, or doing something incorrect in your code because that should not happen. What happens when you run for (Token token : lexer.getAllTokens()) { System.out.println(token); } on the input?
Yes, I ran the code. I'm posting the actual output of running the code (the Java code, that is).
I can't seem to find the Token class. Do you know what namespace it's in?
Nevermind. Got it.
 
1 hour later…
14:25

  last day (23 days later) »