Exemple #1
0
 /// <summary>
 /// Creates a new immutable header from the given node factory, symbol table and template table.
 /// </summary>
 /// <param name="nodeFactory"></param>
 /// <param name="symbolTable"></param>
 /// <param name="templateTable"></param>
 public ReaderState(LNodeFactory nodeFactory, IReadOnlyList <string> symbolTable, IReadOnlyList <NodeTemplate> templateTable)
 {
     this.NodeFactory   = nodeFactory;
     this.SymbolTable   = symbolTable;
     this.SymbolPool    = SymbolPool.@new();
     this.TemplateTable = templateTable;
 }
Exemple #2
0
 public virtual void Done()
 {
     _classBody    = null;
     F             = null;
     _setDeclNames = null;
     _currentRule  = null;
 }
Exemple #3
0
 public virtual void Reset(IListSource <Token> tokens, ISourceFile file)
 {
     _tokensRoot   = _tokens = tokens;
     _sourceFile   = file;
     F             = new LNodeFactory(file);
     InputPosition = 0;             // reads LT(0)
     _missingExpr  = null;
 }
Exemple #4
0
 public virtual void Reset(IListSource <Token> tokens, ISourceFile file, IParsingService hostLanguage = null)
 {
     _hostLanguage = hostLanguage ?? ParsingService.Current;
     _tokensRoot   = _tokens = ReclassifyTokens(tokens);
     _sourceFile   = file;
     F             = new LNodeFactory(file);
     InputPosition = 0;             // reads LT(0)
 }
 protected override void Reset(IList <Token> tokens, Token eofToken, ISourceFile file, int startIndex = 0)
 {
     // Called by base class constructor
     Debug.Assert(eofToken.Type() == TT.EOF);
     base.Reset(ReclassifyTokens(tokens), eofToken, file, startIndex);
     _hostLanguage = ParsingService.Current;
     _tokensRoot   = _tokenList;
     F             = new LNodeFactory(file);
 }
Exemple #6
0
 public virtual void Reset(IListSource <Token> tokens, ISourceFile file)
 {
     CheckParam.IsNotNull("tokens", tokens);
     CheckParam.IsNotNull("file", file);
     _tokensRoot   = _tokens = tokens;
     _sourceFile   = file;
     F             = new LNodeFactory(file);
     InputPosition = 0;             // reads LT(0)
 }
Exemple #7
0
 protected override void Reset(IList <Token> tokens, Func <Token, Token> getEofToken, int eof, ISourceFile file, int startIndex = 0)
 {
     // Called by base class constructor
     Debug.Assert((TT)eof == TT.EOF);
     base.Reset(ReclassifyTokens(tokens), getEofToken, eof, file, startIndex);
     _hostLanguage = ParsingService.Default;
     _tokensRoot   = _tokenList;
     F             = new LNodeFactory(file);
 }
 public bool Evaluate(IPermissionManaged resource, LNode parsedNode)
 {
     lock (IdentifierTable)
     {
         _factory = new LNodeFactory(parsedNode.Source);
         IdentifierTable[ResourceIdentifierName] = () => resource;
         var result = ResolveLiteral(parsedNode);
         return((bool)result.Value);
     }
 }
Exemple #9
0
        private IReadOnlyList <LNode> GenerateRandomNodeList(LNodeFactory Factory, Random Rand, int Depth)
        {
            var results = new LNode[(int)System.Math.Sqrt(Rand.Next(100))];

            for (int i = 0; i < results.Length; i++)
            {
                results[i] = GenerateRandomNode(Factory, Rand, Depth);
            }
            return(results);
        }
Exemple #10
0
 public virtual void Reset(IListSource <Token> tokens, ISourceFile file, IParsingOptions parsingOptions)
 {
     CheckParam.IsNotNull("tokens", tokens);
     CheckParam.IsNotNull("file", file);
     _tokensRoot    = _tokens = tokens;
     _sourceFile    = file;
     _literalParser = parsingOptions?.LiteralParser ?? EcsLiteralHandlers.Value;
     F                = new LNodeFactory(file);
     InputPosition    = 0;          // reads LT(0)
     _tentativeErrors = new TentativeState(false);
 }
Exemple #11
0
 protected override void Reset(IList <Token> list, Func <Token, Token> getEofToken, int eof, ISourceFile file, int startIndex = 0)
 {
     if (list is TokenTree)
     {
         // Token trees can come from token literals, and the user of a
         // token tree expects to be able to parse that tree, but this parser
         // expects a flat token list, so we need to flatten the tree again.
         list = ((TokenTree)list).Flatten();
     }
     CheckParam.IsNotNull("file", file);
     base.Reset(list, getEofToken, eof, file, startIndex);
     F = new LNodeFactory(file);
 }
Exemple #12
0
        private LNode GenerateRandomNode(LNodeFactory Factory, Random Rand, int Depth)
        {
            int index = Rand.Next(5);

            switch (Depth <= 0 && index > 1 ? Rand.Next(2) : index)
            {
            case 0:
                return(Factory.Literal(GenerateRandomLiteral(Rand)));

            case 1:
                return(Factory.Id(GenerateRandomSymbol(Rand)));

            case 2:
                return(Factory.Attr(GenerateRandomNode(Factory, Rand, Depth - 1), GenerateRandomNode(Factory, Rand, Depth - 1)));

            case 3:
                return(Factory.Call(GenerateRandomSymbol(Rand), GenerateRandomNodeList(Factory, Rand, Depth - 1)));

            default:
                return(Factory.Call(GenerateRandomNode(Factory, Rand, Depth - 1), GenerateRandomNodeList(Factory, Rand, Depth - 1)));
            }
        }
Exemple #13
0
 public GenerateCodeVisitor(LLParserGenerator llpg)
 {
     LLPG       = llpg;
     F          = new LNodeFactory(llpg._sourceFile);
     _classBody = llpg._classBody;
 }
Exemple #14
0
 protected override void Reset(IList <Token> list, Token eofToken, ISourceFile file, int startIndex = 0)
 {
     base.Reset(list, eofToken, file, startIndex);
     F = new LNodeFactory(file);
 }
 public MyParser(IList <Token> list, ISourceFile file, int startIndex = 0) : base(list, new Token((int)TT.EOF, 0, 0, null), file, startIndex)
 {
     F = new LNodeFactory(file);
 }
Exemple #16
0
 /// <summary>
 /// Instantiates a Flame IR encoder.
 /// </summary>
 /// <param name="codec">The codec to use for encoding.</param>
 /// <param name="factory">The node factory to use for creating nodes.</param>
 public EncoderState(IrCodec codec, LNodeFactory factory)
 {
     this.Codec   = codec;
     this.Factory = factory;
 }
 public ExprParser(IList <StringToken> tokens, ISourceFile file = null) : base(tokens, default(StringToken), file ?? EmptySourceFile.Unknown)
 {
     F = new LNodeFactory(SourceFile);
 }
Exemple #18
0
 public virtual void Begin(WList <LNode> classBody, ISourceFile sourceFile)
 {
     _classBody    = classBody;
     F             = new LNodeFactory(sourceFile);
     _setDeclNames = new Dictionary <IPGTerminalSet, Symbol>();
 }
Exemple #19
0
 protected override void Reset(IList <Token> list, Token eofToken, ISourceFile file, int startIndex = 0)
 {
     CheckParam.IsNotNull("file", file);
     base.Reset(list, eofToken, file, startIndex);
     F = new LNodeFactory(file);
 }
Exemple #20
0
 public CodeGenHelperBase()
 {
     F               = new LNodeFactory(EmptySourceFile.Unknown);
     ListType        = F.Of(F.Id("List"), F.Id(_T));
     ListInitializer = F.Call(S.New, F.Call(ListType));
 }