source: tools/prettyprinter/lex.ll @ 728df66

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 728df66 was fc1ef62, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

add %precedence operator precedence

  • Property mode set to 100644
File size: 4.6 KB
RevLine 
[6b0b624]1/*
[7d4f6ed]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.
[fda8168]6 *
[7d4f6ed]7 * lex.ll --
[fda8168]8 *
[fc1ef62]9 * Author           : Peter A. Buhr
[fda8168]10 * Created On       : Sat Dec 15 11:45:59 2001
11 * Last Modified By : Peter A. Buhr
[fc1ef62]12 * Last Modified On : Tue Aug 29 17:33:36 2017
13 * Update Count     : 268
[fda8168]14 */
15
16%option stack
17%option yylineno
[fc1ef62]18%option nounput
[fda8168]19
20%{
21#include <list>
22#include <string>
23#include <iostream>
[7d4f6ed]24using namespace std;
[8c97ee7]25#include "ParserTypes.h"
[7d4f6ed]26#include "parser.hh"
[fda8168]27
28#define RETURN_TOKEN( kind ) yylval.tokenp = new Token( yytext, ws_list, kind ); return kind;
29
30list<string> ws_list;
31string comment_str;
32string code_str;
[fc1ef62]33
34// Stop warning due to incorrectly generated flex code.
35#pragma GCC diagnostic ignored "-Wsign-compare"
[fda8168]36%}
37
38integer [0-9]+
39identifier [a-zA-Z_$][0-9a-zA-Z_$]*
40
41simple_escape ['"?\\]
42escape_sequence [\\]{simple_escape}
43c_char [^'\\\n]|{escape_sequence}
44s_char [^"\\\n]|{escape_sequence}
45
46%x C_COMMENT STR C_CODE
47
48/* ---------------------------- Token Section ---------------------------- */
49%%
[fc1ef62]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}
78
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}
91
92";"                             { RETURN_TOKEN( ';' ) }
93":"                             { RETURN_TOKEN( ':' ) }
94"|"                             { RETURN_TOKEN( '|' ) }
95","                             { RETURN_TOKEN( ',' ) }
96"<"                             { RETURN_TOKEN( '<' ) }
97">"                             { RETURN_TOKEN( '>' ) }
98
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}
[fda8168]120
121"%%"                    { RETURN_TOKEN( MARK ) }
122"%{"                    { RETURN_TOKEN( LCURL ) }
[fc1ef62]123<C_CODE>"%}"    { RETURN_TOKEN( RCURL ) }
124
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 ) }
[fda8168]136^"%thong"               { RETURN_TOKEN( THONG ) }
137
138"%prec"                 { RETURN_TOKEN( PREC ) }
139
[fc1ef62]140{integer}           { RETURN_TOKEN( INTEGER ); }
141[']{c_char}[']  { RETURN_TOKEN( CHARACTER ); }
142{identifier}    { RETURN_TOKEN( IDENTIFIER ); }
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}
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}
157
158                                /* unknown characters */
159.                               { printf("unknown character(s):\"%s\" on line %d\n", yytext, yylineno); }
[fda8168]160%%
161void lexC(void) {
162    BEGIN(C_CODE);
163}
164
165string lexYacc(void) {
166    BEGIN(INITIAL);
167    //cerr << "CODE: " << endl << code_str << endl;
168    string temp( code_str );
169    code_str = "";
170    return temp;
171}
172
[7d4f6ed]173// Local Variables: //
174// mode: c++ //
175// tab-width: 4 //
176// compile-command: "make install" //
177// End: //
Note: See TracBrowser for help on using the repository browser.