ScriptStack 1.0.4
Loading...
Searching...
No Matches
ScriptStack.Compiler.Parser Class Reference

The parser builds an ScriptStack.Runtime.Executable out of the Token stream returned from the ScriptStack.Compiler.Lexer while checking for correct syntax. More...

Public Member Functions

string ToLiteral (string input)
 Parser (Script script, List< Token > tokenStream)
Executable Parse ()
 Parse the token stream into an executable.

Detailed Description

The parser builds an ScriptStack.Runtime.Executable out of the Token stream returned from the ScriptStack.Compiler.Lexer while checking for correct syntax.

The parser takes the output from the Lexer in the form of a Token stream and matches it against syntax rules to detect any errors. The output is an abstract syntax tree in form of Instruction's which can be executed by the ScriptStack.Runtime.Interpreter. More details are coming soon.

Not all methods are well documented yet but please be patient - i am working on it.

See https://en.wikipedia.org/wiki/Parsing

Definition at line 21 of file Parser.cs.

Constructor & Destructor Documentation

◆ Parser()

ScriptStack.Compiler.Parser.Parser ( Script script,
List< Token > tokenStream )

Definition at line 3073 of file Parser.cs.

3074 {
3075 this.script = script;
3076 debugMode = false;
3077 nextToken = 0;
3078 variables = new Dictionary<String, bool>();
3079 localVariables = new Dictionary<String, bool>();
3080 functionFrameIndex = 0;
3081 forwardDeclarations = new Dictionary<Instruction, FunctionDescriptor>();
3082 loopControl = new Stack<LoopControl>();
3083 this.tokenStream = new List<Token>(tokenStream);
3084 derivation = new Derivation();
3085 executable = null;
3086 }

Member Function Documentation

◆ Parse()

Executable ScriptStack.Compiler.Parser.Parse ( )

Parse the token stream into an executable.

Returns

Definition at line 3092 of file Parser.cs.

3093 {
3094 nextToken = 0;
3095 variables.Clear();
3096 localVariables.Clear();
3097 functionFrameIndex = -1;
3098 forwardDeclarations.Clear();
3099 loopControl.Clear();
3100
3101 executable = new Executable(script);
3102
3103 ParseScript();
3104 ResolveForwardFunctionDeclarations();
3105 executable.Clean();
3106
3107 return executable;
3108 }

Referenced by ScriptStack.Runtime.Script.Script(), and ScriptStack.Runtime.Script.Script().

◆ ToLiteral()

string ScriptStack.Compiler.Parser.ToLiteral ( string input)

Definition at line 1217 of file Parser.cs.

1218 {
1219 var literal = new StringBuilder(input.Length + 2);
1220 literal.Append("\"");
1221 foreach (var c in input)
1222 {
1223 switch (c)
1224 {
1225 case '\'': literal.Append(@"\'"); break;
1226 case '\"': literal.Append("\\\""); break;
1227 case '\\': literal.Append(@"\\"); break;
1228 case '\0': literal.Append(@"\0"); break;
1229 case '\a': literal.Append(@"\a"); break;
1230 case '\b': literal.Append(@"\b"); break;
1231 case '\f': literal.Append(@"\f"); break;
1232 case '\n': literal.Append(@"\n"); break;
1233 case '\r': literal.Append(@"\r"); break;
1234 case '\t': literal.Append(@"\t"); break;
1235 case '\v': literal.Append(@"\v"); break;
1236 default:
1237 if (char.GetUnicodeCategory(c) != System.Globalization.UnicodeCategory.Control)
1238 {
1239 literal.Append(c);
1240 }
1241 else
1242 {
1243 literal.Append(@"\u");
1244 literal.Append(((ushort)c).ToString("x4"));
1245 }
1246 break;
1247 }
1248 }
1249 literal.Append("\"");
1250 return literal.ToString();
1251 }

The documentation for this class was generated from the following file: