Tedd OKANO
/
RPN_calc__based_on_K_and_R
just a sample of what can be done
PRN電卓プログラム
「プログラミング言語C (K&R本)」に出てくる例を元にした,RPN計算機です.
写真はイメージです
このプログラムは..
- 『mbed祭り 2015@初夏の東銀座』の親睦会で「RPN」と題して行ったLT(LightningTalk)でのデモ・プログラムです.
- mbed LPC1768,mbed LPC1114FN28で実行できることを確認しています(たぶん他のプラットフォームでも動きます)
- プレゼンスライドを置いておきます
stack.cpp
- Committer:
- okano
- Date:
- 2015-06-27
- Revision:
- 5:3b9daee5f734
- Parent:
- 4:b4c8aee2ecad
File content as of revision 5:3b9daee5f734:
#include "mbed.h" #include "calc.h" #define MAXVAL 100 int sp = 0; double val[ MAXVAL ]; void push( double f ) { if ( sp < MAXVAL ) val[ sp++ ] = f; else printf( "error: stack full, can't push %g\n", f ); } double pop( void ) { if ( sp > 0 ) return val[ --sp ]; else { printf( "error: stack empty\n" ); return 0.0; } } void show_stack( void ) { for ( int i = 0; i < sp; i++ ) printf( "%3d: %f\n", ((sp - 1) - i), val[ i ] ); }