comparison libinterp/parse-tree/lex.ll @ 16121:bdf365c5c9bf

maint: move function definition in lex.ll
author John W. Eaton <jwe@octave.org>
date Tue, 26 Feb 2013 12:26:02 -0500
parents 4b68eb9b98b0
children 6884401b2fbb
comparison
equal deleted inserted replaced
16120:4b68eb9b98b0 16121:bdf365c5c9bf
1356 retval.resize (pos); 1356 retval.resize (pos);
1357 1357
1358 return retval; 1358 return retval;
1359 } 1359 }
1360 1360
1361 DEFUN (__display_tokens__, args, nargout,
1362 "-*- texinfo -*-\n\
1363 @deftypefn {Built-in Function} {} __display_tokens__ ()\n\
1364 Query or set the internal variable that determines whether Octave's\n\
1365 lexer displays tokens as they are read.\n\
1366 @end deftypefn")
1367 {
1368 return SET_INTERNAL_VARIABLE (display_tokens);
1369 }
1370
1371 DEFUN (__token_count__, , ,
1372 "-*- texinfo -*-\n\
1373 @deftypefn {Built-in Function} {} __token_count__ ()\n\
1374 Number of language tokens processed since Octave startup.\n\
1375 @end deftypefn")
1376 {
1377 return octave_value (Vtoken_count);
1378 }
1379
1380 DEFUN (__lexer_debug_flag__, args, nargout,
1381 "-*- texinfo -*-\n\
1382 @deftypefn {Built-in Function} {@var{old_val} =} __lexer_debug_flag__ (@var{new_val}))\n\
1383 Undocumented internal function.\n\
1384 @end deftypefn")
1385 {
1386 octave_value retval;
1387
1388 retval = set_internal_variable (lexer_debug_flag, args, nargout,
1389 "__lexer_debug_flag__");
1390
1391 return retval;
1392 }
1393
1394 class
1395 flex_stream_reader : public stream_reader
1396 {
1397 public:
1398 flex_stream_reader (lexical_feedback *l, char *buf_arg)
1399 : stream_reader (), lexer (l), buf (buf_arg)
1400 { }
1401
1402 int getc (void) { return lexer->text_yyinput (); }
1403 int ungetc (int c) { lexer->xunput (c, buf); return 0; }
1404
1405 private:
1406
1407 // No copying!
1408
1409 flex_stream_reader (const flex_stream_reader&);
1410
1411 flex_stream_reader& operator = (const flex_stream_reader&);
1412
1413 lexical_feedback *lexer;
1414
1415 char *buf;
1416 };
1417
1418 lexical_feedback::~lexical_feedback (void)
1419 {
1420 // Clear out the stack of token info used to track line and
1421 // column numbers.
1422
1423 while (! token_stack.empty ())
1424 {
1425 delete token_stack.top ();
1426 token_stack.pop ();
1427 }
1428 }
1429
1361 int 1430 int
1362 lexical_feedback::octave_read (char *buf, unsigned max_size) 1431 lexical_feedback::octave_read (char *buf, unsigned max_size)
1363 { 1432 {
1364 static const char * const eol = "\n"; 1433 static const char * const eol = "\n";
1365 static std::string input_buf; 1434 static std::string input_buf;
1418 if (! eof) 1487 if (! eof)
1419 YY_FATAL_ERROR ("octave_read () in flex scanner failed"); 1488 YY_FATAL_ERROR ("octave_read () in flex scanner failed");
1420 } 1489 }
1421 1490
1422 return status; 1491 return status;
1423 }
1424
1425 DEFUN (__display_tokens__, args, nargout,
1426 "-*- texinfo -*-\n\
1427 @deftypefn {Built-in Function} {} __display_tokens__ ()\n\
1428 Query or set the internal variable that determines whether Octave's\n\
1429 lexer displays tokens as they are read.\n\
1430 @end deftypefn")
1431 {
1432 return SET_INTERNAL_VARIABLE (display_tokens);
1433 }
1434
1435 DEFUN (__token_count__, , ,
1436 "-*- texinfo -*-\n\
1437 @deftypefn {Built-in Function} {} __token_count__ ()\n\
1438 Number of language tokens processed since Octave startup.\n\
1439 @end deftypefn")
1440 {
1441 return octave_value (Vtoken_count);
1442 }
1443
1444 DEFUN (__lexer_debug_flag__, args, nargout,
1445 "-*- texinfo -*-\n\
1446 @deftypefn {Built-in Function} {@var{old_val} =} __lexer_debug_flag__ (@var{new_val}))\n\
1447 Undocumented internal function.\n\
1448 @end deftypefn")
1449 {
1450 octave_value retval;
1451
1452 retval = set_internal_variable (lexer_debug_flag, args, nargout,
1453 "__lexer_debug_flag__");
1454
1455 return retval;
1456 }
1457
1458 class
1459 flex_stream_reader : public stream_reader
1460 {
1461 public:
1462 flex_stream_reader (lexical_feedback *l, char *buf_arg)
1463 : stream_reader (), lexer (l), buf (buf_arg)
1464 { }
1465
1466 int getc (void) { return lexer->text_yyinput (); }
1467 int ungetc (int c) { lexer->xunput (c, buf); return 0; }
1468
1469 private:
1470
1471 // No copying!
1472
1473 flex_stream_reader (const flex_stream_reader&);
1474
1475 flex_stream_reader& operator = (const flex_stream_reader&);
1476
1477 lexical_feedback *lexer;
1478
1479 char *buf;
1480 };
1481
1482 lexical_feedback::~lexical_feedback (void)
1483 {
1484 // Clear out the stack of token info used to track line and
1485 // column numbers.
1486
1487 while (! token_stack.empty ())
1488 {
1489 delete token_stack.top ();
1490 token_stack.pop ();
1491 }
1492 } 1492 }
1493 1493
1494 // GAG. 1494 // GAG.
1495 // 1495 //
1496 // If we're reading a matrix and the next character is '[', make sure 1496 // If we're reading a matrix and the next character is '[', make sure