Esempio n. 1
0
		} // ParseExpression
	
	
	// Parse a LeftHandSideExpression.
	// 
	// If checkForCallExpr is false, then we don't check for CallExpressions.
	// This is used when parsing the function in a "new" expression, to
	// avoid parsing arguments to "new" as part of the expression that
	// specifies the function.
	private ExprFrag ParseLeftHandSideExpression( FunctionInfo info,
												  bool checkForCallExpr )
		{
		ExprFrag expr;
		if (tok.TryMatchKeyword("new"))
			{
			SrcLoc newLoc = tok.Prev().loc;
			
			ExprFrag constructor = ParseLeftHandSideExpression(info, false);
			ArrayList args = null;
			if (tok.TryMatchOp("("))
				args = MatchOptionalArgumentList(info);
			
			expr = gen.Construct(newLoc, constructor, args);
			}
		else if (tok.TryMatchKeyword("function"))
			{
			SrcLoc functionLoc = tok.Prev().loc;
			FunctionInfo childInfo = info.GetNextChild();
			ParseFunction(childInfo, true);
			expr = gen.FunctionExpr(functionLoc, childInfo);
			}
		else
			expr = ParsePrimaryExpression(info);
		
		while (true)
			if (checkForCallExpr && tok.TryMatchOp("("))
				{
				SrcLoc opLoc = tok.Prev().loc;
				ArrayList args = MatchOptionalArgumentList(info);
				expr = gen.Call(opLoc, expr, args);
				}
			else if (tok.TryMatchOp("["))
				{
				SrcLoc opLoc = tok.Prev().loc;
				expr = gen.ArrayReference(opLoc, expr, this.ParseExpression(info, true));
				tok.MatchOp("]");
				}
			else if (tok.TryMatchOp("."))
				{
				SrcLoc opLoc = tok.Prev().loc;
				expr = gen.FieldReference(opLoc, expr, tok.MatchID());
				}
			else
				return expr;
		
		} // ParseLeftHandSideExpression
Esempio n. 2
0
		} // ParseProgram
	
	
	// Parse a SourceElements (i.e. the main program, or a function body)
	// and return the generated code.
	private StmtFrag ParseSourceElements( FunctionInfo info,
										  CGFuncInfo cgFuncInfo )
		{
		SrcLoc loc;
		loc.lineNum     = 1;
		loc.colNum      = 1;
		loc.absPosition = 0;
		loc.len         = 1;
		
		StmtFrag frag = gen.NewStmtFrag(loc);
		while (!tok.atEnd && !tok.PeekOp("}"))
			if (tok.TryMatchKeyword("function"))
				ParseFunction(info.GetNextChild(), false);
			else
				frag.Append(ParseStatement(info));
		
		return frag;
		} // ParseSourceElements