|
| 1 | +/* -*- mode: c -*- */ |
| 2 | + |
| 3 | +/* |
| 4 | + * Copyright (C) 2008, 2010-2011 Nick Gasson |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License |
| 17 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + */ |
| 19 | + |
| 20 | +%{ |
| 21 | +#include "tokens.h" |
| 22 | + |
| 23 | +#define YY_INPUT(buf, result, max_size) { \ |
| 24 | + result = get_next_char(buf, max_size); \ |
| 25 | + if (result <= 0) \ |
| 26 | + result = YY_NULL; \ |
| 27 | + } |
| 28 | + |
| 29 | +Lvals lvals; |
| 30 | +%} |
| 31 | + |
| 32 | +/* TODO: look at string_literal and character_literal */ |
| 33 | + |
| 34 | +ID [a-zA-Z][a-zA-Z_0-9]* |
| 35 | +STRING \".*\" |
| 36 | +CHAR '.' |
| 37 | +COMMENT --.*\n |
| 38 | +INT [0-9]+ |
| 39 | + |
| 40 | +A [aA] |
| 41 | +B [bB] |
| 42 | +C [cC] |
| 43 | +D [dD] |
| 44 | +E [eE] |
| 45 | +F [fF] |
| 46 | +G [gG] |
| 47 | +H [hH] |
| 48 | +I [iI] |
| 49 | +L [lL] |
| 50 | +N [nN] |
| 51 | +M [mM] |
| 52 | +O [oO] |
| 53 | +P [pP] |
| 54 | +R [rR] |
| 55 | +S [sS] |
| 56 | +T [tT] |
| 57 | +U [uU] |
| 58 | +W [wW] |
| 59 | +Y [yY] |
| 60 | +X [xX] |
| 61 | + |
| 62 | +ENTITY {E}{N}{T}{I}{T}{Y} |
| 63 | +IS {I}{S} |
| 64 | +END {E}{N}{D} |
| 65 | +GENERIC {G}{E}{N}{E}{R}{I}{C} |
| 66 | +PORT {P}{O}{R}{T} |
| 67 | +CONSTANT {C}{O}{N}{S}{T}{A}{N}{T} |
| 68 | +CONFIGURATION {C}{O}{N}{F}{I}{G}{U}{R}{A}{T}{I}{O}{N} |
| 69 | +COMPONENT {C}{O}{M}{P}{O}{N}{E}{N}{T} |
| 70 | +ARCHITECTURE {A}{R}{C}{H}{I}{T}{E}{C}{T}{U}{R}{E} |
| 71 | +OF {O}{F} |
| 72 | +BEGIN {B}{E}{G}{I}{N} |
| 73 | +AND {A}{N}{D} |
| 74 | +OR {O}{R} |
| 75 | +XOR {X}{O}{R} |
| 76 | +XNOR {X}{N}{O}{R} |
| 77 | +NAND {N}{A}{N}{D} |
| 78 | +ABS {A}{B}{S} |
| 79 | +NOT {N}{O}{T} |
| 80 | +ALL {A}{L}{L} |
| 81 | +IN {I}{N} |
| 82 | +OUT {O}{U}{T} |
| 83 | +BUFFER {B}{U}{F}{F}{E}{R} |
| 84 | +BUS {B}{U}{S} |
| 85 | +UNAFFECTED {U}{N}{A}{F}{F}{E}{C}{T}{E}{D} |
| 86 | +SIGNAL {S}{I}{G}{N}{A}{L} |
| 87 | +PROCESS {P}{R}{O}{C}{E}{S}{S} |
| 88 | +WAIT {W}{A}{I}{T} |
| 89 | +REPORT {R}{E}{P}{O}{R}{T} |
| 90 | + |
| 91 | +%% |
| 92 | + |
| 93 | +{COMMENT} { begin_token(yytext); } |
| 94 | + |
| 95 | +{ENTITY} { begin_token(yytext); return tENTITY; } |
| 96 | +{IS} { begin_token(yytext); return tIS; } |
| 97 | +{END} { begin_token(yytext); return tEND; } |
| 98 | +{GENERIC} { begin_token(yytext); return tGENERIC; } |
| 99 | +{PORT} { begin_token(yytext); return tPORT; } |
| 100 | +{CONSTANT} { begin_token(yytext); return tCONSTANT; } |
| 101 | +{COMPONENT} { begin_token(yytext); return tCOMPONENT; } |
| 102 | +{CONFIGURATION} { begin_token(yytext); return tCONFIGURATION; } |
| 103 | +{ARCHITECTURE} { begin_token(yytext); return tARCHITECTURE; } |
| 104 | +{OF} { begin_token(yytext); return tOF; } |
| 105 | +{BEGIN} { begin_token(yytext); return tBEGIN; } |
| 106 | +{AND} { begin_token(yytext); return tAND; } |
| 107 | +{OR} { begin_token(yytext); return tOR; } |
| 108 | +{XOR} { begin_token(yytext); return tXOR; } |
| 109 | +{XNOR} { begin_token(yytext); return tXNOR; } |
| 110 | +{NAND} { begin_token(yytext); return tNAND; } |
| 111 | +{ABS} { begin_token(yytext); return tABS; } |
| 112 | +{NOT} { begin_token(yytext); return tNOT; } |
| 113 | +{ALL} { begin_token(yytext); return tALL; } |
| 114 | +{IN} { begin_token(yytext); return tIN; } |
| 115 | +{OUT} { begin_token(yytext); return tOUT; } |
| 116 | +{BUFFER} { begin_token(yytext); return tBUFFER; } |
| 117 | +{BUS} { begin_token(yytext); return tBUS; } |
| 118 | +{UNAFFECTED} { begin_token(yytext); return tUNAFFECTED; } |
| 119 | +{SIGNAL} { begin_token(yytext); return tSIGNAL; } |
| 120 | +{PROCESS} { begin_token(yytext); return tPROCESS; } |
| 121 | +{WAIT} { begin_token(yytext); return tWAIT; } |
| 122 | +{REPORT} { begin_token(yytext); return tREPORT; } |
| 123 | + |
| 124 | +"(" { begin_token(yytext); return tLPAREN; } |
| 125 | +")" { begin_token(yytext); return tRPAREN; } |
| 126 | +";" { begin_token(yytext); return tSEMI; } |
| 127 | +":=" { begin_token(yytext); return tASSIGN; } |
| 128 | +":" { begin_token(yytext); return tCOLON; } |
| 129 | +"**" { begin_token(yytext); return tPOWER; } |
| 130 | +"," { begin_token(yytext); return tCOMMA; } |
| 131 | +"<=" { begin_token(yytext); return tLE; } |
| 132 | +{INT} { begin_token(yytext); return tINT; } |
| 133 | +{STRING} { begin_token(yytext); return tSTRING; } |
| 134 | +{CHAR} { begin_token(yytext); return tCHAR; } |
| 135 | +{ID} { begin_token(yytext); lvals.sval = strdup(yytext); return tID; } |
| 136 | +[ \t\r\n] { begin_token(yytext); } |
| 137 | +<<EOF>> { begin_token(yytext); return 0; } |
| 138 | +. { begin_token(yytext); return tERROR; } |
| 139 | +%% |
| 140 | + |
0 commit comments