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.

slebetman
  • 109,858
  • 19
  • 140
  • 171
Miguel Jiménez
  • 1,276
  • 1
  • 16
  • 24
  • 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.) –  Dec 28 '12 at 04: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? – Miguel Jiménez Dec 28 '12 at 04:28

1 Answers1

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!

freethejazz
  • 2,235
  • 14
  • 19
  • See also, Douglas Crockford's essay [Top Down Operator Precedence](http://javascript.crockford.com/tdop/tdop.html), which gives a lot of background to the internal workings of jsLint. – Beetroot-Beetroot Dec 28 '12 at 04:51