Creating a small programming language for beginners

后端 未结 7 2322
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-06 11:42

I would like to create my own programming language. Maybe not exactly a programming language from scratch but maybe base it on another language.

I\'ve heard of Yacc. So

7条回答
  •  旧时难觅i
    2021-02-06 11:46

    The most easy option would probably be to create a program in Java that reads text files and if it finds something it would start writing a .java file and write what it basically means in Java. So for example my a file called main.boss could be:

    write Hello world
    write Bye!
    

    And my java program would cycle through it and detect the word write and then go one space after it and read the text until the end of the line. Meaning it would get "Hello world" and "Bye!". Because says "write" it would then write a main.java file with this in it:

    public class Main
    {
    System.out.println("Hello world");
    System.out.println("Bye!");
    }
    

    Then you could have a .bat file that is executed by your java program and it would set classpath, compile the file, and turn it into a .jar file. It could possibly bundle a program like Launch4J with it so it could have an option to turn the .jar into a .exe.

提交回复
热议问题