scanner.l

Tue, 01 Jan 2002 03:46:08 +0000

author
eric
date
Tue, 01 Jan 2002 03:46:08 +0000
changeset 27
7a28031fe457
parent 20
a1cd8cb9d09e
child 30
35fad7ec7732
permissions
-rw-r--r--

change 'format' to 'label', add character type, track bookmark level.

eric@12 1 /*
eric@27 2 $Id: scanner.l,v 1.12 2001/12/31 19:46:08 eric Exp $
eric@12 3 */
eric@12 4
eric@5 5 %option case-insensitive
eric@13 6 %option noyywrap
eric@5 7
eric@5 8 %{
eric@15 9 #include <stdio.h>
eric@13 10 #include <string.h>
eric@15 11 #include "type.h"
eric@17 12 #include "semantics.h"
eric@18 13 #include "parser.tab.h"
eric@15 14
eric@15 15 #ifdef SCANNER_DEBUG
eric@15 16 #define LDBG(x) printf x
eric@15 17 #else
eric@15 18 #define LDBG(x)
eric@15 19 #endif
eric@12 20 %}
eric@12 21
eric@5 22
eric@5 23 digit [0-9]
eric@5 24 alpha [a-zA-Z]
eric@15 25 dot [\.]
eric@5 26
eric@5 27 %%
eric@5 28
eric@15 29 [\,;{}] { return (yytext [0]); }
eric@15 30 {dot}{dot} { LDBG(("elipsis\n")); return (ELIPSIS); }
eric@7 31
eric@15 32 {digit}+ { yylval.integer = atoi (yytext); LDBG(("integer %d\n", yylval.integer)); return (INTEGER); }
eric@15 33 {digit}+\.{digit}+ { yylval.fp = atof (yytext); return (FLOAT); }
eric@9 34
eric@9 35 a { yylval.size.width = 8.5 * 25.4;
eric@9 36 yylval.size.height = 11.0 * 25.4;
eric@9 37 return (PAGE_SIZE); }
eric@9 38 b { yylval.size.width = 11.0 * 25.4;
eric@9 39 yylval.size.height = 17.0 * 25.4;
eric@9 40 return (PAGE_SIZE); }
eric@9 41 c { yylval.size.width = 17.0 * 25.4;
eric@9 42 yylval.size.height = 22.0 * 25.4;
eric@9 43 return (PAGE_SIZE); }
eric@9 44 d { yylval.size.width = 22.0 * 25.4;
eric@9 45 yylval.size.height = 34.0 * 25.4;
eric@9 46 return (PAGE_SIZE); }
eric@9 47 e { yylval.size.width = 34.0 * 25.4;
eric@9 48 yylval.size.height = 44.0 * 25.4;
eric@9 49 return (PAGE_SIZE); }
eric@5 50
eric@5 51 all { return (ALL); }
eric@5 52 bookmark { return (BOOKMARK); }
eric@9 53 cm { return (CM); }
eric@5 54 crop { return (CROP); }
eric@5 55 even { return (EVEN); }
eric@11 56 file { return (FILE_KEYWORD); }
eric@5 57 image { return (IMAGE); }
eric@9 58 images { return (IMAGES); }
eric@9 59 inch { return (INCH); }
eric@5 60 input { return (INPUT); }
eric@27 61 label { return (LABEL); }
eric@9 62 landscape { return (LANDSCAPE); }
eric@5 63 odd { return (ODD); }
eric@5 64 output { return (OUTPUT); }
eric@5 65 page { return (PAGE); }
eric@8 66 pages { return (PAGES); }
eric@9 67 portrait { return (PORTRAIT) ; }
eric@11 68 resolution { return (RESOLUTION) ; }
eric@5 69 rotate { return (ROTATE); }
eric@5 70 size { return (SIZE); }
eric@5 71
eric@27 72 '[^\n']' {
eric@27 73 yylval.character = yytext [1];
eric@27 74 return (CHARACTER);
eric@27 75 }
eric@27 76
eric@27 77 \"[^\n"]*\" {
eric@15 78 int len = strlen (yytext) - 2;
eric@15 79 yylval.string = malloc (len + 1);
eric@15 80 memcpy (yylval.string, yytext + 1, len);
eric@15 81 yylval.string [len] = '\0';
eric@15 82 LDBG (("string \"%s\"\n", yylval.string));
eric@15 83 return (STRING);
eric@15 84 }
eric@9 85
eric@15 86 [ \t]+ /* whitespace */
eric@15 87 \n { line++; }
eric@9 88
eric@9 89 --.* /* Ada/VHDL style one-line comment */
eric@15 90 #.* /* shell-style one-line comment */
eric@9 91
eric@15 92 . { fprintf (stderr, "Unrecognized character: %s\n", yytext); }
eric@9 93
eric@12 94 %%