Mon, 26 Aug 2002 06:03:55 +0000
now use C99 stdint.h and stdbool.h
| eric@12 | 1 | /* |
| eric@48 | 2 | $Id: scanner.l,v 1.16 2002/08/25 22:02:31 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@48 | 9 | #include <stdbool.h> |
| eric@48 | 10 | #include <stdint.h> |
| eric@15 | 11 | #include <stdio.h> |
| eric@13 | 12 | #include <string.h> |
| eric@17 | 13 | #include "semantics.h" |
| eric@18 | 14 | #include "parser.tab.h" |
| eric@15 | 15 | |
| eric@15 | 16 | #ifdef SCANNER_DEBUG |
| eric@15 | 17 | #define LDBG(x) printf x |
| eric@15 | 18 | #else |
| eric@15 | 19 | #define LDBG(x) |
| eric@15 | 20 | #endif |
| eric@12 | 21 | %} |
| eric@12 | 22 | |
| eric@5 | 23 | |
| eric@5 | 24 | digit [0-9] |
| eric@5 | 25 | alpha [a-zA-Z] |
| eric@15 | 26 | dot [\.] |
| eric@5 | 27 | |
| eric@5 | 28 | %% |
| eric@5 | 29 | |
| eric@15 | 30 | [\,;{}] { return (yytext [0]); } |
| eric@15 | 31 | {dot}{dot} { LDBG(("elipsis\n")); return (ELIPSIS); } |
| eric@7 | 32 | |
| eric@34 | 33 | /* decimal integer */ |
| eric@15 | 34 | {digit}+ { yylval.integer = atoi (yytext); LDBG(("integer %d\n", yylval.integer)); return (INTEGER); } |
| eric@34 | 35 | |
| eric@34 | 36 | /* floating point number - tricky to make sure it doesn't grab an integer |
| eric@34 | 37 | followed by an elipsis */ |
| eric@34 | 38 | -?{digit}+\.{digit}+ { yylval.fp = atof (yytext); return (FLOAT); } |
| eric@34 | 39 | -?{digit}+\./[^.] { yylval.fp = atof (yytext); return (FLOAT); } |
| eric@9 | 40 | |
| eric@32 | 41 | a { yylval.size.width = 8.5; |
| eric@32 | 42 | yylval.size.height = 11.0; |
| eric@9 | 43 | return (PAGE_SIZE); } |
| eric@32 | 44 | b { yylval.size.width = 11.0; |
| eric@32 | 45 | yylval.size.height = 17.0; |
| eric@9 | 46 | return (PAGE_SIZE); } |
| eric@32 | 47 | c { yylval.size.width = 17.0; |
| eric@32 | 48 | yylval.size.height = 22.0; |
| eric@9 | 49 | return (PAGE_SIZE); } |
| eric@32 | 50 | d { yylval.size.width = 22.0; |
| eric@32 | 51 | yylval.size.height = 34.0; |
| eric@9 | 52 | return (PAGE_SIZE); } |
| eric@32 | 53 | e { yylval.size.width = 34.0; |
| eric@32 | 54 | yylval.size.height = 44.0; |
| eric@9 | 55 | return (PAGE_SIZE); } |
| eric@5 | 56 | |
| eric@5 | 57 | all { return (ALL); } |
| eric@30 | 58 | author { return (AUTHOR); } |
| eric@5 | 59 | bookmark { return (BOOKMARK); } |
| eric@9 | 60 | cm { return (CM); } |
| eric@30 | 61 | creator { return (CREATOR); } |
| eric@5 | 62 | crop { return (CROP); } |
| eric@5 | 63 | even { return (EVEN); } |
| eric@11 | 64 | file { return (FILE_KEYWORD); } |
| eric@5 | 65 | image { return (IMAGE); } |
| eric@9 | 66 | images { return (IMAGES); } |
| eric@9 | 67 | inch { return (INCH); } |
| eric@5 | 68 | input { return (INPUT); } |
| eric@30 | 69 | keywords { return (KEYWORDS); } |
| eric@27 | 70 | label { return (LABEL); } |
| eric@9 | 71 | landscape { return (LANDSCAPE); } |
| eric@5 | 72 | odd { return (ODD); } |
| eric@5 | 73 | output { return (OUTPUT); } |
| eric@5 | 74 | page { return (PAGE); } |
| eric@8 | 75 | pages { return (PAGES); } |
| eric@9 | 76 | portrait { return (PORTRAIT) ; } |
| eric@11 | 77 | resolution { return (RESOLUTION) ; } |
| eric@5 | 78 | rotate { return (ROTATE); } |
| eric@5 | 79 | size { return (SIZE); } |
| eric@30 | 80 | subject { return (SUBJECT); } |
| eric@30 | 81 | title { return (TITLE); } |
| eric@5 | 82 | |
| eric@27 | 83 | '[^\n']' { |
| eric@27 | 84 | yylval.character = yytext [1]; |
| eric@27 | 85 | return (CHARACTER); |
| eric@27 | 86 | } |
| eric@27 | 87 | |
| eric@27 | 88 | \"[^\n"]*\" { |
| eric@15 | 89 | int len = strlen (yytext) - 2; |
| eric@15 | 90 | yylval.string = malloc (len + 1); |
| eric@15 | 91 | memcpy (yylval.string, yytext + 1, len); |
| eric@15 | 92 | yylval.string [len] = '\0'; |
| eric@15 | 93 | LDBG (("string \"%s\"\n", yylval.string)); |
| eric@15 | 94 | return (STRING); |
| eric@15 | 95 | } |
| eric@9 | 96 | |
| eric@15 | 97 | [ \t]+ /* whitespace */ |
| eric@15 | 98 | \n { line++; } |
| eric@9 | 99 | |
| eric@9 | 100 | --.* /* Ada/VHDL style one-line comment */ |
| eric@15 | 101 | #.* /* shell-style one-line comment */ |
| eric@9 | 102 | |
| eric@15 | 103 | . { fprintf (stderr, "Unrecognized character: %s\n", yytext); } |
| eric@9 | 104 | |
| eric@12 | 105 | %% |