cusel/yacc-grammar/parser.l
Juhani Krekelä 2ad67427fb Pattern matching
2026-11-17 02:16:30 +02:00

69 lines
1.1 KiB
Text

%{
void yyerror(const char *);
#include "y.tab.h"
%}
%%
"fn" return FN;
"type" return TYPE;
"break" return BREAK;
"continue" return CONTINUE;
"do" return DO;
"elif" return ELIF;
"else" return ELSE;
"end" return END;
"for" return FOR;
"if" return IF;
"in" return IN;
"match" return MATCH;
"of" return OF;
"return" return RETURN;
"then" return THEN;
"while" return WHILE;
"and" return AND;
"or" return OR;
"not" return NOT;
[0-9]+ return NATURAL;
0x[0-9A-Fa-f]+ return NATURAL;
0o[0-7]+ return NATURAL;
0b[01]+ return NATURAL;
[A-Za-z_][A-Za-z_0-9]* return IDENTIFIER;
[@$.:=,] return *yytext;
[][(){}] return *yytext;
"<<" return SHL;
">>" return SHR;
"<<<" return ROL;
">>>" return ROR;
"<=" return LTE;
">=" return GTE;
"==" return EQ;
"!=" return NEQ;
[<>] return *yytext;
[*/%+-] return *yytext;
[&|^~] return *yytext;
[ \t\n] ; // Skip whitespace
"--".* ; // Skip comments
. {
yyerror("invalid character");
return ERROR;
}
%%
// Some distributions of flex do not install libl (only libfl). To avoid
// needing to work around that in the build system, just inline the
// default definition of yywrap().
int yywrap(void) {
return 1;
}