Commit 0f3fa0ff authored by Ronald Charles Moore's avatar Ronald Charles Moore
Browse files

Skeleton

parent 04bd64d6
# This Makefile made available to his students by
# Prof. Ronald Moore
# https://fbi.h-da.de/personen/ronald-moore/
# mailto:ronald.moore@h-da.de
# with no warranties whatsoever
PROGS := interpreter
# Uncomment only one of the next two lines (choose your c++ compiler)
# CC=g++
CC := clang++
## Add your own CFLAGS if you find them necessary... such as -O3 or so...
CFLAGS :=
## More preliminaries
# See https://www.gnu.org/software/make/manual/html_node/Special-Targets.html
# In this makefile, we want to keep going even if we find errors
.IGNORE :
# Tell make that the following "targets" are "phony"
# Cf. https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html#Phony-Targets
.PHONY : all clean
## Now, the targets -- the things that will get made!
all: $(PROGS)
$(PROGS): %: %.cpp
$(CC) -g $< $(CFLAGS) -o $@
clean:
$(RM) -fv *~ *.o $(PROGS)
Contents
========
Everything here is taken from the slides for the "Compiler Construction"
course, i.e. it is directly from Prof. Ronald C. Moore.
Or at least, after all this time, I really don't remember having stolen
this code from somewhere else, but if you find an older copy that looks
similar, please let me know, so I can give credit where credit is due --
or disavow knowledge of that source (as the case may be).
You are in the following subdirectory
** `interpreter`
This code take mathematical expressions and evaluates them,
i.e. it outputs numbers.
See **Chapter 1 Front End Construction**, Slides 21 and 22 (and please let me know when the inevitable day comes that these slide numbers are no longer correct).
Ronald Moore
https://fbi.h-da.de/personen/ronald-moore/
ronald.moore@h-da.de
30 April 2020
// This code made available to his students by
// Prof. Ronald Moore
// https://fbi.h-da.de/personen/ronald-moore/
// mailto:ronald.moore@h-da.de
// with no warranties whatsoever
//
// The grammar we are going to parse here is:
// Grammar:
// E → T E´
// E´ → + T E´ | - T E´ | ε
// T → F T´
// T´ → * F T´ | / F T´ | ε
// F → ( E ) | num
// where the following are taken to be tokens:
// left and right parenthesis, the plus and minus characters,
// as well as asterisk and forward slash -- and numbers.
// In the script, substraction and division are not supported,
// but it seems like time to add them.
//
// Note that the recursive descent function for (e.g.) E´
// is nameded "E2ndHalf"-
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
// Preliminaries and Utilities
// ============================
// global variables -- sue me if you don't like that!
std::string currentLine( "" );
int currentLineNumber = 0;
int currentColumnNumber = 0;
int currentTokenLength = 0;
// Utility Types
typedef double numberType; // feel fee to change this to something else like int or float or bigint....
// the tokens
enum Token {
tok_number,
tok_lparen,
tok_rparen,
tok_plus,
tok_minus,
tok_times,
tok_div
} next_token; // again with the global variables...
// The Lexer
// ==========
// main (!)
// =========
int main( int argc, char **argv ) {
return 0; // Alles klar!!!
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment