source: src/Parser/lex.ll @ 8ee50281

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 8ee50281 was a67b60e, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

rename files and adjust includes

  • Property mode set to 100644
File size: 16.2 KB
RevLine 
[b87a5ed]1/*
2 * Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3 *
4 * The contents of this file are covered under the licence agreement in the
5 * file "LICENCE" distributed with Cforall.
[8f60f0b]6 *
[6016c87]7 * lex.ll --
[8f60f0b]8 *
[51b7345]9 * Author           : Peter A. Buhr
10 * Created On       : Sat Sep 22 08:58:10 2001
[926af74]11 * Last Modified By : Peter A. Buhr
[a67b60e]12 * Last Modified On : Wed Jun 28 21:03:45 2017
13 * Update Count     : 529
[51b7345]14 */
15
16%option yylineno
[5f2f2d7]17%option nounput
[51b7345]18
19%{
[de62360d]20// This lexer assumes the program has been preprocessed by cpp. Hence, all user level preprocessor directive have been
21// performed and removed from the source. The only exceptions are preprocessor directives passed to the compiler (e.g.,
22// line-number directives) and C/C++ style comments, which are ignored.
[51b7345]23
[8c17ab0]24//**************************** Includes and Defines ****************************
[51b7345]25
26#include <string>
[f487962]27#include <cstdio>                                                                               // FILENAME_MAX
[51b7345]28
[984dce6]29#include "ParseNode.h"
30#include "TypedefTable.h"
[51b7345]31
32char *yyfilename;
[b87a5ed]33std::string *strtext;                                                                   // accumulate parts of character and string constant value
[51b7345]34
[de62360d]35#define RETURN_LOCN(x)          yylval.tok.loc.file = yyfilename; yylval.tok.loc.line = yylineno; return( x )
36#define RETURN_VAL(x)           yylval.tok.str = new std::string( yytext ); RETURN_LOCN( x )
[926af74]37#define RETURN_CHAR(x)          yylval.tok.str = nullptr; RETURN_LOCN( x )
[de62360d]38#define RETURN_STR(x)           yylval.tok.str = strtext; RETURN_LOCN( x )
[5f2f2d7]39
[f487962]40#define WHITE_RETURN(x)         // do nothing
[de62360d]41#define NEWLINE_RETURN()        WHITE_RETURN( '\n' )
42#define ASCIIOP_RETURN()        RETURN_CHAR( (int)yytext[0] ) // single character operator
[f487962]43#define NAMEDOP_RETURN(x)       RETURN_CHAR( x )                        // multichar operator, with a name
[de62360d]44#define NUMERIC_RETURN(x)       rm_underscore(); RETURN_VAL( x ) // numeric constant
45#define KEYWORD_RETURN(x)       RETURN_CHAR( x )                        // keyword
[984dce6]46#define IDENTIFIER_RETURN()     RETURN_VAL( typedefTable.isKind( yytext ) )
[de62360d]47#define ATTRIBUTE_RETURN()      RETURN_VAL( ATTR_IDENTIFIER )
[51b7345]48
[3848e0e]49void rm_underscore() {
[e7aed49]50        // Remove underscores in numeric constant by copying the non-underscore characters to the front of the string.
51        yyleng = 0;
[b87a5ed]52        for ( int i = 0; yytext[i] != '\0'; i += 1 ) {
53                if ( yytext[i] != '_' ) {
[e7aed49]54                        yytext[yyleng] = yytext[i];
55                        yyleng += 1;
[b87a5ed]56                } // if
57        } // for
58        yytext[yyleng] = '\0';
[51b7345]59}
60
61%}
62
63octal [0-7]
64nonzero [1-9]
65decimal [0-9]
66hex [0-9a-fA-F]
[3848e0e]67universal_char "\\"((u"_"?{hex_quad})|(U"_"?{hex_quad}{2}))
[51b7345]68
[b87a5ed]69                                // identifier, GCC: $ in identifier
[51b7345]70identifier ([a-zA-Z_$]|{universal_char})([0-9a-zA-Z_$]|{universal_char})*
71
[b87a5ed]72                                // attribute identifier, GCC: $ in identifier
[51b7345]73attr_identifier "@"{identifier}
74
[b87a5ed]75                                // numeric constants, CFA: '_' in constant
[3848e0e]76hex_quad {hex}("_"?{hex}){3}
[ba2356b]77integer_suffix "_"?(([uU](("ll"|"LL"|[lL])[iI]|[iI]?("ll"|"LL"|[lL])?))|([iI](("ll"|"LL"|[lL])[uU]|[uU]?("ll"|"LL"|[lL])?))|(("ll"|"LL"|[lL])([iI][uU]|[uU]?[iI]?)))
[51b7345]78
79octal_digits ({octal})|({octal}({octal}|"_")*{octal})
80octal_prefix "0""_"?
81octal_constant (("0")|({octal_prefix}{octal_digits})){integer_suffix}?
82
83nonzero_digits ({nonzero})|({nonzero}({decimal}|"_")*{decimal})
84decimal_constant {nonzero_digits}{integer_suffix}?
85
86hex_digits ({hex})|({hex}({hex}|"_")*{hex})
87hex_prefix "0"[xX]"_"?
88hex_constant {hex_prefix}{hex_digits}{integer_suffix}?
89
90decimal_digits ({decimal})|({decimal}({decimal}|"_")*{decimal})
[0213af6]91real_decimal {decimal_digits}"."{exponent}?{floating_suffix}?
92real_fraction "."{decimal_digits}{exponent}?{floating_suffix}?
93real_constant {decimal_digits}{real_fraction}
[51b7345]94exponent "_"?[eE]"_"?[+-]?{decimal_digits}
[ba2356b]95                                // GCC: D (double) and iI (imaginary) suffixes, and DL (long double)
96floating_suffix "_"?([fFdDlL][iI]?|[iI][lLfFdD]?|"DL")
[1b29996]97floating_constant (({real_constant}{exponent}?)|({decimal_digits}{exponent})){floating_suffix}?
[51b7345]98
99binary_exponent "_"?[pP]"_"?[+-]?{decimal_digits}
100hex_fractional_constant ({hex_digits}?"."{hex_digits})|({hex_digits}".")
101hex_floating_constant {hex_prefix}(({hex_fractional_constant}{binary_exponent})|({hex_digits}{binary_exponent})){floating_suffix}?
102
[b87a5ed]103                                // character escape sequence, GCC: \e => esc character
[51b7345]104simple_escape "\\"[abefnrtv'"?\\]
[b87a5ed]105                                // ' stop highlighting
[3848e0e]106octal_escape "\\"{octal}("_"?{octal}){0,2}
107hex_escape "\\""x""_"?{hex_digits}
[51b7345]108escape_seq {simple_escape}|{octal_escape}|{hex_escape}|{universal_char}
[59db689]109cwide_prefix "L"|"U"|"u"
110swide_prefix {cwide_prefix}|"u8"
[51b7345]111
[b87a5ed]112                                // display/white-space characters
[51b7345]113h_tab [\011]
114form_feed [\014]
115v_tab [\013]
116c_return [\015]
117h_white [ ]|{h_tab}
118
[e7aed49]119                                // overloadable operators
[51b7345]120op_unary_only "~"|"!"
121op_unary_binary "+"|"-"|"*"
122op_unary_pre_post "++"|"--"
123op_unary {op_unary_only}|{op_unary_binary}|{op_unary_pre_post}
124
125op_binary_only "/"|"%"|"^"|"&"|"|"|"<"|">"|"="|"=="|"!="|"<<"|">>"|"<="|">="|"+="|"-="|"*="|"/="|"%="|"&="|"|="|"^="|"<<="|">>="
126op_binary_over {op_unary_binary}|{op_binary_only}
[e7aed49]127                                // op_binary_not_over "?"|"->"|"."|"&&"|"||"|"@="
128                                // operator {op_unary_pre_post}|{op_binary_over}|{op_binary_not_over}
[51b7345]129
130%x COMMENT
[3848e0e]131%x BKQUOTE
132%x QUOTE
133%x STRING
[51b7345]134
135%%
[b87a5ed]136                                   /* line directives */
[4040425]137^{h_white}*"#"{h_white}*[0-9]+{h_white}*["][^"\n]+["].*"\n" {
[8c17ab0]138        /* " stop highlighting */
[c1c1112]139        static char filename[FILENAME_MAX];                                     // temporarily store current source-file name
[51b7345]140        char *end_num;
141        char *begin_string, *end_string;
142        long lineno, length;
143        lineno = strtol( yytext + 1, &end_num, 0 );
144        begin_string = strchr( end_num, '"' );
[f487962]145        if ( begin_string ) {                                                           // file name ?
146                end_string = strchr( begin_string + 1, '"' );   // look for ending delimiter
147                assert( end_string );                                                   // closing quote ?
148                length = end_string - begin_string - 1;                 // file-name length without quotes or sentinel
149                assert( length < FILENAME_MAX );                                // room for sentinel ?
150                memcpy( &filename, begin_string + 1, length );  // copy file name from yytext
151                filename[ length ] = '\0';                                              // terminate string with sentinel
152                //std::cout << "file " << filename << " line " << lineno << std::endl;
153                yylineno = lineno;
[c1c1112]154                yyfilename = filename;
[b87a5ed]155        } // if
[51b7345]156}
157
[b87a5ed]158                                /* ignore preprocessor directives (for now) */
[51b7345]159^{h_white}*"#"[^\n]*"\n" ;
160
[cd623a4]161                                /* ignore C style comments (ALSO HANDLED BY CPP) */
[3848e0e]162"/*"                    { BEGIN COMMENT; }
[cd623a4]163<COMMENT>.|\n   ;
164<COMMENT>"*/"   { BEGIN 0; }
[51b7345]165
[cd623a4]166                                /* ignore C++ style comments (ALSO HANDLED BY CPP) */
167"//"[^\n]*"\n"  ;
[51b7345]168
[b87a5ed]169                                /* ignore whitespace */
[3848e0e]170{h_white}+              { WHITE_RETURN(' '); }
171({v_tab}|{c_return}|{form_feed})+ { WHITE_RETURN(' '); }
172({h_white}|{v_tab}|{c_return}|{form_feed})*"\n" { NEWLINE_RETURN(); }
[51b7345]173
[b87a5ed]174                                /* keywords */
175_Alignas                { KEYWORD_RETURN(ALIGNAS); }                    // C11
176_Alignof                { KEYWORD_RETURN(ALIGNOF); }                    // C11
177__alignof               { KEYWORD_RETURN(ALIGNOF); }                    // GCC
178__alignof__             { KEYWORD_RETURN(ALIGNOF); }                    // GCC
179asm                             { KEYWORD_RETURN(ASM); }
180__asm                   { KEYWORD_RETURN(ASM); }                                // GCC
181__asm__                 { KEYWORD_RETURN(ASM); }                                // GCC
[02e5ab6]182_At                             { KEYWORD_RETURN(AT); }                                 // CFA
[b87a5ed]183_Atomic                 { KEYWORD_RETURN(ATOMIC); }                             // C11
184__attribute             { KEYWORD_RETURN(ATTRIBUTE); }                  // GCC
185__attribute__   { KEYWORD_RETURN(ATTRIBUTE); }                  // GCC
[3848e0e]186auto                    { KEYWORD_RETURN(AUTO); }
[b87a5ed]187_Bool                   { KEYWORD_RETURN(BOOL); }                               // C99
[3848e0e]188break                   { KEYWORD_RETURN(BREAK); }
189case                    { KEYWORD_RETURN(CASE); }
[b87a5ed]190catch                   { KEYWORD_RETURN(CATCH); }                              // CFA
[02e5ab6]191catchResume             { KEYWORD_RETURN(CATCHRESUME); }                // CFA
[3848e0e]192char                    { KEYWORD_RETURN(CHAR); }
[b87a5ed]193choose                  { KEYWORD_RETURN(CHOOSE); }                             // CFA
194_Complex                { KEYWORD_RETURN(COMPLEX); }                    // C99
195__complex               { KEYWORD_RETURN(COMPLEX); }                    // GCC
196__complex__             { KEYWORD_RETURN(COMPLEX); }                    // GCC
[3848e0e]197const                   { KEYWORD_RETURN(CONST); }
[b87a5ed]198__const                 { KEYWORD_RETURN(CONST); }                              // GCC
199__const__               { KEYWORD_RETURN(CONST); }                              // GCC
[3848e0e]200continue                { KEYWORD_RETURN(CONTINUE); }
[e04b636]201coroutine               { KEYWORD_RETURN(COROUTINE); }                  // CFA
[3848e0e]202default                 { KEYWORD_RETURN(DEFAULT); }
[02e5ab6]203disable                 { KEYWORD_RETURN(DISABLE); }                    // CFA
[b87a5ed]204do                              { KEYWORD_RETURN(DO); }
[3848e0e]205double                  { KEYWORD_RETURN(DOUBLE); }
[b87a5ed]206dtype                   { KEYWORD_RETURN(DTYPE); }                              // CFA
[3848e0e]207else                    { KEYWORD_RETURN(ELSE); }
[02e5ab6]208enable                  { KEYWORD_RETURN(ENABLE); }                             // CFA
[3848e0e]209enum                    { KEYWORD_RETURN(ENUM); }
[b87a5ed]210__extension__   { KEYWORD_RETURN(EXTENSION); }                  // GCC
[3848e0e]211extern                  { KEYWORD_RETURN(EXTERN); }
[08061589]212fallthrough             { KEYWORD_RETURN(FALLTHRU); }                   // CFA
[b87a5ed]213fallthru                { KEYWORD_RETURN(FALLTHRU); }                   // CFA
214finally                 { KEYWORD_RETURN(FINALLY); }                    // CFA
[3848e0e]215float                   { KEYWORD_RETURN(FLOAT); }
[b87a5ed]216__float128              { KEYWORD_RETURN(FLOAT); }                              // GCC
217for                             { KEYWORD_RETURN(FOR); }
218forall                  { KEYWORD_RETURN(FORALL); }                             // CFA
[3848e0e]219fortran                 { KEYWORD_RETURN(FORTRAN); }
[b87a5ed]220ftype                   { KEYWORD_RETURN(FTYPE); }                              // CFA
221_Generic                { KEYWORD_RETURN(GENERIC); }                    // C11
[3848e0e]222goto                    { KEYWORD_RETURN(GOTO); }
[b87a5ed]223if                              { KEYWORD_RETURN(IF); }
224_Imaginary              { KEYWORD_RETURN(IMAGINARY); }                  // C99
225__imag                  { KEYWORD_RETURN(IMAGINARY); }                  // GCC
226__imag__                { KEYWORD_RETURN(IMAGINARY); }                  // GCC
227inline                  { KEYWORD_RETURN(INLINE); }                             // C99
228__inline                { KEYWORD_RETURN(INLINE); }                             // GCC
229__inline__              { KEYWORD_RETURN(INLINE); }                             // GCC
230int                             { KEYWORD_RETURN(INT); }
231__int128                { KEYWORD_RETURN(INT); }                                // GCC
232__label__               { KEYWORD_RETURN(LABEL); }                              // GCC
[3848e0e]233long                    { KEYWORD_RETURN(LONG); }
[b87a5ed]234lvalue                  { KEYWORD_RETURN(LVALUE); }                             // CFA
[6016c87]235monitor                 { KEYWORD_RETURN(MONITOR); }                    // CFA
[a7c90d4]236mutex                   { KEYWORD_RETURN(MUTEX); }                              // CFA
[b87a5ed]237_Noreturn               { KEYWORD_RETURN(NORETURN); }                   // C11
[5721a6d]238__builtin_offsetof { KEYWORD_RETURN(OFFSETOF); }                // GCC
[3a2128f]239one_t                   { NUMERIC_RETURN(ONE_T); }                              // CFA
[4040425]240otype                   { KEYWORD_RETURN(OTYPE); }                              // CFA
[3848e0e]241register                { KEYWORD_RETURN(REGISTER); }
[b87a5ed]242restrict                { KEYWORD_RETURN(RESTRICT); }                   // C99
243__restrict              { KEYWORD_RETURN(RESTRICT); }                   // GCC
244__restrict__    { KEYWORD_RETURN(RESTRICT); }                   // GCC
[3848e0e]245return                  { KEYWORD_RETURN(RETURN); }
246short                   { KEYWORD_RETURN(SHORT); }
247signed                  { KEYWORD_RETURN(SIGNED); }
[b87a5ed]248__signed                { KEYWORD_RETURN(SIGNED); }                             // GCC
249__signed__              { KEYWORD_RETURN(SIGNED); }                             // GCC
[3848e0e]250sizeof                  { KEYWORD_RETURN(SIZEOF); }
251static                  { KEYWORD_RETURN(STATIC); }
[b87a5ed]252_Static_assert  { KEYWORD_RETURN(STATICASSERT); }               // C11
[3848e0e]253struct                  { KEYWORD_RETURN(STRUCT); }
254switch                  { KEYWORD_RETURN(SWITCH); }
[bd4d011]255thread                  { KEYWORD_RETURN(THREAD); }                             // C11
[b87a5ed]256_Thread_local   { KEYWORD_RETURN(THREADLOCAL); }                // C11
257throw                   { KEYWORD_RETURN(THROW); }                              // CFA
[02e5ab6]258throwResume             { KEYWORD_RETURN(THROWRESUME); }                // CFA
[4040425]259trait                   { KEYWORD_RETURN(TRAIT); }                              // CFA
[b87a5ed]260try                             { KEYWORD_RETURN(TRY); }                                // CFA
[8f60f0b]261ttype                   { KEYWORD_RETURN(TTYPE); }                              // CFA
[3848e0e]262typedef                 { KEYWORD_RETURN(TYPEDEF); }
[b87a5ed]263typeof                  { KEYWORD_RETURN(TYPEOF); }                             // GCC
264__typeof                { KEYWORD_RETURN(TYPEOF); }                             // GCC
265__typeof__              { KEYWORD_RETURN(TYPEOF); }                             // GCC
[3848e0e]266union                   { KEYWORD_RETURN(UNION); }
267unsigned                { KEYWORD_RETURN(UNSIGNED); }
[90c3b1c]268__builtin_va_list { KEYWORD_RETURN(VALIST); }                   // GCC
[3848e0e]269void                    { KEYWORD_RETURN(VOID); }
270volatile                { KEYWORD_RETURN(VOLATILE); }
[b87a5ed]271__volatile              { KEYWORD_RETURN(VOLATILE); }                   // GCC
272__volatile__    { KEYWORD_RETURN(VOLATILE); }                   // GCC
[3848e0e]273while                   { KEYWORD_RETURN(WHILE); }
[3a2128f]274zero_t                  { NUMERIC_RETURN(ZERO_T); }                             // CFA
[51b7345]275
[b87a5ed]276                                /* identifier */
277{identifier}    { IDENTIFIER_RETURN(); }
278{attr_identifier} { ATTRIBUTE_RETURN(); }
[c6b1105]279"`"                             { BEGIN BKQUOTE; }
[b87a5ed]280<BKQUOTE>{identifier} { IDENTIFIER_RETURN(); }
281<BKQUOTE>"`"    { BEGIN 0; }
[51b7345]282
[b87a5ed]283                                /* numeric constants */
284"0"                             { NUMERIC_RETURN(ZERO); }                               // CFA
285"1"                             { NUMERIC_RETURN(ONE); }                                // CFA
[59db689]286{decimal_constant} { NUMERIC_RETURN(INTEGERconstant); }
287{octal_constant} { NUMERIC_RETURN(INTEGERconstant); }
288{hex_constant}  { NUMERIC_RETURN(INTEGERconstant); }
[1b29996]289{real_decimal}  { NUMERIC_RETURN(REALDECIMALconstant); } // must appear before floating_constant
290{real_fraction} { NUMERIC_RETURN(REALFRACTIONconstant); } // must appear before floating_constant
[3848e0e]291{floating_constant}     { NUMERIC_RETURN(FLOATINGconstant); }
292{hex_floating_constant} { NUMERIC_RETURN(FLOATINGconstant); }
[51b7345]293
[b87a5ed]294                                /* character constant, allows empty value */
[c1c1112]295({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new std::string( yytext, yyleng ); }
296<QUOTE>[^'\\\n]* { strtext->append( yytext, yyleng ); }
297<QUOTE>['\n]    { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(CHARACTERconstant); }
[b87a5ed]298                                /* ' stop highlighting */
[51b7345]299
[b87a5ed]300                                /* string constant */
[c1c1112]301({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new std::string( yytext, yyleng ); }
302<STRING>[^"\\\n]* { strtext->append( yytext, yyleng ); }
303<STRING>["\n]   { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(STRINGliteral); }
[b87a5ed]304                                /* " stop highlighting */
[51b7345]305
[59db689]306                                /* common character/string constant */
[c1c1112]307<QUOTE,STRING>{escape_seq} { rm_underscore(); strtext->append( yytext, yyleng ); }
[cd623a4]308<QUOTE,STRING>"\\"{h_white}*"\n" {}                                             // continuation (ALSO HANDLED BY CPP)
[c1c1112]309<QUOTE,STRING>"\\" { strtext->append( yytext, yyleng ); } // unknown escape character
[3848e0e]310
[b87a5ed]311                                /* punctuation */
[615a096]312"@"                             { ASCIIOP_RETURN(); }
[b87a5ed]313"["                             { ASCIIOP_RETURN(); }
314"]"                             { ASCIIOP_RETURN(); }
315"("                             { ASCIIOP_RETURN(); }
316")"                             { ASCIIOP_RETURN(); }
317"{"                             { ASCIIOP_RETURN(); }
318"}"                             { ASCIIOP_RETURN(); }
319","                             { ASCIIOP_RETURN(); }                                   // also operator
320":"                             { ASCIIOP_RETURN(); }
321";"                             { ASCIIOP_RETURN(); }
322"."                             { ASCIIOP_RETURN(); }                                   // also operator
[3848e0e]323"..."                   { NAMEDOP_RETURN(ELLIPSIS); }
324
[b87a5ed]325                                /* alternative C99 brackets, "<:" & "<:<:" handled by preprocessor */
[3848e0e]326"<:"                    { RETURN_VAL('['); }
327":>"                    { RETURN_VAL(']'); }
328"<%"                    { RETURN_VAL('{'); }
329"%>"                    { RETURN_VAL('}'); }
[51b7345]330
[b87a5ed]331                                /* operators */
332"!"                             { ASCIIOP_RETURN(); }
333"+"                             { ASCIIOP_RETURN(); }
334"-"                             { ASCIIOP_RETURN(); }
335"*"                             { ASCIIOP_RETURN(); }
336"/"                             { ASCIIOP_RETURN(); }
337"%"                             { ASCIIOP_RETURN(); }
338"^"                             { ASCIIOP_RETURN(); }
339"~"                             { ASCIIOP_RETURN(); }
340"&"                             { ASCIIOP_RETURN(); }
341"|"                             { ASCIIOP_RETURN(); }
342"<"                             { ASCIIOP_RETURN(); }
343">"                             { ASCIIOP_RETURN(); }
344"="                             { ASCIIOP_RETURN(); }
345"?"                             { ASCIIOP_RETURN(); }
[3848e0e]346
347"++"                    { NAMEDOP_RETURN(ICR); }
348"--"                    { NAMEDOP_RETURN(DECR); }
349"=="                    { NAMEDOP_RETURN(EQ); }
350"!="                    { NAMEDOP_RETURN(NE); }
351"<<"                    { NAMEDOP_RETURN(LS); }
352">>"                    { NAMEDOP_RETURN(RS); }
353"<="                    { NAMEDOP_RETURN(LE); }
354">="                    { NAMEDOP_RETURN(GE); }
355"&&"                    { NAMEDOP_RETURN(ANDAND); }
356"||"                    { NAMEDOP_RETURN(OROR); }
357"->"                    { NAMEDOP_RETURN(ARROW); }
358"+="                    { NAMEDOP_RETURN(PLUSassign); }
359"-="                    { NAMEDOP_RETURN(MINUSassign); }
360"*="                    { NAMEDOP_RETURN(MULTassign); }
361"/="                    { NAMEDOP_RETURN(DIVassign); }
362"%="                    { NAMEDOP_RETURN(MODassign); }
363"&="                    { NAMEDOP_RETURN(ANDassign); }
364"|="                    { NAMEDOP_RETURN(ORassign); }
365"^="                    { NAMEDOP_RETURN(ERassign); }
366"<<="                   { NAMEDOP_RETURN(LSassign); }
367">>="                   { NAMEDOP_RETURN(RSassign); }
[51b7345]368
[08061589]369"@="                    { NAMEDOP_RETURN(ATassign); }                   // CFA
[097e2b0]370
[b87a5ed]371                                /* CFA, operator identifier */
372{op_unary}"?"   { IDENTIFIER_RETURN(); }                                // unary
[a61fea9a]373"?"({op_unary_pre_post}|"()"|"[?]"|"{}") { IDENTIFIER_RETURN(); }
[02e5ab6]374"^?{}" { IDENTIFIER_RETURN(); }
[b87a5ed]375"?"{op_binary_over}"?"  { IDENTIFIER_RETURN(); }                // binary
[51b7345]376        /*
[daf9671]377          This rule handles ambiguous cases with operator identifiers, e.g., "int *?*?()", where the string "*?*?"  can be
378          lexed as "*?"/"*?" or "*"/"?*?". Since it is common practise to put a unary operator juxtaposed to an identifier,
379          e.g., "*i", users will be annoyed if they cannot do this with respect to operator identifiers. Therefore, there is
380          a lexical look-ahead for the second case, with backtracking to return the leading unary operator and then
381          reparsing the trailing operator identifier.  Otherwise a space is needed between the unary operator and operator
382          identifier to disambiguate this common case.
383
384          A similar issue occurs with the dereference, *?(...), and routine-call, ?()(...) identifiers.  The ambiguity
385          occurs when the deference operator has no parameters, *?() and *?()(...), requiring arbitrary whitespace
386          look-ahead for the routine-call parameter-list to disambiguate.  However, the dereference operator must have a
387          parameter/argument to dereference *?(...).  Hence, always interpreting the string *?() as * ?() does not preclude
388          any meaningful program.
389
390          The remaining cases are with the increment/decrement operators and conditional expression:
391
392          i++? ...(...);
393          i?++ ...(...);
394
395          requiring arbitrary whitespace look-ahead for the operator parameter-list, even though that interpretation is an
396      incorrect expression (juxtaposed identifiers).  Therefore, it is necessary to disambiguate these cases with a
397      space:
398
399          i++ ? i : 0;
400          i? ++i : 0;
[51b7345]401        */
[daf9671]402{op_unary}"?"({op_unary_pre_post}|"()"|"[?]"|{op_binary_over}"?") {
[b87a5ed]403        // 1 or 2 character unary operator ?
404        int i = yytext[1] == '?' ? 1 : 2;
405        yyless( i );            // put back characters up to first '?'
406        if ( i > 1 ) {
407                NAMEDOP_RETURN( yytext[0] == '+' ? ICR : DECR );
408        } else {
409                ASCIIOP_RETURN();
410        } // if
411}
412
413                                /* unknown characters */
[3848e0e]414.                       { printf("unknown character(s):\"%s\" on line %d\n", yytext, yylineno); }
[51b7345]415
416%%
417
[b87a5ed]418// Local Variables: //
419// mode: c++ //
[de62360d]420// tab-width: 4 //
[b87a5ed]421// compile-command: "make install" //
422// End: //
Note: See TracBrowser for help on using the repository browser.