练习

 withdigit那里判断小数或者科学计数法的,但是现在只考虑整数就改掉了

#include <iostream>
#include<stdlib.h>
#include <cstring>
#include <ctype.h>
#include<cstdlib>
using namespace std;

class TOKEN{
public:
    int typenum = 0;
    // string type = "";
    string symb = "";
    int value = 0;
    void print(){
        if (typenum == -1)
            return;
        // printf("<%d,\t%s>\n", typenum, symb);
        if (typenum == 111 || typenum == -2){
            cout << '<' << typenum << ",\t" << symb << '>' << endl;
        }
        else if(typenum == 100){
            cout << '<' << typenum << ",\t" << value << '>' << endl;
        }
        else {
            cout << '<' << typenum << ",\t->" << endl;
        }
    }
};

int judge(char a){ //judeg symbol
    if (isdigit(a)){
        return 1;
    }
    else  if (isalnum(a)){
        return 2;
    }
    return 0;
}
int withdigit(char a){ // follow num
    if (isdigit(a)){
        return 1;
    }
    if (a == '.'){
        return 0;
    }
    if (a == 'e' || a == 'E'){
        return 0;
    }
    return 0;
}
// int find(char a, TOKEN &t){
//     switch (a)
//     {
//     case '+':
//         t.typenum = 41;
//         t.symb = "+";
//         break;

//     default:
//         t.typenum = -2;
//         t.symb = "?";
//         break;
//     }
// }
void selfjudge(TOKEN &a){
    if (a.symb == "int"){
        a.typenum = 5;
    }
    else if (a.symb == "else"){
        a.typenum = 15;
    }
    else if (a.symb == "if"){
        a.typenum = 17;
    }
    else if (a.symb == "while"){
        a.typenum = 20;
    }
}
TOKEN lexer(char temp){
    TOKEN target;
    int flag = 1;
    char next;
    if (isdigit(temp)){ //num
        flag = 0;
        target.symb += temp;
        while (1){
            temp = getchar();
            if (!withdigit(temp)){
                flag = 1;
                break;
            }
            target.symb += temp;
        }
        if (flag == 1){
            ungetc(temp, stdin);
        }
        target.typenum = 100;
        target.value = atoi(target.symb.c_str());
    }
    else if (judge(temp) == 2){ // all words
        flag = 0;
        target.symb += temp;
        while (1){
            temp = getchar();
            if (judge(temp) == 0){
                flag = 1;
                break;
            }
            target.symb += temp;
        }
        if (flag == 1){
            ungetc(temp, stdin);
        }
        target.typenum = 111;
    }
    else if (temp == ' ' || temp == '\n'){ // blank
        target.typenum = -1;
    }
    else{ // not word
        // find(temp, target);
            switch (temp)
        {
        case '+':
            next = getchar();
            if (next == '+'){
                target.typenum = 56;
                target.symb = "++";
                break;
            }
            ungetc(next, stdin);
            target.typenum = 41;
            target.symb = "+";
            break;
        case '-':
            next = getchar();
            if (next == '-'){
                target.typenum = 57;
                target.symb = "--";
                break;
            }
            ungetc(next, stdin);
            target.typenum = 42;
            target.symb = "-";
            break;
        case '*':
            target.typenum = 43;
            target.symb = "*";
            break;
        case '/':
            target.typenum = 44;
            target.symb = "/";
            break;
        case '%':
            target.typenum = 45;
            target.symb = "%";
            break;
        case '>':
            next = getchar();
            if (next == '='){
                target.typenum = 48;
                target.symb = ">=";
                break;
            }
            ungetc(next, stdin);
            target.typenum = 47;
            target.symb = ">";
            break;
        case '<':
            next = getchar();
            if (next == '='){
                target.typenum = 50;
                target.symb = "<=";
                break;
            }
            ungetc(next, stdin);
            target.typenum = 49;
            target.symb = "<";
            break;
        case '=':
            next = getchar();
            if (next == '='){
                target.typenum = 50;
                target.symb = "==";
                break;
            }
            ungetc(next, stdin);
            target.typenum = 44;
            target.symb = "=";
            break;
        case '!':
            next = getchar();
            if (next == '='){
                target.typenum = 52;
                target.symb = "!=";
                break;
            }
            ungetc(next, stdin);
            target.typenum = 55;
            target.symb = "!";
            break;
        case '&':
            next = getchar();
            if (next == '&'){
                target.typenum = 53;
                target.symb = "&&";
                break;
            }
            ungetc(next, stdin);
            target.typenum = -2;
            target.symb = "err";
            break;
        case '|':
            next = getchar();
            if (next == '|'){
                target.typenum = 54;
                target.symb = "||";
                break;
            }
            ungetc(next, stdin);
            target.typenum = -2;
            target.symb = "err";
            break;
        case '(':
            target.typenum = 81;
            target.symb = ")";
            break;
        case ')':
            target.typenum = 82;
            target.symb = ")";
            break;
        case ';':
            target.typenum = 84;
            target.symb = ";";
            break;
        case '{':
            target.typenum = 86;
            target.symb = "{";
            break;
        case '}':
            target.typenum = 87;
            target.symb = "}";
            break;
        case '[':
            target.typenum = 88;
            target.symb = "[";
            break;
        case ']':
            target.typenum = 89;
            target.symb = "]";
            break;

        default:
            target.typenum = -2;
            target.symb = "err";
            break;
        }
    }
    selfjudge(target);
    return target;
}

int main(){
    char a;
    while (a=getchar())
    {
        if (a != EOF) {
            TOKEN token = lexer(a);
            token.print();
        }
    }
    return 1;
}

 

源码来自:https://pan.quark.cn/s/a3a3fbe70177 AppBrowser(Application属性查看器,不需要越狱! ! ! ) 不需要越狱,调用私有方法 --- 获取完整的已安装应用列表、打开和删除应用操作、应用运行时相关信息的查看。 支持iOS10.X 注意 目前AppBrowser不支持iOS11应用查看, 由于iOS11目前还处在Beta版, 系统API还没有稳定下来。 等到Private Header更新了iOS11版本,我也会进行更新。 功能 [x] 已安装的应用列表 [x] 应用的详情界面 (打开应用,删除应用,应用的相关信息展示) [x] 应用运行时信息展示(LSApplicationProxy) [ ] 定制喜欢的字段,展示在应用详情界面 介绍 所有已安装应用列表(应用icon+应用名) 为了提供思路,这里只用伪代码,具体的私有代码调用请查看: 获取应用实例: 获取应用名和应用的icon: 应用列表界面展示: 应用列表 应用运行时详情 打开应用: 卸载应用: 获取info.plist文件: 应用运行时详情界面展示: 应用运行时详情 右上角,从左往右第一个按钮用来打开应用;第二个按钮用来卸载这个应用 INFO按钮用来解析并显示出对应的LSApplicationProxy类 树形展示LSApplicationProxy类 通过算法,将LSApplicationProxy类,转换成了字典。 转换规则是:属性名为key,属性值为value,如果value是一个可解析的类(除了NSString,NSNumber...等等)或者是个数组或字典,则继续递归解析。 并且会找到superClass的属性并解析,superClass如...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值