File: flowassert_scan.l

package info (click to toggle)
setools 2.0-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 14,112 kB
  • ctags: 10,502
  • sloc: ansic: 76,267; tcl: 27,222; yacc: 2,943; makefile: 993; sh: 504; lex: 244
file content (78 lines) | stat: -rw-r--r-- 2,181 bytes parent folder | download | duplicates (3)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* Copyright (C) 2004-2005 Tresys Technology, LLC
 * see file 'COPYING' for use and warranty information */

/* 
 * Author: Jason Tang (jtang@tresys.com)
 */
 
%{
#include <stdarg.h>
#include <stdio.h>
#include <string.h>

#include "flowassert.h"
#include "flowassert_parse.h"

extern int fileno (FILE *);

int flowerror(char *msg);
void flowwarn(char *format, ...);

static void flowstrdup (void);
unsigned long flowassert_lineno = 1;

#define YY_NO_UNPUT
%}

%array
%option noyywrap

identifier [A-Za-z][A-Za-z0-9_.]*
number [0-9]+

%%

#[^\n]*                  { /* delete comments */ }
(noflow)|(NOFLOW)        { return (NOFLOW); }
(mustflow)|(MUSTFLOW)    { return (MUSTFLOW); }
(onlyflow)|(ONLYFLOW)    { return (ONLYFLOW); }
{identifier}             { flowstrdup (); return (IDENTIFIER); }
\${identifier}           { flowstrdup (); return (VARNAME); }
{number}                 { flowlval.i = atoi (flowtext); return (NUMBER); }
[ \t\f]+		 { /* delete whitespace */ }
\n			 { /* delete whitespace */ flowassert_lineno++; }
[:;\{\}*=-]              { return (flowtext [0]); } 
.                        { (void) flowwarn ("unrecognized character");}

%%

/* yyerror() specifically for the flowassert tool. */
int flowerror (char *msg) {
        /*    flowwarn ("%s on token `%s'", msg, flowtext); */
        flowassert_add_error_result (FLOW_ASSERT_SYNTAX_ERROR);
        return -1;
}

/* Displays a warning to standard error regarding a problem with the
   assertion file.  Also displays the line on which the warning
   occurred. */
void flowwarn (char *format, ...) {
        /*
          va_list ap;
          (void) fprintf (stderr, "line %ld: ", flowassert_lineno);
          va_start (ap, format);
          (void) vfprintf (stderr, format, ap);
          va_end (ap);
          (void) fprintf (stderr, "\n");
        */
        flowassert_add_error_result (FLOW_ASSERT_SYNTAX_ERROR);    
}

/* strdup()s flowtext (really yytext) to flowlval.s (really
   yylval.s). */
static void flowstrdup (void) {
        if ((flowlval.s = strdup (flowtext)) == NULL) {
                (void) fprintf (stderr, "out of memory in flowstrdup\n");
                exit (-1);
        }
}