org.antlr.analysis
Class SemanticContext

java.lang.Object
  extended by org.antlr.analysis.SemanticContext
Direct Known Subclasses:
SemanticContext.AND, SemanticContext.NOT, SemanticContext.OR, SemanticContext.Predicate

public abstract class SemanticContext
extends java.lang.Object

A binary tree structure used to record the semantic context in which an NFA configuration is valid. It's either a single predicate or a tree representing an operation tree such as: p1&&p2 or p1||p2. For NFA o-p1->o-p2->o, create tree AND(p1,p2). For NFA (1)-p1->(2) | ^ | | (3)-p2---- we will have to combine p1 and p2 into DFA state as we will be adding NFA configurations for state 2 with two predicates p1,p2. So, set context for combined NFA config for state 2: OR(p1,p2). I have scoped the AND, NOT, OR, and Predicate subclasses of SemanticContext within the scope of this outer class. July 7, 2006: TJP altered OR to be set of operands. the Binary tree made it really hard to reduce complicated || sequences to their minimum. Got huge repeated || conditions.


Nested Class Summary
static class SemanticContext.AND
           
static class SemanticContext.NOT
           
static class SemanticContext.OR
           
static class SemanticContext.Predicate
           
static class SemanticContext.TruePredicate
           
 
Field Summary
static SemanticContext EMPTY_SEMANTIC_CONTEXT
          Create a default value for the semantic context shared among all NFAConfigurations that do not have an actual semantic context.
 
Constructor Summary
SemanticContext()
           
 
Method Summary
static SemanticContext and(SemanticContext a, SemanticContext b)
           
abstract  org.antlr.stringtemplate.StringTemplate genExpr(CodeGenerator generator, org.antlr.stringtemplate.StringTemplateGroup templates, DFA dfa)
          Generate an expression that will evaluate the semantic context, given a set of output templates.
abstract  SemanticContext getGatedPredicateContext()
          Given a semantic context expression tree, return a tree with all nongated predicates set to true and then reduced.
abstract  boolean isSyntacticPredicate()
           
static SemanticContext not(SemanticContext a)
           
static SemanticContext or(SemanticContext a, SemanticContext b)
           
 void trackUseOfSyntacticPredicates(Grammar g)
          Notify the indicated grammar of any syn preds used within this context
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_SEMANTIC_CONTEXT

public static final SemanticContext EMPTY_SEMANTIC_CONTEXT
Create a default value for the semantic context shared among all NFAConfigurations that do not have an actual semantic context. This prevents lots of if!=null type checks all over; it represents just an empty set of predicates.

Constructor Detail

SemanticContext

public SemanticContext()
Method Detail

getGatedPredicateContext

public abstract SemanticContext getGatedPredicateContext()
Given a semantic context expression tree, return a tree with all nongated predicates set to true and then reduced. So p&&(q||r) would return p&&r if q is nongated but p and r are gated.


genExpr

public abstract org.antlr.stringtemplate.StringTemplate genExpr(CodeGenerator generator,
                                                                org.antlr.stringtemplate.StringTemplateGroup templates,
                                                                DFA dfa)
Generate an expression that will evaluate the semantic context, given a set of output templates.


isSyntacticPredicate

public abstract boolean isSyntacticPredicate()

trackUseOfSyntacticPredicates

public void trackUseOfSyntacticPredicates(Grammar g)
Notify the indicated grammar of any syn preds used within this context


and

public static SemanticContext and(SemanticContext a,
                                  SemanticContext b)

or

public static SemanticContext or(SemanticContext a,
                                 SemanticContext b)

not

public static SemanticContext not(SemanticContext a)


Copyright © 2011. All Rights Reserved.