0

I am designing a language, and I would like to enhance the user experience with a rich code editor. First I tough in CodeMirror, but then I found ACE Editor, which is open source too :)

I have read everything and decided for the second option. But I can not find how to implement a error detection mechanism; I am referring to the worker file. So...the question, finally, is which is the basic structure of a syntax analyzer for finding syntax errors using javascript? (for example JSHint)

I really appreciate your answers, thank you very much.

2
  • 1
    Do just what any conforming JavaScript/LanguageX engine would do .. lex it into a stream of tokens, parse the tokens into some ADT according to the language grammar, and then detect any syntax errors to that point (usually along the way) or continue with more awesome analysis. These steps are actually very simple in the scheme of things. (Tools like JSHint apply additional heuristics to "detect bad code"; that is, code that is valid but doesn't agree with someones set of rules/conventions or might be problematic for legitimate reasons.) Commented Dec 28, 2012 at 4:22
  • Thank you very much. Do you know if I must bear in mind additional things to get my worker to work with Ace editor? Commented Dec 28, 2012 at 4:28

1 Answer 1

1

To get into JavaScript-driven lexical analysis, checkout the source code of JSLint:

https://github.com/douglascrockford/JSLint/blob/master/jslint.js

You'll want to pay specific attention at line 1183, where lexical analysis and token construction begin. Good Luck!

Sign up to request clarification or add additional context in comments.

1 Comment

See also, Douglas Crockford's essay Top Down Operator Precedence, which gives a lot of background to the internal workings of jsLint.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.