• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2015 PLUMgrid, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17%{
18#include "lexer.h"
19%}
20
21%option yylineno nodefault yyclass="Lexer" noyywrap c++ prefix="ebpfcc"
22%option never-interactive
23%{
24#include <string>
25#include "parser.yy.hh"
26std::string tmp_str_cc;
27%}
28
29%x STRING_
30%%
31
32\"                      {BEGIN STRING_;}
33<STRING_>\"             { BEGIN 0;
34                        yylval_->string = new std::string(tmp_str_cc);
35                        tmp_str_cc = "";
36                        return Tok::TSTRING;
37                        }
38<STRING_>\\n            {tmp_str_cc += "\n"; }
39<STRING_>.              {tmp_str_cc += *yytext; }
40
41
42
43[ \t]+                  { save_text(); }
44\n                      { if (next_line()) { return save(Tok::TSEMI, true); } }
45"//".*\n                { if (next_line()) { return save(Tok::TSEMI, true); } }
46^"#"                    return save(Tok::TPRAGMA);
47"="                     return save(Tok::TEQUAL);
48"=="                    return save(Tok::TCEQ);
49"!="                    return save(Tok::TCNE);
50"<"                     return save(Tok::TCLT);
51"<="                    return save(Tok::TCLE);
52">"                     return save(Tok::TCGT);
53">="                    return save(Tok::TCGE);
54"("                     return save(Tok::TLPAREN);
55")"                     return save(Tok::TRPAREN);
56"{"                     return save(Tok::TLBRACE);
57"}"                     return save(Tok::TRBRACE);
58"["                     return save(Tok::TLBRACK);
59"]"                     return save(Tok::TRBRACK);
60"->"                    return save(Tok::TARROW);
61"."                     return save(Tok::TDOT);
62","                     return save(Tok::TCOMMA);
63"+"                     return save(Tok::TPLUS);
64"++"                    return save(Tok::TINCR);
65"-"                     return save(Tok::TMINUS);
66"--"                    return save(Tok::TDECR);
67"*"                     return save(Tok::TMUL);
68"/"                     return save(Tok::TDIV);
69"%"                     return save(Tok::TMOD);
70"^"                     return save(Tok::TXOR);
71"$"                     return save(Tok::TDOLLAR);
72"!"                     return save(Tok::TNOT);
73"~"                     return save(Tok::TCMPL);
74":"                     return save(Tok::TCOLON);
75"::"                    return save(Tok::TSCOPE);
76";"                     return save(Tok::TSEMI);
77"&&"                    return save(Tok::TAND);
78"||"                    return save(Tok::TOR);
79"&"                     return save(Tok::TLAND);
80"|"                     return save(Tok::TLOR);
81"@"                     return save(Tok::TAT);
82
83"case"                  return save(Tok::TCASE);
84"continue"              return save(Tok::TCONTINUE);
85"else"                  return save(Tok::TELSE);
86"false"                 return save(Tok::TFALSE);
87"goto"                  return save(Tok::TGOTO);
88"if"                    return save(Tok::TIF);
89"next"                  return save(Tok::TNEXT);
90"on_match"              return save(Tok::TMATCH);
91"on_miss"               return save(Tok::TMISS);
92"on_failure"            return save(Tok::TFAILURE);
93"on_valid"              return save(Tok::TVALID);
94"return"                return save(Tok::TRETURN);
95"state"                 return save(Tok::TSTATE);
96"struct"                return save(Tok::TSTRUCT);
97"switch"                return save(Tok::TSWITCH);
98"true"                  return save(Tok::TTRUE);
99"u8"                    return save(Tok::TU8);
100"u16"                   return save(Tok::TU16);
101"u32"                   return save(Tok::TU32);
102"u64"                   return save(Tok::TU64);
103
104[a-zA-Z_][a-zA-Z0-9_]*  return save(Tok::TIDENTIFIER);
105[0-9]+                  return save(Tok::TINTEGER);
1060x[0-9a-fA-F]+          return save(Tok::THEXINTEGER);
107
108.                       printf("Unknown token \"%s\"\n", yytext); yyterminate();
109
110%%
111