$v) { if (is_string($v)) { continue; } if (is_array($v)) { continue; } echo "$k = $v\n"; } } var $_directiveType; var $_directiveBody; var $_inHidden = false; function isHidden() { // doesnt handle nested - needs a stack to do that. // doesnt handle any logic!!! switch ($this->_directiveType) { case 'define': // just handle raw defines! $GLOBALS['_TOKENIZER_DEFINES'][trim($this->_directiveBody)] = true; return $this->_inHidden; case 'if': // simple ones only :) if (isset($GLOBALS['_TOKENIZER_DEFINES'][trim($this->_directiveBody)])) { $this->_inHidden = false; echo "hidden = 1\n"; return false; } echo "hidden = 1\n"; $this->_inHidden = true; return true; case 'else': $this->_inHidden = !$this->_inHidden; echo "hidden = ". ((int) $this->_inHidden ) . "\n"; return $this->_inHidden; case 'endif': echo "hidden = 0\n"; return false; } } // %full removed to see if it helps? // %char removed to see if it helps? %} %line %full %char %state IN_COMMENT IN_STRING IN_PREPROCESSOR IN_PREPROCESSOR_ARGS IN_HIDDEN_CODE IN_AT_STRING LINE_BREAK = [\n\r] WHITE_SPACE = [ \t\n\r] SINGLE_LINE_COMMENT = "//"[^\r\n]*{LINE_BREAK} DEC_DIGIT = [0-9] HEX_DIGIT = [0-9A-Fa-f] LONG_SUFFIX = [Ll] UNSIGNED_SUFFIX = [Uu] UNSIGNED_LONG_SUFFIX = ([Uu][Ll]|[Ll][Uu]) DEC_LITERAL = ({DEC_DIGIT}+) DEC_LITERAL_LONG = ({DEC_DIGIT}+{LONG_SUFFIX}) DEC_LITERAL_UNSIGNED = ({DEC_DIGIT}+{UNSIGNED_SUFFIX}) DEC_LITERAL_UNSIGNED_LONG = ({DEC_DIGIT}+{UNSIGNED_LONG_SUFFIX}) HEX_LITERAL = (0[xX]?{HEX_DIGIT}+) HEX_LITERAL_LONG = (0[xX]?{HEX_DIGIT}+{LONG_SUFFIX}) HEX_LITERAL_UNSIGNED = (0[xX]?{HEX_DIGIT}+{UNSIGNED_SUFFIX}) HEX_LITERAL_UNSIGNED_LONG = (0[xX]?{HEX_DIGIT}+{UNSIGNED_LONG_SUFFIX}) PREPROCESSOR_START = ^[ \t]*#[ \t]* REAL_SUFFIX = [FfDdMm] SIGN = [+\-] EXPONENT_PART = ([eE]{SIGN}?{DEC_DIGIT}+) WHOLE_REAL1 = ({DEC_DIGIT}+{EXPONENT_PART}{REAL_SUFFIX}?) WHOLE_REAL2 = ({DEC_DIGIT}+{REAL_SUFFIX}) PART_REAL = ({DEC_DIGIT}*\.{DEC_DIGIT}+{EXPONENT_PART}?{REAL_SUFFIX}?) REAL_LITERAL = ({WHOLE_REAL1}|{WHOLE_REAL2}|{PART_REAL}) REAL_WITH_EXPONENT = {DEC_DIGIT}+{EXPONENT_PART} REAL_WITH_POINT = {DEC_DIGIT}*\.{DEC_DIGIT}+{EXPONENT_PART}? REAL_LITERAL_DEFAULT = ({REAL_WITH_EXPONENT}|{REAL_WITH_POINT}) REAL_LITERAL_DOUBLE = ({DEC_DIGIT}+|{REAL_WITH_EXPONENT}|{REAL_WITH_POINT})[Dd] REAL_LITERAL_FLOAT = ({DEC_DIGIT}+|{REAL_WITH_EXPONENT}|{REAL_WITH_POINT})[Ff] REAL_LITERAL_DECIMAL = ({DEC_DIGIT}+|{REAL_WITH_EXPONENT}|{REAL_WITH_POINT})[Mm] SINGLE_CHAR = [^\\\'] SIMPLE_ESC_SEQ = \\[\'\"\\0abfnrtv] UNI_ESC_SEQ1 = \\u{HEX_DIGIT}{HEX_DIGIT}{HEX_DIGIT}{HEX_DIGIT} UNI_ESC_SEQ2 = \\U{HEX_DIGIT}{HEX_DIGIT}{HEX_DIGIT}{HEX_DIGIT}{HEX_DIGIT}{HEX_DIGIT}{HEX_DIGIT}{HEX_DIGIT} UNI_ESC_SEQ = {UNI_ESC_SEQ1}|{UNI_ESC_SEQ2} HEX_ESC_SEQ = (\\x{HEX_DIGIT}|\\x{HEX_DIGIT}{HEX_DIGIT}|\\x{HEX_DIGIT}{HEX_DIGIT}{HEX_DIGIT}|\\x{HEX_DIGIT}{HEX_DIGIT}{HEX_DIGIT}{HEX_DIGIT}) CHARACTER = ({SINGLE_CHAR}|{SIMPLE_ESC_SEQ}|{HEX_ESC_SEQ}|{UNI_ESC_SEQ}) CHARACTER_LITERAL = \'{CHARACTER}\' SINGLE_STRING_CHAR = [^\\\"] REG_STRING_CHAR = ({SINGLE_STRING_CHAR}|{SIMPLE_ESC_SEQ}|{HEX_ESC_SEQ}|{UNI_ESC_SEQ}) REGULAR_STRING = \"{REG_STRING_CHAR}*\" SINGLE_VERBATIM_CHAR = [^\"] QUOTE_ESC_SEQ = \"\" VERB_STRING_CHAR = ({SINGLE_VERBATIM_CHAR}|{QUOTE_ESC_SEQ}) VERBATIM_STRING = @\"{VERB_STRING_CHAR}*\" STRING_LITERAL = ({REGULAR_STRING}|{VERBATIM_STRING}) EASY_STRING_LITERAL = \"{SINGLE_STRING_CHAR}*\" COMPLEX_STRING_BEGIN = \"{SINGLE_STRING_CHAR}* COMPLEX_STRING_END = \" LETTER_CHAR = [A-Za-z] IDENT_CHAR = ({DEC_DIGIT}|{LETTER_CHAR}|"_"|"@") IDENTIFIER = ({LETTER_CHAR}|"_"){IDENT_CHAR}* AT_IDENTIFIER = \@{IDENTIFIER} // ' - quote to make sure that it displays ok in editor %% {PREPROCESSOR_START} { $this->_compilerDirective = $this->yytext(); echo "PREPROCESSOR START (OK): ". $this->yytext() . "\n"; $this->yybegin(IN_PREPROCESSOR); return TOKEN_NONE; } # { /* THIS IS VERY FLAKEY AS THE ^char does not appear to work */ $this->_compilerDirective = $this->yytext(); echo "PREPROCESSOR START (BORKED): ". $this->yytext() . "\n"; $this->yybegin(IN_PREPROCESSOR); return TOKEN_NONE; } {IDENTIFIER} { $this->_compilerDirective .= $this->yytext(); $this->_directiveType = $this->yytext(); $this->_directiveBody = ''; $this->yybegin(IN_PREPROCESSOR_ARGS); return TOKEN_NONE;} . { $this->_directiveBody .= $this->yytext(); $this->_compilerDirective .= $this->yytext(); return TOKEN_NONE; } [^\r\n]* { $this->_directiveBody .= $this->yytext(); $this->value = $this->_compilerDirective . $this->yytext(); echo "PREPROCESSOR: {$this->value}\n"; if ($this->isHidden()) { $this->yybegin(IN_HIDDEN_CODE); } else { $this->yybegin(YYINITIAL); } return TOKEN_NONE; } [ \t]*{LINE_BREAK} { $this->_directiveBody .= $this->yytext(); $this->value = $this->_compilerDirective . $this->yytext(); echo "PREPROCESSOR: {$this->value}\n"; if ($this->isHidden()) { $this->yybegin(IN_HIDDEN_CODE); } else { $this->yybegin(YYINITIAL); } return TOKEN_NONE; } [^#]* { $this->value = $this->yytext(); return TOKEN_NONE; } {WHITE_SPACE}+ { $this->value = $this->yytext(); return TOKEN_NONE; } {SINGLE_LINE_COMMENT} { $this->value = $this->yytext(); return TOKEN_NONE; } "/*" { $this->_comment= $this->yytext(); $this->yybegin(IN_COMMENT); return TOKEN_NONE; } "/*" { $this->_comment .= $this->yytext(); return TOKEN_NONE; } [\n\r] { $this->_comment .= $this->yytext(); return TOKEN_NONE; } "*/" { $this->_comment .= $this->yytext(); $this->value = $this->_comment; $this->yybegin(YYINITIAL); return TOKEN_NONE; } [^*]* { $this->_comment .= $this->yytext(); return TOKEN_NONE; } . { $this->_comment .= $this->yytext(); return TOKEN_NONE; } {DEC_LITERAL} { $this->value = $this->yytext(); return TOKEN_LITERAL_INTEGER; } {DEC_LITERAL_LONG} { $this->value = $this->yytext();return TOKEN_LITERAL_INTEGER; } {DEC_LITERAL_UNSIGNED} { $this->value = $this->yytext();return TOKEN_LITERAL_INTEGER; } {DEC_LITERAL_UNSIGNED_LONG} { $this->value = $this->yytext();return TOKEN_LITERAL_INTEGER; } {HEX_LITERAL} { $this->value = $this->yytext(); return TOKEN_LITERAL_INTEGER; } {HEX_LITERAL_LONG} { $this->value = $this->yytext(); return TOKEN_LITERAL_INTEGER; } {HEX_LITERAL_UNSIGNED} { $this->value = $this->yytext(); return TOKEN_LITERAL_INTEGER; } {HEX_LITERAL_UNSIGNED_LONG} { $this->value = $this->yytext(); return TOKEN_LITERAL_INTEGER; } {REAL_LITERAL_DEFAULT} { $this->value = $this->yytext();return TOKEN_LITERAL_DOUBLE; } {REAL_LITERAL_DOUBLE} { $this->value = $this->yytext();return TOKEN_LITERAL_DOUBLE; } {REAL_LITERAL_FLOAT} { $this->value = $this->yytext();return TOKEN_LITERAL_FLOAT; } {REAL_LITERAL_DECIMAL} { $this->value = $this->yytext(); return TOKEN_LITERAL_DECIMAL; } \'{SINGLE_CHAR}\' { $this->value = $this->yytext();return TOKEN_LITERAL_CHARACTER; } \'{SIMPLE_ESC_SEQ}\' { $this->value = $this->yytext();return TOKEN_LITERAL_CHARACTER; } \'({HEX_ESC_SEQ}|{UNI_ESC_SEQ1})\' { $this->value = $this->yytext();return TOKEN_LITERAL_CHARACTER; } \'({UNI_ESC_SEQ2})\' { $this->value = $this->yytext();return TOKEN_LITERAL_CHARACTER; } {EASY_STRING_LITERAL} { $this->value = $this->yytext(); return TOKEN_LITERAL_STRING; } {COMPLEX_STRING_BEGIN} { $this->_string = $this->yytext(); $this->yybegin(IN_STRING); return TOKEN_NONE; } {SINGLE_STRING_CHAR}* { $this->_string .= $this->yytext();return TOKEN_NONE;} {SIMPLE_ESC_SEQ} { $this->_string .= $this->yytext(); return TOKEN_NONE; } {HEX_ESC_SEQ}|{UNI_ESC_SEQ1} { $this->_string .= $this->yytext();return TOKEN_NONE; } {UNI_ESC_SEQ2}) { $this->_string .= $this->yytext();return TOKEN_NONE; } {COMPLEX_STRING_END} { $this->_string .= $this->yytext(); $this->value = $this->_string; $this->yybegin(YYINITIAL); return TOKEN_LITERAL_STRING; } @\" { $this->_string = $this->yytext(); $this->yybegin(IN_AT_STRING); return TOKEN_NONE; } {SINGLE_VERBATIM_CHAR}* { $this->_string .= $this->yytext(); return TOKEN_NONE; } {QUOTE_ESC_SEQ} { $this->_string .= $this->yytext(); return TOKEN_NONE; } "{" { $this->value = $this->yytext();return TOKEN_OPEN_BRACE; } "}" { $this->value = $this->yytext();return TOKEN_CLOSE_BRACE ; } "[" { $this->value = $this->yytext(); return TOKEN_OPEN_BRACKET ; } "]" { $this->value = $this->yytext();return TOKEN_CLOSE_BRACKET ; } "(" { $this->value = $this->yytext();return TOKEN_OPEN_PARENS ; } ")" { $this->value = $this->yytext();return TOKEN_CLOSE_PARENS ; } "." { $this->value = $this->yytext();return TOKEN_DOT ; } "," { $this->value = $this->yytext();return TOKEN_COMMA ; } ":" { $this->value = $this->yytext();return TOKEN_COLON ; } ";" { $this->value = $this->yytext();return TOKEN_SEMICOLON ; } "~" { $this->value = $this->yytext();return TOKEN_TILDE ; } "+" { $this->value = $this->yytext();return TOKEN_PLUS ; } "-" { $this->value = $this->yytext();return TOKEN_MINUS ; } "!" { $this->value = $this->yytext();return TOKEN_BANG ; } "=" { $this->value = $this->yytext();return TOKEN_ASSIGN ; } "<" { $this->value = $this->yytext();return TOKEN_OP_LT ; } ">" { $this->value = $this->yytext();return TOKEN_OP_GT ; } "&" { $this->value = $this->yytext();return TOKEN_BITWISE_AND ; } "|" { $this->value = $this->yytext();return TOKEN_BITWISE_OR ; } "*" { $this->value = $this->yytext();return TOKEN_STAR ; } "%" { $this->value = $this->yytext();return TOKEN_PERCENT ; } "/" { $this->value = $this->yytext();return TOKEN_DIV ; } "^" { $this->value = $this->yytext();return TOKEN_CARRET ; } "?" { $this->value = $this->yytext();return TOKEN_INTERR ; } "++" {$this->value = $this->yytext(); return TOKEN_OP_INC ; } "--" { $this->value = $this->yytext(); return TOKEN_OP_DEC ; } "<<" { $this->value = $this->yytext(); return TOKEN_OP_SHIFT_LEFT ; } ">>" { $this->value = $this->yytext(); return TOKEN_OP_SHIFT_RIGHT ; } "<=" { $this->value = $this->yytext(); return TOKEN_OP_LE ; } ">=" { $this->value = $this->yytext(); return TOKEN_OP_GE ; } "==" { $this->value = $this->yytext(); return TOKEN_OP_EQ ; } "!=" { $this->value = $this->yytext(); return TOKEN_OP_NE ; } "&&" { $this->value = $this->yytext(); return TOKEN_OP_AND ; } "||" { $this->value = $this->yytext(); return TOKEN_OP_OR ; } "*=" { $this->value = $this->yytext(); return TOKEN_OP_MULT_ASSIGN ; } "/=" { $this->value = $this->yytext(); return TOKEN_OP_DIV_ASSIGN ; } "%=" { $this->value = $this->yytext(); return TOKEN_OP_MOD_ASSIGN ; } "+=" { $this->value = $this->yytext(); return TOKEN_OP_ADD_ASSIGN ; } "-=" { $this->value = $this->yytext(); return TOKEN_OP_SUB_ASSIGN ; } "<<=" {$this->value = $this->yytext(); return TOKEN_OP_SHIFT_LEFT_ASSIGN ; } ">>=" { $this->value = $this->yytext(); return TOKEN_OP_SHIFT_RIGHT_ASSIGN ; } "&=" { $this->value = $this->yytext(); return TOKEN_OP_AND_ASSIGN ; } "^=" { $this->value = $this->yytext();return TOKEN_OP_XOR_ASSIGN ; } "|=" { $this->value = $this->yytext();return TOKEN_OP_OR_ASSIGN ; } "->" { $this->value = $this->yytext();return TOKEN_OP_PTR ; } "abstract" { $this->value = $this->yytext();return TOKEN_ABSTRACT ; } "as" { $this->value = $this->yytext();return TOKEN_AS ; } "base" { $this->value = $this->yytext();return TOKEN_BASE ; } "bool" { $this->value = $this->yytext();return TOKEN_BOOL ; } "break" { $this->value = $this->yytext();return TOKEN_BREAK ; } "byte" { $this->value = $this->yytext();return TOKEN_BYTE ; } "case" { $this->value = $this->yytext();return TOKEN_CASE ; } "catch" { $this->value = $this->yytext();return TOKEN_CATCH ; } "char" { $this->value = $this->yytext();return TOKEN_CHAR ; } "checked" { $this->value = $this->yytext();return TOKEN_CHECKED ; } "class" { $this->value = $this->yytext();return TOKEN_CLASS ; } "const" { $this->value = $this->yytext();return TOKEN_CONST ; } "continue" { $this->value = $this->yytext();return TOKEN_CONTINUE ; } "decimal" { $this->value = $this->yytext();return TOKEN_DECIMAL ; } "default" { $this->value = $this->yytext();return TOKEN_DEFAULT ; } "delegate" { $this->value = $this->yytext();return TOKEN_DELEGATE ; } "do" { $this->value = $this->yytext();return TOKEN_DO ; } "double" { $this->value = $this->yytext();return TOKEN_DOUBLE ; } "else" { $this->value = $this->yytext();return TOKEN_ELSE ; } "enum" { $this->value = $this->yytext();return TOKEN_ENUM ; } "event" { $this->value = $this->yytext();return TOKEN_EVENT ; } "explicit" { $this->value = $this->yytext();return TOKEN_EXPLICIT ; } "extern" { $this->value = $this->yytext();return TOKEN_EXTERN ; } "false" { $this->value = $this->yytext();return TOKEN_FALSE ; } "finally" { $this->value = $this->yytext();return TOKEN_FINALLY ; } "fixed" { $this->value = $this->yytext();return TOKEN_FIXED ; } "float" { $this->value = $this->yytext();return TOKEN_FLOAT ; } "for" { $this->value = $this->yytext();return TOKEN_FOR ; } "foreach" { $this->value = $this->yytext();return TOKEN_FOREACH ; } "goto" { $this->value = $this->yytext();return TOKEN_GOTO ; } "if" { $this->value = $this->yytext();return TOKEN_IF ; } "implicit" { $this->value = $this->yytext();return TOKEN_IMPLICIT ; } "in" { $this->value = $this->yytext();return TOKEN_IN ; } "int" { $this->value = $this->yytext();return TOKEN_INT ; } "interface" { $this->value = $this->yytext();return TOKEN_INTERFACE ; } "internal" { $this->value = $this->yytext();return TOKEN_INTERNAL ; } "is" { $this->value = $this->yytext();return TOKEN_IS ; } "lock" { $this->value = $this->yytext();return TOKEN_LOCK ; } "long" { $this->value = $this->yytext();return TOKEN_LONG ; } "namespace" { $this->value = $this->yytext();return TOKEN_NAMESPACE ; } "new" { $this->value = $this->yytext();return TOKEN_NEW ; } "null" { $this->value = $this->yytext();return TOKEN_NULL ; } "object" { $this->value = $this->yytext();return TOKEN_OBJECT ; } "operator" { $this->value = $this->yytext();return TOKEN_OPERATOR ; } "out" { $this->value = $this->yytext();return TOKEN_OUT ; } "override" { $this->value = $this->yytext();return TOKEN_OVERRIDE ; } "params" { $this->value = $this->yytext();return TOKEN_PARAMS ; } "private" { $this->value = $this->yytext();return TOKEN_PRIVATE ; } "protected" { $this->value = $this->yytext();return TOKEN_PROTECTED ; } "public" { $this->value = $this->yytext();return TOKEN_PUBLIC ; } "readonly" { $this->value = $this->yytext();return TOKEN_READONLY ; } "ref" { $this->value = $this->yytext();return TOKEN_REF ; } "return" { $this->value = $this->yytext();return TOKEN_RETURN ; } "sbyte" { $this->value = $this->yytext();return TOKEN_SBYTE ; } "sealed" { $this->value = $this->yytext();return TOKEN_SEALED ; } "short" { $this->value = $this->yytext();return TOKEN_SHORT ; } "sizeof" { $this->value = $this->yytext();return TOKEN_SIZEOF ; } "stackalloc" { $this->value = $this->yytext();return TOKEN_STACKALLOC ; } "static" { $this->value = $this->yytext();return TOKEN_STATIC ; } "string" { $this->value = $this->yytext();return TOKEN_STRING ; } "struct" { $this->value = $this->yytext();return TOKEN_STRUCT ; } "switch" { $this->value = $this->yytext();return TOKEN_SWITCH ; } "this" { $this->value = $this->yytext();return TOKEN_THIS ; } "throw" { $this->value = $this->yytext();return TOKEN_THROW ; } "true" { $this->value = $this->yytext();return TOKEN_TRUE ; } "try" { $this->value = $this->yytext();return TOKEN_TRY ; } "typeof" { $this->value = $this->yytext();return TOKEN_TYPEOF ; } "uint" { $this->value = $this->yytext();return TOKEN_UINT ; } "ulong" { $this->value = $this->yytext();return TOKEN_ULONG ; } "unchecked" { $this->value = $this->yytext();return TOKEN_UNCHECKED ; } "unsafe" { $this->value = $this->yytext();return TOKEN_UNSAFE ; } "ushort" { $this->value = $this->yytext();return TOKEN_USHORT ; } "using" { $this->value = $this->yytext();return TOKEN_USING ; } "virtual" { $this->value = $this->yytext();return TOKEN_VIRTUAL ; } "void" { $this->value = $this->yytext();return TOKEN_VOID ; } "volatile" { $this->value = $this->yytext();return TOKEN_VOLATILE ; } "while" { $this->value = $this->yytext();return TOKEN_WHILE ; } "get" { $this->value = $this->yytext();return TOKEN_IDENTIFIER;// TOKEN_GET; } "set" { $this->value = $this->yytext();return TOKEN_IDENTIFIER;//TOKEN_SET ; } "remove" { $this->value = $this->yytext();return TOKEN_IDENTIFIER;//TOKEN_REMOVE ; } "add" { $this->value = $this->yytext();return TOKEN_IDENTIFIER;//TOKEN_ADD ; } "assembly" { $this->value = $this->yytext();return TOKEN_IDENTIFIER;//TOKEN_ASSEMBLY ; } {IDENTIFIER} { $this->value = $this->yytext();return TOKEN_IDENTIFIER ; } {AT_IDENTIFIER} { $this->value = $this->yytext();return TOKEN_IDENTIFIER; } . { echo "ERROR: unexpected something: character: 0x" . dechex(ord($this->yytext())) . "\n"; return TOKEN_ERROR; }