--- /dev/null
+2003-03-30 Cesar Octavio Lopez Nataren <cesar@ciencias.unam.mx>
+
+ * Added this ChangeLog file.
+
+ * ast.cs: Added this file. Contains the classes used for building
+ the EcmaScript 's AST.
+
+ * JScript*: These are the files generated by antlr (the parser generator).
+
+ * TODOAttribute.cs: Changed the namespace in order to use it freely on Microsoft.JScript.
+
+ * driver.cs: Added this file. Contains the compiler entry point. And some Reflection.Emit methods,
+ that will be moved to other file in the future.
+
+ * jscript-lexer-parser.g: The EcmaScript's antlr grammar.
\ No newline at end of file
--- /dev/null
+// $ANTLR 2.7.2: "jscript-lexer-parser.g" -> "JScriptLexer.cs"$\r
+\r
+namespace Microsoft.JScript\r
+{\r
+ // Generate header specific to lexer CSharp file\r
+ using System;\r
+ using Stream = System.IO.Stream;\r
+ using TextReader = System.IO.TextReader;\r
+ using Hashtable = System.Collections.Hashtable;\r
+ \r
+ using TokenStreamException = antlr.TokenStreamException;\r
+ using TokenStreamIOException = antlr.TokenStreamIOException;\r
+ using TokenStreamRecognitionException = antlr.TokenStreamRecognitionException;\r
+ using CharStreamException = antlr.CharStreamException;\r
+ using CharStreamIOException = antlr.CharStreamIOException;\r
+ using ANTLRException = antlr.ANTLRException;\r
+ using CharScanner = antlr.CharScanner;\r
+ using InputBuffer = antlr.InputBuffer;\r
+ using ByteBuffer = antlr.ByteBuffer;\r
+ using CharBuffer = antlr.CharBuffer;\r
+ using Token = antlr.Token;\r
+ using CommonToken = antlr.CommonToken;\r
+ using RecognitionException = antlr.RecognitionException;\r
+ using NoViableAltForCharException = antlr.NoViableAltForCharException;\r
+ using MismatchedCharException = antlr.MismatchedCharException;\r
+ using TokenStream = antlr.TokenStream;\r
+ using LexerSharedInputState = antlr.LexerSharedInputState;\r
+ using BitSet = antlr.collections.impl.BitSet;\r
+ \r
+ public class JScriptLexer : antlr.CharScanner , TokenStream\r
+ {\r
+ public const int EOF = 1;\r
+ public const int NULL_TREE_LOOKAHEAD = 3;\r
+ public const int LBRACE = 4;\r
+ public const int RBRACE = 5;\r
+ public const int SEMI_COLON = 6;\r
+ public const int LITERAL_var = 7;\r
+ public const int COMMA = 8;\r
+ public const int IDENTIFIER = 9;\r
+ public const int ASSIGNMENT = 10;\r
+ public const int COMPOUND_ASSIGNMENT = 11;\r
+ public const int INTERROGATION = 12;\r
+ public const int COLON = 13;\r
+ public const int LOGICAL_OR = 14;\r
+ public const int LOGICAL_AND = 15;\r
+ public const int BITWISE_OR = 16;\r
+ public const int TRIANGLE = 17;\r
+ public const int BITWISE_AND = 18;\r
+ public const int PLUS = 19;\r
+ public const int MINUS = 20;\r
+ public const int TIMES = 21;\r
+ public const int SLASH = 22;\r
+ public const int PERCENT = 23;\r
+ public const int LITERAL_delete = 24;\r
+ public const int LITERAL_void = 25;\r
+ public const int LITERAL_typeof = 26;\r
+ public const int INCREMENT = 27;\r
+ public const int DECREMENT = 28;\r
+ public const int ADMIRATION = 29;\r
+ public const int LITERAL_new = 30;\r
+ public const int LPAREN = 31;\r
+ public const int RPAREN = 32;\r
+ public const int THIS = 33;\r
+ public const int LITERAL_print = 34;\r
+ public const int STRING_LITERAL = 35;\r
+ public const int LITERAL_function = 36;\r
+ public const int LITERAL_true = 37;\r
+ public const int LITERAL_false = 38;\r
+ public const int LITERAL_null = 39;\r
+ public const int TAB = 40;\r
+ public const int VERTICAL_TAB = 41;\r
+ public const int FORM_FEED = 42;\r
+ public const int SPACE = 43;\r
+ public const int NO_BREAK_SPACE = 44;\r
+ public const int LINE_FEED = 45;\r
+ public const int CARRIGE_RETURN = 46;\r
+ public const int LINE_SEPARATOR = 47;\r
+ public const int PARAGRAPH_SEPARATOR = 48;\r
+ public const int LSQUARE = 49;\r
+ public const int RSQUARE = 50;\r
+ public const int DOT = 51;\r
+ public const int L_THAN = 52;\r
+ public const int G_THAN = 53;\r
+ \r
+ public JScriptLexer(Stream ins) : this(new ByteBuffer(ins))\r
+ {\r
+ }\r
+ \r
+ public JScriptLexer(TextReader r) : this(new CharBuffer(r))\r
+ {\r
+ }\r
+ \r
+ public JScriptLexer(InputBuffer ib) : this(new LexerSharedInputState(ib))\r
+ {\r
+ }\r
+ \r
+ public JScriptLexer(LexerSharedInputState state) : base(state)\r
+ {\r
+ initialize();\r
+ }\r
+ private void initialize()\r
+ {\r
+ caseSensitiveLiterals = true;\r
+ setCaseSensitive(true);\r
+ literals = new Hashtable();\r
+ literals.Add("delete", 24);\r
+ literals.Add("function", 36);\r
+ literals.Add("var", 7);\r
+ literals.Add("null", 39);\r
+ literals.Add("void", 25);\r
+ literals.Add("typeof", 26);\r
+ literals.Add("true", 37);\r
+ literals.Add("print", 34);\r
+ literals.Add("false", 38);\r
+ literals.Add("new", 30);\r
+ }\r
+ \r
+ public new Token nextToken() //throws TokenStreamException\r
+ {\r
+ Token theRetToken = null;\r
+tryAgain:\r
+ for (;;)\r
+ {\r
+ Token _token = null;\r
+ int _ttype = Token.INVALID_TYPE;\r
+ resetText();\r
+ try // for char stream error handling\r
+ {\r
+ try // for lexical error handling\r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case '\t':\r
+ {\r
+ mTAB(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case '\u000b':\r
+ {\r
+ mVERTICAL_TAB(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case '\u000c':\r
+ {\r
+ mFORM_FEED(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case ' ':\r
+ {\r
+ mSPACE(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case '\u00a0':\r
+ {\r
+ mNO_BREAK_SPACE(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case '\n':\r
+ {\r
+ mLINE_FEED(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case '\r':\r
+ {\r
+ mCARRIGE_RETURN(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case '\u2028':\r
+ {\r
+ mLINE_SEPARATOR(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case '\u2029':\r
+ {\r
+ mPARAGRAPH_SEPARATOR(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case '{':\r
+ {\r
+ mLBRACE(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case '}':\r
+ {\r
+ mRBRACE(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case '(':\r
+ {\r
+ mLPAREN(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case ')':\r
+ {\r
+ mRPAREN(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case '[':\r
+ {\r
+ mLSQUARE(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case ']':\r
+ {\r
+ mRSQUARE(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case '.':\r
+ {\r
+ mDOT(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case ';':\r
+ {\r
+ mSEMI_COLON(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case ',':\r
+ {\r
+ mCOMMA(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case '<':\r
+ {\r
+ mL_THAN(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case '>':\r
+ {\r
+ mG_THAN(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case '*':\r
+ {\r
+ mTIMES(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case '/':\r
+ {\r
+ mSLASH(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case '%':\r
+ {\r
+ mPERCENT(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case '&':\r
+ {\r
+ mBITWISE_AND(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case '|':\r
+ {\r
+ mBITWISE_OR(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case '!':\r
+ {\r
+ mADMIRATION(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case '?':\r
+ {\r
+ mINTERROGATION(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case ':':\r
+ {\r
+ mCOLON(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case '=':\r
+ {\r
+ mASSIGNMENT(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case '^':\r
+ {\r
+ mTRIANGLE(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case '"':\r
+ {\r
+ mSTRING_LITERAL(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ case 'A': case 'B': case 'C': case 'D':\r
+ case 'E': case 'F': case 'G': case 'H':\r
+ case 'I': case 'J': case 'K': case 'L':\r
+ case 'M': case 'N': case 'O': case 'P':\r
+ case 'Q': case 'R': case 'S': case 'T':\r
+ case 'U': case 'V': case 'W': case 'X':\r
+ case 'Y': case 'Z': case 'a': case 'b':\r
+ case 'c': case 'd': case 'e': case 'f':\r
+ case 'g': case 'h': case 'i': case 'j':\r
+ case 'k': case 'l': case 'm': case 'n':\r
+ case 'o': case 'p': case 'q': case 'r':\r
+ case 's': case 't': case 'u': case 'v':\r
+ case 'w': case 'x': case 'y': case 'z':\r
+ {\r
+ mIDENTIFIER(true);\r
+ theRetToken = returnToken_;\r
+ break;\r
+ }\r
+ default:\r
+ if ((LA(1)=='+') && (LA(2)=='+'))\r
+ {\r
+ mINCREMENT(true);\r
+ theRetToken = returnToken_;\r
+ }\r
+ else if ((LA(1)=='-') && (LA(2)=='-')) {\r
+ mDECREMENT(true);\r
+ theRetToken = returnToken_;\r
+ }\r
+ else if ((LA(1)=='+') && (true)) {\r
+ mPLUS(true);\r
+ theRetToken = returnToken_;\r
+ }\r
+ else if ((LA(1)=='-') && (true)) {\r
+ mMINUS(true);\r
+ theRetToken = returnToken_;\r
+ }\r
+ else\r
+ {\r
+ if (LA(1)==EOF_CHAR) { uponEOF(); returnToken_ = makeToken(Token.EOF_TYPE); }\r
+ else {throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());}\r
+ }\r
+ break; }\r
+ if ( null==returnToken_ ) goto tryAgain; // found SKIP token\r
+ _ttype = returnToken_.Type;\r
+ returnToken_.Type = _ttype;\r
+ return returnToken_;\r
+ }\r
+ catch (RecognitionException e) {\r
+ throw new TokenStreamRecognitionException(e);\r
+ }\r
+ }\r
+ catch (CharStreamException cse) {\r
+ if ( cse is CharStreamIOException ) {\r
+ throw new TokenStreamIOException(((CharStreamIOException)cse).io);\r
+ }\r
+ else {\r
+ throw new TokenStreamException(cse.Message);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ \r
+ public void mTAB(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = TAB;\r
+ \r
+ match('\u0009');\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mVERTICAL_TAB(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = VERTICAL_TAB;\r
+ \r
+ match('\u000B');\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mFORM_FEED(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = FORM_FEED;\r
+ \r
+ match('\u000C');\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mSPACE(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = SPACE;\r
+ \r
+ match('\u0020');\r
+ _ttype =Token.SKIP;\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mNO_BREAK_SPACE(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = NO_BREAK_SPACE;\r
+ \r
+ match('\u00A0');\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mLINE_FEED(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = LINE_FEED;\r
+ \r
+ match('\u000A');\r
+ newline (); { _ttype =Token.SKIP; }\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mCARRIGE_RETURN(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = CARRIGE_RETURN;\r
+ \r
+ match('\u000D');\r
+ newline (); { _ttype =Token.SKIP; }\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mLINE_SEPARATOR(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = LINE_SEPARATOR;\r
+ \r
+ match('\u2028');\r
+ newline (); { _ttype =Token.SKIP; }\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mPARAGRAPH_SEPARATOR(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = PARAGRAPH_SEPARATOR;\r
+ \r
+ match('\u2029');\r
+ newline (); { _ttype =Token.SKIP; }\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mLBRACE(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = LBRACE;\r
+ \r
+ match('{');\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mRBRACE(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = RBRACE;\r
+ \r
+ match('}');\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mLPAREN(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = LPAREN;\r
+ \r
+ match('(');\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mRPAREN(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = RPAREN;\r
+ \r
+ match(')');\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mLSQUARE(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = LSQUARE;\r
+ \r
+ match('[');\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mRSQUARE(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = RSQUARE;\r
+ \r
+ match(']');\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mDOT(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = DOT;\r
+ \r
+ match('.');\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mSEMI_COLON(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = SEMI_COLON;\r
+ \r
+ match(';');\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mCOMMA(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = COMMA;\r
+ \r
+ match(',');\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mL_THAN(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = L_THAN;\r
+ \r
+ match('<');\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mG_THAN(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = G_THAN;\r
+ \r
+ match('>');\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mPLUS(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = PLUS;\r
+ \r
+ match('+');\r
+ {\r
+ if ((LA(1)=='='))\r
+ {\r
+ match('=');\r
+ _ttype = COMPOUND_ASSIGNMENT;\r
+ }\r
+ else {\r
+ }\r
+ \r
+ }\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mMINUS(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = MINUS;\r
+ \r
+ match('-');\r
+ {\r
+ if ((LA(1)=='='))\r
+ {\r
+ match('=');\r
+ _ttype = COMPOUND_ASSIGNMENT;\r
+ }\r
+ else {\r
+ }\r
+ \r
+ }\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mTIMES(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = TIMES;\r
+ \r
+ match('*');\r
+ {\r
+ if ((LA(1)=='='))\r
+ {\r
+ match('=');\r
+ _ttype = COMPOUND_ASSIGNMENT;\r
+ }\r
+ else {\r
+ }\r
+ \r
+ }\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mSLASH(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = SLASH;\r
+ \r
+ match('/');\r
+ {\r
+ if ((LA(1)=='='))\r
+ {\r
+ match('=');\r
+ _ttype = COMPOUND_ASSIGNMENT;\r
+ }\r
+ else {\r
+ }\r
+ \r
+ }\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mPERCENT(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = PERCENT;\r
+ \r
+ match('%');\r
+ {\r
+ if ((LA(1)=='='))\r
+ {\r
+ match('=');\r
+ _ttype = COMPOUND_ASSIGNMENT;\r
+ }\r
+ else {\r
+ }\r
+ \r
+ }\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mBITWISE_AND(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = BITWISE_AND;\r
+ \r
+ match('&');\r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case '&':\r
+ {\r
+ match('&');\r
+ _ttype = LOGICAL_AND;\r
+ break;\r
+ }\r
+ case '=':\r
+ {\r
+ match('=');\r
+ _ttype = COMPOUND_ASSIGNMENT;\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ }\r
+ break; }\r
+ }\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mBITWISE_OR(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = BITWISE_OR;\r
+ \r
+ match('|');\r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case '|':\r
+ {\r
+ match('|');\r
+ _ttype = LOGICAL_OR;\r
+ break;\r
+ }\r
+ case '=':\r
+ {\r
+ match('=');\r
+ _ttype = COMPOUND_ASSIGNMENT;\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ }\r
+ break; }\r
+ }\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mADMIRATION(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = ADMIRATION;\r
+ \r
+ match('!');\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mINTERROGATION(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = INTERROGATION;\r
+ \r
+ match('?');\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mCOLON(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = COLON;\r
+ \r
+ match(':');\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mASSIGNMENT(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = ASSIGNMENT;\r
+ \r
+ match('=');\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mTRIANGLE(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = TRIANGLE;\r
+ \r
+ match('^');\r
+ {\r
+ if ((LA(1)=='='))\r
+ {\r
+ match('=');\r
+ _ttype = COMPOUND_ASSIGNMENT;\r
+ }\r
+ else {\r
+ }\r
+ \r
+ }\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mINCREMENT(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = INCREMENT;\r
+ \r
+ match("++");\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mDECREMENT(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = DECREMENT;\r
+ \r
+ match("--");\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mSTRING_LITERAL(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = STRING_LITERAL;\r
+ \r
+ int _saveIndex = 0;\r
+ _saveIndex = text.Length;\r
+ match('"');\r
+ text.Length = _saveIndex;\r
+ { // ( ... )+\r
+ int _cnt105=0;\r
+ for (;;)\r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case 'a': case 'b': case 'c': case 'd':\r
+ case 'e': case 'f': case 'g': case 'h':\r
+ case 'i': case 'j': case 'k': case 'l':\r
+ case 'm': case 'n': case 'o': case 'p':\r
+ case 'q': case 'r': case 's': case 't':\r
+ case 'u': case 'v': case 'w': case 'x':\r
+ case 'y': case 'z':\r
+ {\r
+ matchRange('a','z');\r
+ break;\r
+ }\r
+ case 'A': case 'B': case 'C': case 'D':\r
+ case 'E': case 'F': case 'G': case 'H':\r
+ case 'I': case 'J': case 'K': case 'L':\r
+ case 'M': case 'N': case 'O': case 'P':\r
+ case 'Q': case 'R': case 'S': case 'T':\r
+ case 'U': case 'V': case 'W': case 'X':\r
+ case 'Y': case 'Z':\r
+ {\r
+ matchRange('A','Z');\r
+ break;\r
+ }\r
+ case ' ':\r
+ {\r
+ match('\u0020');\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ if (_cnt105 >= 1) { goto _loop105_breakloop; } else { throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());; }\r
+ }\r
+ break; }\r
+ _cnt105++;\r
+ }\r
+_loop105_breakloop: ;\r
+ } // ( ... )+\r
+ _saveIndex = text.Length;\r
+ match('"');\r
+ text.Length = _saveIndex;\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ public void mIDENTIFIER(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException\r
+{\r
+ int _ttype; Token _token=null; int _begin=text.Length;\r
+ _ttype = IDENTIFIER;\r
+ \r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case 'a': case 'b': case 'c': case 'd':\r
+ case 'e': case 'f': case 'g': case 'h':\r
+ case 'i': case 'j': case 'k': case 'l':\r
+ case 'm': case 'n': case 'o': case 'p':\r
+ case 'q': case 'r': case 's': case 't':\r
+ case 'u': case 'v': case 'w': case 'x':\r
+ case 'y': case 'z':\r
+ {\r
+ matchRange('a','z');\r
+ break;\r
+ }\r
+ case 'A': case 'B': case 'C': case 'D':\r
+ case 'E': case 'F': case 'G': case 'H':\r
+ case 'I': case 'J': case 'K': case 'L':\r
+ case 'M': case 'N': case 'O': case 'P':\r
+ case 'Q': case 'R': case 'S': case 'T':\r
+ case 'U': case 'V': case 'W': case 'X':\r
+ case 'Y': case 'Z':\r
+ {\r
+ matchRange('A','Z');\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());\r
+ }\r
+ }\r
+ }\r
+ { // ( ... )*\r
+ for (;;)\r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case 'a': case 'b': case 'c': case 'd':\r
+ case 'e': case 'f': case 'g': case 'h':\r
+ case 'i': case 'j': case 'k': case 'l':\r
+ case 'm': case 'n': case 'o': case 'p':\r
+ case 'q': case 'r': case 's': case 't':\r
+ case 'u': case 'v': case 'w': case 'x':\r
+ case 'y': case 'z':\r
+ {\r
+ matchRange('a','z');\r
+ break;\r
+ }\r
+ case 'A': case 'B': case 'C': case 'D':\r
+ case 'E': case 'F': case 'G': case 'H':\r
+ case 'I': case 'J': case 'K': case 'L':\r
+ case 'M': case 'N': case 'O': case 'P':\r
+ case 'Q': case 'R': case 'S': case 'T':\r
+ case 'U': case 'V': case 'W': case 'X':\r
+ case 'Y': case 'Z':\r
+ {\r
+ matchRange('A','Z');\r
+ break;\r
+ }\r
+ case '0': case '1': case '2': case '3':\r
+ case '4': case '5': case '6': case '7':\r
+ case '8': case '9':\r
+ {\r
+ matchRange('0','9');\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ goto _loop109_breakloop;\r
+ }\r
+ }\r
+ }\r
+_loop109_breakloop: ;\r
+ } // ( ... )*\r
+ _ttype = testLiteralsTable(_ttype);\r
+ if (_createToken && (null == _token) && (_ttype != Token.SKIP))\r
+ {\r
+ _token = makeToken(_ttype);\r
+ _token.setText(text.ToString(_begin, text.Length-_begin));\r
+ }\r
+ returnToken_ = _token;\r
+ }\r
+ \r
+ \r
+ \r
+}\r
+}\r
--- /dev/null
+// $ANTLR 2.7.2: "jscript-lexer-parser.g" -> "JScriptParser.cs"$\r
+\r
+namespace Microsoft.JScript\r
+{\r
+ // Generate the header common to all output files.\r
+ using System;\r
+ \r
+ using TokenBuffer = antlr.TokenBuffer;\r
+ using TokenStreamException = antlr.TokenStreamException;\r
+ using TokenStreamIOException = antlr.TokenStreamIOException;\r
+ using ANTLRException = antlr.ANTLRException;\r
+ using LLkParser = antlr.LLkParser;\r
+ using Token = antlr.Token;\r
+ using TokenStream = antlr.TokenStream;\r
+ using RecognitionException = antlr.RecognitionException;\r
+ using NoViableAltException = antlr.NoViableAltException;\r
+ using MismatchedTokenException = antlr.MismatchedTokenException;\r
+ using SemanticException = antlr.SemanticException;\r
+ using ParserSharedInputState = antlr.ParserSharedInputState;\r
+ using BitSet = antlr.collections.impl.BitSet;\r
+ \r
+ public class JScriptParser : antlr.LLkParser\r
+ {\r
+ public const int EOF = 1;\r
+ public const int NULL_TREE_LOOKAHEAD = 3;\r
+ public const int LBRACE = 4;\r
+ public const int RBRACE = 5;\r
+ public const int SEMI_COLON = 6;\r
+ public const int LITERAL_var = 7;\r
+ public const int COMMA = 8;\r
+ public const int IDENTIFIER = 9;\r
+ public const int ASSIGNMENT = 10;\r
+ public const int COMPOUND_ASSIGNMENT = 11;\r
+ public const int INTERROGATION = 12;\r
+ public const int COLON = 13;\r
+ public const int LOGICAL_OR = 14;\r
+ public const int LOGICAL_AND = 15;\r
+ public const int BITWISE_OR = 16;\r
+ public const int TRIANGLE = 17;\r
+ public const int BITWISE_AND = 18;\r
+ public const int PLUS = 19;\r
+ public const int MINUS = 20;\r
+ public const int TIMES = 21;\r
+ public const int SLASH = 22;\r
+ public const int PERCENT = 23;\r
+ public const int LITERAL_delete = 24;\r
+ public const int LITERAL_void = 25;\r
+ public const int LITERAL_typeof = 26;\r
+ public const int INCREMENT = 27;\r
+ public const int DECREMENT = 28;\r
+ public const int ADMIRATION = 29;\r
+ public const int LITERAL_new = 30;\r
+ public const int LPAREN = 31;\r
+ public const int RPAREN = 32;\r
+ public const int THIS = 33;\r
+ public const int LITERAL_print = 34;\r
+ public const int STRING_LITERAL = 35;\r
+ public const int LITERAL_function = 36;\r
+ public const int LITERAL_true = 37;\r
+ public const int LITERAL_false = 38;\r
+ public const int LITERAL_null = 39;\r
+ public const int TAB = 40;\r
+ public const int VERTICAL_TAB = 41;\r
+ public const int FORM_FEED = 42;\r
+ public const int SPACE = 43;\r
+ public const int NO_BREAK_SPACE = 44;\r
+ public const int LINE_FEED = 45;\r
+ public const int CARRIGE_RETURN = 46;\r
+ public const int LINE_SEPARATOR = 47;\r
+ public const int PARAGRAPH_SEPARATOR = 48;\r
+ public const int LSQUARE = 49;\r
+ public const int RSQUARE = 50;\r
+ public const int DOT = 51;\r
+ public const int L_THAN = 52;\r
+ public const int G_THAN = 53;\r
+ \r
+ \r
+ protected void initialize()\r
+ {\r
+ tokenNames = tokenNames_;\r
+ }\r
+ \r
+ \r
+ protected JScriptParser(TokenBuffer tokenBuf, int k) : base(tokenBuf, k)\r
+ {\r
+ initialize();\r
+ }\r
+ \r
+ public JScriptParser(TokenBuffer tokenBuf) : this(tokenBuf,1)\r
+ {\r
+ }\r
+ \r
+ protected JScriptParser(TokenStream lexer, int k) : base(lexer,k)\r
+ {\r
+ initialize();\r
+ }\r
+ \r
+ public JScriptParser(TokenStream lexer) : this(lexer,1)\r
+ {\r
+ }\r
+ \r
+ public JScriptParser(ParserSharedInputState state) : base(state,1)\r
+ {\r
+ initialize();\r
+ }\r
+ \r
+ public void program(\r
+ Program p\r
+ ) //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ SourceElements elems;\r
+ \r
+ \r
+ try { // for error handling\r
+ source_elements(p.SourceElements);\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_0_);\r
+ }\r
+ }\r
+ \r
+ public void source_elements(\r
+ SourceElements elems\r
+ ) //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ SourceElement se;\r
+ \r
+ \r
+ try { // for error handling\r
+ se=source_element();\r
+ elems.Add (se);\r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case LBRACE:\r
+ case SEMI_COLON:\r
+ case LITERAL_var:\r
+ case LITERAL_print:\r
+ case LITERAL_function:\r
+ {\r
+ source_elements(elems);\r
+ break;\r
+ }\r
+ case EOF:\r
+ case RBRACE:\r
+ {\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_1_);\r
+ }\r
+ }\r
+ \r
+ public SourceElement source_element() //throws RecognitionException, TokenStreamException\r
+{\r
+ SourceElement se;\r
+ \r
+ \r
+ se = new SourceElement ();\r
+ Statement stm = null;\r
+ FunctionDeclaration fd = null;\r
+ \r
+ \r
+ try { // for error handling\r
+ switch ( LA(1) )\r
+ {\r
+ case LBRACE:\r
+ case SEMI_COLON:\r
+ case LITERAL_var:\r
+ case LITERAL_print:\r
+ {\r
+ stm=statement();\r
+ se = stm;\r
+ break;\r
+ }\r
+ case LITERAL_function:\r
+ {\r
+ fd=function_declaration();\r
+ se = fd;\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_2_);\r
+ }\r
+ return se;\r
+ }\r
+ \r
+ public Statement statement() //throws RecognitionException, TokenStreamException\r
+{\r
+ Statement stm;\r
+ \r
+ \r
+ stm = null;\r
+ \r
+ \r
+ try { // for error handling\r
+ switch ( LA(1) )\r
+ {\r
+ case LBRACE:\r
+ {\r
+ block();\r
+ break;\r
+ }\r
+ case LITERAL_var:\r
+ {\r
+ variable_statement();\r
+ break;\r
+ }\r
+ case SEMI_COLON:\r
+ {\r
+ empty_statement();\r
+ break;\r
+ }\r
+ case LITERAL_print:\r
+ {\r
+ stm=print_statement();\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_2_);\r
+ }\r
+ return stm;\r
+ }\r
+ \r
+ public FunctionDeclaration function_declaration() //throws RecognitionException, TokenStreamException\r
+{\r
+ FunctionDeclaration fd;\r
+ \r
+ \r
+ fd = new FunctionDeclaration ();\r
+ \r
+ \r
+ try { // for error handling\r
+ match(LITERAL_function);\r
+ match(IDENTIFIER);\r
+ match(LPAREN);\r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case IDENTIFIER:\r
+ {\r
+ formal_parameter_list();\r
+ break;\r
+ }\r
+ case RPAREN:\r
+ {\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ match(RPAREN);\r
+ match(LBRACE);\r
+ function_body(fd.elems);\r
+ match(RBRACE);\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_2_);\r
+ }\r
+ return fd;\r
+ }\r
+ \r
+ public void block() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ match(LBRACE);\r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case LBRACE:\r
+ case SEMI_COLON:\r
+ case LITERAL_var:\r
+ case LITERAL_print:\r
+ {\r
+ statement_list();\r
+ break;\r
+ }\r
+ case RBRACE:\r
+ {\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ match(RBRACE);\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_2_);\r
+ }\r
+ }\r
+ \r
+ public void variable_statement() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ match(LITERAL_var);\r
+ variable_declaration_list();\r
+ match(SEMI_COLON);\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_2_);\r
+ }\r
+ }\r
+ \r
+ public void empty_statement() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ match(SEMI_COLON);\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_2_);\r
+ }\r
+ }\r
+ \r
+ public PrintStatement print_statement() //throws RecognitionException, TokenStreamException\r
+{\r
+ PrintStatement pn;\r
+ \r
+ Token str = null;\r
+ pn = new PrintStatement ();\r
+ \r
+ try { // for error handling\r
+ match(LITERAL_print);\r
+ match(LPAREN);\r
+ str = LT(1);\r
+ match(STRING_LITERAL);\r
+ match(RPAREN);\r
+ match(SEMI_COLON);\r
+ \r
+ pn.Message = str.getText (); \r
+ \r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_2_);\r
+ }\r
+ return pn;\r
+ }\r
+ \r
+ public void statement_list() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ statement();\r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case LBRACE:\r
+ case SEMI_COLON:\r
+ case LITERAL_var:\r
+ case LITERAL_print:\r
+ {\r
+ statement_list();\r
+ break;\r
+ }\r
+ case RBRACE:\r
+ {\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_3_);\r
+ }\r
+ }\r
+ \r
+ public void variable_declaration_list() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ variable_declaration();\r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case COMMA:\r
+ {\r
+ match(COMMA);\r
+ variable_declaration_list();\r
+ break;\r
+ }\r
+ case SEMI_COLON:\r
+ {\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_4_);\r
+ }\r
+ }\r
+ \r
+ public void variable_declaration() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ match(IDENTIFIER);\r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case ASSIGNMENT:\r
+ {\r
+ initialiser();\r
+ break;\r
+ }\r
+ case SEMI_COLON:\r
+ case COMMA:\r
+ {\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_5_);\r
+ }\r
+ }\r
+ \r
+ public void initialiser() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ match(ASSIGNMENT);\r
+ assignment_expression();\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_5_);\r
+ }\r
+ }\r
+ \r
+ public void assignment_expression() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ conditional_expression();\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_6_);\r
+ }\r
+ }\r
+ \r
+ public void conditional_expression() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ logical_or_expression();\r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case INTERROGATION:\r
+ {\r
+ match(INTERROGATION);\r
+ assignment_expression();\r
+ match(COLON);\r
+ assignment_expression();\r
+ break;\r
+ }\r
+ case SEMI_COLON:\r
+ case COMMA:\r
+ case COLON:\r
+ case RPAREN:\r
+ {\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_6_);\r
+ }\r
+ }\r
+ \r
+ public void assignment_operator() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ switch ( LA(1) )\r
+ {\r
+ case ASSIGNMENT:\r
+ {\r
+ match(ASSIGNMENT);\r
+ break;\r
+ }\r
+ case COMPOUND_ASSIGNMENT:\r
+ {\r
+ match(COMPOUND_ASSIGNMENT);\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_0_);\r
+ }\r
+ }\r
+ \r
+ public void logical_or_expression() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ logical_and_expression();\r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case LOGICAL_OR:\r
+ {\r
+ match(LOGICAL_OR);\r
+ logical_or_expression();\r
+ break;\r
+ }\r
+ case SEMI_COLON:\r
+ case COMMA:\r
+ case INTERROGATION:\r
+ case COLON:\r
+ case RPAREN:\r
+ {\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_7_);\r
+ }\r
+ }\r
+ \r
+ public void logical_and_expression() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ bitwise_or_expression();\r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case LOGICAL_AND:\r
+ {\r
+ match(LOGICAL_AND);\r
+ logical_and_expression();\r
+ break;\r
+ }\r
+ case SEMI_COLON:\r
+ case COMMA:\r
+ case INTERROGATION:\r
+ case COLON:\r
+ case LOGICAL_OR:\r
+ case RPAREN:\r
+ {\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_8_);\r
+ }\r
+ }\r
+ \r
+ public void bitwise_or_expression() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ bitwise_xor_expression();\r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case BITWISE_OR:\r
+ {\r
+ match(BITWISE_OR);\r
+ bitwise_or_expression();\r
+ break;\r
+ }\r
+ case SEMI_COLON:\r
+ case COMMA:\r
+ case INTERROGATION:\r
+ case COLON:\r
+ case LOGICAL_OR:\r
+ case LOGICAL_AND:\r
+ case RPAREN:\r
+ {\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_9_);\r
+ }\r
+ }\r
+ \r
+ public void bitwise_xor_expression() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ bitwise_and_expression();\r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case TRIANGLE:\r
+ {\r
+ match(TRIANGLE);\r
+ bitwise_xor_expression();\r
+ break;\r
+ }\r
+ case SEMI_COLON:\r
+ case COMMA:\r
+ case INTERROGATION:\r
+ case COLON:\r
+ case LOGICAL_OR:\r
+ case LOGICAL_AND:\r
+ case BITWISE_OR:\r
+ case RPAREN:\r
+ {\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_10_);\r
+ }\r
+ }\r
+ \r
+ public void bitwise_and_expression() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ equality_expression();\r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case BITWISE_AND:\r
+ {\r
+ match(BITWISE_AND);\r
+ bitwise_and_expression();\r
+ break;\r
+ }\r
+ case SEMI_COLON:\r
+ case COMMA:\r
+ case INTERROGATION:\r
+ case COLON:\r
+ case LOGICAL_OR:\r
+ case LOGICAL_AND:\r
+ case BITWISE_OR:\r
+ case TRIANGLE:\r
+ case RPAREN:\r
+ {\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_11_);\r
+ }\r
+ }\r
+ \r
+ public void equality_expression() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ relational_expression();\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_12_);\r
+ }\r
+ }\r
+ \r
+ public void relational_expression() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ shift_expression();\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_12_);\r
+ }\r
+ }\r
+ \r
+ public void shift_expression() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ additive_expression();\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_12_);\r
+ }\r
+ }\r
+ \r
+ public void additive_expression() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ multiplicative_expression();\r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case PLUS:\r
+ case MINUS:\r
+ {\r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case PLUS:\r
+ {\r
+ match(PLUS);\r
+ break;\r
+ }\r
+ case MINUS:\r
+ {\r
+ match(MINUS);\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ additive_expression();\r
+ break;\r
+ }\r
+ case SEMI_COLON:\r
+ case COMMA:\r
+ case INTERROGATION:\r
+ case COLON:\r
+ case LOGICAL_OR:\r
+ case LOGICAL_AND:\r
+ case BITWISE_OR:\r
+ case TRIANGLE:\r
+ case BITWISE_AND:\r
+ case RPAREN:\r
+ {\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_12_);\r
+ }\r
+ }\r
+ \r
+ public void multiplicative_expression() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ unary_expression();\r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case TIMES:\r
+ case SLASH:\r
+ case PERCENT:\r
+ {\r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case TIMES:\r
+ {\r
+ match(TIMES);\r
+ break;\r
+ }\r
+ case SLASH:\r
+ {\r
+ match(SLASH);\r
+ break;\r
+ }\r
+ case PERCENT:\r
+ {\r
+ match(PERCENT);\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ multiplicative_expression();\r
+ break;\r
+ }\r
+ case SEMI_COLON:\r
+ case COMMA:\r
+ case INTERROGATION:\r
+ case COLON:\r
+ case LOGICAL_OR:\r
+ case LOGICAL_AND:\r
+ case BITWISE_OR:\r
+ case TRIANGLE:\r
+ case BITWISE_AND:\r
+ case PLUS:\r
+ case MINUS:\r
+ case RPAREN:\r
+ {\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_13_);\r
+ }\r
+ }\r
+ \r
+ public void unary_expression() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ switch ( LA(1) )\r
+ {\r
+ case IDENTIFIER:\r
+ case LITERAL_new:\r
+ case THIS:\r
+ case LITERAL_true:\r
+ case LITERAL_false:\r
+ case LITERAL_null:\r
+ {\r
+ postfix_expression();\r
+ break;\r
+ }\r
+ case PLUS:\r
+ case MINUS:\r
+ case LITERAL_delete:\r
+ case LITERAL_void:\r
+ case LITERAL_typeof:\r
+ case INCREMENT:\r
+ case DECREMENT:\r
+ case ADMIRATION:\r
+ {\r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case LITERAL_delete:\r
+ {\r
+ match(LITERAL_delete);\r
+ break;\r
+ }\r
+ case LITERAL_void:\r
+ {\r
+ match(LITERAL_void);\r
+ break;\r
+ }\r
+ case LITERAL_typeof:\r
+ {\r
+ match(LITERAL_typeof);\r
+ break;\r
+ }\r
+ case INCREMENT:\r
+ {\r
+ match(INCREMENT);\r
+ break;\r
+ }\r
+ case DECREMENT:\r
+ {\r
+ match(DECREMENT);\r
+ break;\r
+ }\r
+ case PLUS:\r
+ {\r
+ match(PLUS);\r
+ break;\r
+ }\r
+ case MINUS:\r
+ {\r
+ match(MINUS);\r
+ break;\r
+ }\r
+ case ADMIRATION:\r
+ {\r
+ match(ADMIRATION);\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ unary_expression();\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_14_);\r
+ }\r
+ }\r
+ \r
+ public void postfix_expression() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ left_hand_side_expression();\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_14_);\r
+ }\r
+ }\r
+ \r
+ public void left_hand_side_expression() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ new_expression();\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_14_);\r
+ }\r
+ }\r
+ \r
+ public void new_expression() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ switch ( LA(1) )\r
+ {\r
+ case IDENTIFIER:\r
+ case THIS:\r
+ case LITERAL_true:\r
+ case LITERAL_false:\r
+ case LITERAL_null:\r
+ {\r
+ member_expression();\r
+ break;\r
+ }\r
+ case LITERAL_new:\r
+ {\r
+ match(LITERAL_new);\r
+ new_expression();\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_14_);\r
+ }\r
+ }\r
+ \r
+ public void member_expression() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ primary_expression();\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_15_);\r
+ }\r
+ }\r
+ \r
+ public void call_expression() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ member_expression();\r
+ arguments();\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_0_);\r
+ }\r
+ }\r
+ \r
+ public void arguments() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ match(LPAREN);\r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case IDENTIFIER:\r
+ case PLUS:\r
+ case MINUS:\r
+ case LITERAL_delete:\r
+ case LITERAL_void:\r
+ case LITERAL_typeof:\r
+ case INCREMENT:\r
+ case DECREMENT:\r
+ case ADMIRATION:\r
+ case LITERAL_new:\r
+ case THIS:\r
+ case LITERAL_true:\r
+ case LITERAL_false:\r
+ case LITERAL_null:\r
+ {\r
+ argument_list();\r
+ break;\r
+ }\r
+ case RPAREN:\r
+ {\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ match(RPAREN);\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_0_);\r
+ }\r
+ }\r
+ \r
+ public void primary_expression() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ switch ( LA(1) )\r
+ {\r
+ case THIS:\r
+ {\r
+ match(THIS);\r
+ break;\r
+ }\r
+ case IDENTIFIER:\r
+ {\r
+ match(IDENTIFIER);\r
+ break;\r
+ }\r
+ case LITERAL_true:\r
+ case LITERAL_false:\r
+ case LITERAL_null:\r
+ {\r
+ literal();\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_15_);\r
+ }\r
+ }\r
+ \r
+ public void argument_list() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ assignment_expression();\r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case COMMA:\r
+ {\r
+ match(COMMA);\r
+ argument_list();\r
+ break;\r
+ }\r
+ case RPAREN:\r
+ {\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_16_);\r
+ }\r
+ }\r
+ \r
+ public void literal() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ switch ( LA(1) )\r
+ {\r
+ case LITERAL_true:\r
+ case LITERAL_false:\r
+ {\r
+ boolean_literal();\r
+ break;\r
+ }\r
+ case LITERAL_null:\r
+ {\r
+ null_literal();\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_15_);\r
+ }\r
+ }\r
+ \r
+ public void boolean_literal() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ switch ( LA(1) )\r
+ {\r
+ case LITERAL_true:\r
+ {\r
+ match(LITERAL_true);\r
+ break;\r
+ }\r
+ case LITERAL_false:\r
+ {\r
+ match(LITERAL_false);\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_15_);\r
+ }\r
+ }\r
+ \r
+ public void null_literal() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ match(LITERAL_null);\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_15_);\r
+ }\r
+ }\r
+ \r
+ public void formal_parameter_list() //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ match(IDENTIFIER);\r
+ {\r
+ switch ( LA(1) )\r
+ {\r
+ case COMMA:\r
+ {\r
+ match(COMMA);\r
+ formal_parameter_list();\r
+ break;\r
+ }\r
+ case RPAREN:\r
+ {\r
+ break;\r
+ }\r
+ default:\r
+ {\r
+ throw new NoViableAltException(LT(1), getFilename());\r
+ }\r
+ }\r
+ }\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_16_);\r
+ }\r
+ }\r
+ \r
+ public void function_body(\r
+ SourceElements elems\r
+ ) //throws RecognitionException, TokenStreamException\r
+{\r
+ \r
+ \r
+ try { // for error handling\r
+ source_elements(elems);\r
+ }\r
+ catch (RecognitionException ex)\r
+ {\r
+ reportError(ex);\r
+ consume();\r
+ consumeUntil(tokenSet_3_);\r
+ }\r
+ }\r
+ \r
+ private void initializeFactory()\r
+ {\r
+ }\r
+ \r
+ public static readonly string[] tokenNames_ = new string[] {\r
+ @"""<0>""",\r
+ @"""EOF""",\r
+ @"""<2>""",\r
+ @"""NULL_TREE_LOOKAHEAD""",\r
+ @"""LBRACE""",\r
+ @"""RBRACE""",\r
+ @"""SEMI_COLON""",\r
+ @"""var""",\r
+ @"""COMMA""",\r
+ @"""IDENTIFIER""",\r
+ @"""ASSIGNMENT""",\r
+ @"""COMPOUND_ASSIGNMENT""",\r
+ @"""INTERROGATION""",\r
+ @"""COLON""",\r
+ @"""LOGICAL_OR""",\r
+ @"""LOGICAL_AND""",\r
+ @"""BITWISE_OR""",\r
+ @"""TRIANGLE""",\r
+ @"""BITWISE_AND""",\r
+ @"""PLUS""",\r
+ @"""MINUS""",\r
+ @"""TIMES""",\r
+ @"""SLASH""",\r
+ @"""PERCENT""",\r
+ @"""delete""",\r
+ @"""void""",\r
+ @"""typeof""",\r
+ @"""INCREMENT""",\r
+ @"""DECREMENT""",\r
+ @"""ADMIRATION""",\r
+ @"""new""",\r
+ @"""LPAREN""",\r
+ @"""RPAREN""",\r
+ @"""THIS""",\r
+ @"""print""",\r
+ @"""STRING_LITERAL""",\r
+ @"""function""",\r
+ @"""true""",\r
+ @"""false""",\r
+ @"""null""",\r
+ @"""TAB""",\r
+ @"""VERTICAL_TAB""",\r
+ @"""FORM_FEED""",\r
+ @"""SPACE""",\r
+ @"""NO_BREAK_SPACE""",\r
+ @"""LINE_FEED""",\r
+ @"""CARRIGE_RETURN""",\r
+ @"""LINE_SEPARATOR""",\r
+ @"""PARAGRAPH_SEPARATOR""",\r
+ @"""LSQUARE""",\r
+ @"""RSQUARE""",\r
+ @"""DOT""",\r
+ @"""L_THAN""",\r
+ @"""G_THAN"""\r
+ };\r
+ \r
+ private static long[] mk_tokenSet_0_()\r
+ {\r
+ long[] data = { 2L, 0L};\r
+ return data;\r
+ }\r
+ public static readonly BitSet tokenSet_0_ = new BitSet(mk_tokenSet_0_());\r
+ private static long[] mk_tokenSet_1_()\r
+ {\r
+ long[] data = { 34L, 0L};\r
+ return data;\r
+ }\r
+ public static readonly BitSet tokenSet_1_ = new BitSet(mk_tokenSet_1_());\r
+ private static long[] mk_tokenSet_2_()\r
+ {\r
+ long[] data = { 85899346162L, 0L};\r
+ return data;\r
+ }\r
+ public static readonly BitSet tokenSet_2_ = new BitSet(mk_tokenSet_2_());\r
+ private static long[] mk_tokenSet_3_()\r
+ {\r
+ long[] data = { 32L, 0L};\r
+ return data;\r
+ }\r
+ public static readonly BitSet tokenSet_3_ = new BitSet(mk_tokenSet_3_());\r
+ private static long[] mk_tokenSet_4_()\r
+ {\r
+ long[] data = { 64L, 0L};\r
+ return data;\r
+ }\r
+ public static readonly BitSet tokenSet_4_ = new BitSet(mk_tokenSet_4_());\r
+ private static long[] mk_tokenSet_5_()\r
+ {\r
+ long[] data = { 320L, 0L};\r
+ return data;\r
+ }\r
+ public static readonly BitSet tokenSet_5_ = new BitSet(mk_tokenSet_5_());\r
+ private static long[] mk_tokenSet_6_()\r
+ {\r
+ long[] data = { 4294975808L, 0L};\r
+ return data;\r
+ }\r
+ public static readonly BitSet tokenSet_6_ = new BitSet(mk_tokenSet_6_());\r
+ private static long[] mk_tokenSet_7_()\r
+ {\r
+ long[] data = { 4294979904L, 0L};\r
+ return data;\r
+ }\r
+ public static readonly BitSet tokenSet_7_ = new BitSet(mk_tokenSet_7_());\r
+ private static long[] mk_tokenSet_8_()\r
+ {\r
+ long[] data = { 4294996288L, 0L};\r
+ return data;\r
+ }\r
+ public static readonly BitSet tokenSet_8_ = new BitSet(mk_tokenSet_8_());\r
+ private static long[] mk_tokenSet_9_()\r
+ {\r
+ long[] data = { 4295029056L, 0L};\r
+ return data;\r
+ }\r
+ public static readonly BitSet tokenSet_9_ = new BitSet(mk_tokenSet_9_());\r
+ private static long[] mk_tokenSet_10_()\r
+ {\r
+ long[] data = { 4295094592L, 0L};\r
+ return data;\r
+ }\r
+ public static readonly BitSet tokenSet_10_ = new BitSet(mk_tokenSet_10_());\r
+ private static long[] mk_tokenSet_11_()\r
+ {\r
+ long[] data = { 4295225664L, 0L};\r
+ return data;\r
+ }\r
+ public static readonly BitSet tokenSet_11_ = new BitSet(mk_tokenSet_11_());\r
+ private static long[] mk_tokenSet_12_()\r
+ {\r
+ long[] data = { 4295487808L, 0L};\r
+ return data;\r
+ }\r
+ public static readonly BitSet tokenSet_12_ = new BitSet(mk_tokenSet_12_());\r
+ private static long[] mk_tokenSet_13_()\r
+ {\r
+ long[] data = { 4297060672L, 0L};\r
+ return data;\r
+ }\r
+ public static readonly BitSet tokenSet_13_ = new BitSet(mk_tokenSet_13_());\r
+ private static long[] mk_tokenSet_14_()\r
+ {\r
+ long[] data = { 4311740736L, 0L};\r
+ return data;\r
+ }\r
+ public static readonly BitSet tokenSet_14_ = new BitSet(mk_tokenSet_14_());\r
+ private static long[] mk_tokenSet_15_()\r
+ {\r
+ long[] data = { 6459224384L, 0L};\r
+ return data;\r
+ }\r
+ public static readonly BitSet tokenSet_15_ = new BitSet(mk_tokenSet_15_());\r
+ private static long[] mk_tokenSet_16_()\r
+ {\r
+ long[] data = { 4294967296L, 0L};\r
+ return data;\r
+ }\r
+ public static readonly BitSet tokenSet_16_ = new BitSet(mk_tokenSet_16_());\r
+ \r
+}\r
+}\r
--- /dev/null
+// $ANTLR 2.7.2: "jscript-lexer-parser.g" -> "JScriptLexer.cs"$\r
+\r
+namespace Microsoft.JScript\r
+{\r
+ public class JScriptParserTokenTypes\r
+ {\r
+ public const int EOF = 1;\r
+ public const int NULL_TREE_LOOKAHEAD = 3;\r
+ public const int LBRACE = 4;\r
+ public const int RBRACE = 5;\r
+ public const int SEMI_COLON = 6;\r
+ public const int LITERAL_var = 7;\r
+ public const int COMMA = 8;\r
+ public const int IDENTIFIER = 9;\r
+ public const int ASSIGNMENT = 10;\r
+ public const int COMPOUND_ASSIGNMENT = 11;\r
+ public const int INTERROGATION = 12;\r
+ public const int COLON = 13;\r
+ public const int LOGICAL_OR = 14;\r
+ public const int LOGICAL_AND = 15;\r
+ public const int BITWISE_OR = 16;\r
+ public const int TRIANGLE = 17;\r
+ public const int BITWISE_AND = 18;\r
+ public const int PLUS = 19;\r
+ public const int MINUS = 20;\r
+ public const int TIMES = 21;\r
+ public const int SLASH = 22;\r
+ public const int PERCENT = 23;\r
+ public const int LITERAL_delete = 24;\r
+ public const int LITERAL_void = 25;\r
+ public const int LITERAL_typeof = 26;\r
+ public const int INCREMENT = 27;\r
+ public const int DECREMENT = 28;\r
+ public const int ADMIRATION = 29;\r
+ public const int LITERAL_new = 30;\r
+ public const int LPAREN = 31;\r
+ public const int RPAREN = 32;\r
+ public const int THIS = 33;\r
+ public const int LITERAL_print = 34;\r
+ public const int STRING_LITERAL = 35;\r
+ public const int LITERAL_function = 36;\r
+ public const int LITERAL_true = 37;\r
+ public const int LITERAL_false = 38;\r
+ public const int LITERAL_null = 39;\r
+ public const int TAB = 40;\r
+ public const int VERTICAL_TAB = 41;\r
+ public const int FORM_FEED = 42;\r
+ public const int SPACE = 43;\r
+ public const int NO_BREAK_SPACE = 44;\r
+ public const int LINE_FEED = 45;\r
+ public const int CARRIGE_RETURN = 46;\r
+ public const int LINE_SEPARATOR = 47;\r
+ public const int PARAGRAPH_SEPARATOR = 48;\r
+ public const int LSQUARE = 49;\r
+ public const int RSQUARE = 50;\r
+ public const int DOT = 51;\r
+ public const int L_THAN = 52;\r
+ public const int G_THAN = 53;\r
+ \r
+ }\r
+}\r
--- /dev/null
+// $ANTLR 2.7.2: jscript-lexer-parser.g -> JScriptParserTokenTypes.txt$\r
+JScriptParser // output token vocab name\r
+LBRACE=4\r
+RBRACE=5\r
+SEMI_COLON=6\r
+LITERAL_var="var"=7\r
+COMMA=8\r
+IDENTIFIER=9\r
+ASSIGNMENT=10\r
+COMPOUND_ASSIGNMENT=11\r
+INTERROGATION=12\r
+COLON=13\r
+LOGICAL_OR=14\r
+LOGICAL_AND=15\r
+BITWISE_OR=16\r
+TRIANGLE=17\r
+BITWISE_AND=18\r
+PLUS=19\r
+MINUS=20\r
+TIMES=21\r
+SLASH=22\r
+PERCENT=23\r
+LITERAL_delete="delete"=24\r
+LITERAL_void="void"=25\r
+LITERAL_typeof="typeof"=26\r
+INCREMENT=27\r
+DECREMENT=28\r
+ADMIRATION=29\r
+LITERAL_new="new"=30\r
+LPAREN=31\r
+RPAREN=32\r
+THIS=33\r
+LITERAL_print="print"=34\r
+STRING_LITERAL=35\r
+LITERAL_function="function"=36\r
+LITERAL_true="true"=37\r
+LITERAL_false="false"=38\r
+LITERAL_null="null"=39\r
+TAB=40\r
+VERTICAL_TAB=41\r
+FORM_FEED=42\r
+SPACE=43\r
+NO_BREAK_SPACE=44\r
+LINE_FEED=45\r
+CARRIGE_RETURN=46\r
+LINE_SEPARATOR=47\r
+PARAGRAPH_SEPARATOR=48\r
+LSQUARE=49\r
+RSQUARE=50\r
+DOT=51\r
+L_THAN=52\r
+G_THAN=53\r
// (C) Ximian, Inc. http://www.ximian.com
//
-namespace System.Runtime.Serialization.Formatters.Soap {
+namespace Microsoft.JScript {
+ using System;
/// <summary>
/// The TODO attribute is used to flag all incomplete bits in our class libraries
///
/// <remarks>
/// Use this to decorate any element which you think is not complete
- /// </remarks>
+ /// </remarks>
[AttributeUsage (AttributeTargets.All, AllowMultiple=true)]
public class MonoTODOAttribute : Attribute {
--- /dev/null
+//
+// ast.cs: Data structures used for building the EcmaScript 's Abstract Syntax
+// Tree.
+//
+// Author: Cesar Octavio Lopez Nataren
+//
+// (C) 2003 Cesar Octavio Lopez Nataren, <cesar@ciencias.unam.mx>
+//
+
+
+namespace Microsoft.JScript
+{
+ using System;
+ using System.Collections;
+ using System.Text;
+
+ using System.Reflection;
+ using System.Reflection.Emit;
+
+
+ public class Program
+ {
+ public SourceElements se;
+
+ public SourceElements SourceElements {
+ get { return se; }
+
+ set { se = value; }
+ }
+
+
+ public Program ()
+ {
+ se = new SourceElements ();
+ }
+
+ public override string ToString ()
+ {
+ return se.ToString ();
+ }
+ }
+
+
+
+ public class SourceElements : IEnumerable, IEnumerator
+ {
+ int pos = -1;
+
+ public ArrayList elems;
+
+ // IEnumerable implementation
+ public IEnumerator GetEnumerator ()
+ {
+ return (IEnumerator) this;
+ }
+
+
+ // IEnumerator methods implementations
+ public bool MoveNext ()
+ {
+ if (pos < Size) {
+ pos++;
+ return true;
+ } else return false;
+ }
+
+ public void Reset () { pos = 0; }
+
+ public object Current
+ {
+ get { return elems [pos]; }
+ }
+
+ public SourceElements ()
+ {
+ elems = new ArrayList ();
+ }
+
+
+
+ public int Size {
+ get {
+ return elems.Count;
+ }
+ }
+
+
+ public void Add (SourceElement se)
+ {
+ elems.Add (se);
+ }
+
+ public void Add (object o)
+ {
+ elems.Add (o);
+ }
+
+ public override string ToString ()
+ {
+ StringBuilder sb = new StringBuilder ();
+ foreach (SourceElement se in elems) {
+ sb.Append (se.ToString ());
+ sb.Append (" ");
+ }
+
+ return sb.ToString ();
+ }
+ }
+
+
+ public class SourceElement
+ {
+ public SourceElement ()
+ {}
+ }
+
+
+ public class Statement : SourceElement
+ {
+ public virtual bool Resolve (Context context)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public virtual void Emit (Context context)
+ {}
+ }
+
+
+ public class PrintStatement: Statement
+ {
+ private string message;
+
+ public PrintStatement ()
+ {}
+
+
+ public PrintStatement (string str)
+ {
+ message = str;
+ }
+
+
+ public string Message {
+ get { return message; }
+ set { message = value; }
+ }
+
+
+ public override void Emit (Context context)
+ {
+ context.ig.Emit (OpCodes.Ldstr, message);
+
+ context.ig.Emit (OpCodes.Call,
+ typeof (Microsoft.JScript.ScriptStream).GetMethod ("WriteLine", new Type [] {typeof (string)}));
+ }
+
+
+
+ public override string ToString ()
+ {
+ return message;
+ }
+ }
+
+
+ public class FunctionDeclaration : SourceElement
+ {
+ public SourceElements elems;
+
+ public FunctionDeclaration ()
+ {
+ elems = new SourceElements ();
+ }
+
+
+ public virtual void Emit (Context context)
+ {}
+ }
+}
--- /dev/null
+//
+// driver.cs: Walks the AST from a JScript program, and generates CIL opcodes.
+//
+// Author: Cesar Octavio Lopez Nataren <cesar@ciencias.unam.mx>
+//
+
+namespace Microsoft.JScript
+{
+ using System;
+ using System.IO;
+ using System.Collections;
+ using System.Reflection.Emit;
+ using System.Reflection;
+ using System.Runtime.CompilerServices;
+
+ public class Context
+ {
+ public Hashtable variables = new Hashtable ();
+ public ILGenerator ig;
+ public TypeBuilder type;
+
+ public Context ()
+ {}
+ }
+
+
+ public class Jsc
+ {
+ AssemblyName assemblyName;
+ AssemblyBuilder assemblyBuilder;
+ ModuleBuilder moduleBuilder;
+ MethodBuilder methodBuilder;
+
+ Context context;
+ string basename;
+
+ Program mainProgram;
+ string JSCRIPT_MODULE = "Jscript Module";
+
+ public Jsc (string output)
+ {
+ basename = output;
+
+ assemblyName = new AssemblyName ();
+
+ assemblyName.Name = basename;
+
+ assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly (assemblyName,
+ AssemblyBuilderAccess.RunAndSave, ".");
+ // FIXME: hard coded ".exe" extension
+ moduleBuilder = assemblyBuilder.DefineDynamicModule (JSCRIPT_MODULE, basename + ".exe", false);
+
+ context = new Context ();
+ }
+
+
+ public void GetAST (string filename)
+ {
+ StreamReader reader = new StreamReader (filename);
+ JScriptLexer lexer = new JScriptLexer (reader);
+ JScriptParser parser = new JScriptParser (lexer);
+
+ mainProgram = new Program ();
+ parser.program (mainProgram);
+ }
+
+
+ private void EmitJScript0Type ()
+ {
+ context.type = moduleBuilder.DefineType ("JScript 0", TypeAttributes.Public | TypeAttributes.Class);
+ context.type.SetParent (typeof (GlobalScope));
+ context.type.SetCustomAttribute (new CustomAttributeBuilder
+ (typeof (CompilerGlobalScopeAttribute).GetConstructor (new Type [] {}), new object [] {}));
+ }
+
+ private void EmitJScript0Cons ()
+ {
+ ConstructorBuilder constructor;
+ constructor = context.type.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard,
+ new Type [] {typeof (GlobalScope)});
+
+ context.ig = constructor.GetILGenerator ();
+
+ context.ig.Emit (OpCodes.Ldarg_0);
+ context.ig.Emit (OpCodes.Ldarg_1);
+ context.ig.Emit (OpCodes.Dup);
+ context.ig.Emit (OpCodes.Ldfld,
+ typeof (ScriptObject).GetField ("engine"));
+ context.ig.Emit (OpCodes.Call,
+ typeof (GlobalScope).GetConstructor (new Type [] {typeof (GlobalScope), typeof (Microsoft.JScript.Vsa.VsaEngine)}));
+ context.ig.Emit (OpCodes.Ret);
+ }
+
+
+ private void EmitGlobalCode ()
+ {
+ methodBuilder = context.type.DefineMethod ("Global Code",
+ MethodAttributes.Public,
+ typeof (object),
+ null);
+
+ context.ig = methodBuilder.GetILGenerator ();
+
+ context.ig.Emit (OpCodes.Ldarg_0);
+
+ context.ig.Emit (OpCodes.Ldfld,
+ typeof (ScriptObject).GetField ("engine"));
+
+ context.ig.Emit (OpCodes.Ldarg_0);
+
+ context.ig.Emit (OpCodes.Call,
+ typeof (Microsoft.JScript.Vsa.VsaEngine).GetMethod ("PushScriptObject", new Type [] {typeof (Microsoft.JScript.ScriptObject)}));
+
+
+ int size = mainProgram.SourceElements.Size;
+
+ // Emit the statements from the program.
+ for (int i = 0; i < size; i++) {
+ mainProgram.SourceElements.MoveNext ();
+ ((Statement) mainProgram.SourceElements.Current).Emit (context);
+ }
+
+ context.ig.Emit (OpCodes.Ldsfld,
+ typeof (Microsoft.JScript.Empty).GetField ("Value"));
+
+ context.ig.Emit (OpCodes.Ldarg_0);
+
+ context.ig.Emit (OpCodes.Ldfld,
+ typeof (ScriptObject).GetField ("engine"));
+
+ context.ig.Emit (OpCodes.Call,
+ typeof (Microsoft.JScript.Vsa.VsaEngine).GetMethod ("PopScriptObject"));
+
+ context.ig.Emit (OpCodes.Pop);
+
+ context.ig.Emit (OpCodes.Ret);
+ }
+
+
+ private void EmitJScript0 ()
+ {
+ EmitJScript0Type ();
+ EmitJScript0Cons ();
+ EmitGlobalCode ();
+
+ Type t = context.type.CreateType ();
+ }
+
+
+
+ private void EmitJScriptMainType ()
+ {
+ context.type = moduleBuilder.DefineType ("JScript Main", TypeAttributes.Public);
+ context.type.SetParent (typeof (System.Object));
+ }
+
+ private void EmitJScriptMainCons ()
+ {
+ // constructor for JScript Main
+ ConstructorBuilder constructor;
+ constructor = context.type.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard,
+ new Type [] {});
+ context.ig = constructor.GetILGenerator ();
+ context.ig.Emit (OpCodes.Ldarg_0);
+ context.ig.Emit (OpCodes.Call,
+ typeof (Object).GetConstructor (new Type [] {}));
+ context.ig.Emit (OpCodes.Ret);
+ }
+
+
+ private void EmitJScriptMainFunction ()
+ {
+ // define Main for JScript Main
+ MethodBuilder methodBuilder;
+ methodBuilder = context.type.DefineMethod ("Main",
+ MethodAttributes.Public | MethodAttributes.Static,
+ typeof (void),
+ new Type [] {typeof (String [])});
+
+ methodBuilder.SetCustomAttribute (new CustomAttributeBuilder
+ (typeof (STAThreadAttribute).GetConstructor (new Type [] {}),
+ new object [] {}));
+
+
+ context.ig = methodBuilder.GetILGenerator ();
+
+ // declare local vars
+ context.ig.DeclareLocal (typeof (Microsoft.JScript.GlobalScope));
+
+ context.ig.Emit (OpCodes.Ldc_I4_1);
+ context.ig.Emit (OpCodes.Ldc_I4_1);
+ context.ig.Emit (OpCodes.Newarr, typeof (string));
+ context.ig.Emit (OpCodes.Dup);
+ context.ig.Emit (OpCodes.Ldc_I4_0);
+ context.ig.Emit (OpCodes.Ldstr,
+ "mscorlib, Version=1.0.3300.0, Culture=neutral, Pub" + "licKeyToken=b77a5c561934e089");
+ context.ig.Emit (OpCodes.Stelem_Ref);
+ context.ig.Emit (OpCodes.Call,
+ typeof (Microsoft.JScript.Vsa.VsaEngine).GetMethod ("CreateEngineAndGetGlobalScope", new Type [] {typeof (bool), typeof (string [])}));
+
+ context.ig.Emit (OpCodes.Stloc_0);
+ context.ig.Emit (OpCodes.Ldloc_0);
+
+
+ context.ig.Emit (OpCodes.Newobj,
+ assemblyBuilder.GetType ("JScript 0").GetConstructor (new Type [] {typeof (Microsoft.JScript.GlobalScope)}));
+
+ context.ig.Emit (OpCodes.Call, assemblyBuilder.GetType ("JScript 0").GetMethod ("Global Code", new Type [] {}));
+
+ context.ig.Emit (OpCodes.Pop);
+ context.ig.Emit (OpCodes.Ret);
+
+ assemblyBuilder.SetEntryPoint (methodBuilder);
+
+ }
+
+ private void EmitJScriptMain ()
+ {
+ EmitJScriptMainType ();
+ EmitJScriptMainCons ();
+ EmitJScriptMainFunction ();
+
+ Type t2 = context.type.CreateType ();
+ }
+
+
+ public void Emit (string outputFile)
+ {
+ EmitJScript0 ();
+ EmitJScriptMain ();
+ assemblyBuilder.Save (outputFile);
+ }
+
+ public static void Main (string [] args)
+ {
+ try {
+ string basename = Path.GetFileNameWithoutExtension (args [0]);
+ Jsc compiler = new Jsc (basename);
+ compiler.GetAST (args [0]);
+ // compiler.Emit (compiler.basename + ".exe");
+
+ } catch (IndexOutOfRangeException) {
+ Console.WriteLine ("Usage: [mono] mjsc.exe filename.js");
+ }
+ }
+ }
+}
--- /dev/null
+//
+// jscript-lexer-parser.g: EcmaScript Grammar written on antlr.
+//
+// Author: Cesar Octavio Lopez Nataren
+//
+// (C) 2003, Cesar Octavio Lopez Nataren (cesar@ciencias.unam.mx)
+//
+
+
+options {
+ language = "CSharp";
+ namespace = "Microsoft.JScript";
+}
+
+
+// Parser
+class JScriptParser extends Parser;
+
+
+// Program, see section 14 from Ecma-262, page 75.
+program [Program p]
+{
+ SourceElements elems;
+}
+ :
+ source_elements [p.SourceElements]
+ ;
+
+
+source_elements [SourceElements elems]
+{
+ SourceElement se;
+}
+ :
+ se = source_element { elems.Add (se); } (source_elements [elems] | )
+ ;
+
+
+// See Section 14 from Ecma-262, page 75.
+source_element returns [SourceElement se]
+{
+ se = new SourceElement ();
+ Statement stm = null;
+ FunctionDeclaration fd = null;
+}
+ :
+ stm = statement
+ { se = stm; }
+ |
+ fd = function_declaration
+ { se = fd; }
+ ;
+
+
+// Statement, see section 12 from Ecma-262, page 61.
+statement returns [Statement stm]
+{
+ stm = null;
+}
+ :
+ block
+ |
+ variable_statement
+ |
+ empty_statement
+ |
+ stm = print_statement
+ ;
+
+
+block: LBRACE (statement_list | ) RBRACE
+ ;
+
+
+empty_statement: SEMI_COLON ;
+
+statement_list
+ :
+ statement (statement_list | )
+ ;
+
+// VariableStatement, see section 12.2 from Ecma-262 3td Edition, page 74.
+variable_statement
+ :
+ "var" variable_declaration_list SEMI_COLON
+ ;
+
+
+variable_declaration_list
+ :
+ variable_declaration (COMMA variable_declaration_list | )
+ ;
+
+variable_declaration
+ :
+ IDENTIFIER (initialiser | )
+ ;
+
+
+initialiser
+ :
+ ASSIGNMENT assignment_expression
+ ;
+
+// FIXME: a conditional_expression can be reduced to a postfixExpression wich
+// is reduced to a left_hand_side_expression
+// AssignmentExpression, see section 11.13 from Ecma-262 3td. Edition, page 59.
+assignment_expression
+ :
+ conditional_expression
+// |
+// left_hand_side_expression assignment_operator assignment_expression
+ ;
+
+
+assignment_operator
+ :
+ ASSIGNMENT
+ |
+ COMPOUND_ASSIGNMENT
+ ;
+
+
+// ConditionalExpression, see section 11.12 from Ecma-262, page 58.
+conditional_expression
+ :
+ logical_or_expression (INTERROGATION assignment_expression COLON assignment_expression | )
+ ;
+
+
+
+// Binary Logical Operators, section 11.11 from Ecma-262 spec, page 58.
+logical_or_expression
+ :
+ logical_and_expression (LOGICAL_OR logical_or_expression | )
+ ;
+
+
+logical_and_expression
+ :
+ bitwise_or_expression (LOGICAL_AND logical_and_expression | )
+ ;
+
+
+// Binary Bitwise Operators, section 11.10 from Ecma-262 spec, page 57.
+bitwise_or_expression
+ :
+ bitwise_xor_expression (BITWISE_OR bitwise_or_expression | )
+ ;
+
+bitwise_xor_expression
+ :
+ bitwise_and_expression (TRIANGLE bitwise_xor_expression | )
+ ;
+
+
+bitwise_and_expression
+ :
+ equality_expression (BITWISE_AND bitwise_and_expression | )
+ ;
+
+
+// Equality Operators, section 11.9 from Ecma-262 spec, page 54.
+// FIXME: more options left to implement
+equality_expression
+ :
+ relational_expression
+ ;
+
+
+// Relational Operators, section 11.4 from Ecma-262 spec, page 52.
+// FIXME: more options left to implement
+relational_expression
+ :
+ shift_expression
+ ;
+
+
+// Bitwise Shift Operators, section 11.7 from Ecma-262, page 51.
+// FIXME: more options left to implement
+shift_expression
+ :
+ additive_expression
+ ;
+
+
+
+// Additive Operators, section 11.6 from Ecma-262, page 50.
+// FIXME: more options left to implement
+additive_expression
+ :
+ multiplicative_expression ((PLUS | MINUS) additive_expression | )
+ ;
+
+
+
+// Multiplicative Operators, section 11.5 from Ecma-262, page 48.
+multiplicative_expression
+ :
+ unary_expression ((TIMES | SLASH | PERCENT) multiplicative_expression | )
+ ;
+
+
+// Unary Operators, Section 11.4 from Ecma-262, page 46.
+unary_expression
+ :
+ postfix_expression
+ |
+ ("delete" | "void" | "typeof" | INCREMENT | DECREMENT | PLUS | MINUS | ADMIRATION) unary_expression
+ ;
+
+
+// Postfix Expressions, section 11.3 from Ecma-262, page 45.
+// FIXME: more options left to implement
+postfix_expression
+ :
+ left_hand_side_expression
+ ;
+
+
+// FIXME: there's a problem with the NEW member_expression arguments rule from member expression
+// section 11.2 from Ecma-262 3td Edition, page 43.
+left_hand_side_expression
+ :
+ new_expression
+// |
+// call_expression
+ ;
+
+
+// FIXME: there's a problem with the NEW member_expression arguments rule from member expression
+new_expression
+ :
+ member_expression
+ |
+ "new" new_expression
+ ;
+
+// FIXME: more options left to implement
+call_expression
+ :
+ member_expression arguments
+ ;
+
+
+// FIXME: more options left to implement
+member_expression
+ :
+ primary_expression
+// |
+// "new" member_expression arguments
+ ;
+
+
+arguments
+ :
+ LPAREN (argument_list | ) RPAREN
+ ;
+
+
+argument_list
+ :
+ assignment_expression (COMMA argument_list | )
+ ;
+
+// Expressions, section 11, from Ecma-262 3d Edition, page 40.
+// FIXME: more options left to implement
+primary_expression
+ :
+ THIS
+ |
+ IDENTIFIER
+ |
+ literal
+ ;
+
+
+// Literals, section 7.8 from Ecma-262 3d Edition, page 16.
+// FIXME: more options left to implement
+literal
+ :
+ boolean_literal
+ |
+ null_literal
+ ;
+
+
+// Non-Ecma statements
+print_statement returns [PrintStatement pn]
+{ pn = new PrintStatement (); }
+ :
+ "print" LPAREN str:STRING_LITERAL RPAREN SEMI_COLON
+ {
+ pn.Message = str.getText ();
+ }
+ ;
+
+
+
+
+// Function definition, see Section 13 from Ecma-262, page 71.
+function_declaration returns [FunctionDeclaration fd]
+{
+ fd = new FunctionDeclaration ();
+}
+ :
+ "function" IDENTIFIER LPAREN (formal_parameter_list | ) RPAREN LBRACE function_body [fd.elems] RBRACE
+ ;
+
+
+formal_parameter_list
+ :
+ IDENTIFIER (COMMA formal_parameter_list | )
+ ;
+
+
+function_body [SourceElements elems]
+ :
+ source_elements [elems]
+ ;
+
+
+boolean_literal
+ :
+ "true"
+ |
+ "false"
+ ;
+
+null_literal
+ :
+ "null"
+ ;
+
+// Lexer
+class JScriptLexer extends Lexer;
+options {
+ charVocabulary='\u0000'..'\uFFFE';
+ testLiterals=false;
+ k = 2;
+}
+
+
+TAB
+ :
+ '\u0009'
+ ;
+
+
+VERTICAL_TAB
+ :
+ '\u000B'
+ ;
+
+
+FORM_FEED
+ :
+ '\u000C'
+ ;
+
+
+SPACE
+ :
+ '\u0020'
+ { _ttype =Token.SKIP; }
+ ;
+
+
+NO_BREAK_SPACE
+ :
+ '\u00A0'
+ ;
+
+// FIXME: find out possibles Unicode "space separator"
+// USP:
+
+
+LINE_FEED
+ :
+ '\u000A'
+ { newline (); { _ttype =Token.SKIP; }}
+ ;
+
+
+CARRIGE_RETURN
+ :
+ '\u000D'
+ { newline (); { _ttype =Token.SKIP; }}
+ ;
+
+
+LINE_SEPARATOR
+ :
+ '\u2028'
+ { newline (); { _ttype =Token.SKIP; }}
+ ;
+
+
+PARAGRAPH_SEPARATOR
+ :
+ '\u2029'
+ { newline (); { _ttype =Token.SKIP; }}
+ ;
+
+
+
+
+// Punctuators
+
+LBRACE: '{' ;
+
+RBRACE: '}' ;
+
+LPAREN: '(' ;
+
+RPAREN: ')' ;
+
+LSQUARE: '[' ;
+
+RSQUARE: ']' ;
+
+DOT: '.' ;
+
+SEMI_COLON: ';' ;
+
+COMMA: ',' ;
+
+L_THAN: '<' ;
+
+G_THAN: '>' ;
+
+PLUS: '+' ('=' { $setType (COMPOUND_ASSIGNMENT); })? ;
+
+MINUS: '-' ('=' { $setType (COMPOUND_ASSIGNMENT); })? ;
+
+TIMES: '*' ('=' { $setType (COMPOUND_ASSIGNMENT); })? ;
+
+SLASH: '/' ('=' { $setType (COMPOUND_ASSIGNMENT); })? ;
+
+PERCENT: '%' ('=' { $setType (COMPOUND_ASSIGNMENT); })? ;
+
+BITWISE_AND: '&' ('&' { $setType (LOGICAL_AND); } | '=' { $setType (COMPOUND_ASSIGNMENT); })?;
+
+BITWISE_OR: '|' ('|' { $setType (LOGICAL_OR); } | '=' { $setType (COMPOUND_ASSIGNMENT); })? ;
+
+ADMIRATION: '!' ;
+
+INTERROGATION: '?' ;
+
+COLON: ':' ;
+
+ASSIGNMENT: '=' ;
+
+TRIANGLE: '^' ('=' { $setType (COMPOUND_ASSIGNMENT); })? ;
+
+INCREMENT: "++" ;
+
+DECREMENT: "--";
+
+
+// FIXME: this just temporal, in order to get into parsing
+STRING_LITERAL
+ :
+ '"'!('a'..'z' | 'A'..'Z' | '\u0020')+'"'!
+ ;
+
+
+// Fixme: this a temporal definition. W
+// We must handle the UNICODE charset, see section 7.6 of the Ecma-262 spec
+IDENTIFIER
+options { testLiterals=true; }
+ :
+ ('a'..'z' | 'A'..'Z') ('a'..'z' | 'A'..'Z' | '0'..'9')*
+ ;