SHARE
TWEET

bison.y

deadlykingdx Jun 28th, 2020 1,294 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %{
  2.     #include <cstdio>
  3.     #include <string>
  4.     #include <iostream>
  5.     #include <stack>
  6.  
  7.     extern FILE* yyin;
  8. %}
  9. %token identifier CLASS DEF COLON LBRACE RBRACE
  10.  
  11. %%
  12. class_def: CLASS classname COLON stuff
  13.     {
  14.         int indent = @1.last_column;
  15.         newclass new_class($2, indent);
  16.     }
  17. ;
  18. classname: identifier
  19.     {
  20.         $$ = $1;
  21.     }
  22. ;
  23.  
  24. func_def: DEF funcname LBRACE [parameter_list] RBRACE COLON stuff
  25.     {
  26.         int ident = @1.last_column
  27.         newfunc new_func($2, indent)
  28.  
  29.     }
  30. ;
  31. funcname: identifier
  32.     {
  33.         $$ = $1;
  34.     }
  35. parameter_list: parameter //care
  36.     {
  37.         $$ = $1;
  38.     }
  39.     |
  40.     {
  41.         $$ = "";
  42.     }
  43. ;
  44. parameter: parameter COMMA
  45.     {
  46.         $$ += $2;
  47.     }
  48. ;
  49. stuff:
  50. ;
  51.  
  52. int main()
  53. {
  54.     return yyparse();
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top