Skip to content

Instantly share code, notes, and snippets.

@y-yu
Created August 22, 2013 03:13
Show Gist options
  • Save y-yu/6302807 to your computer and use it in GitHub Desktop.
Save y-yu/6302807 to your computer and use it in GitHub Desktop.
Rubyの改造(1)
#define YYSTYPE char *
extern int yylex ();
extern void init_yyc (char **);
extern void re_parse (char *);
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "relex.h"
#include "re_parse.h"
#define TEXT_SIZE 64
static char *yyc;
static char *yyold;
static char yytext[TEXT_SIZE];
void
get () {
int size = yyc - yyold;
int i;
if (size > TEXT_SIZE) {
return;
}
for (i = 0; i < size; i++) {
yytext[i] = *(yyold + i);
}
yytext[i] = '\0';
yylval = strdup(yytext);
}
int
yylex ()
{
yyold = yyc;
/*!re2c
re2c:define:YYCTYPE = "unsigned char";
re2c:define:YYCURSOR = yyc;
re2c:yyfill:enable = 0;
re2c:yych:conversion = 1;
re2c:indent:top = 1;
'\\'. {get(); return TOKEN_ESCAPECHAR; }
'['[^\]]*']' {get(); return TOKEN_CLASS; }
([+*?]'+'?|'{'[^}]*'}') {get(); return TOKEN_QUANTIFIER; }
'(' {return TOKEN_BEGINGROUP; }
')' {return TOKEN_ENDGROUP; }
'|' {return TOKEN_ALT; }
[\000-\037] {return TOKEN_END; }
[^+*?(){}[\]|] {get(); return TOKEN_LETTER; }
[^] {return TOKEN_ERR;}
*/
}
void
init_yyc (char **p)
{
yyc = *p;
yyold = *p;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment