Exemplo n.º 1
0
 public LanguageData(Grammar grammar) {
   Grammar = grammar;
   GrammarData = new GrammarData(this);
   ParserData = new ParserData(this);
   ScannerData = new ScannerData(this);
   ConstructAll(); 
 }
Exemplo n.º 2
0
 public FileAssembler(Grammar grammar, ISegmentFactory segmentBuilder, IExecutableFactory executableBuilder)
 {
     this.executableBuilder = executableBuilder;
     this.segmentBuilder = segmentBuilder;
     this.ironyGrammar = grammar;
     this.ironyParser = new Parser(ironyGrammar);
 }
Exemplo n.º 3
0
 private void Init(Grammar grammar) {
   _grammar = grammar;
   _language = new LanguageData(_grammar); 
   var parser = new Parser(_language);
   _scanner = parser.Scanner;
   _context = parser.Context;
   _context.Mode = ParseMode.VsLineScan;
 }
 public ParseTreeNode getRoot(string sourceCode, Grammar fabricGrammar)
 {
     LanguageData fabric = new LanguageData(fabricGrammar);
     Parser parser = new Parser(fabric);
     ParseTree parseTree = parser.Parse(sourceCode);
     ParseTreeNode root = parseTree.Root;
     return root;
 }
Exemplo n.º 5
0
        public IndentFilter(GrammarData grammarData, KeyTerm lineContinuation, KeyTerm bracket_open, KeyTerm bracket_close)
        {
            this.grammarData = grammarData;
            grammar = grammarData.Grammar;
            grammar.LanguageFlags |= LanguageFlags.EmitLineStartToken;

            opening_bracket = bracket_open;
            closing_bracket = bracket_close;
        }
 public bool isValid(string sourceCode, Grammar fabricGrammar)
 {
     // Test whether the sourceCode corresponds to the Fabric grammar
     LanguageData fabric = new LanguageData(fabricGrammar);
     Parser parser = new Parser(fabric);
     ParseTree parseTree = parser.Parse(sourceCode);
     ParseTreeNode root = parseTree.Root;
     return root != null;
 }
Exemplo n.º 7
0
        public static bool IsValid(string sourceCode, Grammar grammar)
        {
            LanguageData language = new LanguageData(grammar);

            Parser parser = new Parser(language);

            ParseTree parseTree = parser.Parse(sourceCode);

            ParseTreeNode root = parseTree.Root;

            return root != null;
        }
Exemplo n.º 8
0
        public static ParseTreeNode GetRoot(string sourceCode, Grammar grammar)
        {
            LanguageData language = new LanguageData(grammar);

            Parser parser = new Parser(language);

            ParseTree parseTree = parser.Parse(sourceCode);

            ParseTreeNode root = parseTree.Root;

            return root;
        }
Exemplo n.º 9
0
    public CommandLine(Grammar grammar) {
      Grammar = grammar;
      Title = grammar.ConsoleTitle;
      Greeting = grammar.ConsoleGreeting;
      Prompt = grammar.ConsolePrompt;
      PromptMoreInput = grammar.ConsolePromptMoreInput;

      Interpreter = new ScriptInterpreter(grammar);
      Interpreter.RethrowExceptions = false;
      Interpreter.ParseMode = ParseMode.CommandLine;
      Interpreter.PrintParseErrors = false; 
    }
Exemplo n.º 10
0
 public Scanner(Parser parser) {
   Parser = parser; 
   Data = parser.Language.ScannerData;
   _grammar = parser.Language.Grammar;
   //create token streams
   var tokenStream = GetUnfilteredTokens();
   //chain all token filters
   Context.TokenFilters.Clear();
   _grammar.CreateTokenFilters(Data.Language, Context.TokenFilters);
   foreach (TokenFilter filter in Context.TokenFilters) {
     tokenStream = filter.BeginFiltering(Context, tokenStream);
   }
   Context.FilteredTokens = tokenStream.GetEnumerator();
 }
Exemplo n.º 11
0
 public CodeOutlineFilter(GrammarData grammarData, OutlineOptions options, KeyTerm continuationTerminal) {
   _grammarData = grammarData;
   _grammar = grammarData.Grammar;
   _grammar.LanguageFlags |= LanguageFlags.EmitLineStartToken;
   Options = options;
   ContinuationTerminal = continuationTerminal;
   if (ContinuationTerminal != null)
     if (!_grammar.NonGrammarTerminals.Contains(ContinuationTerminal))
       _grammarData.Language.Errors.Add(GrammarErrorLevel.Warning, null, Resources.ErrOutlineFilterContSymbol, ContinuationTerminal.Name);
         //"CodeOutlineFilter: line continuation symbol '{0}' should be added to Grammar.NonGrammarTerminals list.",
   _produceIndents = OptionIsSet(OutlineOptions.ProduceIndents);
   _checkBraces = OptionIsSet(OutlineOptions.CheckBraces);
   _checkOperator = OptionIsSet(OutlineOptions.CheckOperator);
   Reset(); 
 }
Exemplo n.º 12
0
        protected void IncludeGrammar(Irony.Parsing.Grammar grammarToInclude, bool includeNonGrammarTerminals = true)
        {
            foreach (var keyTerm in grammarToInclude.KeyTerms)
            {
                this.KeyTerms.Add(keyTerm.Key, keyTerm.Value);
            }

            if (includeNonGrammarTerminals)
            {
                foreach (Terminal nonGrammarTerminal in grammarToInclude.NonGrammarTerminals)
                {
                    this.NonGrammarTerminals.Add(nonGrammarTerminal);
                }
            }
        }
Exemplo n.º 13
0
 public Parser(LanguageData language, NonTerminal root) {
   Language = language;
   Data = Language.ParserData;
   _grammar = Language.Grammar; 
   Context = new ParsingContext(this); 
   Scanner = new Scanner(this);
   Root = root; 
   if(Root == null) {
     Root = Language.Grammar.Root;
     InitialState = Language.ParserData.InitialState;
   } else {
     if(Root != Language.Grammar.Root && !Language.Grammar.SnippetRoots.Contains(Root))
       throw new Exception(string.Format(Resources.ErrRootNotRegistered, root.Name));
     InitialState = Language.ParserData.InitialStates[Root]; 
   }
 }
Exemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShaderLanguageData"/> class.
        /// </summary>
        /// <param name="grammar">The grammar.</param>
        public ShaderLanguageData(Irony.Parsing.Grammar grammar) : base(grammar)
        {
            SymbolToToken = new Terminal[256];

            // Add TokenType to terminals
            foreach (var typeTerm in ((ShaderGrammar)grammar).TokenTypeToTerminals)
            {
                AddTerminal(typeTerm.Key, typeTerm.Value);
            }


            // Add Keywords
            foreach (var term in Grammar.KeyTerms.Values.OfType <Terminal>())
            {
                if (char.IsLetter(term.Name[0]))
                {
                    AddTerminal(TokenType.Identifier, term);
                }
            }
        }
Exemplo n.º 15
0
 internal static StringSet ComputeGroupedExpectedSetForState(Grammar grammar, ParserState state)
 {
     var terms = new TerminalSet();
       terms.UnionWith(state.ExpectedTerminals);
       var result = new StringSet();
       //Eliminate no-report terminals
       foreach(var group in grammar.TermReportGroups)
     if (group.GroupType == TermReportGroupType.DoNotReport)
     terms.ExceptWith(group.Terminals);
       //Add normal and operator groups
       foreach(var group in grammar.TermReportGroups)
     if((group.GroupType == TermReportGroupType.Normal || group.GroupType == TermReportGroupType.Operator) &&
      terms.Overlaps(group.Terminals)) {
       result.Add(group.Alias);
       terms.ExceptWith(group.Terminals);
     }
       //Add remaining terminals "as is"
       foreach(var terminal in terms)
     result.Add(terminal.ErrorAlias);
       return result;
 }
Exemplo n.º 16
0
 public Compiler(Grammar grammar)
 {
     this.grammar = grammar;
 }
Exemplo n.º 17
0
 //Covers simple identifiers like abcd, and also quoted versions: [abc d], "abc d".
 public static IdentifierTerminal CreateSqlExtIdentifier(Grammar grammar, string name) {
   var id = new IdentifierTerminal(name);
   StringLiteral term = new StringLiteral(name + "_qouted");
   term.AddStartEnd("[", "]", StringOptions.NoEscapes);
   term.AddStartEnd("\"", StringOptions.NoEscapes);
   term.SetOutputTerminal(grammar, id); //term will be added to NonGrammarTerminals automatically 
   return id;
 }
Exemplo n.º 18
0
 internal static void ClearCurrentGrammar()
 {
     _currentGrammar = null;
 }
Exemplo n.º 19
0
 public Grammar(bool caseSensitive)
 {
     _currentGrammar = this;
       this.CaseSensitive = caseSensitive;
       bool ignoreCase =  !this.CaseSensitive;
       var stringComparer = StringComparer.Create(System.Globalization.CultureInfo.InvariantCulture, ignoreCase);
       KeyTerms = new KeyTermTable(stringComparer);
       //Initialize console attributes
       ConsoleTitle = Resources.MsgDefaultConsoleTitle;
       ConsoleGreeting = string.Format(Resources.MsgDefaultConsoleGreeting, this.GetType().Name);
       ConsolePrompt = ">";
       ConsolePromptMoreInput = ".";
 }
Exemplo n.º 20
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        /// <param name="parser">
        /// The Parser.
        /// </param>
        public void Initialize(Parser parser)
        {
            Parser = parser;
            Grammar = parser.Language.Grammar;

            PrepareInput();

            // create token streams
            var tokenStream = GetUnfilteredTokens();

            // chain all token filters
            Context.TokenFilters.Clear();
            Grammar.CreateTokenFilters(Parser.Language, Context.TokenFilters);
            foreach (var filter in Context.TokenFilters)
            {
                tokenStream = filter.BeginFiltering(Context, tokenStream);
            }

            filteredTokens = tokenStream.GetEnumerator();
        }
Exemplo n.º 21
0
        public bool isValid(string codigo, Grammar grammar)
        {
            LanguageData lenguaje = new LanguageData(grammar);
            Parser p = new Parser(lenguaje);
            ParseTree arbol = p.Parse(codigo);

            if (arbol.Root != null)
            {
                Genarbol(arbol.Root);
                GenerateGraph("Ejemplo.txt", "C:/Fuentes/");
                try
                {
                    resultado = (Double)ejecutar(arbol.Root);
                }
                catch { }
            }

            return arbol.Root != null;
        }
Exemplo n.º 22
0
 public Grammar(bool caseSensitive)
 {
     _currentGrammar = this;
       this.CaseSensitive = caseSensitive;
       bool ignoreCase =  !this.CaseSensitive;
       LanguageStringComparer = StringComparer.Create(System.Globalization.CultureInfo.InvariantCulture, ignoreCase);
       StringComparisonMode = CaseSensitive ? StringComparison.InvariantCulture : StringComparison.InvariantCultureIgnoreCase;
       KeyTerms = new KeyTermTable(LanguageStringComparer);
       //Initialize console attributes
       ConsoleTitle = Resources.MsgDefaultConsoleTitle;
       ConsoleGreeting = string.Format(Resources.MsgDefaultConsoleGreeting, this.GetType().Name);
       ConsolePrompt = ">";
       ConsolePromptMoreInput = ".";
       OperatorMappings = OperatorUtility.GetDefaultOperatorMappings(caseSensitive);
 }
Exemplo n.º 23
0
 public Parser(Grammar grammar)
     : this(new LanguageData(grammar))
 {
 }
Exemplo n.º 24
0
 /// <summary>
 ///     Sets Irony parser (based on Grammar)
 /// </summary>
 public virtual void SetParser(Grammar grammar)
 {
     SetParser(new LanguageData(grammar));
 }
Exemplo n.º 25
0
 public ScriptInterpreter(Grammar grammar) : this(new LanguageData(grammar)) { }
Exemplo n.º 26
0
 public void SetOutputTerminal(Grammar grammar, Terminal outputTerminal)
 {
     OutputTerminal = outputTerminal;
     grammar.NonGrammarTerminals.Add(this);
 }
Exemplo n.º 27
0
 public GrammarData(LanguageData language)
 {
     Language = language;
     Grammar  = language.Grammar;
 }
Exemplo n.º 28
0
 internal static void ClearCurrentGrammar() {
   _currentGrammar = null; 
 }
Exemplo n.º 29
0
 public Parser(Grammar grammar) : this(new LanguageData(grammar))
 {
 }
Exemplo n.º 30
0
 private void CreateGrammar()
 {
     GrammarItem selItem = cboGrammars.SelectedItem as GrammarItem;
       _grammar = selItem.CreateGrammar();
 }
Exemplo n.º 31
0
 private void CreateGrammar() {
   _grammar = _grammarLoader.CreateGrammar();
 }
Exemplo n.º 32
0
 public VisitorCompiler(Grammar grammar)
 {
     this.grammar = grammar;
 }
Exemplo n.º 33
0
 public ZestParser(Grammar grammar, ImmediateRepresentation immediateRepresentation)
 {
     this.grammar = grammar;
     this.immediateRepresentation = immediateRepresentation;
 }
Exemplo n.º 34
0
 public Analizador(Grammar gramatica)
 {
     this.gramatica = gramatica;
 }
Exemplo n.º 35
0
 private void LoadGrammar()
 {
     //var dlgSelectAssembly = new System.Windows.Forms.OpenFileDialog();
     //dlgSelectAssembly.DefaultExt = "dll";
     //dlgSelectAssembly.Filter = "DLL files|*.dll";
     //dlgSelectAssembly.Title = "Select Grammar Assembly ";
     //if (dlgSelectAssembly.ShowDialog() != DialogResult.OK) return;
     //string location = dlgSelectAssembly.FileName;
     string location = "../Compiler/Zodiac.dll";
     if (string.IsNullOrEmpty(location)) return;
     grammarLoader.SelectedGrammar = SelectGrammars(location);
     if (grammarLoader.SelectedGrammar == null) return;
     grammar = grammarLoader.CreateGrammar();
 }
Exemplo n.º 36
0
 public GrammarData(LanguageData language) {
   Language = language;
   Grammar = language.Grammar;
 }