source: tools/prettyprinter/lex.ll @ fe97a7d8

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 fe97a7d8 was 6b0b624, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

change #ifndef to #pragma once

  • Property mode set to 100644
File size: 4.6 KB
Line 
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.
6 *
7 * lex.ll --
8 *
9 * Author           : Rodolfo Gabriel Esteves
10 * Created On       : Sat Dec 15 11:45:59 2001
11 * Last Modified By : Peter A. Buhr
12 * Last Modified On : Fri Jul 21 23:06:16 2017
13 * Update Count     : 254
14 */
15
16%option stack
17%option yylineno
18
19%{
20#include <list>
21#include <string>
22#include <iostream>
23using namespace std;
24#include "ParserTypes.h"
25#include "parser.hh"
26
27#define RETURN_TOKEN( kind ) yylval.tokenp = new Token( yytext, ws_list, kind ); return kind;
28
29list<string> ws_list;
30string comment_str;
31string code_str;
32%}
33
34integer [0-9]+
35identifier [a-zA-Z_$][0-9a-zA-Z_$]*
36
37simple_escape ['"?\\]
38escape_sequence [\\]{simple_escape}
39c_char [^'\\\n]|{escape_sequence}
40s_char [^"\\\n]|{escape_sequence}
41
42%x C_COMMENT STR C_CODE
43
44/* ---------------------------- Token Section ---------------------------- */
45%%
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                        }
86
87";"                     { RETURN_TOKEN( ';' ) }
88":"                     { RETURN_TOKEN( ':' ) }
89"|"                     { RETURN_TOKEN( '|' ) }
90","                     { RETURN_TOKEN( ',' ) }
91"<"                     { RETURN_TOKEN( '<' ) }
92">"                     { RETURN_TOKEN( '>' ) }
93
94[[:space:]]+            {                               /* [ \t\n]+ */
95                            ws_list.push_back( yytext );
96                            //cerr << "WS : " << "\"" << yytext << "\"" << endl;
97                        }
98
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                        }
115
116"%%"                    { RETURN_TOKEN( MARK ) }
117"%{"                    { RETURN_TOKEN( LCURL ) }
118<C_CODE>"%}"            { RETURN_TOKEN( RCURL ) }
119
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 ) }
130^"%thong"               { RETURN_TOKEN( THONG ) }
131
132"%prec"                 { RETURN_TOKEN( PREC ) }
133
134{integer}               { RETURN_TOKEN( INTEGER ); }
135[']{c_char}[']          { RETURN_TOKEN( CHARACTER ); }
136{identifier}            { RETURN_TOKEN( IDENTIFIER ); }
137
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
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
152.                       { printf("UNKNOWN CHARACTER:%s\n", yytext); } /* unknown characters */
153%%
154void lexC(void) {
155    BEGIN(C_CODE);
156}
157
158string lexYacc(void) {
159    BEGIN(INITIAL);
160    //cerr << "CODE: " << endl << code_str << endl;
161    string temp( code_str );
162    code_str = "";
163    return temp;
164}
165
166// Local Variables: //
167// mode: c++ //
168// tab-width: 4 //
169// compile-command: "make install" //
170// End: //
Note: See TracBrowser for help on using the repository browser.