1 %{ 2 /****************************************************************************** 3 * 4 * Module Name: prparser.l - Flex input file for preprocessor lexer 5 * 6 *****************************************************************************/ 7 8 /* 9 * Copyright (C) 2000 - 2013, Intel Corp. 10 * All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions, and the following disclaimer, 17 * without modification. 18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 19 * substantially similar to the "NO WARRANTY" disclaimer below 20 * ("Disclaimer") and any redistribution must be conditioned upon 21 * including a substantially similar Disclaimer requirement for further 22 * binary redistribution. 23 * 3. Neither the names of the above-listed copyright holders nor the names 24 * of any contributors may be used to endorse or promote products derived 25 * from this software without specific prior written permission. 26 * 27 * Alternatively, this software may be distributed under the terms of the 28 * GNU General Public License ("GPL") version 2 as published by the Free 29 * Software Foundation. 30 * 31 * NO WARRANTY 32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 42 * POSSIBILITY OF SUCH DAMAGES. 43 */ 44 45 #include "aslcompiler.h" 46 #include "prparser.y.h" 47 48 /* Buffer to pass strings to the parser */ 49 50 #define STRING_SETUP strcpy (StringBuffer, PrParsertext);\ 51 PrParserlval.str = StringBuffer 52 53 #define YY_NO_INPUT /* No file input, we use strings only */ 54 55 #define _COMPONENT ACPI_COMPILER 56 ACPI_MODULE_NAME ("prscanner") 57 %} 58 59 %option noyywrap 60 %option nounput 61 62 Number [0-9a-fA-F]+ 63 HexNumber 0[xX][0-9a-fA-F]+ 64 WhiteSpace [ \t\v\r]+ 65 NewLine [\n] 66 Identifier [a-zA-Z][0-9a-zA-Z]* 67 68 %% 69 70 \( return (EXPOP_PAREN_OPEN); 71 \) return (EXPOP_PAREN_CLOSE); 72 \~ return (EXPOP_ONES_COMPLIMENT); 73 \! return (EXPOP_LOGICAL_NOT); 74 \* return (EXPOP_MULTIPLY); 75 \/ return (EXPOP_DIVIDE); 76 \% return (EXPOP_MODULO); 77 \+ return (EXPOP_ADD); 78 \- return (EXPOP_SUBTRACT); 79 ">>" return (EXPOP_SHIFT_RIGHT); 80 "<<" return (EXPOP_SHIFT_LEFT); 81 \< return (EXPOP_LESS); 82 \> return (EXPOP_GREATER); 83 "<=" return (EXPOP_LESS_EQUAL); 84 ">=" return (EXPOP_GREATER_EQUAL); 85 "==" return (EXPOP_EQUAL); 86 "!=" return (EXPOP_NOT_EQUAL); 87 \& return (EXPOP_AND); 88 \^ return (EXPOP_XOR); 89 \| return (EXPOP_OR); 90 "&&" return (EXPOP_LOGICAL_AND); 91 "||" return (EXPOP_LOGICAL_OR); 92 93 "defined" return (EXPOP_DEFINE); 94 {Identifier} {STRING_SETUP; return (EXPOP_IDENTIFIER);} 95 96 <<EOF>> return (EXPOP_EOF); /* null end-of-string */ 97 98 {Number} return (EXPOP_NUMBER); 99 {HexNumber} return (EXPOP_HEX_NUMBER); 100 {NewLine} return (EXPOP_NEW_LINE); 101 {WhiteSpace} /* Ignore */ 102 103 . return (EXPOP_EOF); 104 %% 105 106 /* 107 * Local support functions 108 */ 109 YY_BUFFER_STATE LexBuffer; 110 111 112 /****************************************************************************** 113 * 114 * FUNCTION: PrInitLexer 115 * 116 * PARAMETERS: String - Input string to be parsed 117 * 118 * RETURN: TRUE if parser returns NULL. FALSE otherwise. 119 * 120 * DESCRIPTION: Initialization routine for lexer. The lexer needs 121 * a buffer to handle strings instead of a file. 122 * 123 *****************************************************************************/ 124 125 int 126 PrInitLexer ( 127 char *String) 128 { 129 130 LexBuffer = yy_scan_string (String); 131 return (LexBuffer == NULL); 132 } 133 134 135 /****************************************************************************** 136 * 137 * FUNCTION: PrTerminateLexer 138 * 139 * PARAMETERS: None 140 * 141 * RETURN: None 142 * 143 * DESCRIPTION: Termination routine for thelexer. 144 * 145 *****************************************************************************/ 146 147 void 148 PrTerminateLexer ( 149 void) 150 { 151 152 yy_delete_buffer (LexBuffer); 153 }