bool.l (1525B)
1 /* This program is licensed under the terms of GNU GPL v3 or (at your option) 2 * any later version. Copyright (C) 2026 Страхиња Радић. 3 * See the file LICENSE for exact copyright and license details. */ 4 5 digit [0-9] 6 letter [A-Za-z] 7 ident {letter}({letter}|{digit})* 8 wspace [ \t]+ 9 10 %{ 11 12 #include <stdarg.h> 13 #include "y.tab.h" 14 15 extern int colno, lineno; 16 extern int add_id(const char* id); 17 extern int get_index(const char* id); 18 extern void yydbg(const char* format, ...); 19 extern void yyerror(const char* format, ...); 20 %} 21 22 %% 23 24 {ident} { colno += yyleng; 25 yydbg("Identifier: {%s}", yytext); 26 if((yylval.ident_id = get_index(yytext)) < 0) 27 { 28 yylval.ident_id = add_id(yytext); 29 yydbg("Added, ID = %d", yylval.ident_id); 30 } 31 else 32 yydbg("Present, ID = %d", yylval.ident_id); 33 return IDENT; } 34 \( { colno++; 35 yydbg("Open brace"); 36 return *yytext; 37 } 38 \) { colno++; 39 yydbg("Closing brace"); 40 return *yytext; 41 } 42 \| { colno++; 43 yydbg("OR operator"); 44 return *yytext; 45 } 46 & { colno++; 47 yydbg("AND operator"); 48 return *yytext; 49 } 50 ~ { colno++; 51 yydbg("NOT operator"); 52 return *yytext; 53 } 54 \^ { colno++; 55 yydbg("XOR operator"); 56 return *yytext; 57 } 58 "=>" { colno += 2; 59 yydbg("IMPL operator"); 60 return IMPL; 61 } 62 {wspace} 63 { colno++; 64 yydbg("Whitespace"); 65 } 66 \n { colno = 1; 67 lineno++; 68 yydbg("Newline"); 69 } 70 #.*$ { colno = 1; 71 yydbg("Comment: {%s}", yytext); 72 } 73 . { colno++; 74 yyerror("Unknown character: %s", yytext); 75 yyterminate(); 76 } 77 78 %% 79 80 int 81 yywrap(void) 82 { 83 return 1; 84 }