Lex multiline comments

This commit is contained in:
2025-01-30 01:03:16 +01:00
parent 5178027d9f
commit 1b90829299
7 changed files with 339 additions and 72 deletions

View File

@ -192,6 +192,10 @@ namespace source
{
}
void empty_visitor::visit(number_literal<std::nullptr_t> *)
{
}
void empty_visitor::visit(string_literal *)
{
}

View File

@ -18,15 +18,24 @@
%option c++ noyywrap never-interactive
%option yyclass="elna::source::lexer"
%x IN_COMMENT
%%
%{
this->location.step();
%}
\-\-.* {
/* Skip the comment */
<IN_COMMENT>{
\*\) BEGIN(INITIAL);
[^*\n]+ ; /* Eat comment in chunks. */
\* ; /* Eat the lone star. */
\n+ {
this->location.lines(yyleng);
this->location.step();
}
[\ \t\r] ; /* Skip the whitespaces */
}
\(\* BEGIN(IN_COMMENT);
[\ \t\r] ; /* Skip the whitespaces. */
\n+ {
this->location.lines(yyleng);
this->location.step();
@ -94,6 +103,9 @@ true {
false {
return yy::parser::make_BOOLEAN(false, this->location);
}
nil {
return yy::parser::make_NIL(this->location);
}
and {
return yy::parser::make_AND(this->location);
}
@ -222,7 +234,7 @@ sizeof {
\< {
return yy::parser::make_LESS_THAN(this->location);
}
\/= {
\<\> {
return yy::parser::make_NOT_EQUAL(this->location);
}
= {

View File

@ -70,7 +70,7 @@
%token AND OR NOT CAST AS SIZEOF
%token GREATER_EQUAL LESS_EQUAL LESS_THAN GREATER_THAN NOT_EQUAL EQUALS
%token PLUS MINUS MULTIPLICATION DIVISION REMAINDER
%token ASSIGNMENT COLON HAT AT
%token ASSIGNMENT COLON HAT AT NIL
%type <elna::source::literal *> literal;
%type <elna::source::constant_definition *> constant_definition;
@ -245,6 +245,10 @@ literal:
{
$$ = new elna::source::number_literal<unsigned char>(elna::source::make_position(@1), $1.at(0));
}
| NIL
{
$$ = new elna::source::number_literal<std::nullptr_t>(elna::source::make_position(@1), nullptr);
}
| STRING
{
$$ = new elna::source::string_literal(elna::source::make_position(@1), $1);