File: cmdlex.l

package info (click to toggle)
sdcc 3.8.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 99,212 kB
  • sloc: ansic: 918,594; cpp: 69,526; makefile: 56,790; sh: 29,616; asm: 12,364; perl: 12,136; yacc: 7,179; lisp: 1,672; python: 812; lex: 773; awk: 495; sed: 89
file content (174 lines) | stat: -rw-r--r-- 3,766 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
%{
#include <stdio.h>
//#include <stdint.h>
#include "cmdlexcl.h"
#include "cmdpars.hh"

static int uc_yy_check_id(char *token);
static int uc_yy_input(char *buf, int max_size);
#define YY_INPUT(buf,result,max_size) result = uc_yy_input(buf, max_size) 
%}

%option nounput

%%

[ \t]*			;

"int"			return(PTOK_INT);
"*="			return(PTOK_MUL_ASSIGN);
"/="			return(PTOK_DIV_ASSIGN);
"%="			return(PTOK_MOD_ASSIGN);
"+="			return(PTOK_ADD_ASSIGN);
"-="			return(PTOK_SUB_ASSIGN);
"<<="			return(PTOK_LEFT_ASSIGN);
">>="			return(PTOK_RIGHT_ASSIGN);
"&="			return(PTOK_AND_ASSIGN);
"^="			return(PTOK_XOR_ASSIGN);
"|="			return(PTOK_OR_ASSIGN);
"&&"			return(PTOK_AND_OP);
"||"			return(PTOK_OR_OP);
"++"			return(PTOK_INC_OP);
"--"			return(PTOK_DEC_OP);
"=="			return(PTOK_EQ_OP);
"!="			return(PTOK_NE_OP);
">="			return(PTOK_GE_OP);
"<="			return(PTOK_LE_OP);
">>"			return(PTOK_RIGHT_OP);
"<<"			return(PTOK_LEFT_OP);
"+"			return(PTOK_PLUS);
"-"			return(PTOK_MINUS);
"*"			return(PTOK_ASTERIX);
"/"			return(PTOK_SLASH);
"("			return(PTOK_LEFT_PAREN);
")"			return(PTOK_RIGHT_PAREN);
"["			return(PTOK_LEFT_BRACKET);
"]"			return(PTOK_RIGHT_BRACKET);
"="			return(PTOK_EQUAL);
"."			return(PTOK_DOT);
"&"			return(PTOK_AMPERSAND);
"|"			return(PTOK_PIPE);
"^"			return(PTOK_CIRCUM);
"%"			return(PTOK_PERCENT);
"~"			return(PTOK_TILDE);
"?"			return(PTOK_QUESTION);
":"			return(PTOK_COLON);
"<"			return(PTOK_LESS);
">"			return(PTOK_GREATHER);
"!"			return(PTOK_EXCLAMATION);
","			return(PTOK_COMMA);

([0-9]+)|(0x[0-9a-fA-F]+) {
  //printf("\nlexer found a nr: %s\n",yytext);
  yylval.number = strtol(yytext, 0, 0);
  return PTOK_NUMBER;
}

[a-zA-Z_][0-9a-zA-Z_]*	return(uc_yy_check_id(yytext));

.			return(yytext[0]);

%%

int
yywrap()
{
  return 1;
}

#include "globals.h"
static char *string_to_parse = NULL;

void
uc_yy_set_string_to_parse(const char *str)
{
  string_to_parse = strdup(str);
  YY_FLUSH_BUFFER;
}

static const char *string_ptr = NULL;

void
uc_yy_free_string_to_parse()
{
  free(string_to_parse);
  string_ptr=NULL;
}

static int
uc_yy_input(char *buf, int max_size)
{
  //printf("\nuc_yy_input called for max=%d\n",max_size);
  if (NULL == string_ptr)
    {
      string_ptr = string_to_parse;
      //printf("\nstring_ptr is NULL, start over with %s\n",string_to_parse);
    }
  else
  {
    //printf("\ncontinue with %s\n",string_ptr);
  }

  if (NULL != string_ptr)
    {
      int lrem = strlen(string_ptr);
      int n = max_size;
      if (lrem < max_size)
        n = lrem;
      strncpy(buf, string_ptr, n);
      string_ptr += n;
      //printf("\n%d chars copied, left=%s\n",n,string_ptr);
      return n;
    }
  else
    return 0;
}

static int
uc_yy_check_id(char *token)
{
  class cl_uc *uc= application->get_uc();
  //printf("checking id=\"%s\"\n",token);

  if (uc)
    {
      class cl_memory *mem = uc->memory(token);
      if (mem)
	{
	  yylval.memory_object = mem;
	  return PTOK_MEMORY_OBJECT;
	}
      
      t_addr addr;
      class cl_address_space *as;
      bool found;
      if ((found= uc->symbol2address(yytext, &as, &addr)))
	  {
	      yylval.memory.memory= as;
	      yylval.memory.address= addr;
	      return PTOK_MEMORY;
	  }
      /*
      else if ((found= uc->symbol2address(yytext, uc->sfr_tbl(), &addr)))
	{
	  //yylval.number= addr; return PTOK_NUMBER;
	  yylval.memory.memory = uc->address_space(MEM_SFR_ID);
	  yylval.memory.address = addr;
	  return PTOK_MEMORY;
	}
      */
      //found= uc->symbol2address(yytext, uc->bit_tbl(), &addr);
      if (found)
	{
	  t_addr memaddr;
	  t_mem mask;
	  yylval.bit.memory= uc->bit2mem(addr, &memaddr, &mask);
	  yylval.bit.mem_address = memaddr;
	  yylval.bit.bit_address = addr;
	  yylval.bit.mask = mask;
	  return PTOK_BIT;
	}
    }

  return 0;
}