Home | History | Annotate | Download | only in tool

Lines Matching defs:Grammar

35 import org.antlr.grammar.v3.*;
47 /** Represents a grammar in memory. */
48 public class Grammar {
65 public static final int WILDCARD_TREE_LABEL = 6; // Used in tree grammar x=.
66 public static final int WILDCARD_TREE_LIST_LABEL = 7; // Used in tree grammar x+=.
121 "Parser" // if combined grammar, gen Parser and Lexer will be done later
125 * another tree parser. Maps delegate to set of delegator grammar types.
146 /** This is the buffer of *all* tokens found in the grammar file
155 public Grammar grammar;
184 /** What name did the user provide for this grammar? */
187 /** What type of grammar is this: lexer, parser, tree walker */
190 /** A list of options specified at the grammar level such as language=Java.
278 /** Is there a global fixed lookahead set for this grammar?
293 /** The NFA that represents the grammar with edges labelled with tokens
300 /** If this grammar is part of a larger composite grammar via delegate
306 /** A pointer back into grammar tree. Needed so we can add delegates. */
309 /** If this is a delegate of another grammar, this is the label used
310 * as an instance var by that grammar to point at this grammar. null
335 /** Be able to assign a number to every decision in grammar;
354 /** When we read in a grammar, we track the list of syntactic predicates
357 * This maps the name (we make up) for a pred to the AST grammar fragment.
376 /** At least one backtrack=true in rule or decision or grammar. */
379 /** Was this created from a COMBINED grammar? */
390 /** The list of all rules referenced in this grammar, not defined here,
391 * and defined in a delegate grammar. Not all of these will be generated
393 * definitions in this grammar. I am not sure the Java target will need
409 /** An AST that records entire input grammar with all rules. A simple
410 * grammar with one rule, "grammar t; a : A | B ;", looks like:
411 * ( grammar t ( rule a ( BLOCK ( ALT A ) ( ALT B ) ) <end-of-rule> ) )
434 * I make the new grammar import from the old all in memory; don't want
435 * to force it to read from the disk. Lexer grammar will have same
436 * name as original grammar but will be in different filename. Foo.g
437 * with combined grammar will have FooParser.java generated and
439 * as it's a lexer grammar. A bit odd, but autogenerated. Can tweak
443 "grammar(name, options, imports, actionNames, actions, literals, rules) ::= <<\n" +
444 "lexer grammar <name>;\n" +
457 /** What file name holds this grammar? */
460 /** How long in ms did it take to build DFAs for this grammar?
461 * If this grammar is a combined grammar, it only records time for
462 * the parser grammar component. This only records the time to
501 /** We need a way to detect when a lexer grammar is autogenerated from
502 * another grammar or we are just sending in a string representing a
503 * grammar. We don't want to generate a .tokens file, for example,
514 /** Create a grammar from file name. */
515 public Grammar(Tool tool, String fileName, CompositeGrammar composite) {
524 lexerGrammarST = lexerGrammarSTG.getInstanceOf("grammar");
531 public Grammar() { this((Tool)null); }
533 public Grammar(Tool tool) {
538 lexerGrammarST = lexerGrammarSTG.getInstanceOf("grammar");
543 public Grammar(String grammarString)
552 public Grammar(Tool tool, String grammarString)
629 // BUILD AST FROM GRAMMAR
650 dealWithTreeFilterMode(); // tree grammar and filter=true?
667 //if ( grammarTree!=null ) System.out.println("grammar tree: "+grammarTree.toStringTree());
764 /** Many imports are illegal such as lexer into a tree grammar */
765 public boolean validImport(Grammar delegate) {
770 /** If the grammar is a combined grammar, return the text of the implicit
771 * lexer grammar.
788 // make sure generated grammar has the same options
809 * as grammar name.
811 * just use T regardless of grammar type.
815 List<Grammar> grammarsFromRootToMe = composite.getDelegators(this);
820 for (Grammar g : grammarsFromRootToMe) {
827 if ( type==Grammar.COMBINED ||
828 (type==Grammar.LEXER && implicitLexer) )
830 suffix = Grammar.grammarTypeToFileNameSuffix[type];
845 * grammar, which I think is proper even though it peeks at the info
848 * and adds the resulting tree to the grammar's tree.
943 /** Walk the list of options, altering this Grammar object according
961 * to see rule start/stop states from potentially every grammar. Has
967 //System.out.println("### createRuleStartAndStopNFAStates "+getGrammarTypeString()+" grammar "+name+" NFAs");
998 //System.out.println("### build "+getGrammarTypeString()+" grammar "+name+" NFAs");
1016 /** For each decision in this grammar, compute a single DFA using the
1021 * Store the lookahead DFAs in the AST created from the user's grammar
1025 * Grammar without doing the expensive analysis.
1040 // was there a severe problem while sniffing the grammar?
1086 FASerializer serializer = new FASerializer(nfa.grammar);
1239 GrammarAST decisionAST = nfa.grammar.getDecisionBlockAST(lookaheadDFA.decisionNumber);
1355 /** Terminate DFA creation (grammar analysis).
1372 * old value with a new one. This is called normal grammar processsing
1425 if ( (type==Grammar.PARSER||type==Grammar.TREE_PARSER) &&
1489 /** Given @scope::name {action} define it for this grammar. Later,
1501 //System.out.println("Grammar "+name+" define @"+scope+"::"+nameAST.getText()+"{"+actionAST.getText()+"}");
1519 List<Grammar> allgrammars = composite.getRootGrammar().getDelegates();
1520 for (Grammar delegate : allgrammars) {
1534 !actionsForGrammarScope.containsKey(Grammar.SYNPREDGATE_ACTION_NAME)) )
1540 actionsForGrammarScope.put(Grammar.SYNPREDGATE_ACTION_NAME,
1549 /** Given a grammar type, what should be the default action scope?
1550 * If I say @members in a COMBINED grammar, for example, the
1555 case Grammar.LEXER :
1557 case Grammar.PARSER :
1558 case Grammar.COMBINED :
1560 case Grammar.TREE_PARSER :
1615 // now put the rule into the lexer grammar template
1663 if ( r!=null && r.grammar != this ) {
1672 Grammar scope = composite.getGrammar(scopeName);
1843 * label types such as Grammar.TOKEN_LABEL, Grammar.TOKEN_LIST_LABEL, ...
1855 // if tree grammar and we have a wildcard, only notice it
1909 * Do this for all rules in grammar.
1961 Grammar scopeG = null;
2086 //System.out.println("grammar type "+type+" "+tokenName+"->"+i);
2206 /** Pull your token definitions from an existing grammar in memory.
2207 * You must use Grammar() ctor then this method then setGrammarContent()
2209 * interpreting grammars until I added import grammar functionality.
2210 * When you import a grammar you implicitly import its vocabulary as well
2215 public int importTokenVocabulary(Grammar importFromGr) {
2222 //System.out.println("import token from grammar "+tokenID+"="+tokenType);
2229 /** Import the rules/tokens of a delegate grammar. All delegate grammars are
2230 * read during the ctor of first Grammar created.
2233 * overridden rules in delegation root grammar.
2244 Grammar delegateGrammar = null;
2245 delegateGrammar = new Grammar(tool, gname, composite);
2272 // we have a valid grammar
2278 // but, this parser grammar will need the vocab
2282 //System.out.println("Got grammar:\n"+delegateGrammar);
2304 protected void addDelegateGrammar(Grammar delegateGrammar) {
2307 // make sure new grammar shares this composite
2415 // inside any target's char range and is lexer grammar?
2549 if ( type==Grammar.LEXER ) {
2557 GrammarAST blockAST = nfa.grammar.getDecisionBlockAST(decision);
2560 user_k = nfa.grammar.getGrammarMaxLookahead();
2582 autoBacktrack = (String)nfa.grammar.getOption("backtrack");
2626 * If this grammar is master, get list of all rule definitions from all
2632 * Only the outermost grammar should be used from outside code. The
2633 * other grammar components are specifically generated to work only
2650 * imported into this grammar.
2652 public List<Grammar> getDelegates() {
2661 // compute delegates:{Grammar g | return g.name;}
2663 List<Grammar> delegates = composite.getDelegates(this);
2665 for (Grammar g : delegates) {
2672 public List<Grammar> getDirectDelegates() {
2677 public List<Grammar> getIndirectDelegates() {
2684 public List<Grammar> getDelegators() {
2688 /** Who's my direct parent grammar? */
2689 public Grammar getDelegator() {
2698 return composite.delegateGrammarTreeRoot.grammar == this;
2765 d.grammar = this;
2881 * Grammar g = new Grammar("...");
2913 /** What is the max char value possible for this grammar's target? Use
2925 /** Return a set of all possible token or char types for this grammar */
3013 * grammar. Mostly used in the lexer to do ~T for some fragment rule
3037 * a grammar decides how NFAs are put together to form a decision.