source: other-projects/rsyntax-textarea/devel-packages/jflex-1.4.3/examples/interpreter/scanner.flex@ 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: 2.8 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
22import java_cup.runtime.Symbol;
23
24%%
25
26%cup
27%implements sym
28
29%{
30 SymTab symtab; // externe symbol table
31
32 public void setSymtab(SymTab symtab) {
33 this.symtab = symtab;
34 }
35
36 private Symbol sym(int sym) {
37 return new Symbol(sym);
38 }
39
40 private Symbol sym(int sym, Object val) {
41 return new Symbol(sym, val);
42 }
43%}
44
45%%
46
47"arguments" { return sym(ARGUMENTS); }
48"input" { return sym(INPUT); }
49"functions" { return sym(FUNCTIONS); }
50"output" { return sym(OUTPUT); }
51"end" { return sym(END); }
52"if" { return sym(IF); }
53"then" { return sym(THEN); }
54"else" { return sym(ELSE); }
55"fi" { return sym(FI); }
56[a-z]+ { symtab.enter(yytext(),new SymtabEntry(yytext()));
57 return sym(ID,yytext()); }
58[0-9]+ { return sym(NUMBER,yytext()); }
59"," { return sym(COMMA); }
60"(" { return sym(LPAR); }
61")" { return sym(RPAR); }
62"=" { return sym(EQ); }
63"-" { return sym(MINUS); }
64"+" { return sym(PLUS); }
65"*" { return sym(TIMES); }
66"/" { return sym(DIV); }
67"<" { return sym(LE); }
68"<=" { return sym(LEQ); }
69[\ \t\b\f\r\n]+ { /* eat whitespace */ }
70"//"[^\n]* { /* one-line comment */ }
71. { throw new Error("Unexpected character ["+yytext()+"]"); }
Note: See TracBrowser for help on using the repository browser.