Add grammar and tokens to parser and scanner

This commit is contained in:
Mario Hüttel 2024-01-17 22:43:30 +01:00
parent 5190e3116b
commit 5b4dc705b4
3 changed files with 79 additions and 10 deletions

View File

@ -23,7 +23,7 @@ class TempProfileScanner : public yyFlexLexer{
virtual
int yylex( tpr::TempProfileParser::semantic_type * const lval,
tpr::TempProfileParser::location_type *location );
tpr::TempProfileParser::location_type *loc );
// YY_DECL defined in mc_lexer.l
// Method body created by flex in mc_lexer.yy.cc

View File

@ -1,26 +1,43 @@
%{
#include <tpr/tpr-scanner.hpp>
#include <string>
#undef YY_DECL
#define YY_DECL int tpr::TempProfileScanner::yylex(tpr::TempProfileParser::semantic_type * const lval, tpr::TempProfileParser::location_type *loc )
#define YY_USER_ACTION loc->step(); loc->columns(yyleng);
using token = tpr::TempProfileParser::token;
%}
%option yyclass="tpr::TempProgileScanner"
%option yyclass="tpr::TempProfileScanner"
%option noyywrap
%option never-interactive
%option c++
/* Predefined rules */
NEWLINE "\n"|"\r\n"
SPACE " "|"\t"|"\f"
COMMENT_BEGIN "/*"
COMMENT_END "*/"
COMMENT_LINE "//".*\n
COMMENT_LINE "#".*\n
SPACE "\t"|" "
NUM [-+]?([0-9]*\.[0-9]+|[0-9]+)
%%
SPACE {return 0;}
<*>{SPACE} { /*Ignore spaces */}
{COMMENT_LINE} {loc->lines(); return token::lineend;}
{NEWLINE} {loc->lines(); return token::lineend;}
{NUM} {yylval->build<float>(std::stof(std::string(yytext))); return token::number;}
pid_conf { return token::kw_pid_conf; }
temp_set { return token::kw_temp_set; }
wait_temp { return token::kw_wait_temp; }
wait_time { return token::kw_wait_time; }
temp_ramp { return token::kw_temp_ramp; }
beep { return token::kw_beep; }
temp_off { return token::kw_temp_off; }
clear_flags { return token::kw_clear_flags; }
digio_conf { return token::kw_digio_conf; }
digio_set { return token::kw_digio_set; }
digio_wait { return token::kw_digio_wait; }
%%

View File

@ -30,15 +30,67 @@
%locations
%start tpr_file
%token foo
%token<float> number
%token lineend
%token kw_pid_conf
%token kw_temp_set
%token kw_wait_temp
%token kw_wait_time
%token kw_temp_ramp
%token kw_beep
%token kw_temp_off
%token kw_clear_flags
%token kw_digio_conf
%token kw_digio_set
%token kw_digio_wait
%%
tpr_file: foo
| tpr_file foo
tpr_file: tpr_command
| tpr_file tpr_command
;
tpr_command: tpr_command_inner lineend
| lineend
;
tpr_command_inner: cmd_pid_conf;
| cmd_temp_set
| cmd_wait_temp
| cmd_wait_time
| cmd_temp_ramp
| cmd_beep
| cmd_temp_off
| cmd_clear_flags
| cmd_digio_conf
| cmd_digio_set
| cmd_digio_wait
;
cmd_pid_conf: kw_pid_conf number number number number number number;
cmd_temp_set: kw_temp_set number;
cmd_wait_temp: kw_wait_temp number;
cmd_wait_time: kw_wait_time number;
cmd_temp_ramp: kw_temp_ramp number number;
cmd_beep: kw_beep number;
cmd_temp_off: kw_temp_off;
cmd_clear_flags: kw_clear_flags;
cmd_digio_conf: kw_digio_conf number number;
cmd_digio_set: kw_digio_set number number;
cmd_digio_wait: kw_digio_wait number number;
%%
void tpr::TempProfileParser::error(const location_type &l, const std::string &err_message)