Should I use a formal grammar for my interpreted scripting language

I have a scripting engine I just published as an open source project. It’s been sitting on my harddrive waiting for about a year. My engine of course isn’t complete in any way, but it does work for simple scripts. It has a javascript-ish feel to it, but I don’t wish to abide by the ECMA spec or anything.

Now, the big thing I’m working on is improving code quality while leaving the language working as it is(which I have a few regression tests to “prove”). It doesn’t have a formal grammar at all and works like so:

  1. Preprocess/Tokenize. At this point it removes whitespace and cuts everything into “tokens”, which is basically just a structure containing a string and a rough “hint” as to what the token is (Number, Identifier, Operation, etc) and some debugging info such as line number
  2. A ScriptingEngine class which takes the list of tokens and actually parses them and executes them
  3. An “ExpressionEvaluator” class which will take a subset of the tokens list and build a specific tree of operations, values, and then execute operations and such and collapse the tree down into a single value

My engine has the goals of being portable(works everywhere .Net does) and self-contained. So far, this “works”, but the code is terrible and I’m pretty sure that I’m going about it the wrong way.

I’m wondering if a formal grammar and everything that goes with it might help

Some benefits I’ve heard of being more formal with grammar

  • Unambiguous specification of the language
  • Easier to maintain/change
  • More traditional/Bigger community support?

And some of the disadvantages

  • Some languages can be very difficult to reduce to a formal grammar, ie Perl.
  • A learning curve for someone not in the know(ie, me)
  • Generally rely on tools such as yacc and ANTLR, which introduce another step in your workflow and/or add dependencies(which I’d like to avoid)

Although this project is in .Net, it could equally apply to any other implementing language. Should I use a formal grammar? Can someone expand on the pros/cons of both sides?

3

First of all, a formal grammar doesn’t imply you have to use a parser generator. You can write a recursive descent parser or whatever floats your boat.

Formal grammars are good as documentation. They help programmers decide what foreign code means and tells you what is allowed / mandatory in the language.

For example, in javascript, do I always have to wrap a function literal in parens if I want to call it right away? That is, is this allowed:

function(a1,a2) { ... }(42, "bacon").

Formal grammars are also very helpful when you want to

  1. Make another implementation of the language,
  2. Do code generation targeting the language,
  3. Or for doing static analysis of the language.

Of course, if it’s a quick and dirty scripting language these points are less important.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật