public void TestUsingExpressionWithoutEndStatement() { var inputString = new InputString(@"using System; using Compiler.Parser.Nada using jamones;"); var tokenGenerators = Resources.getTokenGenerators(); var lexer = new Lexer(inputString, tokenGenerators); var parser = new Compiler.Parser(lexer); Assert.Throws <SyntaxTokenExpectedException>(() => parser.parse()); }
private void declaringLocaleVariablesTest() { printHeader("declaringLocaleVariablesTest"); var inputString = new InputFile(@"..\..\..\testFiles\localVariablesTests.txt"); var tokenGenerators = Resources.getTokenGenerators(); var lexer = new Lexer(inputString, tokenGenerators); var parser = new Compiler.Parser(lexer); parser.parse(); Console.Out.WriteLine("Parsed Successfully -> local Variables"); }
public void interfaceDeclarationStmtTest() { printHeader("interfaceDeclarationStmtTest"); var inputString = new InputFile(@"..\..\..\testFiles\interfaceDeclarationTests.txt"); var tokenGenerators = Resources.getTokenGenerators(); var lexer = new Lexer(inputString, tokenGenerators); var parser = new Compiler.Parser(lexer); parser.parse(); Console.Out.WriteLine("Parsed Successfully -> enum"); }
public void usingStmtTest() { printHeader("usingStmtTest"); var inputString = new InputFile(@"..\..\..\testFiles\usingTests.txt"); var tokenGenerators = Resources.getTokenGenerators(); var lexer = new Lexer(inputString, tokenGenerators); var parser = new Compiler.Parser(lexer); parser.parse(); Console.Out.WriteLine("Parsed Successfully -> usings"); }
public void TestVariousAssignOperatorsInEnumExpression() { var inputString = new InputString(@"using System; using Compiler.Parser.Nada; using jamones; public enum DIASDELASEMANA{ LUNES=1,MARTES=2,MIERCOLES==3,JUEVES=4,VIERNES=5, }"); var tokenGenerators = Resources.getTokenGenerators(); var lexer = new Lexer(inputString, tokenGenerators); var parser = new Compiler.Parser(lexer); Assert.Throws <SyntaxTokenExpectedException>(() => parser.parse()); }
public void TestBadArgumentsListInInterfaceMethodExpression() { var inputString = new InputString(@"using System; using Compiler.Parser.Nada; using jamones; public interface DIASDELASEMANA{ void metodo(int argument, float argument argument); }"); var tokenGenerators = Resources.getTokenGenerators(); var lexer = new Lexer(inputString, tokenGenerators); var parser = new Compiler.Parser(lexer); Assert.Throws <SyntaxTokenExpectedException>(() => parser.parse()); }
public void TestInterfaceExpressionWrongInheritanceExpression() { var inputString = new InputString(@"using System; using Compiler.Parser.Nada; using jamones; interface DIASDELASEMANA : Padre,, Tia{ void metodo(int argument, float argument); };"); var tokenGenerators = Resources.getTokenGenerators(); var lexer = new Lexer(inputString, tokenGenerators); var parser = new Compiler.Parser(lexer); Assert.Throws <SyntaxTokenExpectedException>(() => parser.parse()); }
public void TestClassCantHaveAbstractConstructor() { var inputString = new InputString(@"using System; using Compiler.Parser.Nada; using jamones; public class kevin : Nexer, Javier{ public abstract kevin(){} } "); var tokenGenerators = Resources.getTokenGenerators(); var lexer = new Lexer(inputString, tokenGenerators); var parser = new Compiler.Parser(lexer); Assert.Throws <SyntaxTokenExpectedException>(() => parser.parse()); }
public void TestClassWithWrongInheritanceExpression() { var inputString = new InputString(@"using System; using Compiler.Parser.Nada; using jamones; public class kevin : Nexer, Javier,{ public kevin(); } "); var tokenGenerators = Resources.getTokenGenerators(); var lexer = new Lexer(inputString, tokenGenerators); var parser = new Compiler.Parser(lexer); Assert.Throws <SyntaxTokenExpectedException>(() => parser.parse()); }
public void TestWrongIsExpression() { var inputString = new InputString(@"public class kevin : Javier { int x = is persona carlos; }"); printHeader("TestWrongIsExpression"); var tokenGenerators = Resources.getTokenGenerators(); var lexer = new Lexer(inputString, tokenGenerators); var parser = new Compiler.Parser(lexer); Assert.Throws <SyntaxTokenExpectedException>(() => parser.parse()); Console.Out.WriteLine("Parsed Successfully -> TestWrongIsExpression"); }
public static void Main() { String[] args = Environment.GetCommandLineArgs(); CmdIo source = new CmdIo(); try { source = new CmdIo(args); Tok tokenizer = new Tok(source); Lib funclibrary = new Lib(); Parser parser = new Parser(source, tokenizer, funclibrary); parser.parse_and_compile(); source.Finish(); } catch { source.Message("plil: compiler error."); } }
public void TestClassWWrongTernaryOperatorsInExpression() { var inputString = new InputString(@"public class kevin : Javier { int LUNES = x==0? y=(5+3):z/2; bool boleano = y>5? k--: (k>4? y++k++); }"); printHeader("TestClassWWrongTernaryOperatorsInExpression"); var tokenGenerators = Resources.getTokenGenerators(); var lexer = new Lexer(inputString, tokenGenerators); var parser = new Compiler.Parser(lexer); Assert.Throws <SyntaxTokenExpectedException>(() => parser.parse()); Console.Out.WriteLine("Parsed Successfully -> TestClassWWrongTernaryOperatorsInExpression"); }
public void TestWrongLogicalExpression() { var inputString = new InputString(@"public class kevin : Javier { int LUNES = (!(isVisible && isHere) ||); bool boleano = isNull ?? true; }"); printHeader("TestWrongLogicalExpression"); var tokenGenerators = Resources.getTokenGenerators(); var lexer = new Lexer(inputString, tokenGenerators); var parser = new Compiler.Parser(lexer); Assert.Throws <SyntaxTokenExpectedException>(() => parser.parse()); Console.Out.WriteLine("Parsed Successfully -> TestWrongLogicalExpression"); }
public void TestClassWrongNullCoalescingOperatorsInExpression() { var inputString = new InputString(@"public class kevin : Javier { int LUNES = x ?? ( y ?? (t??5) ); bool boleano = j ?? ); }"); printHeader("TestClassWrongNullCoalescingOperatorsInExpression"); var tokenGenerators = Resources.getTokenGenerators(); var lexer = new Lexer(inputString, tokenGenerators); var parser = new Compiler.Parser(lexer); Assert.Throws <SyntaxTokenExpectedException>(() => parser.parse()); Console.Out.WriteLine("Parsed Successfully -> TestClassWrongNullCoalescingOperatorsInExpression"); }
public void TestClassWrongMultiplicativeOperatorsInExpression() { var inputString = new InputString(@"public class kevin : Javier { int LUNES = (1 * 5); bool boleano = (x/5); int otro = 10 * (otro%mama) /; float f = (mama / (0*5)); }"); printHeader("expreTestClassWrongMultiplicativeOperatorsInExpressionssionsTest"); var tokenGenerators = Resources.getTokenGenerators(); var lexer = new Lexer(inputString, tokenGenerators); var parser = new Compiler.Parser(lexer); Assert.Throws <SyntaxTokenExpectedException>(() => parser.parse()); Console.Out.WriteLine("Parsed Successfully -> TestClassWrongMultiplicativeOperatorsInExpression"); }
public void TestUsingAfterANamespaceExpression() { var inputString = new InputString(@"using System; using Otro; using jamones; namespace A{ using prueba; namespace B { using prueba2.prueba3.prueba4; } using system; }"); var tokenGenerators = Resources.getTokenGenerators(); var lexer = new Lexer(inputString, tokenGenerators); var parser = new Compiler.Parser(lexer); Assert.Throws <SyntaxTokenExpectedException>(() => parser.parse()); }
public void TestClassWrongBinaryOperatorsInExpression() { var inputString = new InputString(@"public class kevin : Javier { int LUNES = 1 << 5; bool boleano = 5; int otro = 10; float f = (1 | (0 &) (100^100)); }"); printHeader("TestClassWrongBinaryOperatorsInExpression"); var tokenGenerators = Resources.getTokenGenerators(); var lexer = new Lexer(inputString, tokenGenerators); var parser = new Compiler.Parser(lexer); Assert.Throws <SyntaxTokenExpectedException>(() => parser.parse()); Console.Out.WriteLine("Parsed Successfully -> TestClassWrongBinaryOperatorsInExpression"); }
public void TestClassWrongAccesMemoryOperatorsInExpression() { var inputString = new InputString(@"public class kevin : Javier { float mana = (float)(n.atributo); public int funcion = persona.methodo(x=3).metodo; float f = persona.tryParse(x); Persona persona = this.atributo; Persona persona = this.method(x,y,r,,nada); }"); printHeader("TestClassWrongAccesMemoryOperatorsInExpression"); var tokenGenerators = Resources.getTokenGenerators(); var lexer = new Lexer(inputString, tokenGenerators); var parser = new Compiler.Parser(lexer); Assert.Throws <SyntaxTokenExpectedException>(() => parser.parse()); Console.Out.WriteLine("Parsed Successfully -> TestClassWrongAccesMemoryOperatorsInExpression"); }
public void TestWrongInlineExpression() { var inputString = new InputString(@"public class kevin : Javier { int prueba = (!(isVisible && iden) || noEsta); int LUNES = ((5 + 3) + (4 3)); int MARTES = ((5 * 9 / 3) - 7 + (2 * 7 + 4) / ( (128 >> 5 * 5) - (1 << 7 * 46) / 3 )) + 15; int MIERCOLES = 0; int x = y = z = w = MARTES / 2; Kevin kevin = new persona(); }"); printHeader("TestWrongInlineExpression"); var tokenGenerators = Resources.getTokenGenerators(); var lexer = new Lexer(inputString, tokenGenerators); var parser = new Compiler.Parser(lexer); Assert.Throws <SyntaxTokenExpectedException>(() => parser.parse()); Console.Out.WriteLine("Parsed Successfully -> TestWrongInlineExpression"); }
public void TestClassWrongArraysInExpression() { var inputString = new InputString(@"public class kevin : Javier { float mana = new int[2][][][]; private int arreglo = new float[]{ 5,3,5}; int arreglo = new int[,,]; int arreglo = new int[2][]{ new int[5],new int[8]}; int arreglo = { new int[5], new int[4], array }; int value = new Persona(x,y,w).array[2]; int[,,,] x = new int[5,5,3,4]; }"); printHeader("TestClassWrongArraysInExpression"); var tokenGenerators = Resources.getTokenGenerators(); var lexer = new Lexer(inputString, tokenGenerators); var parser = new Compiler.Parser(lexer); Assert.Throws <SyntaxTokenExpectedException>(() => parser.parse()); Console.Out.WriteLine("Parsed Successfully -> TestClassWrongArraysInExpression"); }
public void TestClassWrongUnaryOperatorsInExpression() { var inputString = new InputString(@"public class kevin : Javier { int LUNES = (x += 5); bool boleano = (y >>= 5); int otro = ((x++)); int nuevo = + ++y; float f = (~nada!); bool c = (~(nada && isVisible) || !isVisible); int t = (int)nada; float mana = (float)(n.atributo); }"); printHeader("TestClassWrongUnaryOperatorsInExpression"); var tokenGenerators = Resources.getTokenGenerators(); var lexer = new Lexer(inputString, tokenGenerators); var parser = new Compiler.Parser(lexer); Assert.Throws <SyntaxTokenExpectedException>(() => parser.parse()); Console.Out.WriteLine("Parsed Successfully -> exprTestClassWrongUnaryOperatorsInExpressionessions"); }
static void Main(string[] args) { StreamReader istr = new StreamReader(Console.OpenStandardInput(), Console.InputEncoding); StreamWriter ostr = new StreamWriter(System.Console.OpenStandardOutput(), Console.OutputEncoding); if (args.Count() < 2) { Help(); return; } bool low_opt = false, hight_opt = false; int index_in = 2, index_out = 3; switch (args[1]) { case "-low": low_opt = true; break; case "-hight": hight_opt = true; break; case "-low-hight": low_opt = hight_opt = true; break; default: index_in = 1; index_out = 2; break; } istr = new StreamReader(args[index_in]); if (index_out < args.Count()) { ostr = new StreamWriter(args[index_out]); } Scaner scaner = null; Parser parser = null; Fasm.CodeGen codegen = null; switch (args[0]) { case "-l": scaner = new Scaner(istr); Token t = null; while (t == null || t.type != Token.Type.EOF) { try { t = scaner.Read(); Console.WriteLine(t.ToString()); } catch (Scaner.Exception e) { ostr.WriteLine(e.Message); } } break; case "-p": parser = new Parser(new Scaner(istr)); parser.Parse(); parser.PrintTree(ostr); ostr.WriteLine(parser.logger.ToString()); break; case "-c": parser = new Parser(new Scaner(istr)); parser.Parse(); if (!parser.logger.isEmpty()) { ostr.WriteLine(parser.logger.ToString()); break; } codegen = new Fasm.CodeGen(parser.tstack); codegen.Generate(ostr); break; case "-cexe": parser = new Parser(new Scaner(istr)); parser.Parse(); if (!parser.logger.isEmpty()) { ostr.WriteLine(parser.logger.ToString()); break; } codegen = new Fasm.CodeGen(parser.tstack); codegen.Generate(ostr); ostr.Flush(); ostr.Close(); if (index_out < args.Count()) { Process.Start(new ProcessStartInfo { FileName = "C:/fasm/fasm.exe", WindowStyle = ProcessWindowStyle.Hidden, Arguments = string.Format("{0} {1}", args[index_out], args[index_out]) }); } break; default: Help(); return; } istr.Close(); ostr.Close(); }
public void Compile(Project proj) { ProjectFile = proj; //Make sure the build directory exists and create it if needed if (!Directory.Exists(proj.Buildfolder)) Directory.CreateDirectory(proj.Buildfolder); if (!Directory.Exists(proj.OutputFolder)) Directory.CreateDirectory(proj.OutputFolder); //Prepare some stuff needed for preprocessing Dictionary<string, PPDefine> defines = new Dictionary<string, PPDefine>(); foreach (var it in flagDefines) defines.Add(it.Name, it); List<preprocessFile_IfDefModes> ifdefs = new List<preprocessFile_IfDefModes>(); List<PostProcessFile> ppFiles = new List<PostProcessFile>(); //do the preprocessing preprocessFile(ifdefs, defines, proj, proj.Mainfile, proj.Mainfile.Substring(proj.Mainfile.LastIndexOf('\\') + 1), ppFiles); var ppMainFile = ppFiles[0]; if (outputFolderCleanup) { Logger.Instance.log(Logger.LogLevel.VERBOSE, "Cleaning up output dir"); cleanupRecursive(proj.OutputFolder); } int errCount = 0; //Check the syntax of all files in ppFiles foreach(var it in ppFiles) { //if (!noPrintOut) //{ // var stream = File.Create(proj.Buildfolder + it.Name + ".obj"); // it.resetPosition(); // it.FileStream.WriteTo(stream); // stream.Flush(); // stream.Close(); //} Scanner scanner = new Scanner(it.FileStream); Base baseObject = new Base(); Parser p = new Parser(scanner); Parser.UsedFiles = new List<string>(); p.BaseObject = baseObject; p.Parse(); if (p.errors.count > 0) { errCount += p.errors.count; Logger.Instance.log(Logger.LogLevel.ERROR, "In file '" + it.Name + "'"); } if (printOutMode > 0) { if (printOutMode == 1 && it == ppMainFile) { var stream = File.Create(proj.Buildfolder + it.Name + ".objF"); it.resetPosition(); it.FullFileStream.WriteTo(stream); stream.Flush(); stream.Close(); } if (printOutMode >= 2) { var stream = File.Create(proj.Buildfolder + it.Name + ".obj"); it.resetPosition(); it.FileStream.WriteTo(stream); stream.Flush(); stream.Close(); if (printOutMode >= 3) { var stream2 = File.Create(proj.Buildfolder + it.Name + ".objF"); it.resetPosition(); it.FullFileStream.WriteTo(stream2); stream2.Flush(); stream2.Close(); } else if(it == ppMainFile) { var stream2 = File.Create(proj.Buildfolder + it.Name + ".objF"); it.resetPosition(); it.FullFileStream.WriteTo(stream2); stream2.Flush(); stream2.Close(); } } } it.resetPosition(); } if(errCount > 0) { Logger.Instance.log(Logger.LogLevel.ERROR, "Errors found (" + errCount + "), cannot continue with Translating!"); return; } //process the actual file Base oosTreeBase = new Base(); NamespaceResolver.BaseClass = oosTreeBase; Parser parser = new Parser(new Scanner(ppMainFile.FullFileStream)); Parser.UsedFiles = new List<string>(); parser.BaseObject = oosTreeBase; parser.Parse(); errCount = parser.errors.count + parser.BaseObject.finalize(); if (errCount > 0) { Logger.Instance.log(Logger.LogLevel.ERROR, "Errors found (" + errCount + "), cannot continue with Comnpiling!"); return; } SqfConfigFile configFile = new SqfConfigFile(configFileName); oosTreeBase.writeOut(null, configFile); configFile.writeOut(proj.OutputFolder); }
public void CheckSyntax(string filepath) { Scanner scanner = new Scanner(filepath); Parser parser = new Parser(scanner); parser.Parse(); }
public static void SetUpMainParser(Token[] tokenSet) { MainParser = new Parser(tokenSet); }