Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yacc/Jay grammar file for JavaScript? [duplicate]

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).

like image 206
thr Avatar asked Sep 10 '09 22:09

thr


People also ask

What is $$ in yacc?

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.

Can yacc parse C?

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.

What is the syntax to declare the tokens in yacc program?

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.


1 Answers

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.

like image 174
JXG Avatar answered Sep 17 '22 18:09

JXG