File: lex.h

package info (click to toggle)
midish 0.2.5-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 760 kB
  • ctags: 1,294
  • sloc: ansic: 13,035; makefile: 119; sh: 114
file content (83 lines) | stat: -rw-r--r-- 2,837 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 * Copyright (c) 2003-2005 Alexandre Ratchov
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions 
 * are met:
 *
 * 	- Redistributions of source code must retain the above
 * 	  copyright notice, this list of conditions and the
 * 	  following disclaimer.
 *
 * 	- Redistributions in binary form must reproduce the above
 * 	  copyright notice, this list of conditions and the
 * 	  following disclaimer in the documentation and/or other
 * 	  materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef MIDISH_LEX_H
#define MIDISH_LEX_H

#define IDENT_MAXLEN	30
#define STRING_MAXLEN	1024
#define TOK_MAXLEN	STRING_MAXLEN

enum SYM_ID {
	TOK_EOF = 0, TOK_ASSIGN, 
	TOK_PLUS, TOK_MINUS, TOK_STAR, TOK_SLASH, TOK_PCT,
	TOK_LSHIFT, TOK_RSHIFT, TOK_BITAND, TOK_BITOR, TOK_BITXOR, TOK_TILDE,
	TOK_EQ, TOK_NEQ, TOK_GE, TOK_GT, TOK_LE, TOK_LT, 
	TOK_EXCLAM, TOK_AND, TOK_OR,
	TOK_LPAR, TOK_RPAR, TOK_LBRACE, TOK_RBRACE, TOK_LBRACKET, TOK_RBRACKET,
	TOK_COMMA, TOK_DOT, TOK_SEMICOLON, TOK_COLON, 
	TOK_AT, TOK_DOLLAR, TOK_ENDLINE,
	/* keywords */
	TOK_IF, TOK_ELSE, TOK_WHILE, TOK_DO, TOK_FOR, TOK_IN,
	TOK_PROC, TOK_LET, TOK_RETURN, TOK_NIL,
	/* data */
	TOK_IDENT, TOK_NUM, TOK_STRING,
};

struct tokdef_s {
	unsigned id;				/* token id */
	char *str;				/* corresponding string */
};

struct lex_s {
	/*struct tokdef_s *op, *kw;*/
	unsigned id;
	char strval[TOK_MAXLEN + 1];
	unsigned long longval;	
	/* input */
	struct textin_s *in;
	/* used by ungetchar */
	int lookchar;
	/* for error reporting */
	unsigned line, col;
};

unsigned lex_init(struct lex_s *, char *);
void     lex_done(struct lex_s *);
unsigned lex_scan(struct lex_s *);
void	 lex_dbg(struct lex_s *);

unsigned lex_getchar(struct lex_s *o, int *c);
void	 lex_ungetchar(struct lex_s *o, int c);
void	 lex_err(struct lex_s *o, char *msg);
void	 lex_recover(struct lex_s *o, char *msg);
unsigned lex_str2long(struct lex_s *o, unsigned base);

#endif /* MIDISH_LEX_H */