1
0
This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
TP-Link_Archer-XR500v/EN7526G_3.18Kernel_SDK/apps/public/linux-atm/qgen/ql.l
2024-07-22 01:58:46 -03:00

73 lines
1.5 KiB
Plaintext
Executable File

%{
/* ql.l - Q.2931 data structures description language */
/* Written 1995,1996 by Werner Almesberger, EPFL-LRC */
#include <stdio.h>
#include <string.h>
#include "common.h"
#include "qgen.h"
#include "y.tab.h"
typedef struct _tree {
struct _tree *left,*right;
const char str[0];
} TREE;
static TREE *tree = NULL;
static int lineno = 1;
static const char *ident(const char *str)
{
TREE **walk;
int diff;
walk = &tree;
while (*walk) {
if (!(diff = strcmp(str,(*walk)->str))) return (*walk)->str;
if (diff < 0) walk = &(*walk)->left;
else walk = &(*walk)->right;
}
*walk = alloc(sizeof(TREE)+strlen(str)+1);
(*walk)->left = (*walk)->right = NULL;
strcpy((char *) (*walk)->str,str);
return (*walk)->str;
}
%}
%%
break return TOK_BREAK;
case return TOK_CASE;
def return TOK_DEF;
default return TOK_DEFAULT;
length return TOK_LENGTH;
multi return TOK_MULTI;
recover return TOK_RECOVER;
abort return TOK_ABORT;
[_a-zA-Z0-9]+ { yylval.str = ident(yytext);
return TOK_ID; }
\n?[\t ]* lineno += *yytext == '\n';
include[\ \t]+\"[^\"\n\t]+\" |
include[\ \t]+\<[^\<\>\n\t]+\> { yylval.str = ident(yytext);
return TOK_INCLUDE; }
\"[^\"\n\t]+\" { *strrchr(yytext,'"') = 0;
yylval.str = ident(yytext+1);
return TOK_STRING; }
[#;][^\n]*\n lineno++;
. return *yytext;
%%
void yyerror(char *s)
{
fprintf(stderr,"line %d: %s near \"%s\"\n",lineno,s,yytext);
exit(1);
}