* fixed GCC 4.4.0 mingw compilation:
[fw/sdcc] / sim / ucsim / cmd.src / cmdlex.l
1 %{
2 #include <stdio.h>
3 #include "cmdlexcl.h"
4 #include "cmdpars.h"
5
6 static YY_cl_ucsim_parser_STYPE *yylval;
7
8 int yywrap(void);
9
10 #define tok(x) (YY_cl_ucsim_parser_CLASS::x)
11 #define lexer_obj (dynamic_cast<class cl_ucsim_lexer *>(this))
12
13 %}
14
15 %%
16
17 [ \t]*                  ;
18
19 "+"                     return(tok(PTOK_PLUS));
20 "-"                     return(tok(PTOK_MINUS));
21 "*"                     return(tok(PTOK_ASTERIX));
22 "/"                     return(tok(PTOK_SLASH));
23 "("                     return(tok(PTOK_LEFT_PAREN));
24 ")"                     return(tok(PTOK_RIGHT_PAREN));
25 "["                     return(tok(PTOK_LEFT_BRACKET));
26 "]"                     return(tok(PTOK_RIGHT_BRACKET));
27 "="                     return(tok(PTOK_EQUAL));
28 "."                     return(tok(PTOK_DOT));
29 "&"                     return(tok(PTOK_AMPERSAND));
30
31 ([0-9]+)|(0x[0-9a-fA-F]+) {
32   yylval->number= strtol(yytext, 0, 0);
33   return(YY_cl_ucsim_parser_CLASS::PTOK_NUMBER);
34 }
35
36 [a-zA-Z_][0-9a-zA-Z_]*  return(lexer_obj->check_id(yytext));
37
38 .                       ;
39
40 %%
41
42 #undef lexer_obj
43
44 int
45 yywrap(void)
46 {
47   return(1);
48 }
49
50 #include "cmdlexcl.h"
51 #include "globals.h"
52
53 int
54 cl_ucsim_lexer::LexerInput(char *buf, int max_size)
55 {
56   if (!string_to_parse)
57     return(yyFlexLexer::LexerInput(buf, max_size));
58   int lrem= strlen(string_ptr);
59   int n= max_size;
60   if (lrem < max_size)
61     n= lrem;
62   strncpy(buf, string_ptr, n);
63   string_ptr+= n;
64   return(n);
65 }
66
67 void
68 cl_ucsim_lexer::activate_lexer_to_parse_into(void *yylv)
69 {
70   yylval= (YY_cl_ucsim_parser_STYPE *)yylv;
71 }
72
73 int
74 cl_ucsim_lexer::check_id(char *token)
75 {
76   class cl_uc *uc= application->get_uc();
77   //printf("checking id=\"%s\"\n",token);
78
79   if (uc)
80     {
81       class cl_memory *mem= uc->memory(token);
82       if (mem)
83         {
84           yylval->memory_object= mem;
85           return(tok(PTOK_MEMORY_OBJECT));
86         }
87       
88       t_addr addr;
89       bool found= uc->symbol2address(yytext, uc->sfr_tbl(), &addr);
90       if (found)
91         {
92           /*yylval->number= addr;
93             return(tok(PTOK_NUMBER));*/
94           yylval->memory.memory= uc->address_space(MEM_SFR_ID);
95           yylval->memory.address= addr;
96           return(tok(PTOK_MEMORY));
97         }
98
99       found= uc->symbol2address(yytext, uc->bit_tbl(), &addr);
100       if (found)
101         {
102           t_addr memaddr;
103           t_mem mask;
104           yylval->bit.memory= uc->bit2mem(addr, &memaddr, &mask);
105           yylval->bit.mem_address= memaddr;
106           yylval->bit.bit_address= addr;
107           yylval->bit.mask= mask;
108           return(tok(PTOK_BIT));
109         }
110     }
111
112   return(0);
113 }