add: string, comment

This commit is contained in:
Eatswap 2022-12-10 17:07:25 +08:00
parent ae30e35334
commit db863b806e
Signed by: Eatswap
GPG Key ID: BE661106A1F3FA0B
3 changed files with 20 additions and 8 deletions

View File

@ -23,6 +23,8 @@ using token = DragonLisp::DLParser::token;
id [a-zA-Z_][a-zA-Z_0-9]*
int [0-9]+
blank [ \t\v\r]
comment ;.*$
string \"[^\r\n]*\"
%%
@ -30,23 +32,35 @@ blank [ \t\v\r]
yylval = lval;
%}
{string} {
loc->step();
std::printf("Scanned string: %s\n", yytext);
yylval->emplace<std::string>(std::string(yytext + 1, yyleng - 2));
return token::TOKEN_STRING;
}
{comment} {
std::printf("Scanned comment: %s\n", yytext);
loc->step();
}
{blank}+ {
loc->step();
std::printf("Skipping blank\n");
};
\n+ {
\n+ {
loc->lines(yyleng);
loc->step();
std::printf("Skipping newline\n");
}
"<=" {
"<=" {
std::printf("Scanned <=\n");
return token::TOKEN_LE;
};
">=" {
">=" {
std::printf("Scanned >=\n");
return token::TOKEN_GE;
};

View File

@ -57,6 +57,7 @@ namespace DragonLisp {
%token END 0 "EOF"
%token <int64_t> NUMBER "number"
%token <std::string> STRING "string"
%type <DragonLisp::Token> basic_operator
%type <DragonLisp::Token> arithmetic_operator
@ -72,6 +73,7 @@ S
R
:
| R S-Expr
| STRING { std::cout << "Scanned string -> " << $1 << std::endl; }
S-Expr
: LPAREN basic_operator NUMBER NUMBER RPAREN {
@ -82,7 +84,6 @@ S-Expr
basic_operator
: arithmetic_operator { $$ = $1; }
| boolean_operator { $$ = $1; }
| comparsion_operator { $$ = $1; }
;
@ -93,10 +94,6 @@ arithmetic_operator
| SLASH { $$ = Token::DIVIDE; std::printf("I am slash /\n"); }
;
boolean_operator
:
;
comparsion_operator
: LE { $$ = Token::LE; }
| LT { $$ = Token::LT; }

View File

@ -14,6 +14,7 @@ enum Token {
MINUS,
MULTIPLY,
DIVIDE,
STRING,
};
}