Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

->proj01;

Extending the Thermostat Grammar

Overview

Accept the invitation to join the GitHub Classroom assignment for this project.

This weeks project is to extend the Lexer, Parser and Listener to include the following keywords:

so that your parser can handle the following commands:

start
    -- Start command received
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 received
set current temperature 63
    -- Error: system is not running
stop
    -- Error: System already stopped

Lines starting with “--” are responses (outputs) your thermostat system should give, not input in to the system.

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 currenttemperature<desiredtemperaturecurrent_temperature < desired_temperature, report that the system is heating, otherwise report that it is not). Similarly for humidity.

Make sure to copy the original files from last weeks lab into your project folder before starting this project.


A few helpful tips:


Rubric

CategoryPointsDescription
Lexer Definitions20All required tokens are defined in the lexer.
Parser Definitions20All required parser rules are defined in the parser.
Listener Implementation40The listener correctly implements the required functionality for each command.
Code Quality10Code is well-organized, readable, and follows standard Java conventions.
Testing10The program has been tested with various inputs and works as expected.

Ways to lose points: