GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — tinyopt/lexer.l at main · leozamboni/tinyopt

Expand file tree

/

lexer.l

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
100 lines (86 loc) · 2.68 KB
/

lexer.l

Copy path

File metadata and controls

100 lines (86 loc) · 2.68 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
%{
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include "tinyopt_ast.h"
#include "parser.tab.h"
uint64_t fnv1a_with_salt(const char *s) {
uint64_t hash = 14695981039346656037ULL;
unsigned long salt = (unsigned long)rand();
hash ^= salt;
while (*s) {
hash ^= (unsigned char)(*s++);
hash *= 1099511628211ULL;
}
return hash;
}
%}
digit [0-9]
letter [a-zA-Z_]
id {letter}({letter}|{digit})*
number {digit}+(\.{digit}+)?([eE][+-]?{digit}+)?
char_literal \'[^\']\'
string_literal \"[^\"]*\"
%%
"int" { return INT; }
"float" { return FLOAT; }
"char" { return CHAR; }
"void" { return VOID; }
"return" { return RETURN; }
"if" { return IF; }
"else" { return ELSE; }
"while" { yylval.hash = fnv1a_with_salt(yytext); return WHILE; }
"for" { yylval.hash = fnv1a_with_salt(yytext); return FOR; }
"break" { return BREAK; }
"continue" { return CONTINUE; }
{number} {
yylval.str = strdup(yytext);
return NUMBER;
}
{char_literal} {
yylval.str = strdup(yytext);
return CHAR_LITERAL;
}
{string_literal} {
yylval.str = strdup(yytext);
return STRING_LITERAL;
}
{id} {
yylval.identifier.hash = fnv1a_with_salt(yytext);
yylval.identifier.name = strdup(yytext);
return ID;
}
"+" { return '+'; }
"-" { return '-'; }
"*" { return '*'; }
"/" { return '/'; }
"%" { return '%'; }
"=" { return '='; }
"==" { return EQ; }
"!=" { return NE; }
"<" { return '<'; }
"<=" { return LE; }
">" { return '>'; }
">=" { return GE; }
"!" { return '!'; }
"&&" { return AND; }
"||" { return OR; }
"++" { return INC; }
"--" { return DEC; }
"+=" { return ADD_ASSIGN; }
"-=" { return SUB_ASSIGN; }
"*=" { return MUL_ASSIGN; }
"/=" { return DIV_ASSIGN; }
"%=" { return MOD_ASSIGN; }
";" { return ';'; }
"," { return ','; }
"(" { return '('; }
")" { return ')'; }
"{" { return '{'; }
"}" { return '}'; }
"[" { return '['; }
"]" { return ']'; }
[ \t\r\n]+ { /* ignorar */ }
. { printf("Caractere inválido: %s\n", yytext); return yytext[0]; }
%%
int yywrap(void) { return 1; }
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.