btcs

bitcoin script parser/evaluator/compiler/decompiler
git clone git://jb55.com/btcs
Log | Files | Refs | README | LICENSE

parser.y (1206B)


      1 
      2 %{
      3 #include <stdio.h>
      4 #include "op.h"
      5 #include "script.h"
      6 #include "stack.h"
      7 #include "valstack.h"
      8 
      9 extern int yylex();
     10 extern struct stack g_reader_stack;
     11 void yyerror(const char *s);
     12 
     13 void script_handle_input(struct stack *stack, const char *str);
     14 void parse_error(const char *err);
     15 
     16 %}
     17 
     18 %union {
     19   enum opcode opcode;
     20   s64 integer;
     21   struct val val;
     22   const char* str;
     23 }
     24 
     25 %token T_OP
     26 %token T_INT
     27 %token T_VAL
     28 %token T_DATA
     29 %token T_RAW
     30 %token T_STR
     31 %token T_COMMENT
     32 %token T_ERR
     33 %token T_NEWLINE T_QUIT T_EXAMPLE
     34 
     35 %type<opcode> T_OP
     36 %type<integer> T_INT
     37 %type<str> T_DATA
     38 %type<str> T_RAW
     39 %type<str> T_STR
     40 %type<val> T_VAL
     41 %type<str> T_EXAMPLE
     42 %type<str> T_ERR
     43 
     44 %start script
     45 
     46 %%
     47 
     48 script:
     49       | script line
     50 ;
     51 
     52 line: T_NEWLINE
     53     | T_COMMENT
     54     | T_RAW     { script_push_raw(&g_reader_stack, $1); }
     55     | T_INT     { script_push_int(&g_reader_stack, $1); }
     56     | T_VAL     { stack_push_val(&g_reader_stack, $1); }
     57     | T_OP      { stack_push_op(&g_reader_stack, $1); }
     58     | T_DATA    { script_push_datastr(&g_reader_stack, $1, 0); }
     59     | T_STR     { script_push_str(&g_reader_stack, $1); }
     60     | T_ERR     { parse_error($1); }
     61     | T_EXAMPLE { script_handle_input(&g_reader_stack, $1); }
     62 
     63 
     64 %%