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 79 80 81 82 83 84 85
|
%{
/*
+-+-+-+-+-+-+-+-+-
*/
/*
** Electronic Radiology Laboratory
** Mallinckrodt Institute of Radiology
** Washington University School of Medicine
**
** Module Name(s):
** Author, Date: Aniruddha Gokhale, 24-May-1995
** Intent: This file defines lexical rules that define valid tokens
** of a DICOM object
** Last Update: $Author: asg $, $Date: 1995-06-19 21:14:38 $
** Source File: $RCSfile: lex.l,v $
** Revision: $Revision: 1.7 $
** Status: $State: Exp $
*/
static char rcsid[] = "$Revision: 1.7 $ $RCSfile: lex.l,v $";
#include <stdio.h>
#include "create.h"
#include "gram.h"
static int count = 0;
static unsigned short IsMultVal = 0;
static unsigned short IsTag = 0;
#define RET(a) ECHO; return (a);
%}
/* define an additional state */
%s STATE_VALUE
%%
"//"[^\n]* { /* ignore comments */ }
<STATE_VALUE>[(] {
BEGIN 0;
RET( *yytext);
}
<STATE_VALUE>"{" {
IsMultVal = 1;
RET( *yytext); /* start of a multiply-valued string */
}
<STATE_VALUE>"}" {
IsMultVal = 0;
BEGIN 0; /* end of value. */
RET( *yytext); /* start of a multiply-valued string */
}
<STATE_VALUE>"<" {
IsTag = 1;
RET( *yytext);
}
<STATE_VALUE>">" {
IsTag = 0;
RET( *yytext);
}
<STATE_VALUE>"," {
RET( *yytext);
}
<STATE_VALUE>[^ \t\n{},()<>]+ {
strcpy(yylval.str, yytext);
if (!IsMultVal && !IsTag)
BEGIN 0;
RET( VALUE);
}
<STATE_VALUE>"\""[^"]*"\"" {
strcpy(yylval.str, &yytext[1]);
yylval.str[yyleng-2] = 0;
if (!IsMultVal)
BEGIN 0;
RET( VALUE);
}
[0-9a-fA-F]+ {
sscanf(yytext, "%x", &yylval.num);
count = (count + 1) % 2;
if (!count)
BEGIN STATE_VALUE;
/* next state is STATE_VALUE */
RET( NUMBER);
}
"(" |
")" { RET( *yytext); }
[ \t\n]* { ECHO; /* nothing */ }
. { printf("Unknown character: %c\n", *yytext); }
%%
|