adding initial src code generation output model objects

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 6842]
This commit is contained in:
parrt 2010-05-05 15:52:29 -08:00
parent c310c3b3a1
commit 9913972caa
21 changed files with 178 additions and 92 deletions

View File

@ -1,92 +0,0 @@
package org.antlr.v4.analysis;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.tool.Grammar;
/** This object holds all information needed to represent
* the lookahead for any particular lookahead computation
* for a <b>single</b> lookahead depth.
*/
public class LookaheadSet {
public IntervalSet set;
/** Used for rule references. If we try
* to compute look(k, ruleref) and there are fewer
* than k lookahead terminals before the end of the
* the rule, eor will be returned (don't want to
* pass the end of the rule). We must track when the
* the lookahead got stuck. For example,
* <pre>
* a : b A B E F G;
* b : C ;
* </pre>
* LOOK(5, ref-to(b)) is {<EPSILON>} with depth = 4, which
* indicates that at 2 (5-4+1) tokens ahead, end of rule was reached.
* Therefore, the token at 4=5-(5-4) past rule ref b must be
* included in the set == F.
* The situation is complicated by the fact that a computation
* may hit the end of a rule at many different depths. For example,
* <pre>
* a : b A B C ;
* b : E F // eor depth of 1 relative to initial k=3
* | G // eor depth of 2
* ;
* </pre>
* Here, LOOK(3,ref-to(b)) returns eor, but the depths are
* {1, 2}; i.e., 3-(3-1) and 3-(3-2). Those are the lookahead depths
* past the rule ref needed for the local follow.
*/
public IntervalSet eorDepths;
public LookaheadSet() {;}
public LookaheadSet(IntervalSet set) { this.set = new IntervalSet(set); }
public static LookaheadSet of(int a) {
LookaheadSet s = new LookaheadSet();
s.set = IntervalSet.of(a);
return s;
}
public static LookaheadSet missingDepth(int k) {
LookaheadSet s = new LookaheadSet();
s.eorDepths = IntervalSet.of(k);
return s;
}
public void combine(LookaheadSet other) {
if (eorDepths != null) {
if (other.eorDepths != null) {
eorDepths.addAll(other.eorDepths);
}
}
else if (other.eorDepths != null) {
eorDepths = new IntervalSet(other.eorDepths);
}
if ( set==null ) set = new IntervalSet(other.set);
else set.addAll(other.set);
}
public LookaheadSet intersection(LookaheadSet s) {
IntervalSet i = (IntervalSet)this.set.and(s.set);
return new LookaheadSet(i);
}
public boolean isNil() {
return set.isNil() && (eorDepths==null || eorDepths.size()==0);
}
@Override
public String toString() {
String s = set.toString();
if ( eorDepths!=null ) s += "+"+eorDepths;
return s;
}
public String toString(Grammar g) {
String s = set.toString(g);
if ( eorDepths!=null ) s += "+"+eorDepths;
return s;
}
}

View File

@ -0,0 +1,6 @@
package org.antlr.v4.codegen.src;
/** */
public class AddToList extends SrcOp {
public SrcOp opWithResultToAdd;
}

View File

@ -0,0 +1,9 @@
package org.antlr.v4.codegen.src;
import org.antlr.v4.misc.IntSet;
/** */
public class BitSetDef {
String name;
IntSet[] set;
}

View File

@ -0,0 +1,12 @@
package org.antlr.v4.codegen.src;
import org.antlr.v4.automata.DFA;
import java.util.List;
/** */
public class Choice extends SrcOp {
//public DFADef dfaDef; ???
public DFA dfa;
public List<CodeBlock> alts;
}

View File

@ -0,0 +1,8 @@
package org.antlr.v4.codegen.src;
import java.util.List;
/** */
public class CodeBlock extends SrcOp {
public List<SrcOp> ops;
}

View File

@ -0,0 +1,10 @@
package org.antlr.v4.codegen.src;
import org.antlr.v4.automata.DFA;
/** */
public class DFADef {
public String name;
public DFA dfa;
}

View File

@ -0,0 +1,23 @@
package org.antlr.v4.codegen.src;
import org.antlr.v4.misc.IntervalSet;
import java.util.List;
/** */
public class InvokeRule extends SrcOp {
public String name;
public String label;
public List<String> args;
public IntervalSet[] follow;
public InvokeRule(String name, String argAction, IntervalSet[] follow) {
// split and translate argAction
// compute follow
}
public InvokeRule(String name, IntervalSet[] follow) {
// split and translate argAction
// compute follow
}
}

View File

@ -0,0 +1,5 @@
package org.antlr.v4.codegen.src;
/** */
public class LL1OptionalBlock extends OptionalBlock {
}

View File

@ -0,0 +1,5 @@
package org.antlr.v4.codegen.src;
/** */
public class LL1OptionalBlockSingleAlt extends OptionalBlock {
}

View File

@ -0,0 +1,5 @@
package org.antlr.v4.codegen.src;
/** */
public class LLStarOptionalBlock extends OptionalBlock {
}

View File

@ -0,0 +1,5 @@
package org.antlr.v4.codegen.src;
/** */
public class LLkOptionalBlock extends OptionalBlock {
}

View File

@ -0,0 +1,9 @@
package org.antlr.v4.codegen.src;
import org.antlr.v4.misc.IntervalSet;
/** */
public class MatchToken extends SrcOp {
public int ttype;
public IntervalSet[] follow;
}

View File

@ -0,0 +1,5 @@
package org.antlr.v4.codegen.src;
/** */
public class OptionalBlock extends Choice {
}

View File

@ -0,0 +1,11 @@
package org.antlr.v4.codegen.src;
import org.antlr.v4.tool.Grammar;
import java.util.List;
/** */
public class Parser {
public Grammar g;
public List<RuleFunction> funcs;
}

View File

@ -0,0 +1,6 @@
package org.antlr.v4.codegen.src;
/** */
public class ParserFile {
public Parser parser;
}

View File

@ -0,0 +1,25 @@
package org.antlr.v4.codegen.src;
import org.antlr.v4.tool.Attribute;
import org.antlr.v4.tool.GrammarAST;
import org.antlr.v4.tool.Rule;
import java.util.ArrayList;
import java.util.List;
/** */
public class RuleFunction {
public String name;
public List<String> modifiers;
public List<Attribute> args;
public List<Attribute> retvals;
public CodeBlock code;
public RuleFunction(Rule r) {
this.name = r.name;
if ( r.modifiers!=null && r.modifiers.size()>0 ) {
this.modifiers = new ArrayList<String>();
for (GrammarAST t : r.modifiers) modifiers.add(t.getText());
}
}
}

View File

@ -0,0 +1,8 @@
package org.antlr.v4.codegen.src;
import org.antlr.v4.tool.GrammarAST;
/** */
public class SrcOp {
public GrammarAST ast;
}

View File

@ -0,0 +1,5 @@
package org.antlr.v4.codegen.src;
/** */
public class Sync {
}

View File

@ -0,0 +1,8 @@
package org.antlr.v4.codegen.src.ast;
import org.antlr.v4.codegen.src.SrcOp;
/** */
public class AddLeaf extends SrcOp {
public SrcOp opWithResultToAdd;
}

View File

@ -0,0 +1,8 @@
package org.antlr.v4.codegen.src.ast;
import org.antlr.v4.codegen.src.SrcOp;
/** */
public class MakeRoot extends SrcOp {
public SrcOp opWithResultToAdd;
}

View File

@ -0,0 +1,5 @@
package org.antlr.v4.codegen.src;
/** */
public class dbg {
}