Grammar Writing Tools [closed]

只愿长相守 提交于 2019-12-03 09:26:52

问题


I am trying to write a grammar in EBNF (barring a really good reason, it has to be EBNF) and am looking for a couple of utilities for it - if there's a GUI interface that can make one, that would be great, but the thing I'm looking for most is something that can check the grammar, for instance to see if it is LALR(n), and if so, what the value of n is. Do such utilities exist? Are there any other useful grammar-writing tools I should know about (I'm not looking for parser generators).


回答1:


Taking Steven Dee's suggestion one step further, you might want to check out ANTLRWorks, which is an interactive GUI development tool for ANTLR grammars.




回答2:


Use TinyPG! Its an amazing all-in-one compiler compiler with a lightweight GUI, where you build your parser with RegEx, EBNF, and write C#/VB code to do something with the parse tree!

Here's a short and informative summary that I did earlier, which also links you to the downloads.


My understandings of TinyPG:

TinyPG allows you to write & develop:

  • Define Terminals using Regular Expressions.
  • Define Non-terminals and parser rules in Extended BNF meta-syntax.
  • Write Compiler code in C# or VB, within TinyPG.

It has an in-built IDE, Windows Only (created in C#.NET, open source).

It allows you to try out & preview Regular Expressions using the inbuilt RegEx tool. RegEx syntax is supported in .NET which means that even your outputted parser code uses .NET's Regular Expressions.

You write EBNF to describe the language of your choice (Here are some freely available BNF Grammers that describe modern programming languages (C, Java, JavaScript, C#, VB.NET, SQL-89)

Using TinyPG, your RegEx along with your EBNF outputs a parse-tree (see this diagram).

Now what do you do with the parse-tree? You write C#/VB code (within TinyPG, per BNF grammer rule) for your Compiler/Interpreter/Translator. (inside TinyPG, open the "simple expression2.tpg" file within the provided Samples to see a demo of a calculator 'compiler')

TinyPG allows you to Compile and Test your tokenizer+parser+complier, within the TinyPG IDE, and it finally outputs the parser source code in C#.NET or VB.NET (your choice), with ready-to-use classes.

An excellent All-in-one Compiler Compiler for the masses. Enjoy!

PS: Correct me if I'm wrong on any of this.




回答3:


To check whether a grammar allows a certain parser algorithm, just put it into the parser generator. In case of LALR(1), pass the grammar to YACC to see whether it detects conflicts.




回答4:


CoCo/R C# is missing from the list. It is simple to use, very versatile and especially useful has code generators for a great variety of languages

Coco/R for C#, Java, C++, F#, VB.Net, Oberon, other languages

[1] http://www.ssw.uni-linz.ac.at/Coco/




回答5:


ANTLR is a GUI parser generator in Java that has extensive capabilities for grammar analysis and factoring. Check the FAQ; it might support what you're looking for.



来源:https://stackoverflow.com/questions/264262/grammar-writing-tools

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!