本文整理汇总了C#中Antlr.Runtime.CommonTokenStream类的典型用法代码示例。如果您正苦于以下问题:C# CommonTokenStream类的具体用法?C# CommonTokenStream怎么用?C# CommonTokenStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CommonTokenStream类属于Antlr.Runtime命名空间,在下文中一共展示了CommonTokenStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Execute
public void Execute()
{
string input =
@"
Sart(0,0)
End(12,15)
";
ANTLRStringStream inStream = new ANTLRStringStream(input);
ConfLexer lexer = new ConfLexer(inStream);
CommonTokenStream tokens = new CommonTokenStream(lexer);
ConfParser parser = new ConfParser(tokens);
ConfParser.prog_return returnParser = parser.prog();
var tree = returnParser.Tree as CommonTree;
foreach (CommonTree item in tree.Children)
{
if (item.Type == ConfLexer.ID)
Console.WriteLine("function=" + item.Text);
else if(item.Type == ConfLexer.INT)
Console.WriteLine("params:" + item.Text);
}
Console.ReadKey();
}
开发者ID:imzjy,项目名称:Antlr.Sample,代码行数:26,代码来源:Main.cs
示例2: Translate
public static List<Error> Translate(Source source)
{
var err = new List<Error>();
var prg = new Program();
try
{
var input = new ANTLRStringStream(source.GetSourceData());
var lexer = new PascalLexer(input);
var tokens = new CommonTokenStream(lexer);
var parser = new PascalParser(tokens);
prg = parser.program();
prg.SetSourceIdentifier(source.GetSourceIdentifier());
}
catch (RecognitionException e)
{
err.Add(new Error(FormatRecognitionException(e, source.GetSourceIdentifier())));
}
if (err.Count != 0)
return err;
var val = new Validator();
err = val.Validate(prg);
Root = prg;
return err;
}
开发者ID:BooMWax,项目名称:ifmo,代码行数:25,代码来源:Translator.cs
示例3: From
public Context From(string source)
{
var stream = new ANTLRStringStream(source);
var lexer = new MessageContractsLexer(stream);
var tokens = new CommonTokenStream(lexer);
var parser = new MessageContractsParser(tokens)
{
TreeAdaptor = new CommonTreeAdaptor()
};
var program = parser.GetProgram();
var commonTree = (CommonTree)program.Tree;
var node = commonTree as CommonErrorNode;
if (node != null)
{
throw new InvalidOperationException(node.ToString());
}
var ctx = new Context();
foreach (var child in commonTree.Children)
{
WalkDeclarations(child, ctx);
}
return ctx;
}
开发者ID:bmavity,项目名称:lokad-cqrs,代码行数:30,代码来源:MessageContractAssembler.cs
示例4: BlaiseInstrumentTreeWalker
public BlaiseInstrumentTreeWalker(CommonTree tree, CommonTokenStream tokens, BlaiseImportOptions options, string agencyId, string mainLanguage)
{
this.tree = tree;
this.tokens = tokens;
this.options = options;
this.MainLanguage = mainLanguage;
this.AgencyId = agencyId;
Result = new XDocument();
DdiInstance = Ddi.Element(Ddi.DdiInstance);
Ddi.AddNamespaces(DdiInstance);
ResourcePackage = Ddi.Element(Ddi.ResourcePackage);
// Required in DDI 3.1
var purpose = Ddi.Element(Ddi.Purpose);
purpose.Add(Ddi.XmlLang(MainLanguage));
purpose.Add(new XElement(Ddi.Content, "Not Specified"));
ResourcePackage.Add(purpose);
Instrument = Ddi.Element(Ddi.Instrument);
ControlConstructScheme = Ddi.Element(Ddi.ControlConstructScheme);
XElement groupDataCollection = Ddi.Element(Ddi.GroupDataCollection, false);
XElement dataCollection = Ddi.Element(Ddi.DataCollection);
groupDataCollection.Add(dataCollection);
dataCollection.Add(Instrument);
ResourcePackage.Add(groupDataCollection);
ResourcePackage.Add(ControlConstructScheme);
DdiInstance.Add(ResourcePackage);
}
开发者ID:Colectica,项目名称:MetadataConverters,代码行数:32,代码来源:BlaiseInstrumentTreeWalker.cs
示例5: Parse
public static InOutStep<EvilLexer, Tuple<CommonTokenStream, CommonTree>> Parse()
{
return new InOutStep<EvilLexer, Tuple<CommonTokenStream, CommonTree>>((lexer) =>
{
CommonTokenStream tokens = new CommonTokenStream(lexer);
EvilParser parser = new EvilParser(tokens);
EvilParser.program_return ret = null;
parser.TraceDestination = Console.Out;
try
{
ret = parser.Program();
}
catch (RecognitionException e)
{
throw new EvilException(EvilSystem.Parsing, "Error parsing.", e);
}
if (parser.NumberOfSyntaxErrors != 0)
throw new EvilException(EvilSystem.Parsing, "Syntax errors.");
CommonTree t = (CommonTree)ret.Tree;
return new Tuple<CommonTokenStream, CommonTree>(tokens, t);
});
}
开发者ID:AustinWise,项目名称:CSC431,代码行数:26,代码来源:FrontEndSteps.cs
示例6: Compile
public Expression Compile(String relinqScript)
{
var input = new ANTLRStringStream(relinqScript);
var lex = new EcmaScriptV3Lexer(input);
var tokens = new CommonTokenStream(lex);
var parser = new EcmaScriptV3Parser(tokens);
var es3Ast = parser.expression();
var rsAst = new RelinqScriptParser().Visit((CommonTree)es3Ast.Tree);
var compilerAst = new TypeInferenceAstBuilder().Visit(rsAst);
using (var engine = new TypeInferenceEngine(compilerAst))
{
#if DEBUG
try
{
var wtf = 0;
while(!engine.Run()) if (wtf++ == 10) break;
return new StronglyTypedAstBuilder().Visit(compilerAst);
}
catch (Exception)
{
engine.Dump();
throw;
}
#else
engine.Run();
return new StronglyTypedAstBuilder().Visit(tiAst);
#endif
}
}
开发者ID:xeno-by,项目名称:relinq,代码行数:31,代码来源:RelinqScriptCompiler2.cs
示例7: Compile
public static string Compile(string input)
{
input = input.Replace("\r", "");
ANTLRStringStream Input = new ANTLRStringStream(input);
SugarCppLexer lexer = new SugarCppLexer(Input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
SugarCppParser parser = new SugarCppParser(tokens);
AstParserRuleReturnScope<CommonTree, IToken> t = parser.root();
CommonTree ct = (CommonTree)t.Tree;
if (parser.errors.Count() > 0)
{
StringBuilder sb = new StringBuilder();
foreach (var error in parser.errors)
{
sb.Append(error);
sb.Append("\n");
}
throw new Exception(sb.ToString());
}
CommonTreeNodeStream nodes = new CommonTreeNodeStream(ct);
SugarWalker walker = new SugarWalker(nodes);
Root ast = walker.root();
TargetCpp target_cpp = new TargetCpp();
return ast.Accept(target_cpp).Render();
}
开发者ID:Connect2Begin,项目名称:SugarCpp,代码行数:32,代码来源:SugarCompiler.cs
示例8: ParseText
/// <summary>
/// Parses an expression in text form for later evaluation.
/// </summary>
/// <param name="pszCode">The expression to be parsed.</param>
/// <param name="dwFlags">A combination of flags from the PARSEFLAGS enumeration that controls parsing.</param>
/// <param name="nRadix">The radix to be used in parsing any numerical information in pszCode.</param>
/// <param name="ppExpr">Returns the IDebugExpression2 object that represents the parsed expression, which is ready for binding and evaluation.</param>
/// <param name="pbstrError">Returns the error message if the expression contains an error.</param>
/// <param name="pichError">Returns the character index of the error in pszCode if the expression contains an error.</param>
/// <returns>If successful, returns S_OK; otherwise, returns an error code.</returns>
/// <remarks>
/// When this method is called, a debug engine (DE) should parse the expression and validate it for correctness.
/// The pbstrError and pichError parameters may be filled in if the expression is invalid.
///
/// Note that the expression is not evaluated, only parsed. A later call to the IDebugExpression2.EvaluateSync
/// or IDebugExpression2.EvaluateAsync methods evaluates the parsed expression.
/// </remarks>
public int ParseText(string pszCode, enum_PARSEFLAGS dwFlags, uint nRadix, out IDebugExpression2 ppExpr, out string pbstrError, out uint pichError)
{
if (pszCode == null)
throw new ArgumentNullException("pszCode");
if (pszCode.Length == 0)
throw new ArgumentException();
// dwFlags=0 in the Immediate window
if (dwFlags != enum_PARSEFLAGS.PARSE_EXPRESSION && dwFlags != 0)
throw new NotImplementedException();
try
{
var expressionInput = new ANTLRStringStream(pszCode);
var expressionUnicodeInput = new JavaUnicodeStream(expressionInput);
var expressionLexer = new Java2Lexer(expressionUnicodeInput);
var expressionTokens = new CommonTokenStream(expressionLexer);
var expressionParser = new Java2Parser(expressionTokens);
IAstRuleReturnScope<CommonTree> result = expressionParser.standaloneExpression();
ppExpr = new JavaDebugExpression(this, result.Tree, pszCode);
pbstrError = null;
pichError = 0;
return VSConstants.S_OK;
}
catch (RecognitionException e)
{
ppExpr = null;
pbstrError = e.Message;
pichError = (uint)Math.Max(0, e.Index);
return VSConstants.E_FAIL;
}
}
开发者ID:Kav2018,项目名称:JavaForVS,代码行数:49,代码来源:JavaDebugExpressionContext.cs
示例9: Parse
public Feature Parse(TextReader featureFileReader)
{
var fileContent = featureFileReader.ReadToEnd() + Environment.NewLine;
CultureInfo language = GetLanguage(fileContent);
var inputStream = new ANTLRReaderStream(new StringReader(fileContent));
var lexer = GetLexter(language, inputStream);
var tokenStream = new CommonTokenStream(lexer);
var parser = new Grammar.SpecFlowLangParser(tokenStream);
var featureTree = parser.feature().Tree as CommonTree;
if (featureTree == null || parser.ParserErrors.Count > 0 || lexer.LexerErrors.Count > 0)
{
throw new SpecFlowParserException("Invalid Gherkin file!", lexer.LexerErrors.Concat(parser.ParserErrors).ToArray());
}
var walker = new SpecFlowLangWalker(new CommonTreeNodeStream(featureTree));
Feature feature = walker.feature();
if (feature == null)
throw new SpecFlowParserException("Invalid Gherkin file!");
feature.Language = language.Name;
return feature;
}
开发者ID:x97mdr,项目名称:SpecFlow,代码行数:29,代码来源:SpecFlowLangParser.cs
示例10: Main
public static void Main(string[] args)
{
if (args.Length == 1)
{
string fullpath;
if ( Path.IsPathRooted(args[0]) )
fullpath = args[0];
else
fullpath = Path.Combine(Environment.CurrentDirectory, args[0]);
Console.Out.WriteLine("Processing file: {0}", fullpath);
ICharStream input = new ANTLRFileStream(fullpath);
SimpleCLexer lex = new SimpleCLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lex);
SimpleCParser parser = new SimpleCParser(tokens);
SimpleCParser.program_return r = parser.program();
Console.Out.WriteLine("tree="+((ITree)r.Tree).ToStringTree());
if ( parser.NumberOfSyntaxErrors > 0 ) {
// don't tree parse if has errors
return;
}
CommonTreeNodeStream nodes = new CommonTreeNodeStream((ITree)r.Tree);
nodes.TokenStream = tokens;
SimpleCWalker walker = new SimpleCWalker(nodes);
walker.program();
}
else
Console.Error.WriteLine("Usage: SimpleC <input-file>");
}
开发者ID:vikas753,项目名称:examples-v3,代码行数:32,代码来源:Main.cs
示例11: GetParser
public ASMParser GetParser(string script)
{
var input = new ANTLRStringStream(script);
var lexer = new ASMLexer(input);
var tokens = new CommonTokenStream(lexer);
return new ASMParser(tokens);
}
开发者ID:ricardoborges,项目名称:NPortugol,代码行数:7,代码来源:ANTLRParserTestCase.cs
示例12: Compile
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);
}
}
开发者ID:emperorstarfinder,项目名称:phlox,代码行数:26,代码来源:ByteCompilerFrontend.cs
示例13: Compile
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();
}
开发者ID:dayanruben,项目名称:TigerConverters,代码行数:25,代码来源:ProgramExpression.cs
示例14: VisitLine
public void VisitLine(String line)
{
Core interp_visitor = new Core();
PrintVisitor print_visitor = new PrintVisitor(interp_visitor);
ANTLRStringStream string_stream = new ANTLRStringStream(line);
spinachLexer lexer = new spinachLexer(string_stream);
CommonTokenStream tokens = new CommonTokenStream(lexer);
spinachParser parser = new Test_Core(tokens, "");
try
{
spinachParser.program_return program = parser.program(); //h= (l+j)*h*l+l-h;
if (strBuilder.ToString() == "")
{
List<Element> elements = program.ret;
///-- call core function. to pass list of element.
for (int i = 0; i < elements.Count; i++)
{
Element curr = elements[i];
curr.Accept(print_visitor);
curr.Accept(interp_visitor);//PlotReceiver
}
}
else
{
Onerror(101, strBuilder.ToString());
}
}
catch (RecognitionException e)
{
Onerror(102, e.Message);
}
}
开发者ID:shranjan,项目名称:pinac,代码行数:34,代码来源:Test_Core.cs
示例15: RunTest
public Boolean RunTest()
{
try
{
GlobalMemory.Clear();
var sStream = new ANTLRStringStream(input);
var lexer = new SGLLexer(sStream);
var tStream = new CommonTokenStream(lexer);
// Parsing
var parser = new SGLParser(tStream);
var t = (CommonTree) parser.main().Tree;
// Printing tree
Console.WriteLine("; " + t.ToStringTree());
// TreeWalking
var treeStream = new CommonTreeNodeStream(t);
var tw = new SGLTreeWalker(treeStream, true);
AbstractNode returned = tw.main();
returned.Evaluate();
if (debug)
{
realOutput = GlobalMemory.Instance.DebugString;
}
else
{
realOutput = GlobalMemory.Instance.StoryboardCode.ToString();
}
// comparison
realOutput = realOutput.Trim();
output.Trim();
if (output.Equals(realOutput))
{
return true;
}
else
{
return false;
}
}
catch (CompilerException ce)
{
Console.WriteLine(ce.GetExceptionAsString());
return false;
}
catch (Exception ex)
{
Console.WriteLine("Es ist ein Fehler aufgetreten.");
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
return false;
}
}
开发者ID:brianex,项目名称:osu-sgl,代码行数:60,代码来源:Unit.cs
示例16: Parse
/// <summary>
/// Parses input stream to tokens and then according to CSS grammar.
/// </summary>
/// <param name="inp">file name of input stream.</param>
public void Parse(string inp)
{
string fullpath;
if (Path.IsPathRooted(inp))
fullpath = inp;
else
fullpath = Common.PathCombine(Environment.CurrentDirectory, inp);
ICharStream input = new ANTLRFileStream(fullpath, Encoding.UTF8);
csst3Lexer lex = new csst3Lexer(input);
CommonTokenStream tokens = new CommonTokenStream(lex);
csst3Parser parser = new csst3Parser(tokens);
// return results as parameters
try
{
Root = (CommonTree)parser.stylesheet().Tree;
Errors = parser.GetErrors();
}
catch (Exception)
{
Errors = parser.GetErrors();
throw;
}
}
开发者ID:neilmayhew,项目名称:pathway,代码行数:29,代码来源:CssTreeParser.cs
示例17: Compile
public static LuaResult Compile(
StaticMetaTables staticTables,
string source,
dynamic globals = null,
string name = null)
{
var result = new LuaResult();
var stopwatch = new Stopwatch();
stopwatch.Start();
try
{
var stream = new ANTLRStringStream(source);
var lexer = new ChunkLexer(stream);
var tokenStream = new CommonTokenStream(lexer);
var parser = new ChunkParser(tokenStream);
var r = parser.chunk();
result.Errors.AddRange(parser.Errors);
Expression e;
var scope = Scope.NewTopLevelScop();
var chunk = new Chunk();
result.Errors.AddRange(chunk.Generate(staticTables, scope, r.Tree, out e));
var fnExp = Expression.Lambda<Func<Table, object>>(e, scope.Env.GlobalParameter);
result.Chunk = new CompiledChunk(fnExp.Compile(), globals ?? new Table(), name);
}
finally
{
stopwatch.Stop();
result.ElapsedTime = stopwatch.Elapsed;
result.Success = !result.Errors.ContainsError();
}
return result;
}
开发者ID:jeffpanici75,项目名称:Tsuki,代码行数:35,代码来源:Chunk.cs
示例18: ParseSql
public static MySQL51Parser.program_return ParseSql(string sql, bool expectErrors, out StringBuilder sb, Version version )
{
// The grammar supports upper case only
MemoryStream ms = new MemoryStream(ASCIIEncoding.ASCII.GetBytes(sql/*.ToUpper() */));
CaseInsensitiveInputStream input = new CaseInsensitiveInputStream(ms);
//ANTLRInputStream input = new ANTLRInputStream(ms);
MySQLLexer lexer = new MySQLLexer(input);
lexer.MySqlVersion = version;
CommonTokenStream tokens = new CommonTokenStream(lexer);
MySQLParser parser = new MySQLParser(tokens);
parser.MySqlVersion = version;
sb = new StringBuilder();
TextWriter tw = new StringWriter(sb);
parser.TraceDestination = tw;
MySQL51Parser.program_return r = parser.program();
if (!expectErrors)
{
if (0 != parser.NumberOfSyntaxErrors)
Assert.AreEqual("", sb.ToString());
//Assert.AreEqual( 0, parser.NumberOfSyntaxErrors);
}
else
{
Assert.AreNotEqual(0, parser.NumberOfSyntaxErrors);
}
return r;
}
开发者ID:eeeee,项目名称:mysql-connector-net,代码行数:27,代码来源:Utility.cs
示例19: compilacion
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;
}
}
}
开发者ID:sgolivernet,项目名称:fkscript,代码行数:59,代码来源:FKVMCompiler.cs
示例20: RunTest
public Boolean RunTest()
{
try
{
ANTLRStringStream sStream = new ANTLRStringStream(input);
SGLLexer lexer = new SGLLexer(sStream);
CommonTokenStream tStream = new CommonTokenStream(lexer);
// Parsing
SGLParser parser = new SGLParser(tStream);
CommonTree t = (CommonTree)parser.compilationUnit().Tree;
// Printing tree
Console.WriteLine("; " + t.ToStringTree());
// TreeWalking
CommonTreeNodeStream treeStream = new CommonTreeNodeStream(t);
SGLTreeWalker tw = new SGLTreeWalker(treeStream);
SGLNode returned = tw.compilationUnit();
returned.Evaluate();
realOutput = tw.GetStoryboardCode().ToString();
// comparison
realOutput = realOutput.Trim();
output.Trim();
if (output.Equals(realOutput))
{
return true;
}
else
{
return false;
}
}
catch (SGLCompilerException ce)
{
if (ce.ErrorType.Equals("Antlr.Parser"))
{
Console.WriteLine("Error (wrong syntax) on " + ce.Message);
}
else
{
Console.WriteLine("Error (" + ce.ErrorType + ") on line " + ce.Line + ": " + ce.Message);
}
return false;
}
catch (Exception ex)
{
Console.WriteLine("Es ist ein Fehler aufgetreten.");
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
return false;
}
}
开发者ID:peppy,项目名称:sgl4cs,代码行数:59,代码来源:Unit.cs
注:本文中的Antlr.Runtime.CommonTokenStream类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论