Implement character escape sequences
This commit is contained in:
@ -752,20 +752,9 @@ namespace source
|
||||
}
|
||||
|
||||
unary_expression::unary_expression(const struct position position, expression *operand,
|
||||
const unsigned char operation)
|
||||
: expression(position), m_operand(std::move(operand))
|
||||
const unary_operator operation)
|
||||
: expression(position), m_operand(std::move(operand)), m_operator(operation)
|
||||
{
|
||||
switch (operation)
|
||||
{
|
||||
case '@':
|
||||
this->m_operator = unary_operator::reference;
|
||||
break;
|
||||
case '!':
|
||||
this->m_operator = unary_operator::negation;
|
||||
break;
|
||||
default:
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
void unary_expression::accept(parser_visitor *visitor)
|
||||
|
@ -112,13 +112,50 @@ return {
|
||||
[0-9]+\.[0-9] {
|
||||
return yy::parser::make_FLOAT(strtof(yytext, NULL), this->location);
|
||||
}
|
||||
'[^']' {
|
||||
return yy::parser::make_CHARACTER(
|
||||
std::string(yytext, 1, strlen(yytext) - 2), this->location);
|
||||
'[[:print:]]' {
|
||||
if (yytext[1] == '\\')
|
||||
{
|
||||
REJECT;
|
||||
}
|
||||
else
|
||||
{
|
||||
return yy::parser::make_CHARACTER(std::string(yytext, 1, 1), this->location);
|
||||
}
|
||||
}
|
||||
'\\[0nabtfrv\\'"?]' {
|
||||
switch (yytext[2])
|
||||
{
|
||||
case 'n':
|
||||
return yy::parser::make_CHARACTER(std::string("\n"), this->location);
|
||||
case 'a':
|
||||
return yy::parser::make_CHARACTER(std::string("\a"), this->location);
|
||||
case 'b':
|
||||
return yy::parser::make_CHARACTER(std::string("\b"), this->location);
|
||||
case 't':
|
||||
return yy::parser::make_CHARACTER(std::string("\t"), this->location);
|
||||
case 'f':
|
||||
return yy::parser::make_CHARACTER(std::string("\f"), this->location);
|
||||
case 'r':
|
||||
return yy::parser::make_CHARACTER(std::string("\r"), this->location);
|
||||
case 'v':
|
||||
return yy::parser::make_CHARACTER(std::string("\v"), this->location);
|
||||
case '\\':
|
||||
return yy::parser::make_CHARACTER(std::string("\\"), this->location);
|
||||
case '\'':
|
||||
return yy::parser::make_CHARACTER(std::string("'"), this->location);
|
||||
case '"':
|
||||
return yy::parser::make_CHARACTER(std::string("\""), this->location);
|
||||
case '?':
|
||||
return yy::parser::make_CHARACTER(std::string("\?"), this->location);
|
||||
case '0':
|
||||
return yy::parser::make_CHARACTER(std::string("\0", 1), this->location);
|
||||
default:
|
||||
REJECT;
|
||||
}
|
||||
}
|
||||
\"[^\"]*\" {
|
||||
return yy::parser::make_STRING(
|
||||
std::string(yytext, 1, strlen(yytext) - 2), this->location);
|
||||
std::string(yytext, 1, strlen(yytext) - 2), this->location);
|
||||
}
|
||||
\( {
|
||||
return yy::parser::make_LEFT_PAREN(this->location);
|
||||
|
@ -227,6 +227,7 @@ literal:
|
||||
pointer:
|
||||
literal { $$ = $1; }
|
||||
| designator_expression { $$ = $1; }
|
||||
| call_expression { $$ = $1; }
|
||||
| LEFT_PAREN expression RIGHT_PAREN { $$ = std::move($2); }
|
||||
summand:
|
||||
factor { $$ = std::move($1); }
|
||||
@ -243,11 +244,13 @@ summand:
|
||||
factor:
|
||||
AT pointer
|
||||
{
|
||||
$$ = new elna::source::unary_expression(elna::source::make_position(@1), $2, '@');
|
||||
$$ = new elna::source::unary_expression(elna::source::make_position(@1), $2,
|
||||
elna::source::unary_operator::reference);
|
||||
}
|
||||
| NOT pointer
|
||||
{
|
||||
$$ = new elna::source::unary_expression(elna::source::make_position(@1), $2, '!');
|
||||
$$ = new elna::source::unary_expression(elna::source::make_position(@1), $2,
|
||||
elna::source::unary_operator::negation);
|
||||
}
|
||||
| pointer { $$ = $1; }
|
||||
comparand:
|
||||
@ -296,7 +299,6 @@ expression:
|
||||
$$ = new elna::source::binary_expression(elna::source::make_position(@1), $1, $3, 'o');
|
||||
}
|
||||
| logical_operand { $$ = $1; }
|
||||
| call_expression { $$ = $1; }
|
||||
expressions:
|
||||
expression COMMA expressions
|
||||
{
|
||||
|
Reference in New Issue
Block a user