This weeks project is to extend the Lexer, Parser and Listener to include the keywords get, set, current, desired, humidity temperature and status so that your parser can handle the following commands: (lines starting with "--" are responses your thermostat system should give, not input in to the system)
start
-- Start command recieved
set current temperature 63
-- Current Temperature set to 63
set desired temperature 68
-- Desired Temperature set to 68
get current temperature
-- Current Temperature is 63
set current humidity 40
-- Current Humidity set to 40
set desired humidity 50
-- Desired Humidity set to 50
get desired humidity
-- Desired Humidity is 50
status
-- heating: yes
-- humidifying: yes
set desired temperature 53
-- Desired Temperature set to 53
status
-- heating: no
-- humidifying: yes
set desired humidity 30
-- Desired Humidity set to 30
status
-- heating: no
-- humidifying: no
stop
-- Stop command recieved
set current temperature 63
-- Error: system is not running
stop
-- Error: System already stopped
Below is a copy of the commands from above without the responses, for use in program.thermostat
start
set current temperature 63
set desired temperature 68
get current temperature
set current humidity 40
set desired humidity 50
get desired humidity
status
set desired temperature 53
status
set desired humidity 30
status
stop
set current temperature 63
stop
In total your thermostat should track 5 different variables:
In addition, based on relative values of temperature and humidity variables, the status command will report if the system should currently be heating and humidifying. (if current_temperature<desired_temperature, report that the system is heating, otherwise report that it is not)
A few helpful tips:
NUM: [0-9]+;
ctx.getText();
Integer.parseInt(...)
Execute your parser with the HeaterScript program outlined above, and record the output into output.txt by running
./run.sh > output.txt
and then cat your files together in to a single file called proj02-results:
cat MyLexer.g4 MyParser.g4 MyListener.java ParserTest.java program.thermostat output.txt > proj02-results
and then copy proj02-results into your lab turn in folder: /home/cs/214/current/:
cp proj02-results /home/cs/214/current/yourUserName
replacing yourUserName with your login name.
The grader will access and grade your work from there.
See Also Lab 2
Calvin > CS > 214 > Projects > 02