Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

How is a syntax checker for a programming language written? I am guessing a grammar has to be written first. How to then proceed?

Motivation

I'm using a programming language (Apex for Salesforce) that is compiled in the cloud and a list of errors is sent back to the basic Eclipse editor. I'd like to skip the process for simple typing mistakes and just check for them locally.

share|improve this question

closed as too broad by Dan Pichelman, Bart van Ingen Schenau, Yusubov, GlenH7, gnat Aug 24 '13 at 20:22

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

    
A tool like Treetop seems like it would be very useful here. –  Robert Harvey Aug 23 '13 at 16:50
1  
Sharing your research helps everyone. Tell us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer. Also see How to Ask –  gnat Aug 23 '13 at 18:25
    
You're right so far. First define the rules, then check them. –  ott-- Aug 23 '13 at 19:06

1 Answer 1

up vote 1 down vote accepted

You're right so far. In all cases, you have to have a rigorous description of the syntax of the language (a "grammar") before you can build something that can take something allegedly in that language and determine if it complies with the syntax rules (a "parser").

The parser is the front end of a compiler. Code generation is the back end.

There are dozens of books out there on compiler construction. Most of them go into great detail on parsing techniques. Some deal only with the back end.

The best and most accessible book I've found for a beginner is Nicklaus Wirth's "Compiler Construction". Available free. You'll have to translate his source code from Oberon (a simple descendant of PASCAL and Modula-2) into your language of choice.

Jack Crenshaw's series, "Let's Build A Compiler", although incomplete, is almost as good, and just as accessible.

There are other tools. ANTLR is popular.

share|improve this answer
    
Yep. An intelligent editor is essentially a compiler minus the code generation. Note that to get anything which even remotely resembles the features of a modern IDE, you need much more than just the parser. You really need the full compiler minus the actual code generator: lexical analysis, syntactic analysis, semantic analysis, type inference, type checking etc. –  Jörg W Mittag Aug 24 '13 at 2:55
    
@JörgWMittag, the problem I have with EVERY "modern" IDE I have encountered is that NOT ONE of them contains an editor that even BEGINS to approach being competitive with GNU Emacs. There's a REASON I've been using GNU Emacs almost exclusively since 1988. Actually, there are a lot of reasons. (I occasionally have to deal with clue-impaired managers who do not understand that quality tools are just as important for software guys as they are for hardware guys.) –  John R. Strohm Aug 24 '13 at 3:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.