Exemple #1
0
        private void ParseProgramName()
        {
            SymbolTable st = SymbolTable.CreateInstance();
            try
            {
                // If first token is white space get the next token and see
                // if it is the program identifier.
                var pde = new ProgramDeclBlock();

                Token programIdentifier = _scanner.GetToken();

                if (programIdentifier.IsIdentifier() && programIdentifier.IsIdentifierProgram())
                 {
                    Token programName = _scanner.GetToken();

                    if (programName.IsIdentifier() && !programName.IsReserverdWord())
                    {
                        Token lbracket = _scanner.GetToken();

                        if (lbracket.Code == ByteCodeIdentifiers.TokenCode.LBracket)
                        {
                            // define anything that will be declared at the global scope.
                            var bde = new BlockDeclExpr { FunctionName = GlobalScope };

                            st.AddTokenToScope(bde, pde);
                            _expressionScopeStack.Push(pde);
                        }
                        else
                        {
                            _bIsErrors = true;
                            _compileErrorList.Add("no left bracket");
                            throw new NireExecutionException("No beginnning left bracket");
                        }
                    }
                    else
                    {
                        throw new Exception("no program statement");
                    }
                }
                else
                {
                    _bIsErrors = true;
                    _compileErrorList.Add(string.Format("There is no program name define"));
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.ToString());
                _bIsErrors = true;
            }
        }
Exemple #2
0
        /// <summary>
        /// Generates the static main function and parameters.
        /// </summary>
        /// <returns>a type array</returns>
        private void GenerateMainMethod(
      TypeBuilder typeBuilder,
      BlockDeclExpr functionDecl,
      List<Expr> mainFunctionParameters)
        {
            List<Expr> parameters = functionDecl.Parameters;

              if (parameters != null && parameters.Count == 1)
              {
            Type[] t = GetFunctionParameterTypes(mainFunctionParameters[0]);

            this.methodbuilder =
              typeBuilder.DefineMethod(functionDecl.FunctionName,
            MethodAttributes.HideBySig |
            MethodAttributes.Static |
            MethodAttributes.Public, typeof (void),
            t);

            //ILGenerator ilGenerator = this.methodbuilder.GetILGenerator();
            //ilGenerator.EmitWriteLine("this is the main method");
            //ilGenerator.Emit(OpCodes.Ret);
              }
        }