Mercurial > hg > octave-nkf
annotate examples/code/funcdemo.cc @ 20800:7c0e10f035bd
Extend parser to accept binary constants that begin with '0b' or '0B'.
* NEWS: Announce change:
* lex.ll: Define NUMBIN to be 0[bB] followed by 0,1, or '_'.
Define NUMBER to be NUMREAL|NUMHEX|NUMBIN.
*lex.ll (looks_like_bin): New function to detect 0[bB] prefix.
*lex.ll (handle_numbe): Call looks_like_bin() and if found then convert
binary string to double.
* parser.tst: Add tests for new behavior.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 09 Oct 2015 18:52:58 -0700 |
parents | 2f8500ca91d3 |
children |
rev | line source |
---|---|
6572 | 1 #include <octave/oct.h> |
2 #include <octave/parse.h> | |
3 | |
4 DEFUN_DLD (funcdemo, args, nargout, "Function Demo") | |
5 { | |
16867
be41c30bcb44
Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
6 octave_value_list retval; |
20753
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
7 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
9932
diff
changeset
|
8 int nargin = args.length (); |
6572 | 9 |
10 if (nargin < 2) | |
11 print_usage (); | |
20753
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
12 |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
13 octave_value_list newargs; |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
14 |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
15 for (octave_idx_type i = nargin - 1; i > 0; i--) |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
16 newargs(i-1) = args(i); |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
17 |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
18 if (args(0).is_function_handle () || args(0).is_inline_function ()) |
6572 | 19 { |
20753
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
20 octave_function *fcn = args(0).function_value (); |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
21 |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
22 retval = feval (fcn, newargs, nargout); |
6572 | 23 } |
20753
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
24 else if (args(0).is_string ()) |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
25 { |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
26 std::string fcn = args(0).string_value (); |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
27 |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
28 retval = feval (fcn, newargs, nargout); |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
29 } |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
30 else |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
31 error ("funcdemo: INPUT must be string, inline, or function handle"); |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
32 |
6572 | 33 return retval; |
34 } |