1 1.18 martin /* $NetBSD: scan.l,v 1.18 2019/02/25 20:47:37 martin Exp $ */ 2 1.1 phil 3 1.1 phil /* 4 1.1 phil * Copyright 1997 Piermont Information Systems Inc. 5 1.1 phil * All rights reserved. 6 1.1 phil * 7 1.1 phil * Written by Philip A. Nelson for Piermont Information Systems Inc. 8 1.1 phil * 9 1.1 phil * Redistribution and use in source and binary forms, with or without 10 1.1 phil * modification, are permitted provided that the following conditions 11 1.1 phil * are met: 12 1.1 phil * 1. Redistributions of source code must retain the above copyright 13 1.1 phil * notice, this list of conditions and the following disclaimer. 14 1.1 phil * 2. Redistributions in binary form must reproduce the above copyright 15 1.1 phil * notice, this list of conditions and the following disclaimer in the 16 1.1 phil * documentation and/or other materials provided with the distribution. 17 1.16 mbalmer * 3. The name of Piermont Information Systems Inc. may not be used to endorse 18 1.1 phil * or promote products derived from this software without specific prior 19 1.1 phil * written permission. 20 1.1 phil * 21 1.1 phil * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS'' 22 1.1 phil * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 1.1 phil * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 1.1 phil * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE 25 1.1 phil * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 1.1 phil * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 1.1 phil * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 1.1 phil * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 1.1 phil * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 1.1 phil * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 1.1 phil * THE POSSIBILITY OF SUCH DAMAGE. 32 1.1 phil * 33 1.1 phil */ 34 1.1 phil 35 1.1 phil %{ 36 1.1 phil /* scan.l: scanner description for menu compiler. */ 37 1.1 phil 38 1.1 phil #include <stdio.h> 39 1.1 phil #include <string.h> 40 1.1 phil #include "defs.h" 41 1.3 tv #include "parse.h" 42 1.1 phil 43 1.1 phil static int level; /* For nested comments. */ 44 1.1 phil static int comstart; /* line number of comment start. */ 45 1.1 phil 46 1.1 phil %} 47 1.1 phil 48 1.1 phil %x COMMENT 49 1.1 phil %x BRACE 50 1.1 phil 51 1.15 christos %option noinput 52 1.15 christos 53 1.1 phil %% 54 1.1 phil 55 1.1 phil [ \t]+ { /* ignore spaces and tabs */ } 56 1.1 phil 57 1.1 phil [\n] { line_no++; } 58 1.1 phil 59 1.1 phil "="|";"|","|"("|")" { return (int)yytext[0]; } 60 1.1 phil 61 1.1 phil x { return X; } 62 1.1 phil 63 1.1 phil y { return Y; } 64 1.1 phil 65 1.1 phil w { return W; } 66 1.1 phil 67 1.1 phil h { return H; } 68 1.1 phil 69 1.1 phil no { return NO; } 70 1.1 phil 71 1.1 phil box { return BOX; } 72 1.1 phil 73 1.18 martin continuous { return CONTINUOUS; } 74 1.18 martin 75 1.1 phil sub { return SUB; } 76 1.4 phil 77 1.4 phil help { return HELP; } 78 1.1 phil 79 1.1 phil menu { return MENU; } 80 1.1 phil 81 1.7 phil menus { return MENUS; } 82 1.7 phil 83 1.1 phil next { return NEXT; } 84 1.1 phil 85 1.1 phil exit { return EXIT; } 86 1.8 cgd 87 1.8 cgd exitstring { return EXITSTRING; } 88 1.1 phil 89 1.1 phil title { return TITLE; } 90 1.1 phil 91 1.1 phil action { return ACTION; } 92 1.1 phil 93 1.1 phil endwin { return ENDWIN; } 94 1.1 phil 95 1.1 phil option { return OPTION; } 96 1.1 phil 97 1.1 phil default { return DEFAULT; } 98 1.1 phil 99 1.1 phil display { return DISPLAY; } 100 1.1 phil 101 1.17 martin expand { return EXPAND; } 102 1.17 martin 103 1.2 phil error { return ERROR; } 104 1.6 phil 105 1.7 phil allow { return ALLOW; } 106 1.6 phil 107 1.6 phil dynamic { return DYNAMIC; } 108 1.10 dsl 109 1.10 dsl messages { return MESSAGES; } 110 1.5 phil 111 1.5 phil scrollable { return SCROLLABLE; } 112 1.9 phil 113 1.9 phil shortcut { return SHORTCUT; } 114 1.12 dsl 115 1.12 dsl clear { return CLEAR; } 116 1.1 phil 117 1.14 dsl always { return ALWAYS; } 118 1.14 dsl 119 1.14 dsl scroll { return SCROLL; } 120 1.14 dsl 121 1.1 phil \"([^\"\n]*(\\\")?)*\" { 122 1.1 phil yylval.s_value = strdup (yytext); 123 1.1 phil max_strlen = max_strlen > strlen(yytext) 124 1.1 phil ? max_strlen : strlen(yytext) + 1; 125 1.1 phil return STRING; 126 1.1 phil } 127 1.1 phil 128 1.1 phil [a-zA-Z][a-zA-Z0-9_]* { 129 1.1 phil yylval.s_value = strdup(yytext); 130 1.1 phil return(NAME); 131 1.1 phil } 132 1.1 phil 133 1.13 dsl 0|[-1-9][0-9]* { 134 1.1 phil yylval.s_value = strdup(yytext); 135 1.1 phil return(INT_CONST); 136 1.1 phil } 137 1.1 phil 138 1.1 phil "'"[^'\\]|(\\[athrn])|(\\[0-9][0-9]?[0-9]?)"'" { 139 1.1 phil yylval.s_value = strdup(yytext); 140 1.1 phil return(CHAR_CONST); 141 1.1 phil } 142 1.1 phil 143 1.1 phil "/*" { level = 1; comstart = line_no; BEGIN COMMENT; } 144 1.1 phil 145 1.1 phil <COMMENT>"/*" { level++; } 146 1.1 phil 147 1.1 phil <COMMENT>"*/" { if (level-- == 1) BEGIN 0; } 148 1.1 phil 149 1.1 phil <COMMENT>"\n" { line_no++; } 150 1.1 phil 151 1.1 phil <COMMENT><<EOF>> { 152 1.1 phil yyerror ("EOF inside a comment that started at line %d", 153 1.1 phil comstart); 154 1.1 phil exit (1); 155 1.1 phil } 156 1.1 phil 157 1.1 phil <COMMENT>. {/* eat character */} 158 1.1 phil 159 1.1 phil "{" { level = 1; BEGIN BRACE; } 160 1.1 phil 161 1.1 phil <BRACE>"{" { buff_add_ch(yytext[0]); level++; } 162 1.1 phil 163 1.1 phil <BRACE>"}" { if (level-- == 1) { 164 1.1 phil BEGIN 0; 165 1.1 phil yylval.s_value = buff_copy(); 166 1.1 phil return CODE; 167 1.1 phil } else 168 1.1 phil buff_add_ch (yytext[0]); 169 1.1 phil } 170 1.1 phil 171 1.1 phil <BRACE>"\n" { buff_add_ch (yytext[0]); line_no++; } 172 1.1 phil 173 1.1 phil <BRACE>. { buff_add_ch (yytext[0]); } 174 1.1 phil 175 1.1 phil . { 176 1.1 phil if (yytext[0] < ' ') 177 1.1 phil yyerror ("illegal character: ^%c",yytext[0] + '@'); 178 1.1 phil else 179 1.1 phil if (yytext[0] > '~') 180 1.1 phil yyerror ("illegal character: \\%3d", (int) yytext[0]); 181 1.1 phil else 182 1.1 phil yyerror ("illegal character: %s",yytext); 183 1.1 phil 184 1.1 phil /* To quiet the compiler */ 185 1.1 phil if (0) unput(0); 186 1.1 phil } 187 1.1 phil %% 188 1.1 phil 189 1.1 phil #ifdef SCAN 190 1.1 phil YYSTYPE yylval; 191 1.1 phil 192 1.1 phil main() 193 1.1 phil { 194 1.1 phil int val; 195 1.1 phil 196 1.1 phil line_no = 1; 197 1.1 phil while ( (val = yylex()) != 0 ) 198 1.1 phil printf ("val = %d\n yytext = %s\n", val, yytext); 199 1.1 phil } 200 1.1 phil #endif 201