コンパイラ
Rev. | d85114e8e96ca773d54f7651aab9a16005944069 |
---|---|
Größe | 7,029 Bytes |
Zeit | 2011-06-13 00:09:32 |
Autor | berupon |
Log Message | ISO/IEC 9899:TC3 Annex A Language syntax summary に基づいた Lexer 記述。
|
#include <stdio.h>
#include <stdlib.h>
#include "lexer.h"
// http://re2c.org/manual.html
namespace Lexer {
char* yyin;
char* yymarker;
void YYDEBUG(int state, char current)
{
}
int yylex()
{
/*!re2c
re2c:define:YYCTYPE = "char";
re2c:define:YYCURSOR = yyin;
re2c:define:YYMARKER = yymarker;
re2c:yyfill:enable = 0;
re2c:indent:top = 1;
Nondigit = [_a-zA-Z];
Digit = [0-9];
NonZerodigit = [1-9];
OctalDigit = [0-7];
HexadecimalDigit = [0-9a-fA-F];
HexQuad = HexadecimalDigit{4};
UniversalCharacterName =
("\\u" HexQuad) |
("\\U" HexQuad{2});
Identifier = Nondigit (Nondigit|Digit)*;
DecimalConstant = NonZerodigit Digit*;
OctalConstant = "0" OctalDigit*;
HexadecimalPrefix = "0" [xX];
HexadecimalConstant = HexadecimalPrefix HexadecimalDigit+;
UnsignedSuffix = [uU];
LongSuffix = [lL];
LongLongSuffix = "ll" | "LL";
IntegerSuffix =
(UnsignedSuffix LongSuffix?) |
(UnsignedSuffix LongLongSuffix) |
(LongSuffix UnsignedSuffix?) |
(LongLongSuffix UnsignedSuffix?);
IntegerConstant = (DecimalConstant | OctalConstant | HexadecimalConstant) IntegerSuffix?;
Sign = [+-];
DigitSequence = Digit+;
FractionalConstant =
(DigitSequence? "." DigitSequence) |
DigitSequence;
ExponentPart = [eE] Sign? DigitSequence;
FloatingSuffix = [flFL];
DecimalFloatingConstant =
(FractionalConstant ExponentPart? FloatingSuffix?) |
(DigitSequence ExponentPart FloatingSuffix?);
BinaryExponentPart = [pP] Sign? DigitSequence;
HexadecimalDigitSequence = HexadecimalDigit+;
HexadecimalFractionalConstant =
(HexadecimalDigitSequence? "." HexadecimalDigitSequence?) |
(HexadecimalDigitSequence ".");
HexadecimalFloatingConstant =
(HexadecimalPrefix HexadecimalFractionalConstant BinaryExponentPart FloatingSuffix?) |
(HexadecimalPrefix HexadecimalDigitSequence BinaryExponentPart FloatingSuffix?);
FloatingConstant =
DecimalFloatingConstant |
HexadecimalFloatingConstant;
EnumerationConstant = Identifier;
SimpleEscapeSequence = "\\'" | "\\\"" | "\?" | "\\\\" | "\\a" | "\\b" | "\\f" | "\\n" | "\\r" | "\\t" | "\\v";
OctalEscapeSequence = "\\" OctalDigit{1,3};
HexadecimalEscapeSequence = "\\x" HexadecimalDigit+;
EscapeSequence = SimpleEscapeSequence | OctalEscapeSequence | HexadecimalEscapeSequence | UniversalCharacterName;
Char = [^\"\\\r\n] | EscapeSequence;
CharSequence = Char+;
CharacterConstant = "L"? "'" CharSequence "'";
StringLiteral = "L"? "\"" CharSequence? "\"";
"auto" { return Token_auto; }
"break" { return Token_break; }
"case" { return Token_case; }
"char" { return Token_char; }
"const" { return Token_const; }
"continue" { return Token_continue; }
"default" { return Token_default; }
"do" { return Token_do; }
"double" { return Token_double; }
"else" { return Token_else; }
"enum" { return Token_enum; }
"extern" { return Token_extern; }
"float" { return Token_float; }
"for" { return Token_for; }
"goto" { return Token_goto; }
"if" { return Token_if; }
"inline" { return Token_inline; }
"int" { return Token_int; }
"long" { return Token_long; }
"register" { return Token_register; }
"restrict" { return Token_restrict; }
"return" { return Token_return; }
"short" { return Token_short; }
"signed" { return Token_signed; }
"sizeof" { return Token_sizeof; }
"static" { return Token_static; }
"struct" { return Token_struct; }
"switch" { return Token_switch; }
"typedef" { return Token_typedef; }
"union" { return Token_union; }
"unsigned" { return Token_unsigned; }
"void" { return Token_void; }
"volatile" { return Token_volatile; }
"while" { return Token_while; }
"_Bool" { return Token__Bool; }
"_Complex" { return Token__Complex; }
"_Imaginary" { return Token__Imaginary; }
Identifier { return Token_Identifier; }
IntegerConstant { return Token_IntegerConstant; }
FloatingConstant { return Token_FloatingConstant; }
EnumerationConstant { return Token_EnumerationConstant; }
CharacterConstant { return Token_CharacterConstant; }
StringLiteral { return Token_StringLiteral; }
"[" { return Token_Punctuator | '['; }
"]" { return Token_Punctuator | ']'; }
"(" { return Token_Punctuator | '('; }
")" { return Token_Punctuator | ')'; }
"{" { return Token_Punctuator | '{'; }
"}" { return Token_Punctuator | '}'; }
"." { return Token_Punctuator | '.'; }
"->" { return Token_Punctuator | Token_PTR_OP; }
"++" { return Token_Punctuator | Token_INC_OP; }
"--" { return Token_Punctuator | Token_DEC_OP; }
"&" { return Token_Punctuator | '&'; }
"*" { return Token_Punctuator | '*'; }
"+" { return Token_Punctuator | '+'; }
"-" { return Token_Punctuator | '-'; }
"~" { return Token_Punctuator | '~'; }
"!" { return Token_Punctuator | '!'; }
"/" { return Token_Punctuator | '/'; }
"%" { return Token_Punctuator | '%'; }
"<<" { return Token_Punctuator | Token_LEFT_OP; }
">>" { return Token_Punctuator | Token_RIGHT_OP; }
"<" { return Token_Punctuator | '<'; }
">" { return Token_Punctuator | '>'; }
"<=" { return Token_Punctuator | Token_LE_OP; }
">=" { return Token_Punctuator | Token_GE_OP; }
"==" { return Token_Punctuator | Token_EQ_OP; }
"!=" { return Token_Punctuator | Token_NE_OP; }
"^" { return Token_Punctuator | '^'; }
"|" { return Token_Punctuator | '|'; }
"&&" { return Token_Punctuator | Token_AND_OP; }
"||" { return Token_Punctuator | Token_OR_OP; }
"?" { return Token_Punctuator | '?'; }
":" { return Token_Punctuator | ':'; }
";" { return Token_Punctuator | ';'; }
"..." { return Token_Punctuator | Token_ELLIPSIS; }
"=" { return Token_Punctuator | Token_Punctuator | '='; }
"*=" { return Token_Punctuator | Token_MUL_ASSIGN; }
"/=" { return Token_Punctuator | Token_DIV_ASSIGN; }
"%=" { return Token_Punctuator | Token_MOD_ASSIGN; }
"+=" { return Token_Punctuator | Token_ADD_ASSIGN; }
"-=" { return Token_Punctuator | Token_SUB_ASSIGN; }
"<<=" { return Token_Punctuator | Token_LEFT_ASSIGN; }
">>=" { return Token_Punctuator | Token_RIGHT_ASSIGN; }
"&=" { return Token_Punctuator | Token_AND_ASSIGN; }
"^=" { return Token_Punctuator | Token_XOR_ASSIGN; }
"|=" { return Token_Punctuator | Token_OR_ASSIGN; }
"," { return Token_Punctuator | Token_Punctuator | ','; }
"#" { return Token_Punctuator | Token_Punctuator | '#'; }
"##" { return Token_Punctuator | Token_PP_CONCAT; }
[ \t]+ { return Token_WhiteSpace; }
[^] { return Token_Error; }
*/
/*
"<:" { return Token_Punctuator | Token_[; }
":>" { return Token_Punctuator | Token_]; }
"<%" { return Token_Punctuator | Token_{; }
"%>" { return Token_Punctuator | Token_}; }
"%:" { return Token_Punctuator | Token_#; }
"%:%:" { return Token_Punctuator | Token_PP_CONCAT; }
*/
}
} // namespace Lexer