[7d4f6ed] | 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 | // parser.yy --
|
---|
| 8 | //
|
---|
| 9 | // Author : Rodolfo G. Esteves
|
---|
| 10 | // Created On : Sat Dec 15 13:44:21 2001
|
---|
| 11 | // Last Modified By : Peter A. Buhr
|
---|
[81bb114] | 12 | // Last Modified On : Sun Apr 15 21:40:30 2018
|
---|
| 13 | // Update Count : 1052
|
---|
[7d4f6ed] | 14 | //
|
---|
| 15 |
|
---|
| 16 | %{
|
---|
| 17 | #define YYDEBUG_LEXER_TEXT( yylval ) // lexer loads this up each time
|
---|
| 18 | #define YYDEBUG 1 // get the pretty debugging code to compile
|
---|
| 19 |
|
---|
| 20 | #include <iostream>
|
---|
| 21 | using namespace std;
|
---|
[8c97ee7] | 22 | #include "ParserTypes.h"
|
---|
[7d4f6ed] | 23 | #include "filter.h"
|
---|
| 24 |
|
---|
| 25 | extern list<string> ws_list; // lex variable containing accumulated whitespace
|
---|
| 26 | void lexC( void );
|
---|
| 27 | string lexYacc( void );
|
---|
| 28 |
|
---|
| 29 | void yyerror( string s ) {
|
---|
| 30 | extern int yylineno;
|
---|
| 31 |
|
---|
| 32 | cerr << "Error in line: " << yylineno << ": " << s << endl;
|
---|
| 33 | return;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | Token *declstart;
|
---|
| 37 | Token *rulestart;
|
---|
| 38 | Token *nameliststart;
|
---|
| 39 | %}
|
---|
| 40 |
|
---|
| 41 | %union {
|
---|
| 42 | Token *tokenp;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | %token<tokenp> ','
|
---|
| 46 | %token<tokenp> '<'
|
---|
| 47 | %token<tokenp> '>'
|
---|
| 48 | %token<tokenp> '{'
|
---|
| 49 | %token<tokenp> '}'
|
---|
| 50 | %token<tokenp> ':'
|
---|
| 51 | %token<tokenp> ';'
|
---|
| 52 | %token<tokenp> '|'
|
---|
| 53 |
|
---|
| 54 | %token<tokenp> MARK // %%
|
---|
| 55 | %token<tokenp> LCURL // %{
|
---|
| 56 | %token<tokenp> RCURL // %}
|
---|
| 57 |
|
---|
| 58 | %token<tokenp> INTEGER // integer constant
|
---|
| 59 | %token<tokenp> CHARACTER // character constant
|
---|
| 60 | %token<tokenp> IDENTIFIER // identifier
|
---|
| 61 | %token<tokenp> CODE // C code
|
---|
| 62 |
|
---|
[81bb114] | 63 | %token<tokenp> DEFINE // %define
|
---|
| 64 | %token<tokenp> EXPECT // %expect
|
---|
[7d4f6ed] | 65 | %token<tokenp> LEFT // %left
|
---|
[81bb114] | 66 | %token<tokenp> LOCATIONS // %locations
|
---|
[7d4f6ed] | 67 | %token<tokenp> NONASSOC // %nonassoc
|
---|
[fc1ef62] | 68 | %token<tokenp> PRECEDENCE // %precedence
|
---|
[7d4f6ed] | 69 | %token<tokenp> PURE_PARSER // %pure_parser
|
---|
[81bb114] | 70 | %token<tokenp> RIGHT // %right
|
---|
[7d4f6ed] | 71 | %token<tokenp> SEMANTIC_PARSER // %semantic_parser
|
---|
[81bb114] | 72 | %token<tokenp> START // %start
|
---|
[7d4f6ed] | 73 | %token<tokenp> THONG // %thong
|
---|
[81bb114] | 74 | %token<tokenp> TOKEN // %token
|
---|
| 75 | %token<tokenp> TYPE // %type
|
---|
| 76 | %token<tokenp> UNION // %union
|
---|
[7d4f6ed] | 77 |
|
---|
| 78 | %token<tokenp> PREC // %prec
|
---|
| 79 |
|
---|
[81bb114] | 80 | %token END_TERMINALS // ALL TERMINAL TOKEN NAMES MUST APPEAR BEFORE THIS
|
---|
[7d4f6ed] | 81 |
|
---|
| 82 | %type<tokenp> sections
|
---|
[81bb114] | 83 | %token _SECTIONS
|
---|
[7d4f6ed] | 84 | %type<tokenp> mark
|
---|
| 85 | %type<tokenp> defsection_opt
|
---|
[81bb114] | 86 | %token _DEFSECTION_OPT
|
---|
[7d4f6ed] | 87 | %type<tokenp> declarations
|
---|
| 88 | %type<tokenp> literalblock
|
---|
[81bb114] | 89 | %token _LITERALBLOCK
|
---|
[7d4f6ed] | 90 | %type<tokenp> declaration
|
---|
[81bb114] | 91 | %token _DECLARATION
|
---|
[7d4f6ed] | 92 | %type<tokenp> union
|
---|
| 93 | %type<tokenp> rword
|
---|
| 94 | %type<tokenp> tag_opt
|
---|
[81bb114] | 95 | %token _TAG_OPT
|
---|
[7d4f6ed] | 96 | %type<tokenp> namenolist
|
---|
[81bb114] | 97 | %token _NAMENOLIST
|
---|
[7d4f6ed] | 98 | %type<tokenp> nameno
|
---|
[81bb114] | 99 | %token _NAMENO
|
---|
[7d4f6ed] | 100 | %type<tokenp> namelist
|
---|
[81bb114] | 101 | %token _NAMELIST
|
---|
[7d4f6ed] | 102 | %type<tokenp> name
|
---|
| 103 | %type<tokenp> rulesection
|
---|
[81bb114] | 104 | %token _RULESECTION
|
---|
[7d4f6ed] | 105 | %type<tokenp> rules
|
---|
[81bb114] | 106 | %token _RULE
|
---|
[7d4f6ed] | 107 | %type<tokenp> lhs
|
---|
[81bb114] | 108 | %token _LHS
|
---|
[7d4f6ed] | 109 | %type<tokenp> rhs
|
---|
[81bb114] | 110 | %token _RHS
|
---|
[7d4f6ed] | 111 | %type<tokenp> prod
|
---|
| 112 | %type<tokenp> prec
|
---|
[81bb114] | 113 | %token _PREC
|
---|
[7d4f6ed] | 114 | %type<tokenp> action
|
---|
[81bb114] | 115 | %token _ACTION
|
---|
[7d4f6ed] | 116 | %type<tokenp> usersection_opt
|
---|
[81bb114] | 117 | %token _USERSECTION_OPT
|
---|
[7d4f6ed] | 118 | %type<tokenp> ccode_opt
|
---|
| 119 | %type<tokenp> blocks
|
---|
| 120 |
|
---|
| 121 | %start grammar
|
---|
| 122 |
|
---|
| 123 | %%
|
---|
| 124 | grammar :
|
---|
| 125 | sections
|
---|
| 126 | {
|
---|
| 127 | filter( $1 ); // filter parse tree
|
---|
| 128 | freeTree( $1 ); // free parse-tree storage (optional: used with purify)
|
---|
| 129 | }
|
---|
| 130 | ;
|
---|
| 131 |
|
---|
| 132 | sections :
|
---|
| 133 | defsection_opt mark rulesection usersection_opt
|
---|
| 134 | {
|
---|
| 135 | $$ = new Token( "sections", _SECTIONS );
|
---|
| 136 | $1->left = $2;
|
---|
| 137 | $2->left = $3;
|
---|
| 138 | $3->left = $4;
|
---|
| 139 | $$->down = $1;
|
---|
| 140 | }
|
---|
| 141 | ;
|
---|
| 142 |
|
---|
| 143 | mark :
|
---|
| 144 | MARK
|
---|
| 145 | | error // missing %%
|
---|
| 146 | {
|
---|
| 147 | cerr << "no input grammar, missing %% mark" << endl;
|
---|
| 148 | exit( -1 );
|
---|
| 149 | }
|
---|
| 150 | ;
|
---|
| 151 |
|
---|
| 152 | defsection_opt :
|
---|
| 153 | // empty
|
---|
| 154 | {
|
---|
| 155 | //cerr << "defsection_opt1: " << endl;
|
---|
| 156 | $$ = new Token( "declaration_opt", _DEFSECTION_OPT );
|
---|
| 157 | }
|
---|
| 158 | | declarations
|
---|
| 159 | {
|
---|
| 160 | //cerr << "defsection_opt2: " << $1->text << "(" << $1 << ")" << endl;
|
---|
| 161 | $$ = new Token( "declaration_opt", _DEFSECTION_OPT );
|
---|
| 162 | $$->down = declstart;
|
---|
| 163 | }
|
---|
| 164 | ;
|
---|
| 165 |
|
---|
| 166 | declarations :
|
---|
| 167 | literalblock
|
---|
| 168 | {
|
---|
| 169 | //cerr << "declarations1: " << $1->text << "(" << $1 << ")" << endl;
|
---|
| 170 | $$ = declstart = $1;
|
---|
| 171 | }
|
---|
| 172 | | declaration
|
---|
| 173 | {
|
---|
| 174 | //cerr << "declarations2: " << $1->text << "(" << $1 << ")" << endl;
|
---|
| 175 | $$ = declstart = new Token( "declaration", _DECLARATION );
|
---|
| 176 | $$->down = $1;
|
---|
| 177 | }
|
---|
| 178 | | declarations literalblock
|
---|
| 179 | {
|
---|
| 180 | //cerr << "declarations3: "<< $1->text << "(" << $1 << ") " << $2->text << "(" << $2 << ")" << endl;
|
---|
| 181 | $1->left = $2;
|
---|
| 182 | $$ = $2;
|
---|
| 183 | }
|
---|
| 184 | | declarations declaration
|
---|
| 185 | {
|
---|
| 186 | //cerr << "declarations4: " << $1->text << "(" << $1 << ") " << $2->text << "(" << $2 << ")" << endl;
|
---|
| 187 | $$ = new Token( "declaration", _DECLARATION );
|
---|
| 188 | $1->left = $$;
|
---|
| 189 | $$->down = $2;
|
---|
| 190 | }
|
---|
| 191 | ;
|
---|
| 192 |
|
---|
| 193 | literalblock :
|
---|
| 194 | LCURL
|
---|
| 195 | { lexC(); }
|
---|
| 196 | ccode_opt
|
---|
| 197 | { $<tokenp>$ = new Token( lexYacc(), CODE ); }
|
---|
| 198 | RCURL
|
---|
| 199 | {
|
---|
| 200 | //cerr << "literalblock: " << $1->text << "(" << $1 << ") " << $<tokenp>4->text << " " << $5->text << "(" << $5 << ")" << endl;
|
---|
| 201 | $1->left = $<tokenp>4;
|
---|
| 202 | $<tokenp>4->left = $5;
|
---|
| 203 | $$ = new Token( "literalblock", _LITERALBLOCK );
|
---|
| 204 | $$->down = $1;
|
---|
| 205 | }
|
---|
| 206 | ;
|
---|
| 207 |
|
---|
| 208 | declaration :
|
---|
| 209 | union
|
---|
| 210 | | START IDENTIFIER
|
---|
| 211 | {
|
---|
| 212 | $1->left = $2;
|
---|
| 213 | $$ = $1;
|
---|
| 214 | }
|
---|
| 215 | | rword tag_opt namenolist
|
---|
| 216 | {
|
---|
| 217 | Token *n = new Token( "namenolist", _NAMENOLIST );
|
---|
| 218 | n->down = nameliststart;
|
---|
| 219 | $1->left = $2;
|
---|
| 220 | $2->left = n;
|
---|
| 221 | $$ = $1;
|
---|
| 222 | }
|
---|
| 223 | | TYPE tag_opt namelist
|
---|
| 224 | {
|
---|
| 225 | Token *n = new Token( "namelist", _NAMELIST );
|
---|
| 226 | n->down = nameliststart;
|
---|
| 227 | $1->left = $2;
|
---|
| 228 | $2->left = n;
|
---|
| 229 | $$ = $1;
|
---|
| 230 | }
|
---|
| 231 | | PURE_PARSER
|
---|
| 232 | | SEMANTIC_PARSER
|
---|
| 233 | | EXPECT INTEGER // bison
|
---|
| 234 | {
|
---|
| 235 | $1->left = $2;
|
---|
| 236 | $$ = $1;
|
---|
| 237 | }
|
---|
[81bb114] | 238 | | DEFINE // bison
|
---|
| 239 | | LOCATIONS
|
---|
[c9383ee] | 240 | | THONG // bison
|
---|
[7d4f6ed] | 241 | ;
|
---|
| 242 |
|
---|
| 243 | union :
|
---|
| 244 | UNION '{'
|
---|
| 245 | { lexC(); }
|
---|
| 246 | ccode_opt
|
---|
| 247 | {
|
---|
| 248 | // Remove the trailing '}' which is added in lex.
|
---|
| 249 | string temp( lexYacc() );
|
---|
| 250 | $<tokenp>$ = new Token( temp.substr( 0, temp.length() - 1 ), CODE );
|
---|
| 251 | }
|
---|
| 252 | '}'
|
---|
| 253 | {
|
---|
| 254 | $1->left = $2;
|
---|
| 255 | $2->left = $<tokenp>5;
|
---|
| 256 | $<tokenp>5->left = $6;
|
---|
| 257 | $$ = $1;
|
---|
| 258 | }
|
---|
| 259 | ;
|
---|
| 260 |
|
---|
| 261 | rword :
|
---|
| 262 | TOKEN
|
---|
| 263 | | LEFT
|
---|
| 264 | | RIGHT
|
---|
| 265 | | NONASSOC
|
---|
[fc1ef62] | 266 | | PRECEDENCE
|
---|
[7d4f6ed] | 267 | ;
|
---|
| 268 |
|
---|
| 269 | tag_opt :
|
---|
| 270 | // empty
|
---|
| 271 | {
|
---|
| 272 | //cerr << "tag_opt" << endl;
|
---|
| 273 | $$ = new Token( "tag_opt", _TAG_OPT );
|
---|
| 274 | }
|
---|
| 275 | | '<' IDENTIFIER '>'
|
---|
| 276 | {
|
---|
| 277 | $1->left = $2;
|
---|
| 278 | $2->left = $3;
|
---|
| 279 | $$ = new Token( "tag_opt", _TAG_OPT );
|
---|
| 280 | $$->down = $1;
|
---|
| 281 | }
|
---|
| 282 | ;
|
---|
| 283 |
|
---|
[c9383ee] | 284 | namenolist :
|
---|
| 285 | nameno
|
---|
| 286 | {
|
---|
| 287 | //cerr << "namenolist1: " << $1->text << "(" << $1 << ")" << endl;
|
---|
| 288 | $$ = nameliststart = $1;
|
---|
| 289 | }
|
---|
| 290 | | namenolist nameno
|
---|
| 291 | {
|
---|
| 292 | //cerr << "namenolist2: " << $1->text << "(" << $1 << ") " << $2->text << "(" << $2 << ")" << endl;
|
---|
| 293 | $1->left = $2;
|
---|
| 294 | $$ = $2;
|
---|
| 295 | }
|
---|
| 296 | | namenolist ',' nameno
|
---|
| 297 | {
|
---|
| 298 | //cerr << "namenolist3: " << $1->text << "(" << $1 << ") " << $2->text << "(" << $2 << ") " << $3->text << "(" << $3 << ")" << endl;
|
---|
| 299 | $1->left = $2;
|
---|
| 300 | $2->left = $3;
|
---|
| 301 | $$ = $3;
|
---|
| 302 | }
|
---|
| 303 | ;
|
---|
| 304 |
|
---|
| 305 | nameno :
|
---|
| 306 | name
|
---|
| 307 | {
|
---|
| 308 | $$ = new Token( "nameno", _NAMENO );
|
---|
| 309 | $$->down = $1;
|
---|
| 310 | }
|
---|
| 311 | | name INTEGER
|
---|
| 312 | {
|
---|
| 313 | $$ = new Token( "nameno", _NAMENO );
|
---|
| 314 | $1->left = $2;
|
---|
| 315 | $$->down = $1;
|
---|
| 316 | }
|
---|
| 317 | ;
|
---|
| 318 |
|
---|
| 319 | namelist :
|
---|
| 320 | name
|
---|
| 321 | {
|
---|
| 322 | //cerr << "namelist1: " << $1->text << "(" << $1 << ")" << endl;
|
---|
| 323 | $$ = nameliststart = $1;
|
---|
| 324 | }
|
---|
| 325 | | namelist name
|
---|
| 326 | {
|
---|
| 327 | //cerr << "namelist2: " << $1->text << "(" << $1 << ") " << $2->text << "(" << $2 << ")" << endl;
|
---|
| 328 | $1->left = $2;
|
---|
| 329 | $$ = $2;
|
---|
| 330 | }
|
---|
| 331 | | namelist ',' name
|
---|
| 332 | {
|
---|
| 333 | //cerr << "namelist3: " << $1->text << "(" << $1 << ") " << $2->text << "(" << $2 << ") " << $3->text << "(" << $3 << ")" << endl;
|
---|
| 334 | $1->left = $2;
|
---|
| 335 | $2->left = $3;
|
---|
| 336 | $$ = $3;
|
---|
| 337 | }
|
---|
| 338 | ;
|
---|
| 339 |
|
---|
| 340 | name :
|
---|
| 341 | IDENTIFIER
|
---|
| 342 | | CHARACTER
|
---|
| 343 | ;
|
---|
| 344 |
|
---|
| 345 | rulesection :
|
---|
| 346 | rules
|
---|
| 347 | {
|
---|
| 348 | //cerr << "rulesection1: " << $1->text << "(" << $1 << ")" << endl;
|
---|
| 349 | $$ = new Token( "rulesection", _RULESECTION );
|
---|
| 350 | $$->down = $1;
|
---|
| 351 | }
|
---|
| 352 | | error // no rules
|
---|
| 353 | {
|
---|
| 354 | cerr << "no rules in the input grammar" << endl;
|
---|
| 355 | exit( -1 );
|
---|
| 356 | }
|
---|
| 357 | ;
|
---|
[7d4f6ed] | 358 |
|
---|
| 359 | // These grammar rules are complex because the Yacc language is LR(2) due to the optional ';' at the end of rules. The
|
---|
| 360 | // following rules convert the LR(2) grammar into LR(1) by lengthening the rules to allow sufficient look
|
---|
| 361 | // ahead. Unfortunately, this change makes handling the semantic actions more complex because there are two lists
|
---|
| 362 | // (rules, rhs) being built but only one list tail can be returned through $$ for chaining.
|
---|
| 363 |
|
---|
[c9383ee] | 364 | rules :
|
---|
| 365 | lhs rhs
|
---|
| 366 | {
|
---|
| 367 | //cerr << "rules1: " << $1->text << "(" << $1 << ") " << $2->text << "(" << $2 << ")" << endl;
|
---|
| 368 | $$ = rulestart;
|
---|
| 369 | }
|
---|
| 370 | | lhs rhs ';'
|
---|
| 371 | {
|
---|
| 372 | //cerr << "rules2: " << $1->text << "(" << $1 << ") " << $2->text << "(" << $2 << ") " << $3->text << "(" << $3 << ")" << endl;
|
---|
| 373 | $2->addDownLeftTail( $3 );
|
---|
| 374 | $$ = rulestart;
|
---|
| 375 | }
|
---|
| 376 | ;
|
---|
| 377 |
|
---|
| 378 | lhs :
|
---|
| 379 | IDENTIFIER ':'
|
---|
| 380 | {
|
---|
| 381 | //cerr << "lhs: " << $1->text << "(" << $1 << ") " << $2->text << "(" << $2 << ")" << endl;
|
---|
| 382 | $$ = new Token( "lhs", _LHS );
|
---|
| 383 | //cerr << " lhs: " << $$->text << "(" << $$ << ")" << endl;
|
---|
| 384 | $1->left = $2;
|
---|
| 385 | $$->down = $1;
|
---|
| 386 | }
|
---|
| 387 | ;
|
---|
[7d4f6ed] | 388 |
|
---|
| 389 | rhs :
|
---|
| 390 | // empty
|
---|
| 391 | {
|
---|
| 392 | //cerr << "rhs1: " << $<tokenp>0->text << "(" << $<tokenp>0 << ")" << endl;
|
---|
| 393 | rulestart = new Token( "rule", _RULE );
|
---|
| 394 | rulestart->down = $<tokenp>0; // initial lhs is already on the stack from "rules"
|
---|
| 395 | $$ = new Token( "rhs", _RHS );
|
---|
| 396 | //cerr << " rhs: " << $$->text << "(" << $$ << ")" << endl;
|
---|
| 397 | $<tokenp>0->left = $$;
|
---|
| 398 | }
|
---|
| 399 | | rhs lhs
|
---|
| 400 | {
|
---|
| 401 | //cerr << "rhs2: " << $1->text << "(" << $1 << ") " << $2->text << "(" << $2 << ")" << endl;
|
---|
| 402 | Token *temp = new Token( "rule", _RULE );
|
---|
| 403 | rulestart->addLeftTail( temp );
|
---|
| 404 | temp->down = $2;
|
---|
| 405 | $$ = new Token( "rhs", _RHS );
|
---|
| 406 | //cerr << " rhs: " << $$->text << "(" << $$ << ")" << endl;
|
---|
| 407 | $2->left = $$;
|
---|
| 408 | }
|
---|
| 409 | | rhs ';' lhs
|
---|
| 410 | {
|
---|
| 411 | //cerr << "rhs3: " << $1->text << "(" << $1 << ") " << $2->text << "(" << $2 << ") " << $3->text << "(" << $3 << ")" << endl;
|
---|
| 412 | $1->addDownLeftTail( $2 );
|
---|
| 413 | Token *temp = new Token( "rule", _RULE );
|
---|
| 414 | rulestart->addLeftTail( temp );
|
---|
| 415 | temp->down = $3;
|
---|
| 416 | $$ = new Token( "rhs", _RHS );
|
---|
| 417 | //cerr << " rhs: " << $$->text << "(" << $$ << ")" << endl;
|
---|
| 418 | $3->left = $$;
|
---|
| 419 | }
|
---|
| 420 | | rhs prod
|
---|
| 421 | {
|
---|
| 422 | //cerr << "rhs4: " << $1->text << "(" << $1 << ") " << $2->text << "(" << $2 << ")" << endl;
|
---|
| 423 | $1->addDownLeftTail( $2 );
|
---|
| 424 | $$ = $1;
|
---|
| 425 | }
|
---|
| 426 | | rhs '|'
|
---|
| 427 | {
|
---|
| 428 | //cerr << "rhs5: " << $1->text << "(" << $1 << ") " << $2->text << "(" << $2 << ")" << endl;
|
---|
| 429 | $1->addDownLeftTail( $2 );
|
---|
| 430 | $$ = new Token( "rhs", _RHS );
|
---|
| 431 | $1->left = $$;
|
---|
| 432 | //cerr << " rhs: " << $$->text << "(" << $$ << ")" << endl;
|
---|
| 433 | }
|
---|
| 434 | ;
|
---|
| 435 |
|
---|
| 436 | prod :
|
---|
| 437 | action
|
---|
| 438 | | IDENTIFIER
|
---|
| 439 | | CHARACTER
|
---|
| 440 | | prec
|
---|
| 441 | ;
|
---|
| 442 |
|
---|
| 443 | prec :
|
---|
| 444 | PREC name
|
---|
| 445 | {
|
---|
| 446 | //cerr << "prec: " << $1->text << "(" << $1 << ") " << $2->text << "(" << $2 << ")" << endl;
|
---|
| 447 | $1->left = $2;
|
---|
| 448 | $$ = new Token( "prec", _PREC );
|
---|
| 449 | $$->down = $1;
|
---|
| 450 | }
|
---|
| 451 | ;
|
---|
| 452 |
|
---|
| 453 | action :
|
---|
| 454 | '{'
|
---|
| 455 | { lexC(); }
|
---|
| 456 | ccode_opt
|
---|
| 457 | {
|
---|
| 458 | // Remove the trailing '}' added in lex.
|
---|
| 459 | string temp( lexYacc() );
|
---|
| 460 | $<tokenp>$ = new Token( temp.substr( 0, temp.length() - 1 ), CODE );
|
---|
| 461 | }
|
---|
| 462 | '}'
|
---|
| 463 | {
|
---|
| 464 | $1->left = $<tokenp>4;
|
---|
| 465 | $<tokenp>4->left = $5;
|
---|
| 466 | $$ = new Token( "action", _ACTION );
|
---|
| 467 | $$->down = $1;
|
---|
| 468 | }
|
---|
| 469 | ;
|
---|
| 470 |
|
---|
| 471 | usersection_opt :
|
---|
| 472 | // empty
|
---|
| 473 | {
|
---|
| 474 | //cerr << "usersection_opt" << endl;
|
---|
| 475 | // attach remaining WS to fictitious code
|
---|
| 476 | Token *temp = new Token( "", ws_list, CODE );
|
---|
| 477 | $$ = new Token( "usersection_opt", _USERSECTION_OPT );
|
---|
| 478 | $$->down = temp;
|
---|
| 479 | }
|
---|
| 480 | | MARK
|
---|
| 481 | { lexC(); }
|
---|
| 482 | ccode_opt
|
---|
| 483 | {
|
---|
| 484 | Token *temp = new Token( lexYacc(), CODE );
|
---|
| 485 | //cerr << "usersection_opt: " << $1->text << " " << temp->text << endl;
|
---|
| 486 | $1->left = temp;
|
---|
| 487 | $$ = new Token( "usersection_opt", _USERSECTION_OPT );
|
---|
| 488 | $$->down = $1;
|
---|
| 489 | }
|
---|
| 490 | ;
|
---|
| 491 |
|
---|
| 492 | ccode_opt :
|
---|
| 493 | // empty
|
---|
[c9383ee] | 494 | {}
|
---|
[7d4f6ed] | 495 | | blocks
|
---|
| 496 | ;
|
---|
| 497 |
|
---|
| 498 | // This rule matches internal braces "{}" in C code to the level of the braces of a union/action. These internal braces
|
---|
| 499 | // are returned as Tokens from the lexer but are unused because the braces are already concatenated into the code string
|
---|
| 500 | // built by the lexer. Therefore, the tokens for the braces are immediately deleted.
|
---|
| 501 |
|
---|
| 502 | blocks :
|
---|
| 503 | '{'
|
---|
| 504 | { delete $1; }
|
---|
| 505 | ccode_opt '}'
|
---|
| 506 | { delete $4; }
|
---|
| 507 | | blocks '{'
|
---|
| 508 | { delete $2; }
|
---|
| 509 | ccode_opt '}'
|
---|
| 510 | { delete $5; }
|
---|
| 511 | ;
|
---|
| 512 | %%
|
---|
| 513 |
|
---|
| 514 | // Local Variables: //
|
---|
| 515 | // mode: c++ //
|
---|
| 516 | // tab-width: 4 //
|
---|
| 517 | // compile-command: "make install" //
|
---|
| 518 | // End: //
|
---|