예제 #1
0
파일: NCalcLexer.cs 프로젝트: sklose/NCalc2
	public NCalcLexer(ICharStream input, RecognizerSharedState state)
		: base(input, state)
	{


		OnCreated();
	}
예제 #2
0
 public CommonToken(ICharStream input, int type, int channel, int start, int stop) {
     this.input = input;
     this.type = type;
     this.channel = channel;
     this.start = start;
     this.stop = stop;
 }
예제 #3
0
	public AssemblerLexer(ICharStream input, RecognizerSharedState state)
		: base(input, state)
	{


		OnCreated();
	}
예제 #4
0
	public UniAspectLexer(ICharStream input, RecognizerSharedState state)
		: base(input, state)
	{


		OnCreated();
	}
        public AlloyColorizerLexer(ICharStream input, AlloyClassifierLexer lexer)
            : this(input)
        {
            Contract.Requires<ArgumentNullException>(lexer != null, "lexer");

            _lexer = lexer;
        }
        public ChapelCodeClassifierLexer(ICharStream input, ChapelClassifierLexer lexer)
            : this(input)
        {
            Contract.Requires<ArgumentNullException>(lexer != null, "lexer");

            _lexer = lexer;
        }
	public MessageContractsLexer(ICharStream input, RecognizerSharedState state)
		: base(input, state)
	{


		OnCreated();
	}
예제 #8
0
        public MatlabLexer(ICharStream input, Configuration configuration)
            : this(input)
        {
            Checker.CheckNotNull(configuration);

            this.Configuration = configuration;
        }
예제 #9
0
		public csLexerWithPreProcessor(ICharStream stream, IEnumerable<string> defines) : base(stream) {
			// By default we are preprocessing input
			Processing.Push(true);

			// Grab what's defined from the command line
			MacroDefines.UnionWith(defines);
		}
        public static MAst Compile(AstHelper runtime, ICharStream stream)
        {
            var lexer = new TigerLexer(stream);
            var tokens = new CommonTokenStream(lexer);
            var parser = new TigerParser(tokens);
            ProgramExpression programExpression = parser.parse();

            if (parser.NumberOfSyntaxErrors > 0)
            {
                IEnumerable<string> errors = from e in parser.Errors
                                             select e.ToString();

                throw new SyntaxException(errors);
            }

            AstHelper helper = runtime.CreateChild(function: true, variables: true, types: true);
            programExpression.CheckSemantics(helper);

            if (helper.Errors.HasErrors)
            {
                throw new SemanticException(helper.Errors);
            }

            return programExpression.Transform();
        }
        public void Compile(ICharStream input)
        {
            try
            {
                AssemblerLexer lex = new AssemblerLexer(input);
                CommonTokenStream tokens = new CommonTokenStream(lex);
                AssemblerParser p = new AssemblerParser(tokens);
                BytecodeGenerator gen = new BytecodeGenerator(Defaults.SystemMethods.Values);
                
                p.SetGenerator(gen);
                p.TraceDestination = _traceDestination;
                p.program();

                if (p.NumberOfSyntaxErrors > 0 && _listener != null)
                {
                    _listener.Error(Convert.ToString(p.NumberOfSyntaxErrors) + " syntax error(s)");
                    return;
                }

                _result = gen.Result;
            }
            catch (GenerationException ex)
            {
                _listener.Error(ex.Message);
            }
        }
	public FuncProtoToShimLexer(ICharStream input, RecognizerSharedState state)
		: base(input, state)
	{


		OnCreated();
	}
예제 #13
0
        private void compilacion(ICharStream input, string pathSalida)
        {
            compilacionOK = false;

            //Plantillas
            //TextReader groupFileR = new StreamReader("C:\\Proyectos\\ProyectosVS\\FKVM\\FKVM\\src\\antlr\\FkvmIL.stg");
            TextReader groupFileR = new StreamReader(
                System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("FKVM.src.antlr.FkvmIL.stg"));
            StringTemplateGroup templates = new StringTemplateGroup(groupFileR);
            groupFileR.Close();

            //Análisis Léxico-Sintáctico
            Console.WriteLine("Análisis léxico-sintáctico...");
            //ANTLRFileStream input = new ANTLRFileStream(pathEntrada);
            FKVMLexer lexer = new FKVMLexer(input);

            CommonTokenStream tokens = new CommonTokenStream(lexer);
            FKVMParser parser = new FKVMParser(tokens);
            parser.TreeAdaptor = adaptor;
            parser.reportarError = re;
            FKVMParser.programa_return result = parser.programa();

            //Si no hay errores léxicos ni sintácticos ==> Análisis Semántico
            if (lexer.numErrors + parser.numErrors == 0)
            {
                //Analisis Semántico
                Console.WriteLine("Análisis semántico...");
                CommonTree t = ((CommonTree)result.Tree);
                //Console.WriteLine(t.ToStringTree() + "\n\n"); //
                CommonTreeNodeStream nodes2 = new CommonTreeNodeStream(t);
                nodes2.TokenStream = tokens;
                FKVMSem walker2 = new FKVMSem(nodes2);
                walker2.reportarError = re;
                walker2.programa(parser.symtable);

                //Si no hay errores en el análisis semántico ==> Generación de código
                if (walker2.numErrors == 0)
                {
                    //Generación de Código
                    Console.WriteLine("Generación de código...");
                    CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);
                    nodes.TokenStream = tokens;
                    FKVMGen walker = new FKVMGen(nodes);
                    walker.TemplateLib = templates;
                    FKVMGen.programa_return r2 = walker.programa(parser.numVars);

                    //Presentación de resultados
                    StringTemplate output = (StringTemplate)r2.Template;
                    //Console.WriteLine(output.ToString());

                    StreamWriter pw = new StreamWriter(pathSalida);
                    pw.WriteLine(output.ToString());
                    pw.Flush();
                    pw.Close();

                    compilacionOK = true;
                }
            }
        }
 public RecognitionException(Lexer lexer, ICharStream input)
 {
     // TODO: make a dummy recognizer for the interpreter to use?
     // Next two (ctx,input) should be what is in recognizer, but
     // won't work when interpreting
     this.recognizer = lexer;
     this.input = input;
 }
        internal AntlrGrammarClassifierLexer(ICharStream input, AntlrClassifierLexer lexer)
            : this(input)
        {
            Contract.Requires<ArgumentNullException>(input != null, "input");
            Contract.Requires<ArgumentNullException>(lexer != null, "lexer");

            _lexer = lexer;
        }
예제 #16
0
        public JavaUnicodeInputStream([NotNull] ICharStream source)
        {
            if (source == null)
                throw new ArgumentNullException("source");

            this._source = source;
            this._la1 = source.La(1);
        }
예제 #17
0
 private ZealCpuDriver(ICharStream antlrInputStream)
 {
     _lexer = new ZealCpuLexer(antlrInputStream);
     _tokenStream = new CommonTokenStream(_lexer);
     _parser = new ZealCpuParser(_tokenStream);
     _parser.RemoveErrorListeners();
     _parser.AddErrorListener(new CpuErrorListener(this));
 }
예제 #18
0
        public InWorldz.Phlox.Glue.CompilerFrontend Compile(ICharStream input)
        {
            InWorldz.Phlox.Glue.CompilerFrontend frontEnd = new InWorldz.Phlox.Glue.CompilerFrontend(_listener, "..\\..\\..\\..\\grammar", true);
            frontEnd.OutputASTGraph = true;

            frontEnd.Compile(input);

            return frontEnd;
        }
예제 #19
0
 /*
  * There's one fairly important difference between mod resolution in rustc and what we do.
  * Given following code:
  * mod bar { mod a; } mod bar { mod b; }
  * We will merget this to mod bar { mod a; mod b; }, but rustc will error out.
  */
 public static ModuleImport ParseImports(ICharStream stream)
 {
     var lexer = new ModuleLexer(stream);
     var tokens = new CommonTokenStream(lexer);
     var parser = new ModuleParser(tokens);
     BodyContext root = parser.body();
     var imports = new ModuleImport();
     TraverseForImports(root, imports);
     return imports;
 }
예제 #20
0
        protected virtual IParseTree CreateTree(ICharStream input, IEnumerable<IAntlrErrorListener<int>> lexerErrorListeners,
            IEnumerable<IAntlrErrorListener<IToken>> errorListeners)
        {
            if (input == null) 
                throw new ArgumentNullException("input");

            var builder = _treeBuilder;
            var tree = builder.CreateTree(input, lexerErrorListeners, errorListeners);

            return tree;
        }
예제 #21
0
        public static IQueryValue ParseValue(IEnvironment env, ICharStream input)
        {
            IQLangLexer lexer = new IQLangLexer(input);
            lexer.RemoveErrorListeners();
            lexer.AddErrorListener(LexerErrorListener.Instance);

            CommonTokenStream tokenStream = new CommonTokenStream(lexer);

            IQLangParser parser = new IQLangParser(tokenStream);
            parser.RemoveErrorListeners();
            parser.AddErrorListener(ParserErrorListener.Instance);

            return parser.value().expr.Evaluate(env);
        }
        public ITokenSource CreateTokenSource(ICharStream charStream, IEnumerable<IAntlrErrorListener<int>> errorListeners)
        {
            var tokenSource = CreateLexer(charStream);
            var currentListeners = errorListeners.ToArray();
            if (currentListeners.Any())
            {
                foreach (var listener in currentListeners)
                {
                    tokenSource.AddErrorListener(listener);
                }
            }

            return tokenSource;
        }
예제 #23
0
 public LexerInterpreter(string grammarFileName, IVocabulary vocabulary, IEnumerable<string> ruleNames, IEnumerable<string> modeNames, ATN atn, ICharStream input)
     : base(input)
 {
     if (atn.grammarType != ATNType.Lexer)
     {
         throw new ArgumentException("The ATN must be a lexer ATN.");
     }
     this.grammarFileName = grammarFileName;
     this.atn = atn;
     this.ruleNames = ruleNames.ToArray();
     this.modeNames = modeNames.ToArray();
     this.vocabulary = vocabulary;
     this.Interpreter = new LexerATNSimulator(this, atn);
 }
예제 #24
0
        public static IQueryStatement[] Parse(ICharStream input)
        {
            IQLangLexer lexer = new IQLangLexer(input);
            lexer.RemoveErrorListeners();
            lexer.AddErrorListener(LexerErrorListener.Instance);

            CommonTokenStream tokenStream = new CommonTokenStream(lexer);

            IQLangParser parser = new IQLangParser(tokenStream);
            parser.RemoveErrorListeners();
            parser.AddErrorListener(ParserErrorListener.Instance);

            return parser.compileUnit().list.ToArray();
        }
예제 #25
0
        public static IExecutable Parse(ICharStream input)
        {
            DSLangLexer lexer = new DSLangLexer(input);
            lexer.RemoveErrorListeners();
            lexer.AddErrorListener(LexerErrorListener.Instance);

            CommonTokenStream tokenStream = new CommonTokenStream(lexer);

            DSLangParser parser = new DSLangParser(tokenStream);
            parser.RemoveErrorListeners();
            parser.AddErrorListener(ParserErrorListener.Instance);

            IExecutable executable = parser.compileUnit().executable;

            return executable;
        }
예제 #26
0
        public static ICompileNode Parse(ICharStream input)
        {
            SLangLexer lexer = new SLangLexer(input);
            lexer.RemoveErrorListeners();
            lexer.AddErrorListener(LexerErrorListener.Instance);

            CommonTokenStream tokenStream = new CommonTokenStream(lexer);

            SLangParser parser = new SLangParser(tokenStream);
            parser.RemoveErrorListeners();
            parser.AddErrorListener(ParserErrorListener.Instance);

            ICompileNode rootNode = parser.compileUnit().rootNode;

            return rootNode;
        }
 public CommonToken(IToken oldToken)
 {
     this.charPositionInLine = -1;
     this.index = -1;
     this.text = oldToken.Text;
     this.type = oldToken.Type;
     this.line = oldToken.Line;
     this.index = oldToken.TokenIndex;
     this.charPositionInLine = oldToken.CharPositionInLine;
     this.channel = oldToken.Channel;
     this.input = oldToken.InputStream;
     if (oldToken is CommonToken)
     {
         this.start = ((CommonToken) oldToken).start;
         this.stop = ((CommonToken) oldToken).stop;
     }
 }
예제 #28
0
        /// <summary>
        /// Parses the specified input stream.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns>A list of ExecutableCommands.</returns>
        public static CommandList Parse(ICharStream input)
        {
            DScriptLexer lexer = new DScriptLexer(input);
            CommonTokenStream tokenStream = new CommonTokenStream(lexer);

            DScriptParser parser = new DScriptParser(tokenStream);
            parser.RemoveErrorListeners();
            parser.AddErrorListener(new LogErrorListener());

            List<ExecutableCommand> commands = parser.compileUnit().finalCommands;

            if (parser.NumberOfSyntaxErrors > 0)
            {
                throw new ParseException("Parser finished with syntax errors");
            }

            return new CommandList(commands);
        }
예제 #29
0
 public LexerInterpreter(string grammarFileName, IVocabulary vocabulary, IEnumerable<string> ruleNames, IEnumerable<string> modeNames, ATN atn, ICharStream input)
     : base(input)
 {
     if (atn.grammarType != ATNType.Lexer)
     {
         throw new ArgumentException("The ATN must be a lexer ATN.");
     }
     this.grammarFileName = grammarFileName;
     this.atn = atn;
     this.ruleNames = ruleNames.ToArray();
     this.modeNames = modeNames.ToArray();
     this.vocabulary = vocabulary;
     this.decisionToDFA = new DFA[atn.NumberOfDecisions];
     for (int i = 0; i < decisionToDFA.Length; i++)
     {
         decisionToDFA[i] = new DFA(atn.GetDecisionState(i), i);
     }
     this.Interpreter = new LexerATNSimulator(this, atn, decisionToDFA, sharedContextCache);
 }
예제 #30
0
        public LexerInterpreter(string grammarFileName, IVocabulary vocabulary, IEnumerable<string> ruleNames, IEnumerable<string> modeNames, ATN atn, ICharStream input)
            : base(input)
        {
            if (atn.grammarType != ATNType.Lexer)
            {
                throw new ArgumentException("The ATN must be a lexer ATN.");
            }
            this.grammarFileName = grammarFileName;
            this.atn = atn;
#pragma warning disable 612 // 'fieldName' is obsolete
            this.tokenNames = new string[atn.maxTokenType];
            for (int i = 0; i < tokenNames.Length; i++)
            {
                tokenNames[i] = vocabulary.GetDisplayName(i);
            }
#pragma warning restore 612
            this.ruleNames = ruleNames.ToArray();
            this.modeNames = modeNames.ToArray();
            this.vocabulary = vocabulary;
            this._interp = new LexerATNSimulator(this, atn);
        }
예제 #31
0
 protected Java9LexerBase(ICharStream input, TextWriter output, TextWriter errorOutput)
     : base(input, output, errorOutput)
 {
     _input = input;
 }
예제 #32
0
 public Combined1Lexer(ICharStream input)
     : base(input)
 {
     _interp = new LexerATNSimulator(this, _ATN);
 }
예제 #33
0
 /// <summary>Reinitialize parser.</summary>
 public void ReInit(ICharStream stream, int lexState)
 {
     ReInit(stream);
     SwitchTo(lexState);
 }
예제 #34
0
 ///<summary>
 ///Constructs a new CaseChangingCharStream wrapping the given <paramref name="stream"/> forcing
 ///all characters to upper case or lower case.
 ///</summary>
 ///<param name="stream">The stream to wrap.</param>
 ///<param name="upper">If true force each symbol to upper case, otherwise force to lower.</param>
 public CaseChangingCharStream(ICharStream stream, bool upper)
 {
     this.stream = stream;
     this.upper  = upper;
 }
예제 #35
0
 public PlanningLexer(ICharStream input)
     : base(input)
 {
     _interp = new LexerATNSimulator(this, _ATN);
 }
예제 #36
0
 public JavaScriptBaseLexer(ICharStream input)
     : base(input)
 {
 }
예제 #37
0
 /// <summary>Constructor.</summary>
 public StandardSyntaxParserTokenManager(ICharStream stream)
 {
     m_input_stream = stream;
 }
예제 #38
0
 public command_lineLexer(ICharStream input, TextWriter output, TextWriter errorOutput)
     : base(input, output, errorOutput)
 {
     Interpreter = new LexerATNSimulator(this, _ATN, decisionToDFA, sharedContextCache);
 }
 public InvertedPolishCalculatorLexer(ICharStream input)
     : this(input, Console.Out, Console.Error)
 {
 }
예제 #40
0
 public MySqlLexer(ICharStream input) : base(input)
 {
 }
예제 #41
0
 public MySqlLexer(ICharStream input, TextWriter output, TextWriter errorOutput) : base(input, output, errorOutput)
 {
 }
예제 #42
0
 /// <summary>Constructor.</summary>
 public StandardSyntaxParserTokenManager(ICharStream stream, int lexState)
     : this(stream)
 {
     SwitchTo(lexState);
 }
 public DebugGrammarLexer(ICharStream input, RecognizerSharedState state)
     : base(input, state)
 {
 }
예제 #44
0
파일: Program.cs 프로젝트: taradinoc/zilf
        public void Format(ICharStream inputStream, TextWriter output)
        {
            ZilLexer        lexer = new ZilLexer(inputStream);
            Stack <Nesting> nesting = new Stack <Nesting>();
            int             last = -1, width = 0;

            nesting.Push(Nesting.TopLevel);

            for (IToken token = lexer.NextToken(); token.Type >= 0; token = lexer.NextToken())
            {
                /*if (token.Type == ZilLexer.WS)
                 *  continue;*/

                //bool brokeLine = false;

                if (NeedBreakBetween(last, token.Type, nesting))
                {
                    output.WriteLine();
                    //brokeLine = true;

                    width = 0;
                    for (int i = 1; i < nesting.Count; i++)
                    {
                        output.Write("  ");
                        width += 2;
                    }
                }
                else if (NeedSpaceBetween(last, token.Type))
                {
                    output.Write(' ');
                    width++;
                }

                switch (token.Type)
                {
                case ZilLexer.WS:
                    // ignore
                    continue;

                case ZilLexer.ATOM:
                case ZilLexer.NUM:
                case ZilLexer.STRING:
                case ZilLexer.CHAR:
                    break;

                case ZilLexer.LANGLE:
                    nesting.Push(Nesting.Form);
                    break;

                case ZilLexer.RANGLE:
                    if (nesting.Peek() == Nesting.Form)
                    {
                        nesting.Pop();
                    }
                    break;

                case ZilLexer.LPAREN:
                    nesting.Push(Nesting.List);
                    break;

                case ZilLexer.RPAREN:
                    if (nesting.Peek() == Nesting.List)
                    {
                        nesting.Pop();
                    }
                    break;

                case ZilLexer.LSQUARE:
                    nesting.Push(Nesting.Vector);
                    break;

                case ZilLexer.RSQUARE:
                    if (nesting.Peek() == Nesting.Vector)
                    {
                        nesting.Pop();
                    }
                    break;
                }

                /*if (!brokeLine && NeedBreakBetween(last, token.Type, nesting))
                 * {
                 *  output.WriteLine();
                 *  brokeLine = true;
                 *
                 *  width = 0;
                 *  for (int i = 1; i < nesting.Count; i++)
                 *  {
                 *      output.Write("  ");
                 *      width += 2;
                 *  }
                 * }*/

                output.Write(token.Text);
                width += token.Text.Length;
                last   = token.Type;
            }
        }
 public DebugGrammarLexer(ICharStream input)
     : this(input, new RecognizerSharedState())
 {
 }
예제 #46
0
 public ExprLexer(ICharStream input)
     : this(input, new RecognizerSharedState())
 {
 }
 protected override ITokenSource CreateLexer(ICharStream stream)
 {
     return(new ObjectiveCLexer(stream));
 }
예제 #48
0
 public DustLexer(ICharStream input)
     : this(input, Console.Out, Console.Error)
 {
 }
예제 #49
0
 public FormulaLexer(ICharStream input)
     : this(input, Console.Out, Console.Error)
 {
 }
예제 #50
0
 public ExprLexer(ICharStream input, RecognizerSharedState state)
     : base(input, state)
 {
 }
예제 #51
0
 public MipsAsmLexer(ICharStream input)
     : this(input, Console.Out, Console.Error)
 {
 }
예제 #52
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CaseChangingCharStream"/> class.
 /// </summary>
 /// <param name="internalStream">The stream.</param>
 public CaseChangingCharStream(ICharStream internalStream)
 {
     InternalStream = internalStream;
 }
 public calculatorLexer(ICharStream input)
     : this(input, Console.Out, Console.Error)
 {
 }
 public InvertedPolishCalculatorLexer(ICharStream input, TextWriter output, TextWriter errorOutput)
     : base(input, output, errorOutput)
 {
     Interpreter = new LexerATNSimulator(this, _ATN, decisionToDFA, sharedContextCache);
 }
예제 #55
0
 public ExplicitCtorLexer(string text)
 {
     this.source = new TextReaderCharStream(new StringReader(text));
 }
예제 #56
0
 public command_lineLexer(ICharStream input)
     : this(input, Console.Out, Console.Error)
 {
 }