File: scan.l

package info (click to toggle)
bison 2%3A3.3.2.dfsg-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 22,540 kB
  • sloc: sh: 197,048; ansic: 57,108; lex: 2,265; cpp: 1,906; yacc: 1,673; perl: 937; java: 628; makefile: 226; sed: 16
file content (43 lines) | stat: -rw-r--r-- 860 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* Prologue (directives).   -*- C++ -*- */

/* Disable Flex features we don't need, to avoid warnings. */
%option nodefault noinput nounput noyywrap

%{
#include <limits.h> /* INT_MIN */
#include <stdlib.h> /* strtol */

#include "parse.h"
%}

%%
 /* Rules.  */

"+"      return TOK_PLUS;
"-"      return TOK_MINUS;
"*"      return TOK_STAR;
"/"      return TOK_SLASH;

"("      return TOK_LPAREN;
")"      return TOK_RPAREN;

 /* Scan an integer.  */
[0-9]+   {
  errno = 0;
  long n = strtol (yytext, NULL, 10);
  if (! (INT_MIN <= n && n <= INT_MAX && errno != ERANGE))
    yyerror (nerrs, "integer is out of range");
  yylval->TOK_NUM = (int) n;
  return TOK_NUM;
}

 /* Ignore white spaces. */
[ \t]+   continue;

"\n"     return TOK_EOL;

.        yyerror (nerrs, "syntax error, invalid character");

<<EOF>>  return TOK_EOF;
%%
/* Epilogue (C code). */