| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- /*
- Part of the Carbon Language project, under the Apache License v2.0 with LLVM
- Exceptions. See /LICENSE for license information.
- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- */
- %{
- #include <cstdlib>
- #include "executable_semantics/syntax.tab.h"
- %}
- %option yylineno
- AND "and"
- ARROW "->"
- AUTO "auto"
- BOOL "Bool"
- BREAK "break"
- CASE "case"
- CHOICE "choice"
- COMMENT \/\/[^\n]*\n
- CONTINUE "continue"
- DBLARROW "=>"
- DEFAULT "default"
- ELSE "else"
- EQUAL "=="
- FALSE "false"
- FN "fn"
- FNTY "fnty"
- IF "if"
- INT "Int"
- MATCH "match"
- NOT "not"
- OR "or"
- RETURN "return"
- STRUCT "struct"
- TRUE "true"
- TYPE "Type"
- VAR "var"
- WHILE "while"
- identifier [A-Za-z_][A-Za-z0-9_]*
- integer_literal [0-9]+
- %%
- {AND} { return AND; }
- {ARROW} { return ARROW; }
- {AUTO} { return AUTO; }
- {BOOL} { return BOOL; }
- {BREAK} { return BREAK; }
- {CASE} { return CASE; }
- {CHOICE} { return CHOICE; }
- {COMMENT} ;
- {CONTINUE} { return CONTINUE; }
- {DBLARROW} { return DBLARROW; }
- {DEFAULT} { return DEFAULT; }
- {ELSE} { return ELSE; }
- {EQUAL} { return EQUAL; }
- {FALSE} { return FALSE; }
- {FN} { return FN; }
- {FNTY} { return FNTY; }
- {IF} { return IF; }
- {INT} { return INT; }
- {MATCH} { return MATCH; }
- {NOT} { return NOT; }
- {OR} { return OR; }
- {RETURN} { return RETURN; }
- {STRUCT} { return STRUCT; }
- {TRUE} { return TRUE; }
- {TYPE} { return TYPE; }
- {VAR} { return VAR; }
- {WHILE} { return WHILE; }
- {identifier} {
- int n = strlen(yytext);
- yylval.str = reinterpret_cast<char*>(malloc((n + 1) * sizeof(char)));
- strncpy(yylval.str, yytext, n + 1);
- return identifier;
- }
- {integer_literal} {
- yylval.num = atof(yytext);
- return integer_literal;
- }
- [ \t\n]+ ;
- . { return yytext[0]; }
- %%
- int yywrap() { return 1; }
|