1 package antlr;
2
3 * <b>SOFTWARE RIGHTS</b>
5 * <p>
6 * ANTLR 2.5.0 MageLang Institute, 1998
7 * <p>
8 * We reserve no legal rights to the ANTLR--it is fully in the
9 * public domain. An individual or company may do whatever
10 * they wish with source code distributed with ANTLR or the
11 * code generated by ANTLR, including the incorporation of
12 * ANTLR, or its output, into commerical software.
13 * <p>
14 * We encourage users to develop software with ANTLR. However,
15 * we do ask that credit is given to us for developing
16 * ANTLR. By "credit", we mean that if you use ANTLR or
17 * incorporate any source code into one of your programs
18 * (commercial product, research project, or otherwise) that
19 * you acknowledge this fact somewhere in the documentation,
20 * research report, etc... If you like ANTLR and have
21 * developed a nice tool with the output, please mention that
22 * you developed it using ANTLR. In addition, we ask that the
23 * headers remain intact in our source code. As long as these
24 * guidelines are kept, we expect to continue enhancing this
25 * system and expect to make other tools available as they are
26 * completed.
27 * <p>
28 * The ANTLR gang:
29 * @version ANTLR 2.5.0 MageLang Institute, 1998
30 * @author Terence Parr, <a href=http://www.MageLang.com>MageLang Institute</a>
31 * @author <br>John Lilley, <a href=http://www.Empathy.com>Empathy Software</a>
32 */
33 class StringLiteralElement extends GrammarAtom {
34 protected String processedAtomText;
36
37
38 public StringLiteralElement(Grammar g, Token t, int autoGenType) {
39 super(g, t, autoGenType);
40 if (!(g instanceof LexerGrammar)) {
41 TokenSymbol ts = grammar.tokenManager.getTokenSymbol(atomText);
43 if (ts == null) {
44 g.tool.error("Undefined literal: " + atomText, t.getLine());
45 } else {
46 tokenType = ts.getTokenType();
47 }
48 }
49 line = t.getLine();
50
51 processedAtomText = new String();
54 for (int i = 1; i < atomText.length()-1; i++)
55 {
56 char c = atomText.charAt(i);
57 if (c == '\\') {
58 if (i+1 < atomText.length()-1) {
59 i++;
60 c = atomText.charAt(i);
61 switch (c) {
62 case 'n' : c = '\n'; break;
63 case 'r' : c = '\r'; break;
64 case 't' : c = '\t'; break;
65 }
66 }
67 }
68 if (g instanceof LexerGrammar) {
69 ((LexerGrammar)g).charVocabulary.add(c);
70 }
71 processedAtomText += c;
72 }
73 }
74 public void generate() {
75 grammar.generator.gen(this);
76 }
77 public Lookahead look(int k) {
78 return grammar.theLLkAnalyzer.look(k, this);
79 }
80 }
81