The_Chosen_Oreo Corporal
| Subject: xJASS Wed Aug 03, 2011 1:17 am | |
| JassHelper is really, really pissing me off. It keeps messing with the code of my maps, so I have decided to create my own version of JASS, called xJASS. The syntax is defined in the spoiler below (Unfinished, does need additions): - Spoiler:
- Code:
-
// Example xJass File
// This is a comment
/* This is a multi-line comment */
/* This is an enclosed comment */
// Types int j; // A single integer integer j2; // Same as int char c; // A single ASCII character string s; // A String of text or an array of characters float fl; // Converts to a Real real r; // Same as real code c; // A code block, such as a Function or Method bool b; // Boolean Value, either 0 or 1, true or false, etc.. boolean b2; // Same as bool handle h; // Can be converted to ANY type // Other types can be created off these, such as the ones // located in the file "common.j". I will not list them here. // Types of Types local // Is private global // Is public semiglobal // Is public ONLY to the current trigger array // An array of values // Types of Functions Execution x { // Code Here } // Executations are the Jass type of // function func1 takes nothing returns nothing
Function f ( int i ) { // Code Here } // Functions are the Jass type of // function func2 takes int i returns nothing int RetFunction rf { // Code Here } // RetFunctions are the Jass type of // function func3 takes nothing returns int int Method m ( int i ) { // Code Here } // Methods are the Jass type of // function func4 takes int i returns int // Loops
// If Loop if ( local int i != 1 ) { // Code Here }
// For Loop for ( local int i = 0; i != 1; i ++ ) { // Code Here } // Do Loop do { // Code Here } while ( local int i != 8 )
// While Loop while ( local int i != 5 ) { // Code Here }
// Calling Methods / Functions / Executions / RetFunctions // Simply enter the name of the block you wish to execute as follows call m (23); // This calls the method m that was created above.
// Ending A Statement // Statements are ended with ; local int i;
// Structs and Enumerations
// Struct global struct sct1 { int var1; // Variables inside a Struct string var2 = "hello"; // This one is defined a default value bool var3 = false; // This one is also defined a default value } obj1; // Structs can have objects created directly from them by putting them // at the end of the struct. They are not necessary however.
// Enumeration global enum DIFFICULTY { DIFF_VERYEASY; DIFF_EASY; DIFF_NORMAL; DIFF_HARD; DIFF_VERYHARD; DIFF_IMPOSSIBLE; }; // Enums go from 0,1,2,3,etc... // You can also give explicit values to enums. They will // continue incrementing by 1 from the last explicit value. // Also, values CANNOT overlap. If they do, = ERROR global enum DIRECTION { DCT_NORTH; DCT_EAST = 90; DCT_SOUTH = 180; DCT_WEST = 270; }; // Enums can be used as follows: DIFFICULTY currentdifficulty = DIFF_NORMAL;
My website is being a douche so the userDefineLang.xml is not being uploaded right now. Anyways, its better to just copy the following code into your userDefineLang.xml - Spoiler:
- Code:
-
<UserLang name="xJass" ext="xj"> <Settings> <Global caseIgnored="no" /> <TreatAsSymbol comment="no" commentLine="no" /> <Prefix words1="no" words2="no" words3="no" words4="no" /> </Settings> <KeywordLists> <Keywords name="Delimiters">"'0"'0</Keywords> <Keywords name="Folder+">{</Keywords> <Keywords name="Folder-">}</Keywords> <Keywords name="Operators">% ( ) ; [ ]</Keywords> <Keywords name="Comment"> 1/* 2*/ 0//</Keywords> <Keywords name="Words1"></Keywords> <Keywords name="Words2">== = != > < >= <= || && ++ -- += -= if for do while</Keywords> <Keywords name="Words3">int string float code handle integer single real bool boolean char false true</Keywords> <Keywords name="Words4">Execution Function RetFunction Method local global semiglobal array call struct enum enum eunmeration</Keywords> </KeywordLists> <Styles> <WordsStyle name="DEFAULT" styleID="11" fgColor="FFFFFF" bgColor="000000" fontName="" fontStyle="0" /> <WordsStyle name="FOLDEROPEN" styleID="12" fgColor="FF8000" bgColor="000000" fontName="" fontStyle="1" /> <WordsStyle name="FOLDERCLOSE" styleID="13" fgColor="FF8000" bgColor="000000" fontName="" fontStyle="1" /> <WordsStyle name="KEYWORD1" styleID="5" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" /> <WordsStyle name="KEYWORD2" styleID="6" fgColor="808080" bgColor="000000" fontName="" fontStyle="0" /> <WordsStyle name="KEYWORD3" styleID="7" fgColor="0080C0" bgColor="000000" fontName="" fontStyle="0" /> <WordsStyle name="KEYWORD4" styleID="8" fgColor="FF0080" bgColor="000000" fontName="" fontStyle="0" /> <WordsStyle name="COMMENT" styleID="1" fgColor="00FF00" bgColor="000000" fontName="" fontStyle="0" /> <WordsStyle name="COMMENT LINE" styleID="2" fgColor="00FF00" bgColor="000000" fontName="" fontStyle="0" /> <WordsStyle name="NUMBER" styleID="4" fgColor="FF0000" bgColor="000000" fontName="" fontStyle="0" /> <WordsStyle name="OPERATOR" styleID="10" fgColor="FFFF00" bgColor="000000" fontName="" fontStyle="1" /> <WordsStyle name="DELIMINER1" styleID="14" fgColor="753609" bgColor="000000" fontName="" fontStyle="0" /> <WordsStyle name="DELIMINER2" styleID="15" fgColor="006C6C" bgColor="000000" fontName="" fontStyle="0" /> <WordsStyle name="DELIMINER3" styleID="16" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" /> </Styles> </UserLang>
There will be more soon. Enjoy whats here for now. Current Task List (One I'm working on in Green, Completed ones in Blue, Started ones in Yellow, Unstarted ones in Red): - Preprocessor Scanner
- Preprocessor Parser
- Scanner
- Parser
- AST
- Jass Generator
- GUI
Program Code: - Spoiler:
Scanner: - Code:
-
using Collections = System.Collections.Generic; using IO = System.IO; using Text = System.Text;
namespace xJASS_Compiler { public sealed class Scanner { private readonly Collections.IList<object> result;
public Scanner(IO.TextReader input) { this.result = new Collections.List<object>(); this.Scan(input); } public Collections.IList<object> Tokens { get { return this.result; } } #region Constants... #region Arithmitic_Constants public static readonly object Add = new object(); public static readonly object Sub = new object(); public static readonly object Mul = new object(); public static readonly object Div = new object(); #endregion #region Assignment_Constants public static readonly object Equals = new object(); public static readonly object Add_Equals = new object(); public static readonly object Sub_Equals = new object(); public static readonly object Mul_Equals = new object(); public static readonly object Div_Equals = new object(); #endregion #region Comparison_Constants public static readonly object Comp_Equals = new object(); public static readonly object Comp_NotEquals = new object(); public static readonly object Comp_GreaterEqual = new object(); public static readonly object Comp_LessEqual = new object(); public static readonly object Comp_Greater = new object(); public static readonly object Comp_Less = new object(); #endregion #region Boolean_Constants public static readonly object Bool_And = new object(); public static readonly object Bool_Or = new object(); public static readonly object Bool_Not = new object(); #endregion #region Function_Constants public static readonly object Function = new object(); public static readonly object RetFunction = new object(); public static readonly object Method = new object(); public static readonly object Execution = new object(); #endregion #region TypeOfTypes_Constants public static readonly object Global = new object(); public static readonly object SemiGlobal = new object(); public static readonly object Local = new object(); public static readonly object Array = new object(); #endregion #region Types_Constants public static readonly object Integer = new object(); public static readonly object Character = new object(); public static readonly object String = new object(); public static readonly object Real = new object(); public static readonly object Code = new object(); public static readonly object Boolean = new object(); public static readonly object Handle = new object(); #endregion #region Miscellanious_Constants public static readonly object Semicolon = new object(); public static readonly object Invert = new object(); public static readonly object BlockComment = new object(); public static readonly object StartBlock = new object(); public static readonly object EndBlock = new object(); #endregion #endregion
private void Scan(IO.TextReader input) { while (input.Peek() != -1) { char ch = (char)input.Peek(); if (char.IsWhiteSpace(ch)) { input.Read(); } else if (char.IsLetter(ch) || ch == '_') { Text.StringBuilder accum = new Text.StringBuilder();
while (char.IsLetter(ch) || ch == '_') { accum.Append(ch); input.Read();
if (input.Peek() == -1) { break; } else { ch = (char)input.Peek(); } }
this.result.Add(accum.ToString()); } else if (ch == '"') { Text.StringBuilder accum = new Text.StringBuilder();
input.Read();
if (input.Peek() == -1) { throw new System.Exception("Unterminated String Literal (SCANERROR:0001)"); } while ((ch = (char)input.Peek()) != '"') { accum.Append(ch); input.Read();
if (input.Peek() == -1) { throw new System.Exception("Unterminated String Literal (SCANERROR:0001)"); } } input.Read(); this.result.Add(accum); } else if (char.IsDigit(ch)) { Text.StringBuilder accum = new Text.StringBuilder();
while (char.IsDigit(ch)) { accum.Append(ch); input.Read();
if (input.Peek() == -1) { break; } else { ch = (char)input.Peek(); } } this.result.Add(int.Parse(accum.ToString())); } else switch (ch) { case '+': if ((char)input.Peek() == '=') { input.Read(); this.result.Add(Scanner.Add_Equals); goto endswitch; } input.Read(); this.result.Add(Scanner.Add); break; case '-': if ((char)input.Peek() == '=') { input.Read(); this.result.Add(Scanner.Sub_Equals); goto endswitch; } input.Read(); this.result.Add(Scanner.Sub); break; case '*': if ((char)input.Peek() == '=') { input.Read(); this.result.Add(Scanner.Mul_Equals); goto endswitch; } input.Read(); this.result.Add(Scanner.Mul); break; case '/': if ((char)input.Peek() == '=') { input.Read(); this.result.Add(Scanner.Div_Equals); goto endswitch; } if ((char)input.Peek() == '*') { if (input.Peek() == -1) { throw new System.Exception("Unclosed Block Comment (SCANERROR:0002)"); } retry: while ((ch = (char)input.Peek()) != '*') { input.Read();
if (input.Peek() == -1) { throw new System.Exception("Unclosed Block Comment (SCANERROR:0002)"); } } input.Read(); if ((ch = (char)input.Peek()) == '/') { input.Read(); this.result.Add(Scanner.BlockComment); goto endswitch; } else { goto retry; }
} input.Read(); this.result.Add(Scanner.Div); break; case '=': if ((char)input.Peek() == '=') { input.Read(); this.result.Add(Scanner.Comp_Equals); goto endswitch; } input.Read(); this.result.Add(Scanner.Equals); break; case '!': if ((char)input.Peek() == '=') { input.Read(); this.result.Add(Scanner.Comp_NotEquals); goto endswitch; } if ((char)input.Peek() == '!') { input.Read(); this.result.Add(Scanner.Bool_Not); goto endswitch; } input.Read(); this.result.Add(Scanner.Invert); break; case '>': if ((char)input.Peek() == '=') { input.Read(); this.result.Add(Scanner.Comp_GreaterEqual); goto endswitch; } input.Read(); this.result.Add(Scanner.Comp_Greater); break; case '<': if ((char)input.Peek() == '=') { input.Read(); this.result.Add(Scanner.Comp_LessEqual); goto endswitch; } input.Read(); this.result.Add(Scanner.Comp_Less); break; case ';': input.Read(); this.result.Add(Scanner.Semicolon); break; case '{': input.Read(); this.result.Add(Scanner.StartBlock); break; case '}': input.Read(); this.result.Add(Scanner.EndBlock); break; case 'ß': endswitch: break; } } } } }
IF YOU WISH TO HELP, POST HERE OR PM ME!!!!!! -Oreo
Last edited by The_Chosen_Oreo on Mon Aug 08, 2011 10:31 am; edited 5 times in total | |
|
The_Chosen_Oreo Corporal
| Subject: Re: xJASS Mon Aug 08, 2011 10:29 am | |
| | |
|
Serenity09 Moderator
| Subject: Re: xJASS Tue Aug 09, 2011 1:12 pm | |
| this is super cool but i've got way too much on my hands as is
if you have any specific questions, i'll try and help though | |
|