mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-25 06:30:09 +01:00
96 lines
2.0 KiB
Plaintext
96 lines
2.0 KiB
Plaintext
/*
|
|
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"
|
|
%}
|
|
|
|
/* Turn off legacy bits we don't need */
|
|
%option noyywrap nounput nodefault noinput
|
|
|
|
/* maintains the number of the current line read from input in the
|
|
global variable yylineno.
|
|
*/
|
|
%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]; }
|
|
|
|
%%
|