1 22 23 package net.percederberg.grammatica.output; 24 25 import java.io.IOException ; 26 27 import net.percederberg.grammatica.Grammar; 28 import net.percederberg.grammatica.code.CodeStyle; 29 import net.percederberg.grammatica.parser.ProductionPattern; 30 import net.percederberg.grammatica.parser.TokenPattern; 31 32 41 public class VisualBasicParserGenerator extends ParserGenerator { 42 43 46 private String baseName = null; 47 48 51 private String namespace = null; 52 53 56 private boolean publicAccess = false; 57 58 63 public VisualBasicParserGenerator(Grammar grammar) { 64 super(grammar); 65 initialize(); 66 } 67 68 71 private void initialize() { 72 String str; 73 74 str = getGrammar().getFileName(); 76 if (str.indexOf('/') >= 0) { 77 str = str.substring(str.lastIndexOf('/') + 1); 78 } 79 if (str.indexOf('\\') >= 0) { 80 str = str.substring(str.lastIndexOf('\\') + 1); 81 } 82 if (str.indexOf('.') > 0) { 83 str = str.substring(0, str.indexOf('.')); 84 } 85 if (Character.isLowerCase(str.charAt(0))) { 86 str = Character.toUpperCase(str.charAt(0)) + str.substring(1); 87 } 88 baseName = str; 89 } 90 91 97 public String getNamespace() { 98 return namespace; 99 } 100 101 106 public void setNamespace(String namespace) { 107 this.namespace = namespace; 108 } 109 110 115 public String getBaseName() { 116 return baseName; 117 } 118 119 124 public void setBaseName(String name) { 125 this.baseName = name; 126 } 127 128 134 public boolean getPublicAccess() { 135 return publicAccess; 136 } 137 138 143 public void setPublicAccess(boolean flag) { 144 publicAccess = flag; 145 } 146 147 152 public CodeStyle getCodeStyle() { 153 return CodeStyle.VISUAL_BASIC; 154 } 155 156 161 public void write() throws IOException { 162 Grammar grammar = getGrammar(); 163 VisualBasicConstantsFile constants; 164 VisualBasicTokenizerFile tokenizer; 165 VisualBasicParserFile parser; 166 VisualBasicAnalyzerFile analyzer; 167 TokenPattern token; 168 ProductionPattern production; 169 int i; 170 171 constants = new VisualBasicConstantsFile(this); 173 tokenizer = new VisualBasicTokenizerFile(this); 174 parser = new VisualBasicParserFile(this, tokenizer); 175 analyzer = new VisualBasicAnalyzerFile(this); 176 177 for (i = 0; i < grammar.getTokenPatternCount(); i++) { 179 token = grammar.getTokenPattern(i); 180 constants.addToken(token); 181 tokenizer.addToken(token, constants); 182 analyzer.addToken(token, constants); 183 } 184 185 for (i = 0; i < grammar.getProductionPatternCount(); i++) { 187 production = grammar.getProductionPattern(i); 188 constants.addProduction(production); 189 parser.addProductionConstant(production); 190 analyzer.addProduction(production, constants); 191 } 192 193 for (i = 0; i < grammar.getProductionPatternCount(); i++) { 195 production = grammar.getProductionPattern(i); 196 parser.addProduction(production, constants); 197 } 198 199 constants.writeCode(); 201 tokenizer.writeCode(); 202 parser.writeCode(); 203 analyzer.writeCode(); 204 } 205 } 206 | Popular Tags |