Author: olivier
Date: 2007-06-01 13:31:29 -0400 (Fri, 01 Jun 2007)
New Revision: 78440
Modified:
trunk/olive/class/Microsoft.JScript.Compiler/ChangeLog
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler.Hosting/LanguageProvider.cs
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/Compiler.cs
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/CompilerOption.cs
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/DList.cs
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/Engine.cs
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/EngineOptions.cs
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/JavaScriptCompiler.cs
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/Parser.cs
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/RegularExpressionLiteralToken.cs
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/SplayTree.cs
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/Table.cs
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/TextPoint.cs
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/Token.cs
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/TokenCategorizer.cs
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/Tokenizer.cs
Log:
2007-06-01 Olivier Dufour <[EMAIL PROTECTED]>
* Fill a lot of easy stub class
* Make a lot of needed parser function and change return with what is
in ParseTree
Note: ParseTree is great to know which function need to be implement in parser!
Modified: trunk/olive/class/Microsoft.JScript.Compiler/ChangeLog
===================================================================
--- trunk/olive/class/Microsoft.JScript.Compiler/ChangeLog 2007-06-01
17:26:16 UTC (rev 78439)
+++ trunk/olive/class/Microsoft.JScript.Compiler/ChangeLog 2007-06-01
17:31:29 UTC (rev 78440)
@@ -1,3 +1,10 @@
+2007-06-01 Olivier Dufour <[EMAIL PROTECTED]>
+
+ * Fill a lot of easy stub class
+ * Make a lot of needed parser function and change return with what is
in ParseTree
+
+Note: ParseTree is great to know which function need to be implement in
parser!
+
2007-05-31 Olivier Dufour <[EMAIL PROTECTED]>
* start to build ast in parser
Modified:
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/Compiler.cs
===================================================================
---
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/Compiler.cs
2007-06-01 17:26:16 UTC (rev 78439)
+++
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/Compiler.cs
2007-06-01 17:31:29 UTC (rev 78440)
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
-using Microsoft.Scripting.Internal.Ast;
+using Mono.JScript.Compiler.ParseTree;
namespace Mono.JScript.Compiler
{
@@ -11,34 +11,47 @@
{
}
- public CodeBlock CompileExpression(string Input, ref
List<Diagnostic> Diagnostics)
+ public Microsoft.Scripting.Internal.Ast.CodeBlock
CompileExpression(string Input, ref List<Diagnostic> Diagnostics)
{
- throw new NotImplementedException();
+ return CompileExpression (Input.ToCharArray (), ref
Diagnostics);
}
- public CodeBlock CompileExpression(char[] Input, ref
List<Diagnostic> Diagnostics)
+ public Microsoft.Scripting.Internal.Ast.CodeBlock
CompileExpression (char[] Input, ref List<Diagnostic> Diagnostics)
{
- throw new NotImplementedException();
+ Parser parser = new Parser (Input, new IdentifierTable
());
+ List<Comment> comments = null;
+ Expression expr = parser.ParseExpression (ref comments);
+ Diagnostics = parser.Diagnostics;
+ //TODO return
+ return null;
}
- public CodeBlock CompileProgram(char[] Input, ref
List<Diagnostic> Diagnostics, ref bool IncompleteInput)
+ public Microsoft.Scripting.Internal.Ast.CodeBlock
CompileProgram (char[] Input, ref List<Diagnostic> Diagnostics, ref bool
IncompleteInput)
{
- throw new NotImplementedException();
+ return CompileProgram (Input, ref Diagnostics, ref
IncompleteInput, false);
}
- public CodeBlock CompileProgram(char[] Input, ref
List<Diagnostic> Diagnostics, ref bool IncompleteInput, bool PrintExpressions)
+ public Microsoft.Scripting.Internal.Ast.CodeBlock
CompileProgram (char[] Input, ref List<Diagnostic> Diagnostics, ref bool
IncompleteInput, bool PrintExpressions)
{
- throw new NotImplementedException();
+ Parser parser = new Parser (Input, new IdentifierTable
());
+ List<Comment> comments = null;
+ DList<Statement, BlockStatement> list =
parser.ParseProgram (ref comments);
+ Diagnostics = parser.Diagnostics;
+ IncompleteInput = parser.SyntaxIncomplete();
+ //TODO return
+ return null;
}
- public Statement CompileStatement(char[] Input)
+ public Mono.JScript.Compiler.ParseTree.Statement
CompileStatement(char[] Input)
{
- throw new NotImplementedException();
+ Parser parser = new Parser (Input, new IdentifierTable
());
+ List<Comment> comments = null;
+ return parser.ParseStatement (ref comments);
}
public Statement CompileStatement(string Input)
{
- throw new NotImplementedException();
+ return CompileStatement (Input.ToCharArray ());
}
}
}
Modified:
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/CompilerOption.cs
===================================================================
---
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/CompilerOption.cs
2007-06-01 17:26:16 UTC (rev 78439)
+++
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/CompilerOption.cs
2007-06-01 17:31:29 UTC (rev 78440)
@@ -8,13 +8,11 @@
{
public CompilerOptions()
{
- throw new NotImplementedException();
}
public override object Clone()
{
- throw new NotImplementedException();
+ return this.MemberwiseClone ();
}
}
-
}
Modified:
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/DList.cs
===================================================================
---
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/DList.cs
2007-06-01 17:26:16 UTC (rev 78439)
+++
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/DList.cs
2007-06-01 17:31:29 UTC (rev 78440)
@@ -4,55 +4,137 @@
namespace Mono.JScript.Compiler
{
+ // double linked list because of name so must have a node somewhere
public class DList<ElementType, ParentType>
{
public DList ()
{
- throw new NotImplementedException ();
}
+
+ private Node head;
+ private Node tail;
+ private ParentType parent;
+
public void Append (ElementType Item)
{
- throw new NotImplementedException ();
+ Node newNode = new Node(Item);
+ if (tail != null) {
+ tail.Next = newNode;
+ newNode.Previous = tail;
+ }
+ else
+ head = newNode;
+
+ tail = newNode;
}
+
public DList<ElementType, ParentType> Copy ()
{
- throw new NotImplementedException ();
+ DList<ElementType, ParentType> result = new
DList<ElementType, ParentType> ();
+ //while (ite)
+ //result.Append(
+ return null;
}
+
public ElementType Last ()
{
- throw new NotImplementedException ();
+ return tail.Data;
}
public ParentType Parent {
- get { throw new NotImplementedException (); }
- set { throw new NotImplementedException (); }
+ get { return parent; }
+ set { parent = value; }
}
public class Iterator
{
public Iterator (DList<ElementType, ParentType> DL)
{
- throw new NotImplementedException ();
+ current = DL.head;
+ this.DL = DL;
}
+
+ private Node current;
+ private DList<ElementType, ParentType> DL;
+
public void Advance ()
{
- throw new NotImplementedException ();
+ if (current != null)
+ current = current.Next;
}
+
public void Insert (ElementType Item)
{
- throw new NotImplementedException ();
+ Node newNode = new Node (Item);
+ newNode.Next = current.Next;
+ newNode.Previous = current;
+ current.Next.Previous = newNode;
+ current.Next = newNode;
+ current = newNode;
}
+
public void Remove ()
{
- throw new NotImplementedException ();
+ if (current == null) {
+ return;
+ }
+
+ if (current.Next == null && current.Previous ==
null) {
+ current = null;
+ DL.head = null;
+ DL.tail = null;
+ }
+ if (current.Next != null) {//if not tail
+ current.Next.Previous =
current.Previous;
+ current = current.Next;
+ }
+ else
+ DL.tail = current.Previous;
+
+ if (current.Previous != null) {//if not head
+ current.Previous.Next = current.Next;
+ current = current.Previous;
+ }
+ else
+ DL.head = current.Next;
}
public ElementType Element {
- get { throw new NotImplementedException (); }
+ get { return current.Data; }
}
+
public bool ElementAvailable {
- get { throw new NotImplementedException (); }
+ get { return (current != null); }
}
+
}
+
+ private class Node
+ {
+ public Node (ElementType Item)
+ {
+ data = Item;
+ }
+
+ private Node prev;
+ private Node next;
+ private ElementType data;
+
+ public Node Previous {
+ get { return prev; }
+ set { prev = value; }
+ }
+
+ public Node Next {
+ get { return next; }
+ set { next = value; }
+ }
+
+ public ElementType Data
+ {
+ get { return data; }
+ set { data = value; }
+ }
+ }
}
}
Modified:
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/Engine.cs
===================================================================
---
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/Engine.cs
2007-06-01 17:26:16 UTC (rev 78439)
+++
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/Engine.cs
2007-06-01 17:31:29 UTC (rev 78440)
@@ -12,9 +12,7 @@
{
public Engine(LanguageProvider provider, EngineOptions
engineOptions)
: base(provider, engineOptions)
-
{
- throw new NotImplementedException();
}
public override void AddAssembly(Assembly assembly)
Modified:
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/EngineOptions.cs
===================================================================
---
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/EngineOptions.cs
2007-06-01 17:26:16 UTC (rev 78439)
+++
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/EngineOptions.cs
2007-06-01 17:31:29 UTC (rev 78440)
@@ -8,12 +8,14 @@
{
public EngineOptions()
{
- throw new NotImplementedException();
}
+
+ //TODO Default value
+ private int maximumRecursion;
public int MaximumRecursion {
- get { throw new NotImplementedException(); }
- set { throw new NotImplementedException(); }
+ get { return maximumRecursion; }
+ set { maximumRecursion = value; }
}
}
Modified:
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/JavaScriptCompiler.cs
===================================================================
---
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/JavaScriptCompiler.cs
2007-06-01 17:26:16 UTC (rev 78439)
+++
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/JavaScriptCompiler.cs
2007-06-01 17:31:29 UTC (rev 78440)
@@ -11,28 +11,45 @@
{
public JavaScriptCompiler(Engine engine) : base(engine)
{
- throw new NotImplementedException();
}
public override CodeBlock ParseExpressionCode(CompilerContext
Context)
{
- throw new NotImplementedException();
+ Compiler compiler = new Compiler();
+ List<Diagnostic> diagnostics = null;
+ return compiler.CompileExpression
(Context.SourceUnit.GetCode (), ref diagnostics);
}
public override CodeBlock ParseFile(CompilerContext Context)
{
- throw new NotImplementedException();
+ Compiler compiler = new Compiler ();
+ List<Diagnostic> diagnostics = null;
+ bool incompleteInput = false;
+ return compiler.CompileProgram
(Context.SourceUnit.GetCode ().ToCharArray (), ref diagnostics, ref
incompleteInput);
}
public override CodeBlock ParseInteractiveCode(CompilerContext
cc, bool allowIncomplete, out InteractiveCodeProperties properties)
{
- throw new NotImplementedException();
+ Compiler compiler = new Compiler ();
+ List<Diagnostic> diagnostics = null;
+ bool IncompleteInput = false;
+ CodeBlock result = compiler.CompileProgram
(cc.SourceUnit.GetCode ().ToCharArray(), ref diagnostics, ref IncompleteInput,
false);
+ //TODO properties
+ properties = InteractiveCodeProperties.IsEmpty;
+ if (allowIncomplete && IncompleteInput)
+ {
+ throw new Exception ("Incomplete code!");
+ }
+ //TODO
+ return result;
}
public override CodeBlock ParseStatementCode(CompilerContext
Context)
{
- throw new NotImplementedException();
+ Compiler compiler = new Compiler ();
+ List<Diagnostic> diagnostics = null;
+ bool IncompleteInput = false;
+ return compiler.CompileProgram
(Context.SourceUnit.GetCode ().ToCharArray (), ref diagnostics, ref
IncompleteInput, false);
}
-
}
}
Modified:
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/Parser.cs
===================================================================
---
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/Parser.cs
2007-06-01 17:26:16 UTC (rev 78439)
+++
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/Parser.cs
2007-06-01 17:31:29 UTC (rev 78440)
@@ -22,6 +22,7 @@
private Token current;
private List<String> SyntaxError = new List<string>();
private bool syntaxIncomplete = false;
+
#endregion
#region public methods
@@ -62,12 +63,12 @@
public bool SyntaxOK ()
{
- return (SyntaxError.Count > 0);
+ return (diagnostics.Count > 0);
}
#endregion
- private Statement ParseFunctionDeclaration()
+ private FunctionStatement ParseFunctionDeclaration ()
{
Token start = current;
@@ -143,52 +144,35 @@
{
switch (current.Kind) {
case Token.Type.LeftBrace:
- ParseBlock ();
- break;
+ return ParseBlock ();
case Token.Type.Var:
- ParseVarDeclaration ();
- break;
+ return ParseVarDeclaration ();
case Token.Type.If:
- ParseIfElse ();
- break;
+ return ParseIfElse ();
case Token.Type.While:
- ParseWhile ();
- break;
+ return ParseWhile ();
case Token.Type.Do:
- ParseDo ();
- break;
+ return ParseDo ();
case Token.Type.For:
- ParseFor ();
- break;
+ return ParseFor ();
case Token.Type.Continue:
- ParseContinue ();
- break;
+ case Token.Type.Break:
+ return ParseBreakOrContinue ();
case Token.Type.With:
- ParseWith ();
- break;
+ return ParseWith ();
case Token.Type.Switch:
- ParseSwitch ();
- break;
+ return ParseSwitch ();
+ case Token.Type.Try:
+ return ParseTry ();
case Token.Type.Throw:
- ParseThrow ();
- break;
- case Token.Type.Try:
- ParseTry ();
- break;
- case Token.Type.Break:
- ParseBreak ();
- break;
case Token.Type.Return:
- ParseReturn ();
- break;
+ return ParseReturnOrThrow ();
case Token.Type.Function:
- ParseFunctionDeclaration ();
- break;
+ return ParseFunctionDeclaration ();
case Token.Type.Identifier:
- Token ident = current;
+ IdentifierToken ident = current as
IdentifierToken;
Next ();
- ParseExpression ();
- break;
+ return ParseExpressionStatement ();
default:
SyntaxError.Add("Statement start with a
strange token :" + Enum.GetName(typeof(Token.Type), current.Kind));
break;
@@ -198,66 +182,121 @@
}
- private void ParseVarDeclaration ()
+ private ExpressionStatement ParseExpressionStatement ()
{
- throw new Exception ("The method or operation is not
implemented.");
+ Token start = current;
+ Expression expr = ParseExpression();
+ return new ExpressionStatement (expr, new TextSpan
(start, current));
}
- private void ParseIfElse ()
+ private VariableDeclarationStatement ParseVarDeclaration ()
{
- throw new Exception ("The method or operation is not
implemented.");
- }
+ Token start = current;
+ List<VariableDeclarationListElement> declarations = new
List<VariableDeclarationListElement>();
+ do {
+ Next ();
+ CheckSyntaxExpected (Token.Type.Identifier);
+ Identifier name = (current as
IdentifierToken).Spelling;
+ Next ();
+ VariableDeclaration declaration;
+ if (current.Kind == Token.Type.Equal) {
+ Token start2 = current;
+ Next ();
+ Expression initializer =
ParseExpression ();
+ declaration = new
InitializerVariableDeclaration (name, initializer, new TextSpan (start2,
current), new TextPoint (start2.StartPosition));
+ Next ();
+ }
+ else
+ declaration = new VariableDeclaration
(name, new TextSpan (current, current));
- private void ParseWhile ()
- {
- throw new Exception ("The method or operation is not
implemented.");
+ VariableDeclarationListElement vardeclarListElt
= new VariableDeclarationListElement (declaration, new TextPoint
(current.StartPosition));
+ declarations.Add (vardeclarListElt);
+ } while (current.Kind == Token.Type.Comma);
+ VariableDeclarationStatement statement = new
VariableDeclarationStatement (declarations, new TextSpan (start, current));
+ CheckSyntaxExpected (Token.Type.SemiColon);
+ return statement;
}
- private void ParseDo ()
+ private IfStatement ParseIfElse ()
{
throw new Exception ("The method or operation is not
implemented.");
}
- private void ParseFor ()
+ private WhileStatement ParseWhile ()
{
throw new Exception ("The method or operation is not
implemented.");
}
- private void ParseContinue ()
+ private DoStatement ParseDo ()
{
throw new Exception ("The method or operation is not
implemented.");
}
- private void ParseWith ()
+ private ForStatement ParseFor ()
{
throw new Exception ("The method or operation is not
implemented.");
}
- private void ParseSwitch ()
+ private BreakOrContinueStatement ParseBreakOrContinue ()
{
throw new Exception ("The method or operation is not
implemented.");
}
- private void ParseThrow ()
+ private WithStatement ParseWith ()
{
throw new Exception ("The method or operation is not
implemented.");
}
- private void ParseTry ()
+ private SwitchStatement ParseSwitch ()
{
throw new Exception ("The method or operation is not
implemented.");
}
- private void ParseReturn ()
+ private ReturnOrThrowStatement ParseReturnOrThrow ()
{
throw new Exception ("The method or operation is not
implemented.");
}
- private void ParseBreak ()
+ private TryStatement ParseTry ()
{
throw new Exception ("The method or operation is not
implemented.");
}
-
+ /*
+ ArgumentList.cs
+ ArrayLiteralExpression.cs
+ BinaryOperatorExpression.cs
+ CaseClause.cs
+ CatchClause.cs
+ DeclarationForInStatement.cs
+ DeclarationForStatement.cs
+ DefaultCaseClause.cs
+ ExpressionForInStatement.cs
+ ExpressionForStatement.cs
+ ExpressionListElement.cs
+ FinallyClause.cs
+ ForInStatement.cs
+ FunctionDefinition.cs
+ HexLiteralExpression.cs
+ IdentifierExpression.cs
+ InvocationExpression.cs
+ LabelStatement.cs
+ LoopStatement.cs
+ NullExpression.cs
+ NumericLiteralExpression.cs
+ ObjectLiteralElement.cs
+ ObjectLiteralExpression.cs
+ OctalLiteralExpression.cs
+ Parameter.cs
+ QualifiedExpression.cs
+ RegularExpressionLiteralExpression.cs
+ StringLiteralExpression.cs
+ SubscriptExpression.cs
+ TernaryOperatorExpression.cs
+ UnaryOperatorExpression.cs
+ ValueCaseClause.cs
+ VariableDeclaration.cs
+ VariableDeclarationListElement.cs
+ */
private Expression ParseExpression ()
{
switch (current.Kind) {
@@ -309,62 +348,62 @@
}
- private void ParseGreaterGreater ()
+ private Expression ParseGreaterGreater ()
{
throw new Exception ("The method or operation is not
implemented.");
}
- private void ParseStar ()
+ private Expression ParseStar ()
{
throw new Exception ("The method or operation is not
implemented.");
}
- private void ParseNew ()
+ private Expression ParseNew ()
{
throw new Exception ("The method or operation is not
implemented.");
}
- private void ParseMemberCall ()
+ private Expression ParseMemberCall ()
{
throw new Exception ("The method or operation is not
implemented.");
}
- private void ParseLessLess ()
+ private Expression ParseLessLess ()
{
throw new Exception ("The method or operation is not
implemented.");
}
- private void ParsePercent ()
+ private Expression ParsePercent ()
{
throw new Exception ("The method or operation is not
implemented.");
}
- private void ParseDivide ()
+ private Expression ParseDivide ()
{
throw new Exception ("The method or operation is not
implemented.");
}
- private void ParseMinus ()
+ private Expression ParseMinus ()
{
throw new Exception ("The method or operation is not
implemented.");
}
- private void ParseMinusMinus ()
+ private Expression ParseMinusMinus ()
{
throw new Exception ("The method or operation is not
implemented.");
}
- private void ParsePlus ()
+ private Expression ParsePlus ()
{
throw new Exception ("The method or operation is not
implemented.");
}
- private void ParsePlusPlus ()
+ private Expression ParsePlusPlus ()
{
throw new Exception ("The method or operation is not
implemented.");
}
- private void ParseFunctionCall ()
+ private FunctionExpression ParseFunctionCall ()
{
throw new Exception ("The method or operation is not
implemented.");
}
@@ -381,10 +420,52 @@
private void CheckSyntaxExpected (Token.Type type)
{
- if (current.Kind != type)
- SyntaxError.Add (Enum.GetName
(typeof(Token.Type), type) + " expected.");
+ if (current.Kind == type)
+ return;
+
+ //default
+ DiagnosticCode code = DiagnosticCode.SyntaxError;
+
+ switch (type) {
+ case Token.Type.Case:
+ case Token.Type.Default:
+ code =
DiagnosticCode.CaseOrDefaultExpected;
+ break;
+ case Token.Type.Identifier:
+ code =
DiagnosticCode.IdentifierExpected;
+ break;
+ case Token.Type.LeftBrace:
+ code = DiagnosticCode.LeftBraceExpected;
+ break;
+ case Token.Type.LeftParenthesis:
+ code = DiagnosticCode.LeftParenExpected;
+ break;
+ case Token.Type.SemiColon:
+ current.InsertSemicolonBefore ();
+ return;
+ }
+ diagnostics.Add(new Diagnostic(code, new
TextSpan(current.StartLine,current.StartColumn, lexer.Position.Line,
lexer.Position.Column,current.StartPosition, lexer.Position.Index)));
}
+ private List<Diagnostic> diagnostics;
+ public List<Diagnostic> Diagnostics { get { return
diagnostics; } }
+ /* TODO
+ SwitchHasMultipleDefaults,
+ TryHasNoHandlers,
+ BadDivideOrRegularExpressionLiteral,
+ EnclosingLabelShadowed,
+ NoEnclosingLabel,
+ BreakContextInvalid,
+ ContinueContextInvalid,
+ ContinueLabelInvalid,
+ MalformedEscapeSequence,
+ HexLiteralNoDigits,
+ MalformedNumericLiteral,
+ NumericLiteralThenIdentifier,
+ UnterminatedStringLiteral,
+ UnterminatedComment,
+ ExtraneousCharacter
+ */
}
}
Modified:
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/RegularExpressionLiteralToken.cs
===================================================================
---
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/RegularExpressionLiteralToken.cs
2007-06-01 17:26:16 UTC (rev 78439)
+++
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/RegularExpressionLiteralToken.cs
2007-06-01 17:31:29 UTC (rev 78440)
@@ -4,7 +4,20 @@
namespace Mono.JScript.Compiler
{
- public class RegularExpressionLiteralToken
+ public class RegularExpressionLiteralToken : Token
{
+ public readonly string BodySpelling;
+ public readonly string FlagsSpelling;
+ private readonly int width;
+
+ public RegularExpressionLiteralToken (string BodySpelling,
string FlagsSpelling, int Width, int StartCharacterPosition, int StartLine, int
StartColumn, bool FirstOnLine)
+ :base(Type.RegularExpressionLiteral,
StartCharacterPosition, StartLine, StartColumn, FirstOnLine)
+ {
+ this.BodySpelling = BodySpelling;
+ this.FlagsSpelling = FlagsSpelling;
+ this.width = Width;
+ }
+
+ public override int Width { get { return width; } }
}
}
Modified:
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/SplayTree.cs
===================================================================
---
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/SplayTree.cs
2007-06-01 17:26:16 UTC (rev 78439)
+++
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/SplayTree.cs
2007-06-01 17:31:29 UTC (rev 78440)
@@ -13,12 +13,12 @@
public void AddAsLeftChild(SplayTree Child)
{
- throw new NotImplementedException();
+ this.left = Child;
}
public void AddAsRightChild(SplayTree Child)
{
- throw new NotImplementedException();
+ this.right = Child;
}
public void SplayToRoot()
@@ -31,11 +31,14 @@
throw new NotImplementedException();
}
+ private SplayTree left;
+ private SplayTree right;
+
public SplayTree Left {
- get { throw new NotImplementedException(); }
+ get { return left; }
}
public SplayTree Right {
- get { throw new NotImplementedException(); }
+ get { return right; }
}
}
}
Modified:
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/Table.cs
===================================================================
---
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/Table.cs
2007-06-01 17:26:16 UTC (rev 78439)
+++
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/Table.cs
2007-06-01 17:31:29 UTC (rev 78440)
@@ -19,7 +19,7 @@
public void InsertIfNotPresent(KeyType Key, ValueType Value)
{
- throw new NotImplementedException();
+ Insert (Key, Value, false);
}
public ValueType Lookup(KeyType Key)
Modified:
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/TextPoint.cs
===================================================================
---
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/TextPoint.cs
2007-06-01 17:26:16 UTC (rev 78439)
+++
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/TextPoint.cs
2007-06-01 17:31:29 UTC (rev 78440)
@@ -6,13 +6,15 @@
{
public struct TextPoint
{
+ private int position;
+
public TextPoint(int Position)
{
- throw new NotImplementedException();
+ position = Position;
}
public int Position {
- get { throw new NotImplementedException(); }
+ get { return position; }
}
}
Modified:
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/Token.cs
===================================================================
---
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/Token.cs
2007-06-01 17:26:16 UTC (rev 78439)
+++
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/Token.cs
2007-06-01 17:31:29 UTC (rev 78440)
@@ -12,7 +12,7 @@
public enum Type
{
None = 0,
- EndOfInput = 0,
+ EndOfInput = 1,
//Punctuator
LeftBrace,// {
@@ -154,13 +154,18 @@
public readonly int StartLine;
public readonly int StartPosition;
private bool firstOnLine;
+ private Token next = null;
+
public Token InsertSemicolonBefore()
{
- throw new NotImplementedException();
+ Token semicolon = new Token (Token.Type.SemiColon,
StartPosition, StartLine, StartColumn, false);
+ semicolon.next = this;
+ return semicolon;
}
+ //by default 1 must be change in inherited token which differ
public virtual int Width {
- get { throw new NotImplementedException(); }
+ get { return 1; }
}
public bool FirstOnLine
@@ -169,7 +174,11 @@
}
public Token this[Tokenizer InputStream]
{
- get { return InputStream.GetNext(); }
+ get {
+ if (next == null)
+ return InputStream.GetNext();
+ return next;
+ }
}
}
Modified:
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/TokenCategorizer.cs
===================================================================
---
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/TokenCategorizer.cs
2007-06-01 17:26:16 UTC (rev 78439)
+++
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/TokenCategorizer.cs
2007-06-01 17:31:29 UTC (rev 78440)
@@ -10,45 +10,312 @@
{
public TokenCategorizer()
{
- throw new NotImplementedException();
}
+ private Tokenizer tokenizer;
+ private object state;
+ private ErrorSink errorSink;
+
public override void Initialize(object state, SourceUnitReader
sourceReader, SourceLocation initialLocation)
{
- throw new NotImplementedException();
+ Tokenizer tokenizer = new Tokenizer
(sourceReader.ReadToEnd ().ToCharArray (), new IdentifierTable ());
+ tokenizer.Position = initialLocation;
+ this.state = state;
+ errorSink = new ErrorSink ();
}
public override TokenInfo ReadToken()
{
- throw new NotImplementedException();
+ Token token = tokenizer.GetNext ();
+ SourceLocation location = new
SourceLocation(token.StartPosition,token.StartLine,token.StartColumn);
+ SourceSpan span = new SourceSpan (location,
tokenizer.Position);
+ TokenTriggers trigger = GetTrigger(token.Kind);
+ TokenCategory category = GetCategory (token.Kind);
+ return new TokenInfo (span, category, trigger);
}
+ //TODO
+ private TokenCategory GetCategory(Token.Type type)
+ {
+ switch (type) {
+ case Token.Type.None:
+ case Token.Type.EndOfInput:
+ case Token.Type.LeftBrace:
+ case Token.Type.RightBrace:
+ case Token.Type.LeftParenthesis:
+ case Token.Type.RightParenthesis:
+ case Token.Type.LeftBracket:
+ case Token.Type.RightBracket:
+ case Token.Type.Dot:
+ case Token.Type.SemiColon:
+ case Token.Type.Comma:
+ case Token.Type.Less:
+ case Token.Type.Greater:
+ case Token.Type.LessEqual:
+ case Token.Type.GreaterEqual:
+ case Token.Type.EqualEqual:
+ case Token.Type.BangEqual:
+ case Token.Type.EqualEqualEqual:
+ case Token.Type.BangEqualEqual:
+ case Token.Type.Plus:
+ case Token.Type.Minus:
+ case Token.Type.Star:
+ case Token.Type.Percent:
+ case Token.Type.PlusPlus:
+ case Token.Type.MinusMinus:
+ case Token.Type.LessLess:
+ case Token.Type.GreaterGreater:
+ case Token.Type.GreaterGreaterGreater:
+ case Token.Type.Ampersand:
+ case Token.Type.Bar:
+ case Token.Type.Circumflex:
+ case Token.Type.Bang:
+ case Token.Type.Tilda:
+ case Token.Type.AmpersandAmpersand:
+ case Token.Type.BarBar:
+ case Token.Type.Question:
+ case Token.Type.Colon:
+ case Token.Type.Equal:
+ case Token.Type.PlusEqual:
+ case Token.Type.MinusEqual:
+ case Token.Type.StarEqual:
+ case Token.Type.PercentEqual:
+ case Token.Type.LessLessEqual:
+ case Token.Type.GreaterGreaterEqual:
+ case Token.Type.GreaterGreaterGreaterEqual:
+ case Token.Type.AmpersandEqual:
+ case Token.Type.BarEqual:
+ case Token.Type.CircumflexEqual:
+ case Token.Type.Divide:
+ case Token.Type.DivideEqual:
+ case Token.Type.Break:
+ case Token.Type.Else:
+ case Token.Type.New:
+ case Token.Type.Var:
+ case Token.Type.Case:
+ case Token.Type.Finally:
+ case Token.Type.Return:
+ case Token.Type.Void:
+ case Token.Type.Catch:
+ case Token.Type.For:
+ case Token.Type.Switch:
+ case Token.Type.While:
+ case Token.Type.Continue:
+ case Token.Type.Function:
+ case Token.Type.This:
+ case Token.Type.With:
+ case Token.Type.Default:
+ case Token.Type.If:
+ case Token.Type.Throw:
+ case Token.Type.Delete:
+ case Token.Type.In:
+ case Token.Type.Try:
+ case Token.Type.Do:
+ case Token.Type.Instanceof:
+ case Token.Type.Typeof:
+ case Token.Type.Abstract:
+ case Token.Type.Enum:
+ case Token.Type.Int:
+ case Token.Type.Short:
+ case Token.Type.Boolean:
+ case Token.Type.Export:
+ case Token.Type.Interface:
+ case Token.Type.Static:
+ case Token.Type.Byte:
+ case Token.Type.Extends:
+ case Token.Type.Long:
+ case Token.Type.Super:
+ case Token.Type.Char:
+ case Token.Type.Final:
+ case Token.Type.Native:
+ case Token.Type.Synchronized:
+ case Token.Type.Class:
+ case Token.Type.Float:
+ case Token.Type.Package:
+ case Token.Type.Throws:
+ case Token.Type.Const:
+ case Token.Type.Goto:
+ case Token.Type.Private:
+ case Token.Type.Transient:
+ case Token.Type.Debugger:
+ case Token.Type.Implements:
+ case Token.Type.Protected:
+ case Token.Type.Volatile:
+ case Token.Type.Double:
+ case Token.Type.Import:
+ case Token.Type.Public:
+ case Token.Type.Null:
+ case Token.Type.True:
+ case Token.Type.False:
+ case Token.Type.NumericLiteral:
+ case Token.Type.HexIntegerLiteral:
+ case Token.Type.OctalIntegerLiteral:
+ case Token.Type.StringLiteral:
+ case Token.Type.RegularExpressionLiteral:
+ case Token.Type.Identifier:
+ case Token.Type.Bad:
+ case Token.Type.Comment:
+ return TokenCategory.Comment;
+ }
+ return TokenCategory.Comment;
+ }
+
+ //TODO
+ private TokenTriggers GetTrigger(Token.Type type)
+ {
+ switch (type) {
+ case Token.Type.Abstract:
+ case Token.Type.None:
+ case Token.Type.EndOfInput:
+ case Token.Type.LeftBrace:
+ case Token.Type.RightBrace:
+ case Token.Type.LeftParenthesis:
+ case Token.Type.RightParenthesis:
+ case Token.Type.LeftBracket:
+ case Token.Type.RightBracket:
+ case Token.Type.Dot:
+ case Token.Type.SemiColon:
+ case Token.Type.Comma:
+ case Token.Type.Less:
+ case Token.Type.Greater:
+ case Token.Type.LessEqual:
+ case Token.Type.GreaterEqual:
+ case Token.Type.EqualEqual:
+ case Token.Type.BangEqual:
+ case Token.Type.EqualEqualEqual:
+ case Token.Type.BangEqualEqual:
+ case Token.Type.Plus:
+ case Token.Type.Minus:
+ case Token.Type.Star:
+ case Token.Type.Percent:
+ case Token.Type.PlusPlus:
+ case Token.Type.MinusMinus:
+ case Token.Type.LessLess:
+ case Token.Type.GreaterGreater:
+ case Token.Type.GreaterGreaterGreater:
+ case Token.Type.Ampersand:
+ case Token.Type.Bar:
+ case Token.Type.Circumflex:
+ case Token.Type.Bang:
+ case Token.Type.Tilda:
+ case Token.Type.AmpersandAmpersand:
+ case Token.Type.BarBar:
+ case Token.Type.Question:
+ case Token.Type.Colon:
+ case Token.Type.Equal:
+ case Token.Type.PlusEqual:
+ case Token.Type.MinusEqual:
+ case Token.Type.StarEqual:
+ case Token.Type.PercentEqual:
+ case Token.Type.LessLessEqual:
+ case Token.Type.GreaterGreaterEqual:
+ case Token.Type.GreaterGreaterGreaterEqual:
+ case Token.Type.AmpersandEqual:
+ case Token.Type.BarEqual:
+ case Token.Type.CircumflexEqual:
+ case Token.Type.Divide:
+ case Token.Type.DivideEqual:
+ case Token.Type.Break:
+ case Token.Type.Else:
+ case Token.Type.New:
+ case Token.Type.Var:
+ case Token.Type.Case:
+ case Token.Type.Finally:
+ case Token.Type.Return:
+ case Token.Type.Void:
+ case Token.Type.Catch:
+ case Token.Type.For:
+ case Token.Type.Switch:
+ case Token.Type.While:
+ case Token.Type.Continue:
+ case Token.Type.Function:
+ case Token.Type.This:
+ case Token.Type.With:
+ case Token.Type.Default:
+ case Token.Type.If:
+ case Token.Type.Throw:
+ case Token.Type.Delete:
+ case Token.Type.In:
+ case Token.Type.Try:
+ case Token.Type.Do:
+ case Token.Type.Instanceof:
+ case Token.Type.Typeof:
+ case Token.Type.Enum:
+ case Token.Type.Int:
+ case Token.Type.Short:
+ case Token.Type.Boolean:
+ case Token.Type.Export:
+ case Token.Type.Interface:
+ case Token.Type.Static:
+ case Token.Type.Byte:
+ case Token.Type.Extends:
+ case Token.Type.Long:
+ case Token.Type.Super:
+ case Token.Type.Char:
+ case Token.Type.Final:
+ case Token.Type.Native:
+ case Token.Type.Synchronized:
+ case Token.Type.Class:
+ case Token.Type.Float:
+ case Token.Type.Package:
+ case Token.Type.Throws:
+ case Token.Type.Const:
+ case Token.Type.Goto:
+ case Token.Type.Private:
+ case Token.Type.Transient:
+ case Token.Type.Debugger:
+ case Token.Type.Implements:
+ case Token.Type.Protected:
+ case Token.Type.Volatile:
+ case Token.Type.Double:
+ case Token.Type.Import:
+ case Token.Type.Public:
+ case Token.Type.Null:
+ case Token.Type.True:
+ case Token.Type.False:
+ case Token.Type.NumericLiteral:
+ case Token.Type.HexIntegerLiteral:
+ case Token.Type.OctalIntegerLiteral:
+ case Token.Type.StringLiteral:
+ case Token.Type.RegularExpressionLiteral:
+ case Token.Type.Identifier:
+ case Token.Type.Bad:
+ case Token.Type.Comment:
+ return TokenTriggers.MatchBraces;
+ }
+ return TokenTriggers.MatchBraces;
+ }
+
public override IEnumerable<TokenInfo> ReadTokens(int
countOfChars)
{
- throw new NotImplementedException();
+ List<TokenInfo> list = new List<TokenInfo>
(countOfChars);
+ for (int i = 0; i < countOfChars; i++)
+ list.Add(ReadToken ());
+ return list;
}
public override bool SkipToken()
{
- throw new NotImplementedException();
+ Token token = tokenizer.GetNext ();
+ return (token.Kind != Token.Type.EndOfInput &&
token.Kind != Token.Type.Bad);
}
-
public override SourceLocation CurrentPosition {
- get { throw new NotImplementedException(); }
+ get { return tokenizer.Position; }
}
+ //TO check with test
public override object CurrentState {
- get { throw new NotImplementedException(); }
+ get { return state; }
}
public override ErrorSink ErrorSink {
- get { throw new NotImplementedException(); }
- set { throw new NotImplementedException(); }
+ get { return errorSink; }
+ set { errorSink = value; }
}
public override bool IsRestartable {
- get { throw new NotImplementedException(); }
+ get { return false; }
}
}
Modified:
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/Tokenizer.cs
===================================================================
---
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/Tokenizer.cs
2007-06-01 17:26:16 UTC (rev 78439)
+++
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler/Tokenizer.cs
2007-06-01 17:31:29 UTC (rev 78440)
@@ -294,7 +294,21 @@
public RegularExpressionLiteralToken ScanRegularExpression
(Token Divide)
{
- throw new NotImplementedException();
+ int startpos = Divide.StartPosition;
+ int startrow = Divide.StartLine;
+ int startcol = Divide.StartColumn;
+
+ Token current = Divide[this];
+ StringBuilder regexp = new StringBuilder ();
+ while (current.Kind == Token.Type.Divide) {
+ //get the value of the current token
+ for (int i = 0; i < current.Width; i++)
+ regexp.Append(source [position + i]);
+ current = Divide[this];
+ }
+ //TODO flags maybe but not always so must peek and not
advance
+ //TODO firstonline
+ return new RegularExpressionLiteralToken
(regexp.ToString (), "", position - startpos, startpos, startrow, startcol,
false);
}
@@ -307,10 +321,17 @@
get { return comments; }
}
+ // we gain a that we only move on position (I have see that on
an other compiler)
+ // but maybe it is better with working with sourcelocation
object directely
+ // it perform less but more OO ...
public SourceLocation Position
{
- get { throw new NotImplementedException(); }
- set { throw new NotImplementedException(); }
+ get { return new SourceLocation(position, row, position
- lineStartPosition +1); }
+ set {
+ position = value.Index;
+ row = value.Line;
+ lineStartPosition = position - value.Column + 1;
+ }
}
#region token
@@ -553,7 +574,6 @@
row++;
lineStartPosition = position;
position++;
-
}
private void CreateBlockComment()
Modified:
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler.Hosting/LanguageProvider.cs
===================================================================
---
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler.Hosting/LanguageProvider.cs
2007-06-01 17:26:16 UTC (rev 78439)
+++
trunk/olive/class/Microsoft.JScript.Compiler/Microsoft.JScript.Compiler.Hosting/LanguageProvider.cs
2007-06-01 17:31:29 UTC (rev 78440)
@@ -1,6 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
using Microsoft.Scripting.Hosting;
using Microsoft.Scripting.Shell;
using Microsoft.Scripting;
@@ -11,31 +8,31 @@
{
public LanguageProvider(ScriptDomainManager environment) :
base(environment)
{
- throw new NotImplementedException();
}
public override CommandLine GetCommandLine()
{
- throw new NotImplementedException();
+ return new Mono.JScript.Compiler.Shell.CommandLine ();
}
public override ScriptEngine
GetEngine(Microsoft.Scripting.EngineOptions options)
{
- throw new NotImplementedException();
+ return new Engine (this,
(Mono.JScript.Compiler.EngineOptions)options);
}
public override Microsoft.Scripting.OptionsParser
GetOptionsParser()
{
- throw new NotImplementedException();
+ return new Mono.JScript.Compiler.OptionsParser ();
}
public override Microsoft.Scripting.Hosting.TokenCategorizer
GetTokenCategorizer()
{
- throw new NotImplementedException();
+ return new Mono.JScript.Compiler.TokenCategorizer ();
}
+ //TODO Test to get exact name maybe + version or "JScript"
public override string LanguageDisplayName {
- get { throw new NotImplementedException(); }
+ get { return "JavaScript"; }
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches