## cool / src / lib / GMLMIP-0.1 / parser / mlf-parser.yy @ 7c4d2eb4

History | View | Annotate | Download (2.38 KB)

1 | e034e268 | Thorsten Wißmann | %skeleton "lalr1.cc" |
---|---|---|---|

2 | %require "2.4" |
||

3 | %defines |
||

4 | %define parser_class_name "mlf_parser" |
||

5 | |||

6 | %code requires { |
||

7 | #include <string> |
||

8 | #include "bdd.h" |
||

9 | #include "../formulas/GML_formula.h" |
||

10 | #include "../formulas/PML_formula.h" |
||

11 | #include "../formulas/rational.h" |
||

12 | |||

13 | using namespace std; |
||

14 | |||

15 | class mlf_driver; |
||

16 | #define YYSTYPE ParserType |
||

17 | |||

18 | struct ParserType |
||

19 | { |
||

20 | int number; |
||

21 | struct fraction { |
||

22 | int numerator; |
||

23 | int denominator; |
||

24 | } fraction; |
||

25 | bdd binarydd; |
||

26 | }; |
||

27 | } |
||

28 | |||

29 | |||

30 | |||

31 | // Parsing context |
||

32 | %parse-param { mlf_driver& driver} |
||

33 | %lex-param { mlf_driver& driver} |
||

34 | |||

35 | %locations |
||

36 | %initial-action { |
||

37 | // Initialize the initial location. |
||

38 | @$.begin.filename = @$.end.filename = &driver.file; |
||

39 | }; |
||

40 | |||

41 | %debug |
||

42 | %error-verbose |
||

43 | |||

44 | %code { |
||

45 | #include "mlf-driver.h" |
||

46 | } |
||

47 | |||

48 | /* operators and precendences */ |
||

49 | %nonassoc IFF |
||

50 | %right IMP |
||

51 | %left OR |
||

52 | %left AND |
||

53 | %nonassoc <number> GMDIA GMBOX |
||

54 | %nonassoc <fraction> PMDIA PMBOX |
||

55 | %nonassoc <binarydd> PVAR |
||

56 | %nonassoc NOT TRUE FALSE |
||

57 | |||

58 | /* auxiliary */ |
||

59 | %token END 0 "end of file" |
||

60 | %token LPAREN |
||

61 | %token RPAREN |
||

62 | |||

63 | %token GML |
||

64 | %token PML |
||

65 | //%token PMLI |
||

66 | |||

67 | // %printer { debug_stream () << $$; } "identifier" |
||

68 | %destructor { delete &$$; } "identifier" |
||

69 | |||

70 | %type <binarydd> formula |
||

71 | |||

72 | %% |
||

73 | input: |
||

74 | spec |
||

75 | formula {driver.set_formula_bdd($2); } |
||

76 | ; |
||

77 | |||

78 | spec: |
||

79 | GML {driver.set_formula_gml();} |
||

80 | | PML {driver.set_formula_pml();} |
||

81 | //| PMLI {} |
||

82 | ; |
||

83 | |||

84 | formula: |
||

85 | formula IFF formula { $$ = bdd_biimp($1,$3); } |
||

86 | | formula IMP formula { $$ = bdd_imp($1,$3); } |
||

87 | | formula OR formula { $$ = bdd_or($1,$3); } |
||

88 | | formula AND formula { $$ = bdd_and($1,$3); } |
||

89 | |||

90 | | GMDIA formula { bdd* b = new bdd($2); $$ = driver.modal(b, $1, 0); } |
||

91 | | GMBOX formula { bdd* b = new bdd(bdd_not($2)); $$ = bdd_not(driver.modal(b, $1, 0)); } // box is not-dia-not |
||

92 | |||

93 | | PMDIA formula { bdd* b = new bdd($2); $$ = driver.modal(b, $1.numerator, $1.denominator); } |
||

94 | | PMBOX formula { bdd* b = new bdd(bdd_not($2)); $$ = bdd_not(driver.modal(b, $1.numerator, $1.denominator)); } |
||

95 | |||

96 | | NOT formula { $$ = bdd_not($2); } |
||

97 | | PVAR { $$ = $$; } |
||

98 | | TRUE { $$ = bdd_true(); } |
||

99 | | FALSE { $$ = bdd_false(); } |
||

100 | | LPAREN formula RPAREN { $$ = $2; } |
||

101 | ; |
||

102 | %% |
||

103 | |||

104 | |||

105 | void yy::mlf_parser::error (const yy::mlf_parser::location_type& l, const std::string& m){ |
||

106 | driver.error (l, m); |
||

107 | } |
||

108 | |||

109 | |||

110 | |||

111 |