Java code must take place within the Lexer rules! This is what was causing the issue of variable resetting.