File tree Expand file tree Collapse file tree 4 files changed +27
-16
lines changed Expand file tree Collapse file tree 4 files changed +27
-16
lines changed Original file line number Diff line number Diff line change 55CritLang /Properties /PublishProfiles /FolderProfile.pubxml
66CritLang /Properties /PublishProfiles /FolderProfile.pubxml.user
77CritLang /CritLang.csproj.user
8+ CritLang /Content /ola.txt
Original file line number Diff line number Diff line change 11
2- str_num1 = ReadLine("Digite um numero: ");
3- str_num2 = ReadLine("Digite outro numero: ");
42
5- int_num1 = Convert(str_num1, "int");
6- int_num2 = Convert(str_num2, "int");
3+ path = "./Content/ola.txt";
74
8- WriteLine(int_num1 + int_num2);
95
6+ text = ReadText(path);
107
11- lista = [1, 2, "tres", 69];
128
13- num = 0 ;
9+ WriteLine(text + CritVersion) ;
1410
15- while num < Len(lista) {
16- WriteLine(lista[num]);
17- num += 1;
18- }
19-
20-
21- WriteLine("FINAL");
2211
Original file line number Diff line number Diff line change @@ -10,8 +10,9 @@ public class CritVisitor: CritBaseVisitor<object?>
1010
1111
1212
13- public CritVisitor ( )
13+ public CritVisitor ( string version )
1414 {
15+ string _version = version ;
1516 //Math Functions
1617 Variables [ "PI" ] = Math . PI ;
1718 Variables [ "Sqrt" ] = new Func < object ? [ ] , object ? > ( Sqrt ) ;
@@ -28,9 +29,29 @@ public CritVisitor()
2829 Variables [ "Remove" ] = new Func < object ? [ ] , object ? > ( RemoveArr ) ;
2930 Variables [ "Len" ] = new Func < object ? [ ] , object ? > ( LenArr ) ;
3031
32+ //OS Functions
33+ Variables [ "ReadText" ] = new Func < object ? [ ] , object ? > ( ReadText ) ;
3134
3235 //Gerenal Functions
3336 Variables [ "Convert" ] = new Func < object ? [ ] , object ? > ( ConvertTo ) ;
37+ Variables [ "CritVersion" ] = _version ;
38+
39+ }
40+
41+
42+ public static object ? ReadText ( object ? [ ] args )
43+ {
44+ if ( args . Length != 1 ) throw new Exception ( "ReadText expects 1 argument" ) ;
45+
46+ try
47+ {
48+ return File . ReadAllText ( args [ 0 ] ! . ToString ( ) ! ) ;
49+ }
50+ catch ( Exception e )
51+ {
52+ throw new Exception ( "ReadText failed: " + e . Message ) ;
53+ }
54+
3455
3556 }
3657
Original file line number Diff line number Diff line change 3131var commonTokenStream = new CommonTokenStream ( critLexer ) ;
3232var critParser = new CritParser ( commonTokenStream ) ;
3333var critContext = critParser . program ( ) ;
34- var visitor = new CritVisitor ( ) ;
34+ var visitor = new CritVisitor ( VERSION ) ;
3535
3636visitor . Visit ( critContext ) ;
You can’t perform that action at this time.
0 commit comments