FreeCalypso > hg > freecalypso-reveng
annotate dspanal/charparse.c @ 407:183e81c8f6c0
hr-bits: sid-count program written
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 22 Jul 2024 10:00:58 +0000 |
parents | f8344bc4fd61 |
children |
rev | line source |
---|---|
308
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module reads C char array files; it will be linked into programs |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * that do further processing. |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <ctype.h> |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <string.h> |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <strings.h> |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 /* lexer tokens */ |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #define WORD 256 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #define NUMBER 257 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #define HEXBYTE 258 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 /* limits */ |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 #define MAXWORD 63 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 #define MAXDIGITS 5 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 static char *parser_filename; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 static FILE *parser_readF; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 static int parser_lineno; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 static char parser_read_word[MAXWORD+1]; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 static int parser_read_number; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 static void |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 parse_error(msg) |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 char *msg; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 { |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 fprintf(stderr, "%s line %d: %s\n", parser_filename, parser_lineno, |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 msg); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 exit(1); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 static |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 my_getchar() |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 { |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 register int c; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 c = getc(parser_readF); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 if (c < 0) |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 return(c); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 if (!isascii(c)) |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 parse_error("non-ASCII character"); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 if (iscntrl(c) && c != '\n' && c != '\t') |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 parse_error("invalid control character"); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 return(c); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 static void |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 handle_trad_comment() |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 { |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 register int c, flag; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 for (flag = 0; ; ) { |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 c = my_getchar(); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 if (c < 0) |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 parse_error("/* comment ends in EOF"); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 if (c == '\n') |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 parser_lineno++; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 if (c == '/' && flag) |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 return; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 flag = (c == '*'); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 } |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 } |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 static void |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 handle_line_comment() |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 { |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 register int c; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 for (;;) { |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 c = my_getchar(); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 if (c < 0) |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 parse_error("// comment ends in EOF"); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 if (c == '\n') { |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 parser_lineno++; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 return; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 } |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 } |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 } |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 static void |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 handle_comment() |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 { |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 int c; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 c = my_getchar(); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 switch (c) { |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 case '*': |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 /* traditional C comment style */ |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 handle_trad_comment(); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 return; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 case '/': |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 /* new-fangled double slash comment style */ |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 handle_line_comment(); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 return; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 default: |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 parse_error("character after '/' is not '*' or '/'"); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 exit(1); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 } |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 } |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 static void |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 handle_num_token(first_digit) |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 { |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 register int c, n; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 parser_read_number = first_digit - '0'; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 for (n = 1; ; n++) { |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 c = my_getchar(); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 if (!isdigit(c)) |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 break; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 parser_read_number *= 10; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 parser_read_number += c - '0'; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 } |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 if (c >= 0) { |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 if (isalpha(c) || c == '_') |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 parse_error( |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 "digits followed by letters: neither word nor number"); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 ungetc(c, parser_readF); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 } |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 if (n > MAXDIGITS) |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 parse_error("number is too long (MAXDIGITS exceeded)"); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 } |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 static int |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 decode_hex_digit(c) |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 register int c; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 { |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 if (isdigit(c)) |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 return(c - '0'); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 else if (isupper(c)) |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 return(c - 'A' + 10); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 else |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 return(c - 'a' + 10); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 } |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 static void |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 handle_hex_token() |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 { |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 register int c, n; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 c = my_getchar(); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 if (c != 'x' && c != 'X') |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 parse_error("\'0\' not followed by \'x\'"); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 parser_read_number = 0; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 for (n = 0; n < 2; n++) { |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 c = my_getchar(); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 if (!isxdigit(c)) |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 parse_error("0x not followed by two hex digits"); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 parser_read_number <<= 4; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 parser_read_number += decode_hex_digit(c); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 } |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 } |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 static void |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 handle_word_token(first_char) |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 { |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 register int c; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 register char *cp; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 register int len; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 cp = parser_read_word; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 *cp++ = first_char; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 for (len = 1; ; ) { |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 c = my_getchar(); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 if (!isalnum(c) && c != '_') |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 break; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 if (len >= MAXWORD) |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 parse_error("text token is too long"); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 *cp++ = c; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 len++; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 } |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 *cp = '\0'; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 if (c < 0) |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 return; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 ungetc(c, parser_readF); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 } |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 static int |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 get_token() |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 { |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 register int c; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 loop: c = my_getchar(); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 switch (c) { |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 case EOF: |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 return(0); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 case ' ': |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 case '\t': |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 goto loop; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 case '\n': |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 parser_lineno++; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 goto loop; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 case '/': |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 handle_comment(); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 goto loop; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 case ',': |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 case ';': |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 case '=': |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 case '[': |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 case ']': |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 case '{': |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 case '}': |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 return(c); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 case '0': |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 handle_hex_token(); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 return(HEXBYTE); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 } |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 if (isdigit(c)) { |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 handle_num_token(c); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 return(NUMBER); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 } |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 if (isalpha(c) || c == '_') { |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 handle_word_token(c); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 return(WORD); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 } |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 fprintf(stderr, "%s line %d: bad character \'%c\'\n", parser_filename, |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 parser_lineno, c); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
223 exit(1); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 } |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
225 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 unsigned |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 read_char_file(filename, outbuf, buflimit) |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 char *filename; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 u_char *outbuf; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 unsigned buflimit; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 { |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
232 register int t; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
233 u_char *outptr; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
234 unsigned bytecnt; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
235 |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
236 parser_filename = filename; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
237 parser_readF = fopen(parser_filename, "r"); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
238 if (!parser_readF) { |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
239 perror(parser_filename); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
240 exit(1); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
241 } |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
242 parser_lineno = 1; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
243 t = get_token(); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
244 if (t != WORD || strcmp(parser_read_word, "const")) |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
245 parse_error("expected \"const\" keyword"); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
246 t = get_token(); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
247 if (t != WORD || strcmp(parser_read_word, "unsigned")) |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
248 parse_error("expected \"unsigned\" keyword"); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
249 t = get_token(); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
250 if (t != WORD || strcmp(parser_read_word, "char")) |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
251 parse_error("expected \"char\" keyword"); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
252 t = get_token(); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
253 if (t != WORD) |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
254 parse_error("expected char array name"); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
255 t = get_token(); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
256 if (t != '[') |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
257 parse_error("expected \'[\'"); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
258 t = get_token(); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
259 if (t == NUMBER) |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
260 t = get_token(); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
261 if (t != ']') |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
262 parse_error("expected \']\'"); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
263 t = get_token(); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
264 if (t != '=') |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
265 parse_error("expected \'=\'"); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
266 t = get_token(); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
267 if (t != '{') |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
268 parse_error("expected \'{\'"); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
269 /* get first hex byte */ |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
270 t = get_token(); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
271 if (t != HEXBYTE) |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
272 parse_error("expected first hex byte"); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
273 outptr = outbuf; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
274 *outptr++ = parser_read_number; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
275 bytecnt = 1; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
276 for (;;) { |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
277 t = get_token(); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
278 if (t == '}') |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
279 break; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
280 if (t != ',') |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
281 parse_error("expected comma between bytes"); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
282 t = get_token(); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
283 if (t == '}') |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
284 break; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
285 if (t != HEXBYTE) |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
286 parse_error("expected next hex byte"); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
287 if (bytecnt >= buflimit) |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
288 parse_error("buffer limit exceeded"); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
289 *outptr++ = parser_read_number; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
290 bytecnt++; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
291 } |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
292 t = get_token(); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
293 if (t != ';') |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
294 parse_error("expected terminating \';\'"); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
295 fclose(parser_readF); |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
296 return bytecnt; |
f8344bc4fd61
dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
297 } |