【问题标题】:How to see if first character of a string is " " (a string starting with ")如何查看字符串的第一个字符是否为“”(以“开头的字符串”)
【发布时间】:2019-12-05 06:22:14
【问题描述】:
static boolean isLiteralTexto(String lexema) {
           String letra = [34];
            String caracter = "";
            int estado = 1;
            for (int i = 0; i < lexema.length(); i++) {
                caracter = lexema.charAt(i) + "";
                switch (estado) {
                case 1:
                    if (caracter.matches(letra))
                        estado = 2;
                                    System.out.println("HOLA");
                    else
                        estado = 3;
                    break;

我不知道怎么做,JAVA能帮我吗? 我正在做一个词法分析器和一个解析器

【问题讨论】:

  • if (lexema.startsWith(" ")) if (lexema.charAt(0) == ' ')
  • 你能更详细地描述你的问题吗?你想做什么,为什么?你试过什么?为什么这对你不起作用?你遇到了什么错误?
  • lexema.charAt(0) == ' '?
  • 好吧,我正在做一个我自己的语言的编译器,是一个有很多类的项目,所以我必须识别一个文本文字......我们称之为代码行的东西就是这个“嗨”所以我想检查文件的第一行并确定第一个字符是否是 "" 表示这是一个文字

标签: java compiler-errors lexer


【解决方案1】:

使用标准java:yourstring.startsWith(" ");

【讨论】:

    【解决方案2】:

    您可以使用以下 sn-p 进行检查: if(lexema.indexOf(" ")==0)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-27
      • 2011-06-13
      • 2013-09-04
      • 1970-01-01
      • 2011-05-04
      • 2022-11-16
      • 2011-05-09
      • 2014-01-15
      相关资源
      最近更新 更多