PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/src/freebsd/sys/dev/aic7xxx/aicasm/aicasm_macro_scan.l

https://bitbucket.org/killerpenguinassassins/open_distrib_devel
LEX | 157 lines | 92 code | 11 blank | 54 comment | 0 complexity | 8027e060bb1f73c963ba76f6853a9f4e MD5 | raw file
Possible License(s): CC0-1.0, MIT, LGPL-2.0, LGPL-3.0, WTFPL, GPL-2.0, BSD-2-Clause, AGPL-3.0, CC-BY-SA-3.0, MPL-2.0, JSON, BSD-3-Clause-No-Nuclear-License-2014, LGPL-2.1, CPL-1.0, AGPL-1.0, 0BSD, ISC, Apache-2.0, GPL-3.0, IPL-1.0, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. %{
  2. /*-
  3. * Sub-Lexical Analyzer for macro invokation in
  4. * the Aic7xxx SCSI Host adapter sequencer assembler.
  5. *
  6. * Copyright (c) 2001 Adaptec Inc.
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions, and the following disclaimer,
  14. * without modification.
  15. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  16. * substantially similar to the "NO WARRANTY" disclaimer below
  17. * ("Disclaimer") and any redistribution must be conditioned upon
  18. * including a substantially similar Disclaimer requirement for further
  19. * binary redistribution.
  20. * 3. Neither the names of the above-listed copyright holders nor the names
  21. * of any contributors may be used to endorse or promote products derived
  22. * from this software without specific prior written permission.
  23. *
  24. * Alternatively, this software may be distributed under the terms of the
  25. * GNU General Public License ("GPL") version 2 as published by the Free
  26. * Software Foundation.
  27. *
  28. * NO WARRANTY
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  30. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  31. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  32. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  33. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  34. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  35. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  36. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  37. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  38. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  39. * POSSIBILITY OF SUCH DAMAGES.
  40. *
  41. * $Id: //depot/aic7xxx/aic7xxx/aicasm/aicasm_macro_scan.l#8 $
  42. *
  43. * $FreeBSD$
  44. */
  45. #include <sys/types.h>
  46. #include <inttypes.h>
  47. #include <limits.h>
  48. #include <regex.h>
  49. #include <stdio.h>
  50. #include <string.h>
  51. #include <sysexits.h>
  52. #include <sys/queue.h>
  53. #include "aicasm.h"
  54. #include "aicasm_symbol.h"
  55. #include "aicasm_macro_gram.h"
  56. #define MAX_STR_CONST 4096
  57. static char string_buf[MAX_STR_CONST];
  58. static char *string_buf_ptr;
  59. static int parren_count;
  60. static char msgbuf[255];
  61. extern int mmlex(void);
  62. %}
  63. %option noinput
  64. WORD [A-Za-z_][-A-Za-z_0-9]*
  65. SPACE [ \t]+
  66. MCARG [^(), \t]+
  67. %x ARGLIST
  68. %%
  69. \n {
  70. ++yylineno;
  71. }
  72. \r ;
  73. <ARGLIST>{SPACE} ;
  74. <ARGLIST>\( {
  75. parren_count++;
  76. if (parren_count == 1) {
  77. string_buf_ptr = string_buf;
  78. return ('(');
  79. }
  80. *string_buf_ptr++ = '(';
  81. }
  82. <ARGLIST>\) {
  83. if (parren_count == 1) {
  84. if (string_buf_ptr != string_buf) {
  85. /*
  86. * Return an argument and
  87. * rescan this parren so we
  88. * can return it as well.
  89. */
  90. *string_buf_ptr = '\0';
  91. mmlval.str = string_buf;
  92. string_buf_ptr = string_buf;
  93. unput(')');
  94. return T_ARG;
  95. }
  96. BEGIN INITIAL;
  97. return (')');
  98. }
  99. parren_count--;
  100. *string_buf_ptr++ = ')';
  101. }
  102. <ARGLIST>{MCARG} {
  103. char *yptr;
  104. yptr = mmtext;
  105. while (*yptr)
  106. *string_buf_ptr++ = *yptr++;
  107. }
  108. <ARGLIST>\, {
  109. if (string_buf_ptr != string_buf) {
  110. /*
  111. * Return an argument and
  112. * rescan this comma so we
  113. * can return it as well.
  114. */
  115. *string_buf_ptr = '\0';
  116. mmlval.str = string_buf;
  117. string_buf_ptr = string_buf;
  118. unput(',');
  119. return T_ARG;
  120. }
  121. return ',';
  122. }
  123. {WORD}[(] {
  124. /* May be a symbol or a macro invocation. */
  125. mmlval.sym = symtable_get(mmtext);
  126. if (mmlval.sym->type != MACRO) {
  127. stop("Expecting Macro Name",
  128. EX_DATAERR);
  129. }
  130. unput('(');
  131. parren_count = 0;
  132. BEGIN ARGLIST;
  133. return T_SYMBOL;
  134. }
  135. . {
  136. snprintf(msgbuf, sizeof(msgbuf), "Invalid character "
  137. "'%c'", mmtext[0]);
  138. stop(msgbuf, EX_DATAERR);
  139. }
  140. %%
  141. int
  142. mmwrap(void)
  143. {
  144. stop("EOF encountered in macro call", EX_DATAERR);
  145. return (1);
  146. }