1+ using EZCode . Variables ;
2+ using System ;
3+ using System . Collections . Generic ;
4+ using System . Linq ;
5+ using System . Text ;
6+ using System . Threading . Tasks ;
7+ using static System . Net . Mime . MediaTypeNames ;
8+ using static System . Runtime . InteropServices . JavaScript . JSType ;
9+
10+ namespace EZCode
11+ {
12+ public class EasierCode
13+ {
14+ /// <summary>
15+ /// EZCode object EZR Code is referencing
16+ /// </summary>
17+ public EzCode EZCode { get ; set ; }
18+ /// <summary>
19+ /// Easier Code Given
20+ /// </summary>
21+ public string EZRCode { get ; set ; }
22+ /// <summary>
23+ /// Translated Code. Set as <see cref="EzCode.Code"/>
24+ /// </summary>
25+ public string Code
26+ {
27+ get => Code ;
28+ set
29+ {
30+ Code = value ;
31+ EZCode . Code = value ;
32+ }
33+ }
34+ public EasierCode ( )
35+ {
36+ EZCode = new EzCode ( ) ;
37+ EZCode . Initialize ( ) ;
38+ EZCode . Code ??= "" ;
39+ }
40+ public EasierCode ( EzCode ezcode )
41+ {
42+ EZCode = ezcode ;
43+ EZCode . Code ??= "" ;
44+ }
45+ public EasierCode ( string code )
46+ {
47+ EZCode = new EzCode ( )
48+ {
49+ Code = code
50+ } ;
51+ }
52+ public string Translate ( string InputCode )
53+ {
54+ try
55+ {
56+ string [ ] lines = InputCode . Split ( Environment . NewLine ) . Select ( x => x . Trim ( ) ) . Where ( y => ! y . Equals ( "" ) && ! y . StartsWith ( "//" ) ) . ToArray ( ) ;
57+ for ( int i = 0 ; i < lines . Length ; i ++ )
58+ {
59+ EZCode . codeLine ++ ;
60+ string line = lines [ i ] ;
61+ string [ ] words = line . Split ( " " ) . Select ( x => x . Trim ( ) ) . Where ( y => ! y . Equals ( "" ) ) . ToArray ( ) ;
62+ string first = words [ 0 ] , second = words [ 1 ] ;
63+ switch ( first )
64+ {
65+ case "add" :
66+ try
67+ {
68+ string third = words [ 2 ] , fourth = words [ 3 ] ;
69+ if ( third == "to" )
70+ {
71+ Code += $ "{ second } + { fourth } ";
72+ }
73+ else
74+ {
75+ Error ( "Expected 'to' for English syntax 'Add X to Var'" ) ;
76+ }
77+ }
78+ catch
79+ {
80+ EZCode . ErrorText ( words , EzCode . ErrorTypes . normal , first ) ;
81+ }
82+ break ;
83+ default :
84+ Error ( $ "Keyword { first } could not be found.") ;
85+ Code += "// Error Occured with tranlateing this line: " + line ;
86+ break ;
87+ }
88+ Code += Environment . NewLine ;
89+ }
90+ }
91+ catch
92+ {
93+ Error ( "Unhandled Error Occured" ) ;
94+ }
95+ return Code ;
96+ }
97+ public void Error ( string error )
98+ {
99+ EZCode . ErrorText ( new string [ 0 ] , EzCode . ErrorTypes . custom , custom : error ) ;
100+ }
101+ }
102+ }
0 commit comments