Exemplo n.º 1
0
 public static Definition ParseDefinition(Scanner scanner)
 {
     if (scanner.TryGetIdentifier("function"))
     {
         string returntype;
         string name;
         List<string> parametertypes = new List<string>();
         List<string> parameternames = new List<string>();
         scanner.GetIdentifier(out returntype);
         scanner.GetIdentifier(out name);
         scanner.GetDelimiter("(");
         if (!scanner.TryGetDelimiter(")"))
         {
             do
             {
                 string parametertype;
                 string parametername;
                 scanner.GetIdentifier(out parametertype);
                 scanner.GetIdentifier(out parametername);
                 parametertypes.Add(parametertype);
                 parameternames.Add(parametername);
             }
             while (scanner.TryGetDelimiter(","));
             scanner.GetDelimiter(")");
         }
         scanner.GetDelimiter("{");
         Statement statement = CodeParser.ParseBlock(scanner.ScanAcross("{","}"));
         return new FunctionDefinition(name,returntype,parametertypes.ToArray(),parameternames.ToArray(),statement);
     }
     else if (scanner.TryGetIdentifier("linedefspecial"))
     {
         List<LinedefSpecialAttribute> attributes = new List<LinedefSpecialAttribute>();
         do
         {
             int number;
             scanner.GetInteger(out number);
             LinedefSpecialAttribute attribute = new LinedefSpecialAttribute(number);
             scanner.GetDelimiter("(");
             while (!scanner.TryGetDelimiter(")"))
             {
                 if (scanner.TryGetIdentifier("auto"))
                     attribute.ActivationType |= LinedefActivationType.Automatic;
                 else if (scanner.TryGetIdentifier("use"))
                     attribute.ActivationType |= LinedefActivationType.Use;
                 else if (scanner.TryGetIdentifier("monsteruse"))
                     attribute.ActivationType |= LinedefActivationType.MonsterUse;
                 else if (scanner.TryGetIdentifier("cross"))
                     attribute.ActivationType |= LinedefActivationType.Cross;
                 else if (scanner.TryGetIdentifier("monstercross"))
                     attribute.ActivationType |= LinedefActivationType.MonsterCross;
                 else if (scanner.TryGetIdentifier("shoot"))
                     attribute.ActivationType |= LinedefActivationType.Shoot;
                 else if (scanner.TryGetIdentifier("monstershoot"))
                     attribute.ActivationType |= LinedefActivationType.MonsterShoot;
                 else if (scanner.TryGetIdentifier("repeatable"))
                     attribute.Repeatable = true;
                 else
                     throw new ApplicationException();
             }
             attributes.Add(attribute);
         }
         while (scanner.TryGetDelimiter(","));
         scanner.GetDelimiter("{");
         Statement statement = CodeParser.ParseBlock(scanner.ScanAcross("{","}"));
         return new LinedefSpecialDefinition(statement,attributes);
     }
     else
     {
         throw new ApplicationException();
     }
 }
Exemplo n.º 2
0
 public static Definition ParseDefinition(Scanner scanner)
 {
     if (scanner.TryGetIdentifier("function"))
     {
         string        returntype;
         string        name;
         List <string> parametertypes = new List <string>();
         List <string> parameternames = new List <string>();
         scanner.GetIdentifier(out returntype);
         scanner.GetIdentifier(out name);
         scanner.GetDelimiter("(");
         if (!scanner.TryGetDelimiter(")"))
         {
             do
             {
                 string parametertype;
                 string parametername;
                 scanner.GetIdentifier(out parametertype);
                 scanner.GetIdentifier(out parametername);
                 parametertypes.Add(parametertype);
                 parameternames.Add(parametername);
             }while (scanner.TryGetDelimiter(","));
             scanner.GetDelimiter(")");
         }
         scanner.GetDelimiter("{");
         Statement statement = CodeParser.ParseBlock(scanner.ScanAcross("{", "}"));
         return(new FunctionDefinition(name, returntype, parametertypes.ToArray(), parameternames.ToArray(), statement));
     }
     else if (scanner.TryGetIdentifier("linedefspecial"))
     {
         List <LinedefSpecialAttribute> attributes = new List <LinedefSpecialAttribute>();
         do
         {
             int number;
             scanner.GetInteger(out number);
             LinedefSpecialAttribute attribute = new LinedefSpecialAttribute(number);
             scanner.GetDelimiter("(");
             while (!scanner.TryGetDelimiter(")"))
             {
                 if (scanner.TryGetIdentifier("auto"))
                 {
                     attribute.ActivationType |= LinedefActivationType.Automatic;
                 }
                 else if (scanner.TryGetIdentifier("use"))
                 {
                     attribute.ActivationType |= LinedefActivationType.Use;
                 }
                 else if (scanner.TryGetIdentifier("monsteruse"))
                 {
                     attribute.ActivationType |= LinedefActivationType.MonsterUse;
                 }
                 else if (scanner.TryGetIdentifier("cross"))
                 {
                     attribute.ActivationType |= LinedefActivationType.Cross;
                 }
                 else if (scanner.TryGetIdentifier("monstercross"))
                 {
                     attribute.ActivationType |= LinedefActivationType.MonsterCross;
                 }
                 else if (scanner.TryGetIdentifier("shoot"))
                 {
                     attribute.ActivationType |= LinedefActivationType.Shoot;
                 }
                 else if (scanner.TryGetIdentifier("monstershoot"))
                 {
                     attribute.ActivationType |= LinedefActivationType.MonsterShoot;
                 }
                 else if (scanner.TryGetIdentifier("repeatable"))
                 {
                     attribute.Repeatable = true;
                 }
                 else
                 {
                     throw new ApplicationException();
                 }
             }
             attributes.Add(attribute);
         }while (scanner.TryGetDelimiter(","));
         scanner.GetDelimiter("{");
         Statement statement = CodeParser.ParseBlock(scanner.ScanAcross("{", "}"));
         return(new LinedefSpecialDefinition(statement, attributes));
     }
     else
     {
         throw new ApplicationException();
     }
 }
Exemplo n.º 3
0
 private static Statement ParseStatement(Scanner scanner)
 {
     if (scanner.TryGetIdentifier("if"))
     {
         scanner.GetDelimiter("(");
         Expression condition = ParseExpression(scanner);
         scanner.GetDelimiter(")");
         Statement thenstatement = ParseStatement(scanner);
         Statement elsestatement = new NullStatement();
         if (scanner.TryGetIdentifier("else"))
         {
             elsestatement = ParseStatement(scanner);
         }
         return new IfStatement(condition,thenstatement,elsestatement);
     }
     else if (scanner.TryGetIdentifier("while"))
     {
         scanner.GetDelimiter("(");
         Expression condition = ParseExpression(scanner);
         scanner.GetDelimiter(")");
         Statement loopstatement = ParseStatement(scanner);
         Statement elsestatement = new NullStatement();
         if (scanner.TryGetIdentifier("else"))
         {
             elsestatement = ParseStatement(scanner);
         }
         return new WhileStatement(condition,loopstatement,elsestatement);
     }
     else if (scanner.TryGetIdentifier("foreach"))
     {
         scanner.GetDelimiter("(");
         string variabletype;
         string variablename;
         scanner.GetIdentifier(out variabletype);
         scanner.GetIdentifier(out variablename);
         scanner.GetIdentifier("in");
         Expression collection = ParseExpression(scanner);
         scanner.GetDelimiter(")");
         Statement loopstatement = ParseStatement(scanner);
         Statement elsestatement = new NullStatement();
         if (scanner.TryGetIdentifier("else"))
         {
             elsestatement = ParseStatement(scanner);
         }
         return new ForEachStatement(variabletype,variablename,collection,loopstatement,elsestatement);
     }
     else if (scanner.TryGetIdentifier("var"))
     {
         string variablename;
         scanner.GetIdentifier(out variablename);
         scanner.GetDelimiter("=");
         Expression expression = ParseExpression(scanner);
         scanner.GetDelimiter(";");
         return new VarStatement(variablename,expression);
     }
     else if (scanner.TryGetIdentifier("return"))
     {
         if (scanner.TryGetDelimiter(";"))
         {
             return new ReturnStatement(null);
         }
         else
         {
             Expression expression = ParseExpression(scanner);
             scanner.GetDelimiter(";");
             return new ReturnStatement(expression);
         }
     }
     else if (scanner.TryGetDelimiter("{"))
     {
         return CodeParser.ParseBlock(scanner.ScanAcross("{","}"));
     }
     else if (scanner.TryGetDelimiter(";"))
     {
         return new NullStatement();
     }
     else
     {
         Expression expression = ParseExpression(scanner);
         scanner.GetDelimiter(";");
         return new ExpressionStatement(expression);
     }
 }
Exemplo n.º 4
0
 private static Statement ParseStatement(Scanner scanner)
 {
     if (scanner.TryGetIdentifier("if"))
     {
         scanner.GetDelimiter("(");
         Expression condition = ParseExpression(scanner);
         scanner.GetDelimiter(")");
         Statement thenstatement = ParseStatement(scanner);
         Statement elsestatement = new NullStatement();
         if (scanner.TryGetIdentifier("else"))
         {
             elsestatement = ParseStatement(scanner);
         }
         return(new IfStatement(condition, thenstatement, elsestatement));
     }
     else if (scanner.TryGetIdentifier("while"))
     {
         scanner.GetDelimiter("(");
         Expression condition = ParseExpression(scanner);
         scanner.GetDelimiter(")");
         Statement loopstatement = ParseStatement(scanner);
         Statement elsestatement = new NullStatement();
         if (scanner.TryGetIdentifier("else"))
         {
             elsestatement = ParseStatement(scanner);
         }
         return(new WhileStatement(condition, loopstatement, elsestatement));
     }
     else if (scanner.TryGetIdentifier("foreach"))
     {
         scanner.GetDelimiter("(");
         string variabletype;
         string variablename;
         scanner.GetIdentifier(out variabletype);
         scanner.GetIdentifier(out variablename);
         scanner.GetIdentifier("in");
         Expression collection = ParseExpression(scanner);
         scanner.GetDelimiter(")");
         Statement loopstatement = ParseStatement(scanner);
         Statement elsestatement = new NullStatement();
         if (scanner.TryGetIdentifier("else"))
         {
             elsestatement = ParseStatement(scanner);
         }
         return(new ForEachStatement(variabletype, variablename, collection, loopstatement, elsestatement));
     }
     else if (scanner.TryGetIdentifier("var"))
     {
         string variablename;
         scanner.GetIdentifier(out variablename);
         scanner.GetDelimiter("=");
         Expression expression = ParseExpression(scanner);
         scanner.GetDelimiter(";");
         return(new VarStatement(variablename, expression));
     }
     else if (scanner.TryGetIdentifier("return"))
     {
         if (scanner.TryGetDelimiter(";"))
         {
             return(new ReturnStatement(null));
         }
         else
         {
             Expression expression = ParseExpression(scanner);
             scanner.GetDelimiter(";");
             return(new ReturnStatement(expression));
         }
     }
     else if (scanner.TryGetDelimiter("{"))
     {
         return(CodeParser.ParseBlock(scanner.ScanAcross("{", "}")));
     }
     else if (scanner.TryGetDelimiter(";"))
     {
         return(new NullStatement());
     }
     else
     {
         Expression expression = ParseExpression(scanner);
         scanner.GetDelimiter(";");
         return(new ExpressionStatement(expression));
     }
 }