Example #1
0
        static void Main(string[] args)
        {
            var lines = (File.ReadAllLines(Environment.CurrentDirectory + @"\..\..\Language.txt"));

            Tokenizer tokenizer = new Tokenizer(lines);

            Compilers.Compiler compiler = new Compilers.Compiler();
            compiler.TokenList = tokenizer.tokenList;

            VirtualMachine vm = new VirtualMachine();

            vm.Run(compiler.compile());

            Console.ReadKey();
        }
Example #2
0
        public XElement Compile()
        {
            IList<Pair<string, string>> tokens = null;

            using (Tokenizer tokenizer = new Tokenizer(this.inputPath))
            {
                tokens = tokenizer.GetTokens();
            }

            tokens=  tokens.Where(t => t.Value1 != "Comment").ToList();

            CompilationEngine compilationEngine = new CompilationEngine(tokens);
            XElement xmlCompiledClass = compilationEngine.CompileClass();

            return xmlCompiledClass;
        }
Example #3
0
 public CompilerOutput EvaluateString(string input)
 {
     Tokens tokens = new Tokenizer(input).Scan();
     System.Numerics.Complex returnValue = 0;
     PostfixedTokens postFixedTokens = null;
     ParseTree parseTree = null;
     string output = string.Empty;
     if (tokens != null && tokens.InAList.Count() > 0) {
         postFixedTokens = new PostfixedTokens(tokens.InAList);
         //TODO: Within the postfixed tokens class learn to handle variable names that can't be evaluated
         //TODO: since variables can't start with a number, parse 3PI as 3*PI
         parseTree = postFixedTokens.BuildParseTree();
         if (parseTree != null) {
             returnValue = parseTree.val;
             SystemLog.AddToReturnValues(returnValue);
             output = returnValue.FullVisualization();
         }
     }
     return new CompilerOutput(input, tokens, returnValue, parseTree, postFixedTokens, output);
 }
Example #4
0
        public static void Main(string[] args)
        {
            Syms.init("ssupl.tokens");

            string gdata;

            using (var r = new StreamReader("terminals.txt"))
            {
                gdata = r.ReadToEnd();
            }
            var tokenizer = new Tokenizer(gdata);

            string idata;

            using (var r = new StreamReader("input.txt"))
            {
                idata = r.ReadToEnd();
            }


            var rex = new Regex(@"\n[ \t]+([^\n]+)");

            idata  = rex.Replace(idata, " $1");
            idata += "\n";

            tokenizer.setInput(idata);
            IList <IToken> tokens = new List <IToken>();

            while (true)
            {
                Token t = tokenizer.next();
                if (t.Symbol == "$")
                {
                    break;
                }
                CommonToken T = new CommonToken(Syms.stringToInt[t.Symbol], t.Lexeme);
                T.Line = t.Line;
                tokens.Add(T);
            }



            var antlrtokenizer = new BufferedTokenStream(new ListTokenSource(tokens));
            var parser         = new ssuplParser(antlrtokenizer);

            parser.BuildParseTree = true;
            parser.ErrorHandler   = new BailErrorStrategy();
            var antlrroot = parser.start();

            var listener = new CodeGenerator();
            var walker   = new ParseTreeWalker();

            walker.Walk(listener, antlrroot);
            var allcode = new ASM(
                "default rel",
                "section .text",
                "global main",
                "main:",
                listener.code.Get(antlrroot),
                "section .data");

            using (var w = new StreamWriter("out.asm"))
            {
                w.Write(allcode.ToString());
            }
        }