home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ssvpar.zip / SSCALC.YCC < prev    next >
Text File  |  1994-12-01  |  3KB  |  95 lines

  1. //--------------------------------------------------------------
  2. //
  3. // Copyright (c) 1994 SandStone Technology Inc.
  4. // All rights reserved.
  5. //
  6. // This is the calculator rule file described in the Visual
  7. // Parse++ Guide and Reference.
  8. //
  9. //--------------------------------------------------------------
  10. %expression Main
  11.  
  12. '[ \n\t]+'               %ignore;
  13. '/\*'                    %ignore, %push MLCom;
  14. '//'                     %ignore, %push SLCom;
  15. ';'                      End, ';';
  16. '\+'                     Plus, '+';
  17. '\-'                     Minus, '-';
  18. '\/'                     Div, '/';
  19. '\*'                     Mult, '*';
  20. '%'                      Mod, '%';
  21. '\*\*'                   Pow, '**';
  22. '[oO][rR]'               Or 'or';
  23. '[aA][nN][dD]'           And 'and';
  24. '[nN][oO][tT]'           Not 'not';
  25. '\('                     OParen, '(';
  26. '\)'                     CParen, ')';
  27. '[1-9][0-9]*'            Dec, 'dec';
  28. '0[0-7]*'                Oct, 'oct';
  29. '0(x|X)[0-9a-fA-F]+'     Hex, 'hex';
  30.  
  31. //------------------------------------------------------------------------
  32. //
  33. // Process multi line comments
  34. //
  35. //------------------------------------------------------------------------
  36. %expression MLCom
  37.  
  38. '.'                      %ignore;
  39. '\n'                     %ignore;
  40. '\*/'                    %ignore, %pop;
  41.  
  42. //------------------------------------------------------------------------
  43. //
  44. // Process single line comments
  45. //
  46. //------------------------------------------------------------------------
  47. %expression SLCom
  48.  
  49. '.'                      %ignore;
  50. '\n'                     %ignore, %pop;
  51.  
  52. //------------------------------------------------------------------------
  53. //
  54. // Precedence table
  55. //
  56. //------------------------------------------------------------------------
  57. %prec
  58.  
  59. 1, '+',   %left;
  60. 1, '-',   %left;
  61. 1, 'or',  %left;
  62. 2, '*',   %left;
  63. 2, '/',   %left;
  64. 2, '%',   %left;
  65. 2, 'and', %left;
  66. 2, 'not', %right;
  67. 3, '**',  %right;
  68.  
  69. //------------------------------------------------------------------------
  70. //
  71. // Grammar
  72. //
  73. //------------------------------------------------------------------------
  74. %production start
  75.  
  76. Start         start         -> exprStatement;
  77. StartList     start         -> start exprStatement;
  78.  
  79. ExprSingle    exprStatement -> expr ';';
  80. ExprError     exprStatement -> %error ';';
  81.  
  82. ExprPlus      expr          -> expr '+'  expr;
  83. ExprMinus     expr          -> expr '-'  expr;
  84. ExprMult      expr          -> expr '*'  expr;
  85. ExprDiv       expr          -> expr '/'  expr;
  86. ExprMod       expr          -> expr '%'  expr;
  87. ExprNot       expr          -> 'not' expr;
  88. ExprAnd       expr          -> expr 'and' expr;
  89. ExprOr        expr          -> expr 'or' expr;
  90. ExprNested    expr          -> '(' expr ')';
  91. ExprNumber    expr          -> number;
  92. NumberDec     number        -> 'dec';
  93. NumberOct     number        -> 'oct';
  94. NumberHex     number        -> 'hex';
  95.