Changeset fc1ef62 for tools


Ignore:
Timestamp:
Aug 29, 2017, 5:40:44 PM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
9ed4f94
Parents:
6454949
Message:

add %precedence operator precedence

Location:
tools/prettyprinter
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • tools/prettyprinter/lex.ll

    r6454949 rfc1ef62  
    77 * lex.ll --
    88 *
    9  * Author           : Rodolfo Gabriel Esteves
     9 * Author           : Peter A. Buhr
    1010 * Created On       : Sat Dec 15 11:45:59 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Fri Jul 21 23:06:16 2017
    13  * Update Count     : 254
     12 * Last Modified On : Tue Aug 29 17:33:36 2017
     13 * Update Count     : 268
    1414 */
    1515
    1616%option stack
    1717%option yylineno
     18%option nounput
    1819
    1920%{
     
    3031string comment_str;
    3132string code_str;
     33
     34// Stop warning due to incorrectly generated flex code.
     35#pragma GCC diagnostic ignored "-Wsign-compare"
    3236%}
    3337
     
    4448/* ---------------------------- Token Section ---------------------------- */
    4549%%
    46 <INITIAL,C_CODE>"/*"    {                               /* C style comments */
    47                         #if defined(DEBUG_ALL) | defined(DEBUG_COMMENT)
    48                             cerr << "\"/*\" : " << yytext << endl;
    49                         #endif
    50                             if ( YYSTATE == C_CODE ) code_str += yytext;
    51                             else comment_str += yytext;
    52                             yy_push_state(C_COMMENT);
    53                         }
    54 <C_COMMENT>(.|"\n")     {                               /* C style comments */
    55                         #if defined(DEBUG_ALL) | defined(DEBUG_COMMENT)
    56                             cerr << "<C_COMMENT>(.|\\n) : " << yytext << endl;
    57                         #endif
    58                             if ( yy_top_state() == C_CODE ) code_str += yytext;
    59                             else comment_str += yytext;
    60                         }
    61 <C_COMMENT>"*/"         {                               /* C style comments */
    62                         #if defined(DEBUG_ALL) | defined(DEBUG_COMMENT)
    63                             cerr << "<C_COMMENT>\"*/\" : " << yytext << endl;
    64                         #endif
    65                             if ( yy_top_state() == C_CODE ) code_str += yytext;
    66                             else {
    67                                 comment_str += yytext;
    68                                 //cerr << "C COMMENT : " << endl << comment_str << endl;
    69                                 ws_list.push_back( comment_str );
    70                                 comment_str = "";
    71                             }
    72                             yy_pop_state();
    73                         }
    74 <INITIAL,C_CODE>"//"[^\n]*"\n" {                        /* C++ style comments */
    75                         #if defined(DEBUG_ALL) | defined(DEBUG_COMMENT)
    76                             cerr << "\"//\"[^\\n]*\"\n\" : " << yytext << endl;
    77                         #endif
    78                             if ( YYSTATE == C_CODE ) code_str += yytext;
    79                             else {
    80                                 comment_str += yytext;
    81                                 //cerr << "C++ COMMENT : " << endl << comment_str << endl;
    82                                 ws_list.push_back( comment_str );
    83                                 comment_str = "";
    84                             }
    85                         }
     50<INITIAL,C_CODE>"/*" {                                                                  // C style comments */
     51#if defined(DEBUG_ALL) | defined(DEBUG_COMMENT)
     52    cerr << "\"/*\" : " << yytext << endl;
     53#endif
     54    if ( YYSTATE == C_CODE ) code_str += yytext;
     55    else comment_str += yytext;
     56    yy_push_state(C_COMMENT);
     57}
     58<C_COMMENT>(.|"\n")     {                                                                       // C style comments
     59#if defined(DEBUG_ALL) | defined(DEBUG_COMMENT)
     60    cerr << "<C_COMMENT>(.|\\n) : " << yytext << endl;
     61#endif
     62    if ( yy_top_state() == C_CODE ) code_str += yytext;
     63    else comment_str += yytext;
     64}
     65<C_COMMENT>"*/" {                                                                               // C style comments
     66#if defined(DEBUG_ALL) | defined(DEBUG_COMMENT)
     67        cerr << "<C_COMMENT>\"*/\" : " << yytext << endl;
     68#endif
     69        if ( yy_top_state() == C_CODE ) code_str += yytext;
     70        else {
     71                comment_str += yytext;
     72                //cerr << "C COMMENT : " << endl << comment_str << endl;
     73                ws_list.push_back( comment_str );
     74                comment_str = "";
     75        }
     76        yy_pop_state();
     77}
    8678
    87 ";"                     { RETURN_TOKEN( ';' ) }
    88 ":"                     { RETURN_TOKEN( ':' ) }
    89 "|"                     { RETURN_TOKEN( '|' ) }
    90 ","                     { RETURN_TOKEN( ',' ) }
    91 "<"                     { RETURN_TOKEN( '<' ) }
    92 ">"                     { RETURN_TOKEN( '>' ) }
     79<INITIAL,C_CODE>"//"[^\n]*"\n" {                                                // C++ style comments
     80#if defined(DEBUG_ALL) | defined(DEBUG_COMMENT)
     81        cerr << "\"//\"[^\\n]*\"\n\" : " << yytext << endl;
     82#endif
     83        if ( YYSTATE == C_CODE ) code_str += yytext;
     84        else {
     85                comment_str += yytext;
     86                //cerr << "C++ COMMENT : " << endl << comment_str << endl;
     87                ws_list.push_back( comment_str );
     88                comment_str = "";
     89        }
     90}
    9391
    94 [[:space:]]+            {                               /* [ \t\n]+ */
    95                             ws_list.push_back( yytext );
    96                             //cerr << "WS : " << "\"" << yytext << "\"" << endl;
    97                         }
     92";"                             { RETURN_TOKEN( ';' ) }
     93":"                             { RETURN_TOKEN( ':' ) }
     94"|"                             { RETURN_TOKEN( '|' ) }
     95","                             { RETURN_TOKEN( ',' ) }
     96"<"                             { RETURN_TOKEN( '<' ) }
     97">"                             { RETURN_TOKEN( '>' ) }
    9898
    99 <INITIAL>"{"            { RETURN_TOKEN( '{' ) }
    100 <INITIAL>"}"            { RETURN_TOKEN( '}' ) }
    101 <C_CODE>"{"             {
    102                         #if defined(DEBUG_ALL) | defined(DEBUG_C)
    103                             cerr << "<C_CODE>. : " << yytext << endl;
    104                         #endif
    105                             code_str += yytext;
    106                             RETURN_TOKEN( '{' )
    107                         }
    108 <C_CODE>"}"             {
    109                         #if defined(DEBUG_ALL) | defined(DEBUG_C)
    110                             cerr << "<C_CODE>. : " << yytext << endl;
    111                         #endif
    112                             code_str += yytext;
    113                             RETURN_TOKEN( '}' )
    114                         }
     99[[:space:]]+ {                                                                                  // [ \t\n]+
     100        ws_list.push_back( yytext );
     101        //cerr << "WS : " << "\"" << yytext << "\"" << endl;
     102}
     103
     104<INITIAL>"{"    { RETURN_TOKEN( '{' ) }
     105<INITIAL>"}"    { RETURN_TOKEN( '}' ) }
     106<C_CODE>"{"     {
     107#if defined(DEBUG_ALL) | defined(DEBUG_C)
     108        cerr << "<C_CODE>. : " << yytext << endl;
     109#endif
     110        code_str += yytext;
     111        RETURN_TOKEN( '{' )
     112}
     113<C_CODE>"}"     {
     114#if defined(DEBUG_ALL) | defined(DEBUG_C)
     115        cerr << "<C_CODE>. : " << yytext << endl;
     116#endif
     117        code_str += yytext;
     118        RETURN_TOKEN( '}' )
     119}
    115120
    116121"%%"                    { RETURN_TOKEN( MARK ) }
    117122"%{"                    { RETURN_TOKEN( LCURL ) }
    118 <C_CODE>"%}"            { RETURN_TOKEN( RCURL ) }
     123<C_CODE>"%}"    { RETURN_TOKEN( RCURL ) }
    119124
    120 ^"%union"               { RETURN_TOKEN( UNION ) }
    121 ^"%start"               { RETURN_TOKEN( START ) }
    122 ^"%token"               { RETURN_TOKEN( TOKEN ) }
    123 ^"%type"                { RETURN_TOKEN( TYPE ) }
    124 ^"%left"                { RETURN_TOKEN( LEFT ) }
    125 ^"%right"               { RETURN_TOKEN( RIGHT ) }
    126 ^"%nonassoc"            { RETURN_TOKEN( NONASSOC ) }
    127 ^"%pure_parser"         { RETURN_TOKEN( PURE_PARSER ) }
    128 ^"%semantic_parser"     { RETURN_TOKEN( SEMANTIC_PARSER ) }
    129 ^"%expect"              { RETURN_TOKEN( EXPECT ) }
     125^"%union"       { RETURN_TOKEN( UNION ) }
     126^"%start"       { RETURN_TOKEN( START ) }
     127^"%token"       { RETURN_TOKEN( TOKEN ) }
     128^"%type"            { RETURN_TOKEN( TYPE ) }
     129^"%left"            { RETURN_TOKEN( LEFT ) }
     130^"%right"           { RETURN_TOKEN( RIGHT ) }
     131^"%nonassoc"    { RETURN_TOKEN( NONASSOC ) }
     132^"%precedence"  { RETURN_TOKEN( PRECEDENCE ) }
     133^"%pure_parser" { RETURN_TOKEN( PURE_PARSER ) }
     134^"%semantic_parser"     { RETURN_TOKEN( SEMANTIC_PARSER ) }
     135^"%expect"      { RETURN_TOKEN( EXPECT ) }
    130136^"%thong"               { RETURN_TOKEN( THONG ) }
    131137
    132138"%prec"                 { RETURN_TOKEN( PREC ) }
    133139
    134 {integer}               { RETURN_TOKEN( INTEGER ); }
    135 [']{c_char}[']          { RETURN_TOKEN( CHARACTER ); }
    136 {identifier}            { RETURN_TOKEN( IDENTIFIER ); }
     140{integer}           { RETURN_TOKEN( INTEGER ); }
     141[']{c_char}[']  { RETURN_TOKEN( CHARACTER ); }
     142{identifier}    { RETURN_TOKEN( IDENTIFIER ); }
    137143
    138 <C_CODE>["]{s_char}*["] {                               /* hide braces "{}" in strings */
    139                         #if defined(DEBUG_ALL) | defined(DEBUG_C)
    140                             cerr << "<C_CODE>. : " << yytext << endl;
    141                         #endif
    142                             code_str += yytext;
    143                         }
     144<C_CODE>["]{s_char}*["] {                                                               // hide braces "{}" in strings
     145#if defined(DEBUG_ALL) | defined(DEBUG_C)
     146        cerr << "<C_CODE>. : " << yytext << endl;
     147#endif
     148        code_str += yytext;
     149}
    144150
    145 <C_CODE>(.|\n)          {                               /* must be last rule of C_CODE */
    146                         #if defined(DEBUG_ALL) | defined(DEBUG_C)
    147                             cerr << "<C_CODE>. : " << yytext << endl;
    148                         #endif
    149                             code_str += yytext;
    150                         }
     151<C_CODE>(.|\n) {                                                                                // must be last rule of C_CODE
     152#if defined(DEBUG_ALL) | defined(DEBUG_C)
     153        cerr << "<C_CODE>. : " << yytext << endl;
     154#endif
     155        code_str += yytext;
     156}
    151157
    152 .                       { printf("UNKNOWN CHARACTER:%s\n", yytext); } /* unknown characters */
     158                                /* unknown characters */
     159.                               { printf("unknown character(s):\"%s\" on line %d\n", yytext, yylineno); }
    153160%%
    154161void lexC(void) {
  • tools/prettyprinter/parser.hh

    r6454949 rfc1ef62  
    5959    RIGHT = 269,
    6060    NONASSOC = 270,
    61     TYPE = 271,
    62     PURE_PARSER = 272,
    63     SEMANTIC_PARSER = 273,
    64     EXPECT = 274,
    65     THONG = 275,
    66     PREC = 276,
    67     END_TERMINALS = 277,
    68     _SECTIONS = 278,
    69     _DEFSECTION_OPT = 279,
    70     _LITERALBLOCK = 280,
    71     _DECLARATION = 281,
    72     _TAG_OPT = 282,
    73     _NAMENOLIST = 283,
    74     _NAMENO = 284,
    75     _NAMELIST = 285,
    76     _RULESECTION = 286,
    77     _RULE = 287,
    78     _LHS = 288,
    79     _RHS = 289,
    80     _PREC = 290,
    81     _ACTION = 291,
    82     _USERSECTION_OPT = 292
     61    PRECEDENCE = 271,
     62    TYPE = 272,
     63    PURE_PARSER = 273,
     64    SEMANTIC_PARSER = 274,
     65    EXPECT = 275,
     66    THONG = 276,
     67    PREC = 277,
     68    END_TERMINALS = 278,
     69    _SECTIONS = 279,
     70    _DEFSECTION_OPT = 280,
     71    _LITERALBLOCK = 281,
     72    _DECLARATION = 282,
     73    _TAG_OPT = 283,
     74    _NAMENOLIST = 284,
     75    _NAMENO = 285,
     76    _NAMELIST = 286,
     77    _RULESECTION = 287,
     78    _RULE = 288,
     79    _LHS = 289,
     80    _RHS = 290,
     81    _PREC = 291,
     82    _ACTION = 292,
     83    _USERSECTION_OPT = 293
    8384  };
    8485#endif
     
    9798#define RIGHT 269
    9899#define NONASSOC 270
    99 #define TYPE 271
    100 #define PURE_PARSER 272
    101 #define SEMANTIC_PARSER 273
    102 #define EXPECT 274
    103 #define THONG 275
    104 #define PREC 276
    105 #define END_TERMINALS 277
    106 #define _SECTIONS 278
    107 #define _DEFSECTION_OPT 279
    108 #define _LITERALBLOCK 280
    109 #define _DECLARATION 281
    110 #define _TAG_OPT 282
    111 #define _NAMENOLIST 283
    112 #define _NAMENO 284
    113 #define _NAMELIST 285
    114 #define _RULESECTION 286
    115 #define _RULE 287
    116 #define _LHS 288
    117 #define _RHS 289
    118 #define _PREC 290
    119 #define _ACTION 291
    120 #define _USERSECTION_OPT 292
     100#define PRECEDENCE 271
     101#define TYPE 272
     102#define PURE_PARSER 273
     103#define SEMANTIC_PARSER 274
     104#define EXPECT 275
     105#define THONG 276
     106#define PREC 277
     107#define END_TERMINALS 278
     108#define _SECTIONS 279
     109#define _DEFSECTION_OPT 280
     110#define _LITERALBLOCK 281
     111#define _DECLARATION 282
     112#define _TAG_OPT 283
     113#define _NAMENOLIST 284
     114#define _NAMENO 285
     115#define _NAMELIST 286
     116#define _RULESECTION 287
     117#define _RULE 288
     118#define _LHS 289
     119#define _RHS 290
     120#define _PREC 291
     121#define _ACTION 292
     122#define _USERSECTION_OPT 293
    121123
    122124/* Value type.  */
     
    129131        Token *tokenp;
    130132
    131 #line 132 "parser.hh" /* yacc.c:1909  */
     133#line 134 "parser.hh" /* yacc.c:1909  */
    132134};
    133135
  • tools/prettyprinter/parser.yy

    r6454949 rfc1ef62  
    1010// Created On       : Sat Dec 15 13:44:21 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun 29 09:26:47 2017
    13 // Update Count     : 1045
     12// Last Modified On : Tue Aug 29 16:34:10 2017
     13// Update Count     : 1047
    1414//
    1515
     
    6767%token<tokenp>  RIGHT                                                                   // %right
    6868%token<tokenp>  NONASSOC                                                                // %nonassoc
     69%token<tokenp>  PRECEDENCE                                                              // %precedence
    6970%token<tokenp>  TYPE                                                                    // %type
    7071%token<tokenp>  PURE_PARSER                                                             // %pure_parser
     
    259260        | RIGHT
    260261        | NONASSOC
     262        | PRECEDENCE
    261263        ;
    262264
Note: See TracChangeset for help on using the changeset viewer.