source: other-projects/rsyntax-textarea/devel-packages/jflex-1.4.3/examples/interpreter/parser.cup@ 25584

Last change on this file since 25584 was 25584, checked in by davidb, 12 years ago

Initial cut an a text edit area for GLI that supports color syntax highlighting

File size: 4.3 KB
Line 
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Copyright (C) 2001 Gerwin Klein <[email protected]> *
3 * Copyright (C) 2001 Bernhard Rumpe <[email protected]> *
4 * All rights reserved. *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License. See the file *
8 * COPYRIGHT for more information. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License along *
16 * with this program; if not, write to the Free Software Foundation, Inc., *
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
18 * *
19 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
20
21
22// definition of tokens, if applicable with token type
23terminal INPUT, FUNCTIONS, OUTPUT, END, ARGUMENTS;
24terminal IF, THEN, ELSE, FI, ERROR;
25terminal COMMA, LPAR, RPAR;
26terminal EQ, LE, LEQ, MINUS, PLUS, TIMES, DIV, UMINUS;
27
28terminal String ID, NUMBER;
29
30non terminal Tprogram program;
31non terminal Tparlist parlist;
32non terminal Texplist explist;
33non terminal Tdekllist dekllist;
34non terminal Tdekl dekl;
35non terminal Texp exp;
36non terminal Tboolexp boolexp;
37non terminal Tident ident;
38non terminal Tnumber number;
39
40
41// precedences, left associativity
42precedence left EQ, LE, LEQ;
43precedence left MINUS, PLUS;
44precedence left TIMES, DIV;
45precedence left UMINUS;
46
47
48// here the rules start
49program ::= INPUT parlist:p FUNCTIONS dekllist:d OUTPUT explist:o
50 ARGUMENTS explist:a END
51 {: RESULT = new Tprogram(p,d,o,a); :}
52 ;
53
54parlist ::= ident:i
55 {: RESULT = new Tparlist(i); :}
56 | parlist:p COMMA ident:i
57 {: RESULT = new Tparlist(p,i); :}
58 ;
59
60explist ::= exp:e
61 {: RESULT = new Texplist(e); :}
62 | explist:l COMMA exp:e
63 {: RESULT = new Texplist(l,e); :}
64 ;
65
66dekllist ::= dekl:d
67 {: RESULT = new Tdekllist(d);:}
68 | dekllist:l COMMA dekl:d
69 {: RESULT = new Tdekllist(l,d); :}
70 ;
71
72dekl ::= ident:i LPAR parlist:p RPAR EQ exp:e
73 {: RESULT = new Tdekl(i,p,e); :}
74 ;
75
76exp ::= number:n
77 {: RESULT = n; :}
78 | ident:i
79 {: RESULT = i; :}
80 | ident:i LPAR explist:e RPAR
81 {: RESULT = new Tfun(i,e); :}
82 | LPAR exp:e RPAR
83 {: RESULT = e; :}
84 | MINUS exp:e
85 {: RESULT = new Tuminus(e); :} %prec UMINUS
86 | exp:l PLUS exp:r
87 {: RESULT = new Texpinfix(l,'+',r); :}
88 | exp:l TIMES exp:r
89 {: RESULT = new Texpinfix(l,'*',r); :}
90 | exp:l DIV exp:r
91 {: RESULT = new Texpinfix(l,'/',r); :}
92 | exp:l MINUS exp:r
93 {: RESULT = new Texpinfix(l,'-',r); :}
94 | IF boolexp:b THEN exp:t ELSE exp:e FI
95 {: RESULT = new Tifthenelse(b,t,e); :}
96 ;
97
98boolexp ::= exp:l EQ exp:r
99 {: RESULT = new Tboolexp(l,'=',r); :}
100 | exp:l LE exp:r
101 {: RESULT = new Tboolexp(l,'<',r); :}
102 | exp:l LEQ exp:r
103 {: RESULT = new Tboolexp(l,'!',r); :}
104 ;
105
106ident ::= ID:n
107 {: RESULT = new Tident(n); :}
108 ;
109
110number ::= NUMBER:z
111 {: RESULT = new Tnumber(z); :}
112 ;
Note: See TracBrowser for help on using the repository browser.