Possible Duplicate:
Where can I find a yacc gammar for ECMAscript/Actionscript/Javascript
I'm trying to find a grammar file for JavaScript for Yacc (preferably for Jay, but since Jay is a Yacc clone I should be fine, since I need to implement it on .NET).
those $$ , $1 , $3 are the semantic values for for the symbols and tokens used in the rule in the order that they appear. The semantic value is that one that you get in yylval when the scanner gets a new token.
The yacc tool generates the C code required to parse this information; yacc doesn't do the parsing. The code in the braces is quasi-C source code. Yacc handles the translation from the original into the C source code based on your definitions and the rest of the code that is required to actually parse the content.
The declaration for a token must be made by specifying it in the YACC declarations section using the %token feature offered by YACC. The following example shows the declaration of the token DIGIT in a YACC program. The YACC program given above contains the declaration of the token DIGIT in the declarations section.
I think you would have to build it yourself, but there are hints along the way.
The complete JavaScript grammar should be available somewhere; a quick search showed me a JavaScript LL(1) Grammar. (There's also a BNF schema for JavaScript at RPA Toolkit: Parse JavaScript.)
Since you're asking only about a parser, I'm going to assume you already have a lexer.
Turning that grammar into a Yacc file really doesn't look so terrible. As an example, there is a C grammar for Yacc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With